Skip to content

Commit

Permalink
libct: rm initWaiter
Browse files Browse the repository at this point in the history
This initWaiter logic was introduced by commit 4ecff8d, but since the logic of
/proc/self/exe was moved out of runc init in commit 0e9a335, this
seems unnecessary to have initWaiter.

Remove it.

This essentially reverts commit 4ecff8d.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Oct 17, 2024
1 parent d82235c commit b5bdf59
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 73 deletions.
22 changes: 0 additions & 22 deletions libcontainer/nsenter/nsenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ func TestNsenterValidPaths(t *testing.T) {
t.Fatal(err)
}

initWaiter(t, parent)

if err := cmd.Wait(); err != nil {
t.Fatalf("nsenter error: %v", err)
}
Expand Down Expand Up @@ -94,7 +92,6 @@ func TestNsenterInvalidPaths(t *testing.T) {
t.Fatal(err)
}

initWaiter(t, parent)
if err := cmd.Wait(); err == nil {
t.Fatalf("nsenter exits with a zero exit status")
}
Expand Down Expand Up @@ -133,7 +130,6 @@ func TestNsenterIncorrectPathType(t *testing.T) {
t.Fatal(err)
}

initWaiter(t, parent)
if err := cmd.Wait(); err == nil {
t.Fatalf("nsenter error: %v", err)
}
Expand Down Expand Up @@ -177,8 +173,6 @@ func TestNsenterChildLogging(t *testing.T) {
t.Fatal(err)
}

initWaiter(t, parent)

getLogs(t, logread)
if err := cmd.Wait(); err != nil {
t.Fatalf("nsenter error: %v", err)
Expand Down Expand Up @@ -208,22 +202,6 @@ func newPipe(t *testing.T) (parent *os.File, child *os.File) {
return
}

// initWaiter reads back the initial \0 from runc init
func initWaiter(t *testing.T, r io.Reader) {
inited := make([]byte, 1)
n, err := r.Read(inited)
if err == nil {
if n < 1 {
err = errors.New("short read")
} else if inited[0] != 0 {
err = fmt.Errorf("unexpected %d != 0", inited[0])
} else {
return
}
}
t.Fatalf("waiting for init preliminary setup: %v", err)
}

func reapChildren(t *testing.T, parent *os.File) {
t.Helper()
decoder := json.NewDecoder(parent)
Expand Down
7 changes: 0 additions & 7 deletions libcontainer/nsenter/nsexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,6 @@ void nsexec(void)
return;
}

/*
* Inform the parent we're past initial setup.
* For the other side of this, see initWaiter.
*/
if (write(pipenum, "", 1) != 1)
bail("could not inform the parent we are past initial setup");

write_log(DEBUG, "=> nsexec container setup");

/* Parse all of the netlink configuration. */
Expand Down
44 changes: 0 additions & 44 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,12 @@ func (p *setnsProcess) start() (retErr error) {
return fmt.Errorf("error starting setns process: %w", err)
}

waitInit := initWaiter(p.comm.initSockParent)
defer func() {
if retErr != nil {
if newOom, err := p.manager.OOMKillCount(); err == nil && newOom != oom {
// Someone in this cgroup was killed, this _might_ be us.
retErr = fmt.Errorf("%w (possibly OOM-killed)", retErr)
}
werr := <-waitInit
if werr != nil {
logrus.WithError(werr).Warn()
}
err := ignoreTerminateErrors(p.terminate())
if err != nil {
logrus.WithError(err).Warn("unable to terminate setnsProcess")
Expand All @@ -163,10 +158,6 @@ func (p *setnsProcess) start() (retErr error) {
return fmt.Errorf("error copying bootstrap data to pipe: %w", err)
}
}
err = <-waitInit
if err != nil {
return err
}
if err := p.execSetns(); err != nil {
return fmt.Errorf("error executing setns process: %w", err)
}
Expand Down Expand Up @@ -536,7 +527,6 @@ func (p *initProcess) start() (retErr error) {
return fmt.Errorf("unable to start init: %w", err)
}

waitInit := initWaiter(p.comm.initSockParent)
defer func() {
if retErr != nil {
// Find out if init is killed by the kernel's OOM killer.
Expand All @@ -559,11 +549,6 @@ func (p *initProcess) start() (retErr error) {
}
}

werr := <-waitInit
if werr != nil {
logrus.WithError(werr).Warn()
}

// Terminate the process to ensure we can remove cgroups.
if err := ignoreTerminateErrors(p.terminate()); err != nil {
logrus.WithError(err).Warn("unable to terminate initProcess")
Expand Down Expand Up @@ -601,10 +586,6 @@ func (p *initProcess) start() (retErr error) {
if _, err := io.Copy(p.comm.initSockParent, p.bootstrapData); err != nil {
return fmt.Errorf("can't copy bootstrap data to pipe: %w", err)
}
err = <-waitInit
if err != nil {
return err
}

childPid, err := p.getChildPid()
if err != nil {
Expand Down Expand Up @@ -975,31 +956,6 @@ func (p *Process) InitializeIO(rootuid, rootgid int) (i *IO, err error) {
return i, nil
}

// initWaiter returns a channel to wait on for making sure
// runc init has finished the initial setup.
func initWaiter(r io.Reader) chan error {
ch := make(chan error, 1)
go func() {
defer close(ch)

inited := make([]byte, 1)
n, err := r.Read(inited)
if err == nil {
if n < 1 {
err = errors.New("short read")
} else if inited[0] != 0 {
err = fmt.Errorf("unexpected %d != 0", inited[0])
} else {
ch <- nil
return
}
}
ch <- fmt.Errorf("waiting for init preliminary setup: %w", err)
}()

return ch
}

func setIOPriority(ioprio *configs.IOPriority) error {
const ioprioWhoPgrp = 1

Expand Down

0 comments on commit b5bdf59

Please sign in to comment.