Skip to content

Commit

Permalink
pasta: Let it run in background, and wait until it forks
Browse files Browse the repository at this point in the history
pasta(1), like many daemons, will fork to background only once it's
ready to operate (handle traffic). On top of that, it doesn't need an
explicit clean-up phase (unless --no-netns-quit is given), because it
will terminate as soon as the target network namespace goes away.

If we make it run in foreground and proceed as soon as we invoked the
command (in background), we'll claim we're done too early, and tests
such as integration-net.sh will occasionally fail, because pasta is
still initialising sockets and interfaces as UDP packets are sent.

Drop --foreground, and use CombinedOutput() instead of the Start()
method of exec.Command(). Drop the explicit cleanup steps, too.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
  • Loading branch information
sbrivio-rh committed Aug 16, 2024
1 parent 87e5dca commit 674a883
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions pkg/network/pasta/pasta.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPat
}

opts := []string{
"--foreground",
"--stderr",
"--ns-ifname=" + d.ifname,
"--mtu=" + strconv.Itoa(d.mtu),
Expand Down Expand Up @@ -147,21 +146,18 @@ func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPat
// `Couldn't open user namespace /proc/51813/ns/user: Permission denied`
// Possibly related to AppArmor.
cmd := exec.Command(d.binary, opts...)
cmd.Stdout = d.logWriter
cmd.Stderr = d.logWriter
cleanups = append(cleanups, func() error {
logrus.Debugf("killing pasta")
if cmd.Process != nil {
_ = cmd.Process.Kill()
}
wErr := cmd.Wait()
logrus.Debugf("killed pasta: %v", wErr)
return nil
})
logrus.Debugf("Executing %v", cmd.Args)
if err := cmd.Start(); err != nil {
out, err := cmd.CombinedOutput()
if err != nil {
exitErr := &exec.ExitError{}
if errors.As(err, &exitErr) {
return nil, common.Seq(cleanups),
fmt.Errorf("pasta failed with exit code %d:\n%s",
exitErr.ExitCode(), string(out))
}
return nil, common.Seq(cleanups), fmt.Errorf("executing %v: %w", cmd, err)
}

netmsg := messages.ParentInitNetworkDriverCompleted{
Dev: tap,
MTU: d.mtu,
Expand Down

0 comments on commit 674a883

Please sign in to comment.