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[])
}
/* 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++)
......
......@@ -26,18 +26,29 @@
#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;
}
}
......
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