/* * lxc_log_init: * 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) { int lxc_priority = LXC_LOG_PRIORITY_ERROR; int ret; if (lxc_log_fd != -1) { WARN("lxc_log_init called with log already initialized"); return 0; } if (priority) lxc_priority = lxc_log_priority_to_int(priority); if (!lxc_loglevel_specified) { lxc_log_category_lxc.priority = lxc_priority; lxc_loglevel_specified = 1; } if (!lxc_quiet_specified) { if (!quiet) lxc_log_category_lxc.appender->next = &log_appender_stderr; } if (prefix) lxc_log_set_prefix(prefix); if (file) { if (strcmp(file, "none") == 0) return 0; ret = __lxc_log_set_file(file, 1); lxc_log_use_global_fd = 1; } else { /* if no name was specified, there nothing to do */ if (!name) return 0; ret = -1; if (!lxcpath) 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); /* try in lxcpath */ if (ret < 0) ret = _lxc_log_set_file(name, lxcpath, 1); /* try LOGPATH in case its writable by the caller */ if (ret < 0) ret = _lxc_log_set_file(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) { INFO("Ignoring failure to open default logfile."); ret = 0; } return ret; }
extern int lxc_log_init(const char *name, const char *file, const char *priority, const char *prefix, int quiet, const char *lxcpath) { int lxc_priority = LXC_LOG_PRIORITY_ERROR; int ret; if (lxc_log_fd != -1) { WARN("lxc_log_init called with log already initialized"); return 0; } if (priority) { if (lxc_priority == LXC_LOG_PRIORITY_NOTSET) { ERROR("invalid log priority %s", priority); return -1; } lxc_loglevel_specified = 1; lxc_priority = lxc_log_priority_to_int(priority); } lxc_log_category_lxc.priority = lxc_priority; lxc_log_category_lxc.appender = &log_appender_logfile; if (!quiet) lxc_log_category_lxc.appender->next = &log_appender_stderr; if (prefix) lxc_log_set_prefix(prefix); if (file) { if (strcmp(file, "none") == 0) return 0; lxc_logfile_specified = 1; ret = __lxc_log_set_file(file, 1); } else { ret = -1; if (!lxcpath) lxcpath = LOGPATH; /* try LOGPATH if lxcpath is the default */ if (strcmp(lxcpath, default_lxc_path()) == 0) ret = _lxc_log_set_file(name, NULL, 0); /* try in lxcpath */ if (ret < 0) ret = _lxc_log_set_file(name, lxcpath, 1); /* try LOGPATH in case its writable by the caller */ if (ret < 0) ret = _lxc_log_set_file(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) { INFO("Ignoring failure to open default logfile."); ret = 0; } return ret; }