]> err.no Git - systemd/commitdiff
nspawn: add -b switch to automatically look for an init binary
authorLennart Poettering <lennart@poettering.net>
Sun, 22 Apr 2012 11:37:24 +0000 (13:37 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 22 Apr 2012 12:11:32 +0000 (14:11 +0200)
TODO
man/systemd-nspawn.xml
src/nspawn/nspawn.c
src/shared/util.h

diff --git a/TODO b/TODO
index 62b5ebf6e4054b0c6ee8f37b26eed35d00806951..2569b41bd6414e549588716a1dd234a76108b50e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -21,6 +21,8 @@ Bugfixes:
 
 Features:
 
+* fix utmp for console logins in containers
+
 * Add pretty name for seats in logind
 
 * nspawn wants dev_setup() for /dev/fd/ and friends?
index f63f72c18d80b70cbf7f6b0caed00344051fea1c..28e50359f3fdaf35b097d9e38717e499e8892577 100644 (file)
                                 used.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><option>--boot</option></term>
+                                <term><option>-b</option></term>
+
+                                <listitem><para>Automatically search
+                                for an init binary and invoke it
+                                instead of a shell or a user supplied
+                                program.</para></listitem>
+                        </varlistentry>
+
                         <varlistentry>
                                 <term><option>--user=</option></term>
                                 <term><option>-u</option></term>
index 50f2c5911100acfd70c83fd4b45c649e397aea09..7050c05ec2be3e059a9b8da3f29945443744b26c 100644 (file)
@@ -56,6 +56,7 @@ static char *arg_directory = NULL;
 static char *arg_user = NULL;
 static char **arg_controllers = NULL;
 static bool arg_private_network = false;
+static bool arg_boot = false;
 
 static int help(void) {
 
@@ -63,6 +64,7 @@ static int help(void) {
                "Spawn a minimal namespace container for debugging, testing and building.\n\n"
                "  -h --help             Show this help\n"
                "  -D --directory=NAME   Root directory for the container\n"
+               "  -b --boot             Boot up full system (i.e. invoke init)\n"
                "  -u --user=USER        Run the command under specified user or uid\n"
                "  -C --controllers=LIST Put the container in specified comma-separated cgroup hierarchies\n"
                "     --private-network  Disable network in container\n",
@@ -83,6 +85,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "user",            required_argument, NULL, 'u'                 },
                 { "controllers",     required_argument, NULL, 'C'                 },
                 { "private-network", no_argument,       NULL, ARG_PRIVATE_NETWORK },
+                { "boot",            no_argument,       NULL, 'b'                 },
                 { NULL,              0,                 NULL, 0                   }
         };
 
@@ -91,7 +94,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "+hD:u:C:", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "+hD:u:C:b", options, NULL)) >= 0) {
 
                 switch (c) {
 
@@ -133,6 +136,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_private_network = true;
                         break;
 
+                case 'b':
+                        arg_boot = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -1024,7 +1031,25 @@ int main(int argc, char *argv[]) {
 
                 setup_hostname();
 
-                if (argc > optind)
+                if (arg_boot) {
+                        char **a;
+                        size_t l;
+
+                        /* Automatically search for the init system */
+
+                        l = 1 + argc - optind;
+                        a = newa(char*, l + 1);
+                        memcpy(a + 1, argv + optind, l * sizeof(char*));
+
+                        a[0] = (char*) "/usr/lib/systemd/systemd";
+                        execve(a[0], a, (char**) envp);
+
+                        a[0] = (char*) "/lib/systemd/systemd";
+                        execve(a[0], a, (char**) envp);
+
+                        a[0] = (char*) "/sbin/init";
+                        execve(a[0], a, (char**) envp);
+                } else if (argc > optind)
                         execvpe(argv[optind], argv + optind, (char**) envp);
                 else {
                         chdir(home ? home : "/root");
index 35ba0057d6783bfd80eee30f8d7fea786d60de89..a26c1d9d0613e1f100c8c1bfe17548cd8074a338 100644 (file)
@@ -100,6 +100,8 @@ bool streq_ptr(const char *a, const char *b);
 
 #define new0(t, n) ((t*) calloc((n), sizeof(t)))
 
+#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
+
 #define newdup(t, p, n) ((t*) memdup(p, sizeof(t)*(n))
 
 #define malloc0(n) (calloc((n), 1))