]> git.proxmox.com Git - mirror_lxc.git/commitdiff
add support of lxc log file to lxc-init
authorMichel Normand <normand@fr.ibm.com>
Mon, 18 May 2009 20:27:35 +0000 (22:27 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Mon, 18 May 2009 20:27:35 +0000 (22:27 +0200)
pass to lxc-init the log options given to lxc-execute
(in fact logfile logpriority and quiet)

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Michel Normand <normand@fr.ibm.com>
src/lxc/lxc_execute.c
src/lxc/lxc_init.c

index 92d8076f4ff471ea823db830ac06bcf94bd5c67c..eb7ef9cbdfc3c2e65b146541b8cca06f8b7a67e0 100644 (file)
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
        }
 
        /* lxc-init --mount-procfs -- .... */
-       args = malloc((argc + 3)*sizeof(*args));
+       args = malloc((my_args.argc + 8)*sizeof(*args));
        if (!args) {
                ERROR("failed to allocate memory for '%s'", my_args.name);
                goto out;
@@ -114,6 +114,17 @@ int main(int argc, char *argv[])
        nbargs = 0;
        args[nbargs++] = LXCLIBEXECDIR "/lxc-init";
        args[nbargs++] = "--mount-procfs";
+       if (my_args.log_file) {
+               args[nbargs++] = "--logfile";
+               args[nbargs++] = my_args.log_file;
+       }
+       if (my_args.log_priority) {
+               args[nbargs++] = "--logpriority";
+               args[nbargs++] = my_args.log_priority;
+       }
+       if (my_args.quiet) {
+               args[nbargs++] = "--quiet";
+       }
        args[nbargs++] = "--";
 
        for (opt = 0; opt < my_args.argc; opt++)
index 13caec63e73ca54f23ac54d11cb9eeb331fa9ec8..5b00d147a112bc3c4be28822b367475e052149ae 100644 (file)
 #include <stdlib.h>
 #include <errno.h>
 #include <signal.h>
+#include <libgen.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/mount.h>
 #define _GNU_SOURCE
 #include <getopt.h>
+#include "log.h"
+
+lxc_log_define(lxc_init, lxc);
 
 static int mount_sysfs;
 static int mount_procfs;
+static char const *log_file;
+static char const *log_priority;
+static int quiet;
 
 static struct option options[] = {
        { "mount-sysfs", no_argument, &mount_sysfs, 1 },
        { "mount-procfs", no_argument, &mount_procfs, 1 },
+       { "logfile", required_argument, 0, 'o' },
+       { "logpriority", required_argument, 0, 'l' },
+       { "quiet", no_argument, &quiet, 1 },
+       { 0, 0, 0, 0 },
 };
 
 int main(int argc, char *argv[])
@@ -48,15 +59,23 @@ int main(int argc, char *argv[])
 
        while (1) {
                int ret = getopt_long_only(argc, argv, "", options, NULL);
-               if (ret == -1)
+               if (ret == -1) {
                        break;
-               if (ret == '?')
+               }
+               switch (ret) {
+               case 'o':       log_file = optarg; break;
+               case 'l':       log_priority = optarg; break;
+               case '?':
                        exit(1);
+               }
                nbargs++;
        }
 
+       if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
+               exit(1);
+
        if (!argv[optind]) {
-               fprintf(stderr, "missing command to launch\n");
+               ERROR("missing command to launch");
                exit(1);
        }
 
@@ -71,22 +90,20 @@ int main(int argc, char *argv[])
        if (!pid) {
                
                if (mount_sysfs && mount("sysfs", "/sys", "sysfs", 0, NULL)) {
-                       fprintf(stderr, "failed to mount '/sys'\n");
+                       ERROR("failed to mount '/sys' : %s", strerror(errno));
                        exit(1);
                }
                
                if (mount_procfs && mount("proc", "/proc", "proc", 0, NULL)) {
-                       fprintf(stderr, "failed to mount '/proc'\n");
+                       ERROR("failed to mount '/proc' : %s", strerror(errno));
                        exit(1);
                }
 
                execvp(aargv[0], aargv);
-               fprintf(stderr, "failed to exec: %s\n", aargv[0]);
+               ERROR("failed to exec: '%s' : %s", aargv[0], strerror(errno));
                exit(1);
        }
 
-       
-
        for (;;) {
                int status;
                if (wait(&status) < 0) {
@@ -94,7 +111,7 @@ int main(int argc, char *argv[])
                                exit(0);
                        if (errno == EINTR)
                                continue;
-                       fprintf(stderr, "failed to wait child\n");
+                       ERROR("failed to wait child");
                        return 1;
                }
        }