#include "log.h"
#include "caps.h"
#include "utils.h"
+#include "lxccontainer.h"
/* We're logging in seconds and nanoseconds. Assuming that the underlying
* datatype is currently at maximum a 64bit integer, we have a date string that
* Called from lxc front-end programs (like lxc-create, lxc-start) to
* initalize the log defaults.
*/
-extern int lxc_log_init(const char *name, const char *file,
- const char *priority, const char *prefix, int quiet,
- const char *lxcpath)
+extern int lxc_log_init(struct lxc_log *log)
{
int lxc_priority = LXC_LOG_PRIORITY_ERROR;
int ret;
return 0;
}
- if (priority)
- lxc_priority = lxc_log_priority_to_int(priority);
+ if (log->priority)
+ lxc_priority = lxc_log_priority_to_int(log->priority);
if (!lxc_loglevel_specified) {
lxc_log_category_lxc.priority = lxc_priority;
}
if (!lxc_quiet_specified) {
- if (!quiet)
+ if (!log->quiet)
lxc_log_category_lxc.appender->next = &log_appender_stderr;
}
- if (prefix)
- lxc_log_set_prefix(prefix);
+ if (log->prefix)
+ lxc_log_set_prefix(log->prefix);
- if (name)
- log_vmname = strdup(name);
+ if (log->name)
+ log_vmname = strdup(log->name);
- if (file) {
- if (strcmp(file, "none") == 0)
+ if (log->file) {
+ if (strcmp(log->file, "none") == 0)
return 0;
- ret = __lxc_log_set_file(file, 1);
+ ret = __lxc_log_set_file(log->file, 1);
lxc_log_use_global_fd = 1;
} else {
/* if no name was specified, there nothing to do */
- if (!name)
+ if (!log->name)
return 0;
ret = -1;
- if (!lxcpath)
- lxcpath = LOGPATH;
+ if (!log->lxcpath)
+ log->lxcpath = LOGPATH;
/* try LOGPATH if lxcpath is the default for the privileged containers */
- if (!geteuid() && strcmp(LXCPATH, lxcpath) == 0)
- ret = _lxc_log_set_file(name, NULL, 0);
+ if (!geteuid() && strcmp(LXCPATH, log->lxcpath) == 0)
+ ret = _lxc_log_set_file(log->name, NULL, 0);
/* try in lxcpath */
if (ret < 0)
- ret = _lxc_log_set_file(name, lxcpath, 1);
+ ret = _lxc_log_set_file(log->name, log->lxcpath, 1);
/* try LOGPATH in case its writable by the caller */
if (ret < 0)
- ret = _lxc_log_set_file(name, NULL, 0);
+ ret = _lxc_log_set_file(log->name, NULL, 0);
}
/*
* If !file, that is, if the user did not request this logpath, then
* ignore failures and continue logging to console
*/
- if (!file && ret != 0) {
+ if (!log->file && ret != 0) {
INFO("Ignoring failure to open default logfile.");
ret = 0;
}
extern int lxc_log_fd;
-extern int lxc_log_init(const char *name, const char *file,
- const char *priority, const char *prefix, int quiet,
- const char *lxcpath);
-
extern int lxc_log_set_file(int *fd, const char *fname);
extern int lxc_log_syslog(int facility);
extern void lxc_log_enable_syslog(void);
#include "mainloop.h"
#include "monitor.h"
#include "utils.h"
+#include "lxccontainer.h"
#define CLIENTFDS_CHUNK 64
char *lxcpath = argv[1];
bool mainloop_opened = false;
bool monitord_created = false;
+ struct lxc_log log;
if (argc != 3) {
fprintf(stderr,
if (ret < 0 || ret >= sizeof(logpath))
exit(EXIT_FAILURE);
- ret = lxc_log_init(NULL, logpath, "DEBUG", "lxc-monitord", 0, lxcpath);
+ log.name = NULL;
+ log.file = logpath;
+ log.priority = "DEBUG";
+ log.prefix = "lxc-monitord";
+ log.quiet = 0;
+ log.lxcpath = lxcpath;
+ ret = lxc_log_init(&log);
if (ret)
INFO("Failed to open log file %s, log will be lost.", lxcpath);
lxc_log_options_no_override();
*/
int list_all_containers(const char *lxcpath, char ***names, struct lxc_container ***cret);
+struct lxc_log {
+ const char *name;
+ const char *lxcpath;
+ const char *file;
+ const char *priority;
+ const char *prefix;
+ bool quiet;
+};
+
+/*!
+ *\brief Initialize the log
+ *
+ *\param log lxc log configuration.
+ */
+int lxc_log_init(struct lxc_log *log);
+
/*!
* \brief Close log file.
*/
{
int ret = -1, r;
int wexit = 0;
+ struct lxc_log log;
pid_t pid;
lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT;
lxc_attach_command_t command = (lxc_attach_command_t){.program = NULL};
if (!my_args.log_file)
my_args.log_file = "none";
- r = lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]);
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = 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)
exit(EXIT_FAILURE);
lxc_log_options_no_override();
struct lxc_container **containers = NULL;
struct lxc_list **c_groups_lists = NULL;
struct lxc_list *cmd_group;
+ struct lxc_log log;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
{
char *state_object = NULL, *value = NULL;
struct lxc_container *c;
+ struct lxc_log log;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
bool ret;
if (lxc_arguments_parse(&my_args, argc, argv))
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
{
int ret;
struct lxc_container *c;
+ struct lxc_log log;
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
if (!my_args.log_file)
my_args.log_file = "none";
- ret = lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]);
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ ret = lxc_log_init(&log);
if (ret)
return EXIT_FAILURE;
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
int flags = 0;
int ret = EXIT_FAILURE;
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(ret);
lxc_log_options_no_override();
{
struct lxc_container *c;
struct bdev_specs spec;
+ struct lxc_log log;
int flags = 0;
if (lxc_arguments_parse(&my_args, argc, argv))
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
bool bret;
if (lxc_arguments_parse(&my_args, argc, argv))
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
if (my_args.quiet)
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
char *cmd, *dev_name, *dst_name;
bool ret = false;
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
goto err;
lxc_log_options_no_override();
#include "config.h"
#include "start.h"
#include "utils.h"
+#include "lxccontainer.h"
lxc_log_define(lxc_execute_ui, lxc);
{
char *rcfile;
struct lxc_conf *conf;
+ struct lxc_log log;
int ret;
lxc_list_init(&defines);
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
int ret = EXIT_FAILURE;
+ struct lxc_log log;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(ret);
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(ret);
lxc_log_options_no_override();
#include "caps.h"
#include "error.h"
#include "initutils.h"
+#include "lxccontainer.h"
lxc_log_define(lxc_init, lxc);
int i, have_status = 0, shutdown = 0;
int opt;
char *lxcpath = NULL, *name = NULL, *logpriority = NULL;
+ struct lxc_log log;
while ((opt = getopt_long(argc, argv, "n:l:qP:", options, NULL)) != -1) {
switch(opt) {
break;
case 'q':
quiet = 1;
- break;
+ break;
case 'P':
lxcpath = optarg;
break;
}
}
- err = lxc_log_init(name, name ? NULL : "none", logpriority,
- basename(argv[0]), quiet, lxcpath);
+ log.name = name;
+ log.file = name ? NULL : "none";
+ log.priority = logpriority;
+ log.prefix = basename(argv[0]);
+ log.quiet = quiet;
+ log.lxcpath = lxcpath;
+
+ err = lxc_log_init(&log);
if (err < 0)
exit(EXIT_FAILURE);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
int ret = EXIT_FAILURE;
+ struct lxc_log log;
/*
* The lxc parser requires that my_args.name is set. So let's satisfy
* that condition by setting a dummy name which is never used.
* 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.
*/
- if (lxc_log_init(NULL, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = NULL;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
#include "log.h"
#include "monitor.h"
#include "arguments.h"
+#include "lxccontainer.h"
lxc_log_define(lxc_monitor_ui, lxc);
struct pollfd *fds;
nfds_t nfds;
int len, rc_main, rc_snp, i;
+ struct lxc_log log;
rc_main = EXIT_FAILURE;
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(rc_main);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
int ret;
if (lxc_arguments_parse(&my_args, argc, argv))
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
{
int err = EXIT_FAILURE;
struct lxc_conf *conf;
+ struct lxc_log log;
char *const *args;
char *rcfile = NULL;
char *const default_args[] = {
else
args = my_args.argv;
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(err);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
bool s;
int ret = EXIT_FAILURE;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(ret);
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(ret);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();
int main(int argc, char *argv[])
{
struct lxc_container *c;
+ struct lxc_log log;
if (lxc_arguments_parse(&my_args, argc, argv))
exit(EXIT_FAILURE);
if (!my_args.log_file)
my_args.log_file = "none";
- if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
- my_args.progname, my_args.quiet, my_args.lxcpath[0]))
+ log.name = my_args.name;
+ log.file = my_args.log_file;
+ log.priority = my_args.log_priority;
+ log.prefix = my_args.progname;
+ log.quiet = my_args.quiet;
+ log.lxcpath = my_args.lxcpath[0];
+
+ if (lxc_log_init(&log))
exit(EXIT_FAILURE);
lxc_log_options_no_override();