Skip to content

Commit 2aabb29

Browse files
authored
Merge pull request opencontainers#3113 from kolyshkin/init-rm-code
runc init: remove some code
2 parents d962bb0 + 5110bd2 commit 2aabb29

File tree

4 files changed

+6
-47
lines changed

4 files changed

+6
-47
lines changed

init.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"github.com/opencontainers/runc/libcontainer/logs"
1111
_ "github.com/opencontainers/runc/libcontainer/nsenter"
1212
"github.com/sirupsen/logrus"
13-
"github.com/urfave/cli"
1413
)
1514

1615
func init() {
1716
if len(os.Args) > 1 && os.Args[1] == "init" {
17+
// This is the golang entry point for runc init, executed
18+
// before main() but after libcontainer/nsenter's nsexec().
1819
runtime.GOMAXPROCS(1)
1920
runtime.LockOSThread()
2021

@@ -38,19 +39,13 @@ func init() {
3839
panic(fmt.Sprintf("libcontainer: failed to configure logging: %v", err))
3940
}
4041
logrus.Debug("child process in init()")
41-
}
42-
}
4342

44-
var initCommand = cli.Command{
45-
Name: "init",
46-
Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`,
47-
Action: func(context *cli.Context) error {
4843
factory, _ := libcontainer.New("")
4944
if err := factory.StartInitialization(); err != nil {
5045
// as the error is sent back to the parent there is no need to log
5146
// or write it to stderr because the parent process will handle this
5247
os.Exit(1)
5348
}
5449
panic("libcontainer: container init failed to exec")
55-
},
50+
}
5651
}

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)

main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func main() {
119119
deleteCommand,
120120
eventsCommand,
121121
execCommand,
122-
initCommand,
123122
killCommand,
124123
listCommand,
125124
pauseCommand,
@@ -149,10 +148,7 @@ func main() {
149148
if err := reviseRootDir(context); err != nil {
150149
return err
151150
}
152-
// let init configure logging on its own
153-
if args := context.Args(); args != nil && args.First() == "init" {
154-
return nil
155-
}
151+
156152
return logs.ConfigureLogging(createLogConfig(context))
157153
}
158154

0 commit comments

Comments
 (0)