Merge pull request #2344 from brauner/2018-05-23/on_demand_log_file

tools: only create log file when requested
This commit is contained in:
Stéphane Graber 2018-05-23 11:28:01 -04:00 committed by GitHub
commit f217dcd039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 209 additions and 203 deletions

View File

@ -270,18 +270,18 @@ int main(int argc, char *argv[])
if (r)
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
log.prefix = my_args.progname;
log.quiet = my_args.quiet;
log.lxcpath = my_args.lxcpath[0];
r = lxc_log_init(&log);
if (r)
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
if (geteuid()) {
if (access(my_args.lxcpath[0], O_RDONLY) < 0) {

View File

@ -347,6 +347,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -356,6 +358,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
count = list_defined_containers(my_args.lxcpath[0], NULL, &containers);

View File

@ -73,9 +73,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -85,6 +84,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
state_object = my_args.argv[0];

View File

@ -257,9 +257,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -269,6 +268,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {

View File

@ -97,9 +97,8 @@ int main(int argc, char *argv[])
if (ret)
return EXIT_FAILURE;
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -107,9 +106,9 @@ int main(int argc, char *argv[])
log.quiet = my_args.quiet;
log.lxcpath = my_args.lxcpath[0];
ret = lxc_log_init(&log);
if (ret)
return EXIT_FAILURE;
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {

View File

@ -163,9 +163,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(ret);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -175,6 +174,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(ret);
}
if (geteuid()) {
if (access(my_args.lxcpath[0], O_RDONLY) < 0) {

View File

@ -227,9 +227,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -239,6 +238,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
if (!my_args.template) {
fprintf(stderr, "A template must be specified.\n");

View File

@ -70,9 +70,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -82,6 +81,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
if (my_args.quiet)
quiet = true;

View File

@ -110,9 +110,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
goto err;
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -121,7 +120,8 @@ int main(int argc, char *argv[])
log.lxcpath = my_args.lxcpath[0];
if (lxc_log_init(&log))
goto err;
exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {

View File

@ -151,6 +151,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(err);
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -160,6 +162,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(err);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {

View File

@ -60,9 +60,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -72,6 +71,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {

View File

@ -396,9 +396,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(ret);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -408,6 +407,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(ret);
}
if (print_info(my_args.name, my_args.lxcpath[0]) == 0)
ret = EXIT_SUCCESS;

View File

@ -211,13 +211,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/*
* We set the first argument that usually takes my_args.name to NULL so
* that the log is only used when the user specifies a file.
*/
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = NULL;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -227,6 +222,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
struct lengths max_len = {
/* default header length */

View File

@ -503,9 +503,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(rc_main);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -515,6 +514,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(rc_main);
}
if (quit_monitord) {
int ret = EXIT_SUCCESS;

View File

@ -84,9 +84,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -96,6 +95,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
if (geteuid()) {
if (access(my_args.lxcpath[0], O_RDONLY) < 0) {

View File

@ -189,6 +189,8 @@ int main(int argc, char *argv[])
else
args = my_args.argv;
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -198,6 +200,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(err);
}
lxcpath = my_args.lxcpath[0];
if (access(lxcpath, O_RDONLY) < 0) {

View File

@ -104,6 +104,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(ret);
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -113,6 +115,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(ret);
}
/* Set default timeout */
if (my_args.timeout == -2) {

View File

@ -60,9 +60,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -70,9 +69,9 @@ int main(int argc, char *argv[])
log.quiet = my_args.quiet;
log.lxcpath = my_args.lxcpath[0];
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {

View File

@ -87,9 +87,8 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name;
log.file = my_args.log_file;
log.level = my_args.log_priority;
@ -99,6 +98,7 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c)