From: Michel Normand Date: Mon, 18 May 2009 20:27:35 +0000 (+0200) Subject: add support of lxc log file to lxc-init X-Git-Tag: lxc_0_6_3~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8559e7039c60be8a91a372541ed4ca30ca398530;p=thirdparty%2Flxc.git add support of lxc log file to lxc-init pass to lxc-init the log options given to lxc-execute (in fact logfile logpriority and quiet) Signed-off-by: Daniel Lezcano Signed-off-by: Michel Normand --- diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c index 92d8076f4..eb7ef9cbd 100644 --- a/src/lxc/lxc_execute.c +++ b/src/lxc/lxc_execute.c @@ -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++) diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 13caec63e..5b00d147a 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -26,18 +26,29 @@ #include #include #include +#include #include #include #include #define _GNU_SOURCE #include +#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; } }