Commit 51cab631 by Michel Normand Committed by Daniel Lezcano

add support of a lxc log file to cli

this is adding -o and -l options to all cli of lxc Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 3ab87b66
...@@ -127,9 +127,21 @@ static int log_open(const char *name) ...@@ -127,9 +127,21 @@ static int log_open(const char *name)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
extern int lxc_log_init(const char *file, int priority, const char *prefix) extern int lxc_log_init(const char *file, const char *priority,
const char *prefix)
{ {
lxc_log_category_lxc.priority = priority; int lxc_priority = LXC_LOG_PRIORITY_ERROR;
if (priority) {
lxc_priority = lxc_log_priority_to_int(priority);
if (lxc_priority == LXC_LOG_PRIORITY_NOTSET) {
ERROR("invalid log priority %s", priority);
return -1;
}
}
lxc_log_category_lxc.priority = lxc_priority;
if (prefix) if (prefix)
lxc_log_setprefix(prefix); lxc_log_setprefix(prefix);
......
...@@ -278,4 +278,6 @@ extern struct lxc_log_category lxc_log_category_lxc; ...@@ -278,4 +278,6 @@ extern struct lxc_log_category lxc_log_category_lxc;
ERROR("%s - " format "\n", strerror(errno), ##__VA_ARGS__); \ ERROR("%s - " format "\n", strerror(errno), ##__VA_ARGS__); \
} while (0) } while (0)
extern int lxc_log_init(const char *file, const char *priority,
const char *prefix);
#endif #endif
...@@ -34,6 +34,8 @@ void usage(char *cmd) ...@@ -34,6 +34,8 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd)); fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
...@@ -41,13 +43,20 @@ int main(int argc, char *argv[]) ...@@ -41,13 +43,20 @@ int main(int argc, char *argv[])
{ {
int opt; int opt;
char *name = NULL, *subsystem = NULL, *value = NULL; char *name = NULL, *subsystem = NULL, *value = NULL;
const char *log_file = NULL, *log_priority = NULL;
int nbargs = 0; int nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -56,6 +65,9 @@ int main(int argc, char *argv[]) ...@@ -56,6 +65,9 @@ int main(int argc, char *argv[])
if (!name || (argc-optind) < 1) if (!name || (argc-optind) < 1)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if ((argc -optind) >= 1) if ((argc -optind) >= 1)
subsystem = argv[optind]; subsystem = argv[optind];
......
...@@ -31,6 +31,8 @@ void usage(char *cmd) ...@@ -31,6 +31,8 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <statefile>\n", basename(cmd)); fprintf(stderr, "%s <statefile>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
...@@ -38,11 +40,12 @@ int main(int argc, char *argv[]) ...@@ -38,11 +40,12 @@ int main(int argc, char *argv[])
{ {
int opt; int opt;
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int stop = 0; int stop = 0;
int nbargs = 0; int nbargs = 0;
int ret = 1; int ret = 1;
while ((opt = getopt(argc, argv, "sn:")) != -1) { while ((opt = getopt(argc, argv, "sn:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
...@@ -50,6 +53,12 @@ int main(int argc, char *argv[]) ...@@ -50,6 +53,12 @@ int main(int argc, char *argv[])
case 's': case 's':
stop = 1; stop = 1;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -61,6 +70,9 @@ int main(int argc, char *argv[]) ...@@ -61,6 +70,9 @@ int main(int argc, char *argv[])
if (!argv[1]) if (!argv[1])
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return -1;
if (lxc_freeze(name)) if (lxc_freeze(name))
return -1; return -1;
......
...@@ -48,12 +48,15 @@ void usage(char *cmd) ...@@ -48,12 +48,15 @@ void usage(char *cmd)
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t [-t <tty#>] : tty number\n"); fprintf(stderr, "\t [-t <tty#>] : tty number\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt; int opt;
int nbargs = 0; int nbargs = 0;
int master = -1; int master = -1;
...@@ -62,7 +65,7 @@ int main(int argc, char *argv[]) ...@@ -62,7 +65,7 @@ int main(int argc, char *argv[])
int err = LXC_ERROR_INTERNAL; int err = LXC_ERROR_INTERNAL;
struct termios tios, oldtios; struct termios tios, oldtios;
while ((opt = getopt(argc, argv, "t:n:")) != -1) { while ((opt = getopt(argc, argv, "t:n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
...@@ -71,6 +74,12 @@ int main(int argc, char *argv[]) ...@@ -71,6 +74,12 @@ int main(int argc, char *argv[])
case 't': case 't':
ttynum = atoi(optarg); ttynum = atoi(optarg);
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -79,6 +88,9 @@ int main(int argc, char *argv[]) ...@@ -79,6 +88,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
/* Get current termios */ /* Get current termios */
if (tcgetattr(0, &tios)) { if (tcgetattr(0, &tios)) {
ERROR("failed to get current terminal settings : %s", ERROR("failed to get current terminal settings : %s",
......
...@@ -39,16 +39,19 @@ void usage(char *cmd) ...@@ -39,16 +39,19 @@ void usage(char *cmd)
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t -f <confile> : path of the configuration file\n"); fprintf(stderr, "\t -f <confile> : path of the configuration file\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *name = NULL, *file = NULL; const char *name = NULL, *file = NULL;
const char *log_file = NULL, *log_priority = NULL;
struct lxc_conf lxc_conf; struct lxc_conf lxc_conf;
int err, opt; int err, opt;
while ((opt = getopt(argc, argv, "f:n:")) != -1) { while ((opt = getopt(argc, argv, "f:n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
...@@ -56,12 +59,23 @@ int main(int argc, char *argv[]) ...@@ -56,12 +59,23 @@ int main(int argc, char *argv[])
case 'f': case 'f':
file = optarg; file = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
} }
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_conf_init(&lxc_conf))
return 1;
if (file && lxc_config_read(file, &lxc_conf)) if (file && lxc_config_read(file, &lxc_conf))
return 1; return 1;
......
...@@ -31,21 +31,30 @@ void usage(char *cmd) ...@@ -31,21 +31,30 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt; int opt;
int nbargs = 0; int nbargs = 0;
int err; int err;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -54,6 +63,9 @@ int main(int argc, char *argv[]) ...@@ -54,6 +63,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
err = lxc_destroy(name); err = lxc_destroy(name);
if (err) if (err)
return 1; return 1;
......
...@@ -40,12 +40,15 @@ void usage(char *cmd) ...@@ -40,12 +40,15 @@ void usage(char *cmd)
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t [-f <confile>] : path of the configuration file\n"); fprintf(stderr, "\t [-f <confile>] : path of the configuration file\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL, *file = NULL; const char *name = NULL, *file = NULL;
const char *log_file = NULL, *log_priority = NULL;
static char **args; static char **args;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
int opt; int opt;
...@@ -54,7 +57,7 @@ int main(int argc, char *argv[]) ...@@ -54,7 +57,7 @@ int main(int argc, char *argv[])
int ret = 1; int ret = 1;
struct lxc_conf lxc_conf; struct lxc_conf lxc_conf;
while ((opt = getopt(argc, argv, "f:n:")) != -1) { while ((opt = getopt(argc, argv, "f:n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
...@@ -62,6 +65,12 @@ int main(int argc, char *argv[]) ...@@ -62,6 +65,12 @@ int main(int argc, char *argv[])
case 'f': case 'f':
file = optarg; file = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -72,6 +81,9 @@ int main(int argc, char *argv[]) ...@@ -72,6 +81,9 @@ int main(int argc, char *argv[])
argc -= nbargs; argc -= nbargs;
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
goto out;
if (lxc_conf_init(&lxc_conf)) if (lxc_conf_init(&lxc_conf))
goto out; goto out;
......
...@@ -32,20 +32,29 @@ void usage(char *cmd) ...@@ -32,20 +32,29 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt; int opt;
int nbargs = 0; int nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -54,6 +63,9 @@ int main(int argc, char *argv[]) ...@@ -54,6 +63,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_freeze(name)) if (lxc_freeze(name))
return 1; return 1;
......
...@@ -31,19 +31,28 @@ void usage(char *cmd) ...@@ -31,19 +31,28 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, state, nbargs = 0; int opt, state, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -52,6 +61,9 @@ int main(int argc, char *argv[]) ...@@ -52,6 +61,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
state = lxc_getstate(name); state = lxc_getstate(name);
if (state < 0) if (state < 0)
return 1; return 1;
......
...@@ -35,28 +35,40 @@ void usage(char *cmd) ...@@ -35,28 +35,40 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container or regular expression\n"); fprintf(stderr, "\t -n <name> : name of the container or regular expression\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
char *regexp; char *regexp;
struct lxc_msg msg; struct lxc_msg msg;
regex_t preg; regex_t preg;
int fd, opt; int fd, opt;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
} }
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
regexp = malloc(strlen(name) + 3); regexp = malloc(strlen(name) + 3);
sprintf(regexp, "^%s$", name); sprintf(regexp, "^%s$", name);
......
...@@ -33,19 +33,28 @@ void usage(char *cmd) ...@@ -33,19 +33,28 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <statefile>\n", basename(cmd)); fprintf(stderr, "%s <statefile>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, nbargs = 0; int opt, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -54,9 +63,12 @@ int main(int argc, char *argv[]) ...@@ -54,9 +63,12 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (!argv[1]) if (!argv[optind])
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_restart(name, argv[1], 0)) { if (lxc_restart(name, argv[1], 0)) {
ERROR("failed to restart %s", name); ERROR("failed to restart %s", name);
return 1; return 1;
......
...@@ -43,12 +43,15 @@ void usage(char *cmd) ...@@ -43,12 +43,15 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
char **args; char **args;
int opt, err = LXC_ERROR_INTERNAL, nbargs = 0; int opt, err = LXC_ERROR_INTERNAL, nbargs = 0;
struct termios tios; struct termios tios;
...@@ -58,11 +61,17 @@ int main(int argc, char *argv[]) ...@@ -58,11 +61,17 @@ int main(int argc, char *argv[])
'\0', '\0',
}; };
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -78,6 +87,9 @@ int main(int argc, char *argv[]) ...@@ -78,6 +87,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (tcgetattr(0, &tios)) { if (tcgetattr(0, &tios)) {
ERROR("failed to get current terminal settings : %s", ERROR("failed to get current terminal settings : %s",
strerror(errno)); strerror(errno));
......
...@@ -31,19 +31,28 @@ void usage(char *cmd) ...@@ -31,19 +31,28 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, err, nbargs = 0; int opt, err, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -52,6 +61,9 @@ int main(int argc, char *argv[]) ...@@ -52,6 +61,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
err = lxc_stop(name); err = lxc_stop(name);
if (err) { if (err) {
fprintf(stderr, "%s\n", lxc_strerror(err)); fprintf(stderr, "%s\n", lxc_strerror(err));
......
...@@ -31,19 +31,28 @@ void usage(char *cmd) ...@@ -31,19 +31,28 @@ void usage(char *cmd)
{ {
fprintf(stderr, "%s <command>\n", basename(cmd)); fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL; char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, nbargs = 0; int opt, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) { while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
nbargs++; nbargs++;
...@@ -52,6 +61,9 @@ int main(int argc, char *argv[]) ...@@ -52,6 +61,9 @@ int main(int argc, char *argv[])
if (!name) if (!name)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_unfreeze(name)) if (lxc_unfreeze(name))
return 1; return 1;
......
...@@ -45,6 +45,8 @@ void usage(char *cmd) ...@@ -45,6 +45,8 @@ void usage(char *cmd)
"\t MOUNT, PID, UTSNAME, IPC, USER, NETWORK\n"); "\t MOUNT, PID, UTSNAME, IPC, USER, NETWORK\n");
fprintf(stderr, "\t -u <id> : new id to be set if -s USER is specified\n"); fprintf(stderr, "\t -u <id> : new id to be set if -s USER is specified\n");
fprintf(stderr, "\t if -f or -s PID is specified, <command> is mandatory)\n"); fprintf(stderr, "\t if -f or -s PID is specified, <command> is mandatory)\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
...@@ -131,11 +133,12 @@ int main(int argc, char *argv[]) ...@@ -131,11 +133,12 @@ int main(int argc, char *argv[])
int ret; int ret;
char *namespaces = NULL; char *namespaces = NULL;
char **args; char **args;
const char *log_file = NULL, *log_priority = NULL;
long flags = 0; long flags = 0;
uid_t uid = -1; /* valid only if (flags & CLONE_NEWUSER) */ uid_t uid = -1; /* valid only if (flags & CLONE_NEWUSER) */
pid_t pid; pid_t pid;
while ((opt = getopt(argc, argv, "fs:u:")) != -1) { while ((opt = getopt(argc, argv, "fs:u:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 's': case 's':
namespaces = optarg; namespaces = optarg;
...@@ -147,11 +150,20 @@ int main(int argc, char *argv[]) ...@@ -147,11 +150,20 @@ int main(int argc, char *argv[])
case 'f': case 'f':
hastofork = 1; hastofork = 1;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
} }
args = &argv[optind]; args = &argv[optind];
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
ret = lxc_fill_namespace_flags(namespaces, &flags); ret = lxc_fill_namespace_flags(namespaces, &flags);
if (ret) if (ret)
usage(argv[0]); usage(argv[0]);
......
...@@ -36,6 +36,8 @@ void usage(char *cmd) ...@@ -36,6 +36,8 @@ void usage(char *cmd)
fprintf(stderr, "\t -n <name> : name of the container\n"); fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t -s <states> : ORed states to wait for STOPPED, " \ fprintf(stderr, "\t -s <states> : ORed states to wait for STOPPED, " \
"STARTING, RUNNING, STOPPING, ABORTING, FREEZING, FROZEN\n"); "STARTING, RUNNING, STOPPING, ABORTING, FREEZING, FROZEN\n");
fprintf(stderr, "\t[-o <logfile>] : path of the log file\n");
fprintf(stderr, "\t[-l <logpriority>]: log level priority\n");
_exit(1); _exit(1);
} }
...@@ -61,10 +63,11 @@ static int fillwaitedstates(char *strstates, int *states) ...@@ -61,10 +63,11 @@ static int fillwaitedstates(char *strstates, int *states)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *name = NULL, *states = NULL; char *name = NULL, *states = NULL;
const char *log_file = NULL, *log_priority = NULL;
struct lxc_msg msg; struct lxc_msg msg;
int s[MAX_STATE] = { }, fd, opt; int s[MAX_STATE] = { }, fd, opt;
while ((opt = getopt(argc, argv, "s:n:")) != -1) { while ((opt = getopt(argc, argv, "s:n:o:l:")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
name = optarg; name = optarg;
...@@ -72,12 +75,21 @@ int main(int argc, char *argv[]) ...@@ -72,12 +75,21 @@ int main(int argc, char *argv[])
case 's': case 's':
states = optarg; states = optarg;
break; break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
} }
} }
if (!name || !states) if (!name || !states)
usage(argv[0]); usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return -1;
if (fillwaitedstates(states, s)) { if (fillwaitedstates(states, s)) {
usage(argv[0]); usage(argv[0]);
} }
......
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