Skip to content

Commit 5110bd2

Browse files
committed
nsenter: remove cgroupns sync mechanism
As pointed out in TODO item added by commit 64bb59f, it is not necessary to have a special sync mechanism for cgroupns, as the parent adds runc init to cgroup way earlier (before sending nl bootstrap data. This sync was added by commit df3fa11, which was also added a second cgroup manager.Apply() call, later removed in commit d1ba8e3. It seems the original author had the idea to wait for that second Apply(). Fixes: df3fa11 Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 7a0302f commit 5110bd2

File tree

2 files changed

+2
-34
lines changed

2 files changed

+2
-34
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ enum sync_t {
4141
SYNC_CHILD_FINISH = 0x45, /* The child or grandchild has finished. */
4242
};
4343

44-
/*
45-
* Synchronisation value for cgroup namespace setup.
46-
* The same constant is defined in process_linux.go as "createCgroupns".
47-
*/
48-
#define CREATECGROUPNS 0x80
49-
5044
#define STAGE_SETUP -1
5145
/* longjmp() arguments. */
5246
#define STAGE_PARENT 0
@@ -1075,24 +1069,9 @@ void nsexec(void)
10751069
bail("setgroups failed");
10761070
}
10771071

1078-
/*
1079-
* Wait until our topmost parent has finished cgroup setup in
1080-
* p.manager.Apply().
1081-
*
1082-
* TODO(cyphar): Check if this code is actually needed because we
1083-
* should be in the cgroup even from stage-0, so
1084-
* waiting until now might not make sense.
1085-
*/
10861072
if (config.cloneflags & CLONE_NEWCGROUP) {
1087-
uint8_t value;
1088-
if (read(pipenum, &value, sizeof(value)) != sizeof(value))
1089-
bail("read synchronisation value failed");
1090-
if (value == CREATECGROUPNS) {
1091-
write_log(DEBUG, "unshare cgroup namespace");
1092-
if (unshare(CLONE_NEWCGROUP) < 0)
1093-
bail("failed to unshare cgroup namespace");
1094-
} else
1095-
bail("received unknown synchronisation value");
1073+
if (unshare(CLONE_NEWCGROUP) < 0)
1074+
bail("failed to unshare cgroup namespace");
10961075
}
10971076

10981077
write_log(DEBUG, "signal completion to stage-0");

libcontainer/process_linux.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import (
2525
"golang.org/x/sys/unix"
2626
)
2727

28-
// Synchronisation value for cgroup namespace setup.
29-
// The same constant is defined in nsexec.c as "CREATECGROUPNS".
30-
const createCgroupns = 0x80
31-
3228
type parentProcess interface {
3329
// pid returns the pid for the running process.
3430
pid() int
@@ -411,13 +407,6 @@ func (p *initProcess) start() (retErr error) {
411407
}
412408
p.setExternalDescriptors(fds)
413409

414-
// Now it's time to setup cgroup namesapce
415-
if p.config.Config.Namespaces.Contains(configs.NEWCGROUP) && p.config.Config.Namespaces.PathOf(configs.NEWCGROUP) == "" {
416-
if _, err := p.messageSockPair.parent.Write([]byte{createCgroupns}); err != nil {
417-
return fmt.Errorf("error sending synchronization value to init process: %w", err)
418-
}
419-
}
420-
421410
// Wait for our first child to exit
422411
if err := p.waitForChildExit(childPid); err != nil {
423412
return fmt.Errorf("error waiting for our first child to exit: %w", err)

0 commit comments

Comments
 (0)