Commit 8559e703 by Michel Normand Committed by Daniel Lezcano

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com>
parent e043236e
...@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) ...@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
} }
/* lxc-init --mount-procfs -- .... */ /* lxc-init --mount-procfs -- .... */
args = malloc((argc + 3)*sizeof(*args)); args = malloc((my_args.argc + 8)*sizeof(*args));
if (!args) { if (!args) {
ERROR("failed to allocate memory for '%s'", my_args.name); ERROR("failed to allocate memory for '%s'", my_args.name);
goto out; goto out;
...@@ -114,6 +114,17 @@ int main(int argc, char *argv[]) ...@@ -114,6 +114,17 @@ int main(int argc, char *argv[])
nbargs = 0; nbargs = 0;
args[nbargs++] = LXCLIBEXECDIR "/lxc-init"; args[nbargs++] = LXCLIBEXECDIR "/lxc-init";
args[nbargs++] = "--mount-procfs"; 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++] = "--"; args[nbargs++] = "--";
for (opt = 0; opt < my_args.argc; opt++) for (opt = 0; opt < my_args.argc; opt++)
......
...@@ -26,18 +26,29 @@ ...@@ -26,18 +26,29 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <libgen.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mount.h> #include <sys/mount.h>
#define _GNU_SOURCE #define _GNU_SOURCE
#include <getopt.h> #include <getopt.h>
#include "log.h"
lxc_log_define(lxc_init, lxc);
static int mount_sysfs; static int mount_sysfs;
static int mount_procfs; static int mount_procfs;
static char const *log_file;
static char const *log_priority;
static int quiet;
static struct option options[] = { static struct option options[] = {
{ "mount-sysfs", no_argument, &mount_sysfs, 1 }, { "mount-sysfs", no_argument, &mount_sysfs, 1 },
{ "mount-procfs", no_argument, &mount_procfs, 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[]) int main(int argc, char *argv[])
...@@ -48,15 +59,23 @@ int main(int argc, char *argv[]) ...@@ -48,15 +59,23 @@ int main(int argc, char *argv[])
while (1) { while (1) {
int ret = getopt_long_only(argc, argv, "", options, NULL); int ret = getopt_long_only(argc, argv, "", options, NULL);
if (ret == -1) if (ret == -1) {
break; break;
if (ret == '?') }
switch (ret) {
case 'o': log_file = optarg; break;
case 'l': log_priority = optarg; break;
case '?':
exit(1); exit(1);
}
nbargs++; nbargs++;
} }
if (lxc_log_init(log_file, log_priority, basename(argv[0]), quiet))
exit(1);
if (!argv[optind]) { if (!argv[optind]) {
fprintf(stderr, "missing command to launch\n"); ERROR("missing command to launch");
exit(1); exit(1);
} }
...@@ -71,22 +90,20 @@ int main(int argc, char *argv[]) ...@@ -71,22 +90,20 @@ int main(int argc, char *argv[])
if (!pid) { if (!pid) {
if (mount_sysfs && mount("sysfs", "/sys", "sysfs", 0, NULL)) { 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); exit(1);
} }
if (mount_procfs && mount("proc", "/proc", "proc", 0, NULL)) { 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); exit(1);
} }
execvp(aargv[0], aargv); 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); exit(1);
} }
for (;;) { for (;;) {
int status; int status;
if (wait(&status) < 0) { if (wait(&status) < 0) {
...@@ -94,7 +111,7 @@ int main(int argc, char *argv[]) ...@@ -94,7 +111,7 @@ int main(int argc, char *argv[])
exit(0); exit(0);
if (errno == EINTR) if (errno == EINTR)
continue; continue;
fprintf(stderr, "failed to wait child\n"); ERROR("failed to wait child");
return 1; return 1;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment