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)
}
/*---------------------------------------------------------------------------*/
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)
lxc_log_setprefix(prefix);
......
......@@ -278,4 +278,6 @@ extern struct lxc_log_category lxc_log_category_lxc;
ERROR("%s - " format "\n", strerror(errno), ##__VA_ARGS__); \
} while (0)
extern int lxc_log_init(const char *file, const char *priority,
const char *prefix);
#endif
......@@ -34,6 +34,8 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd));
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);
}
......@@ -41,13 +43,20 @@ int main(int argc, char *argv[])
{
int opt;
char *name = NULL, *subsystem = NULL, *value = NULL;
const char *log_file = NULL, *log_priority = NULL;
int nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -56,6 +65,9 @@ int main(int argc, char *argv[])
if (!name || (argc-optind) < 1)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if ((argc -optind) >= 1)
subsystem = argv[optind];
......
......@@ -31,6 +31,8 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <statefile>\n", basename(cmd));
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);
}
......@@ -38,11 +40,12 @@ int main(int argc, char *argv[])
{
int opt;
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int stop = 0;
int nbargs = 0;
int ret = 1;
while ((opt = getopt(argc, argv, "sn:")) != -1) {
while ((opt = getopt(argc, argv, "sn:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
......@@ -50,6 +53,12 @@ int main(int argc, char *argv[])
case 's':
stop = 1;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -61,6 +70,9 @@ int main(int argc, char *argv[])
if (!argv[1])
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return -1;
if (lxc_freeze(name))
return -1;
......
......@@ -48,12 +48,15 @@ void usage(char *cmd)
fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt;
int nbargs = 0;
int master = -1;
......@@ -62,7 +65,7 @@ int main(int argc, char *argv[])
int err = LXC_ERROR_INTERNAL;
struct termios tios, oldtios;
while ((opt = getopt(argc, argv, "t:n:")) != -1) {
while ((opt = getopt(argc, argv, "t:n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
......@@ -71,6 +74,12 @@ int main(int argc, char *argv[])
case 't':
ttynum = atoi(optarg);
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -79,6 +88,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
/* Get current termios */
if (tcgetattr(0, &tios)) {
ERROR("failed to get current terminal settings : %s",
......
......@@ -39,16 +39,19 @@ void usage(char *cmd)
fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\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);
}
int main(int argc, char *argv[])
{
const char *name = NULL, *file = NULL;
const char *log_file = NULL, *log_priority = NULL;
struct lxc_conf lxc_conf;
int err, opt;
while ((opt = getopt(argc, argv, "f:n:")) != -1) {
while ((opt = getopt(argc, argv, "f:n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
......@@ -56,12 +59,23 @@ int main(int argc, char *argv[])
case 'f':
file = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
}
if (!name)
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))
return 1;
......
......@@ -31,21 +31,30 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt;
int nbargs = 0;
int err;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -54,6 +63,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
err = lxc_destroy(name);
if (err)
return 1;
......
......@@ -40,12 +40,15 @@ void usage(char *cmd)
fprintf(stderr, "%s <command>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\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);
}
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;
char path[MAXPATHLEN];
int opt;
......@@ -54,7 +57,7 @@ int main(int argc, char *argv[])
int ret = 1;
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) {
case 'n':
name = optarg;
......@@ -62,6 +65,12 @@ int main(int argc, char *argv[])
case 'f':
file = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -72,6 +81,9 @@ int main(int argc, char *argv[])
argc -= nbargs;
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
goto out;
if (lxc_conf_init(&lxc_conf))
goto out;
......
......@@ -32,20 +32,29 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt;
int nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -54,6 +63,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_freeze(name))
return 1;
......
......@@ -31,19 +31,28 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, state, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -52,6 +61,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
state = lxc_getstate(name);
if (state < 0)
return 1;
......
......@@ -35,28 +35,40 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
char *regexp;
struct lxc_msg msg;
regex_t preg;
int fd, opt;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
}
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
regexp = malloc(strlen(name) + 3);
sprintf(regexp, "^%s$", name);
......
......@@ -33,19 +33,28 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <statefile>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -54,9 +63,12 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (!argv[1])
if (!argv[optind])
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_restart(name, argv[1], 0)) {
ERROR("failed to restart %s", name);
return 1;
......
......@@ -43,12 +43,15 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
char **args;
int opt, err = LXC_ERROR_INTERNAL, nbargs = 0;
struct termios tios;
......@@ -58,11 +61,17 @@ int main(int argc, char *argv[])
'\0',
};
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -78,6 +87,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (tcgetattr(0, &tios)) {
ERROR("failed to get current terminal settings : %s",
strerror(errno));
......
......@@ -31,19 +31,28 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, err, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -52,6 +61,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
err = lxc_stop(name);
if (err) {
fprintf(stderr, "%s\n", lxc_strerror(err));
......
......@@ -31,19 +31,28 @@ void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
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);
}
int main(int argc, char *argv[])
{
char *name = NULL;
const char *log_file = NULL, *log_priority = NULL;
int opt, nbargs = 0;
while ((opt = getopt(argc, argv, "n:")) != -1) {
while ((opt = getopt(argc, argv, "n:o:l:")) != -1) {
switch (opt) {
case 'n':
name = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
nbargs++;
......@@ -52,6 +61,9 @@ int main(int argc, char *argv[])
if (!name)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
if (lxc_unfreeze(name))
return 1;
......
......@@ -45,6 +45,8 @@ void usage(char *cmd)
"\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 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);
}
......@@ -131,11 +133,12 @@ int main(int argc, char *argv[])
int ret;
char *namespaces = NULL;
char **args;
const char *log_file = NULL, *log_priority = NULL;
long flags = 0;
uid_t uid = -1; /* valid only if (flags & CLONE_NEWUSER) */
pid_t pid;
while ((opt = getopt(argc, argv, "fs:u:")) != -1) {
while ((opt = getopt(argc, argv, "fs:u:o:l:")) != -1) {
switch (opt) {
case 's':
namespaces = optarg;
......@@ -147,11 +150,20 @@ int main(int argc, char *argv[])
case 'f':
hastofork = 1;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
}
args = &argv[optind];
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return 1;
ret = lxc_fill_namespace_flags(namespaces, &flags);
if (ret)
usage(argv[0]);
......
......@@ -36,6 +36,8 @@ void usage(char *cmd)
fprintf(stderr, "\t -n <name> : name of the container\n");
fprintf(stderr, "\t -s <states> : ORed states to wait for STOPPED, " \
"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);
}
......@@ -61,10 +63,11 @@ static int fillwaitedstates(char *strstates, int *states)
int main(int argc, char *argv[])
{
char *name = NULL, *states = NULL;
const char *log_file = NULL, *log_priority = NULL;
struct lxc_msg msg;
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) {
case 'n':
name = optarg;
......@@ -72,12 +75,21 @@ int main(int argc, char *argv[])
case 's':
states = optarg;
break;
case 'o':
log_file = optarg;
break;
case 'l':
log_priority = optarg;
break;
}
}
if (!name || !states)
usage(argv[0]);
if (lxc_log_init(log_file, log_priority, basename(argv[0])))
return -1;
if (fillwaitedstates(states, s)) {
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