diff --git a/src/condition.c b/src/condition.c index 2b51a16..f50df1a 100644 --- a/src/condition.c +++ b/src/condition.c @@ -80,14 +80,10 @@ static bool test_kernel_command_line(const char *parameter) { assert(parameter); - if (detect_container(NULL) > 0) + if ((r = read_cmdline(&line)) < 0) return false; - - r = read_one_line_file("/proc/cmdline", &line); - if (r < 0) { - log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + if (!line) return false; - } equal = !!strchr(parameter, '='); pl = strlen(parameter); diff --git a/src/fsck.c b/src/fsck.c index d3ac83c..f55eb89 100644 --- a/src/fsck.c +++ b/src/fsck.c @@ -109,14 +109,11 @@ static int parse_proc_cmdline(void) { int r; size_t l; - if (detect_container(NULL) > 0) + if ((r = read_cmdline(&line)) < 0) + return r; + if (!line) return 0; - if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) { - log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); - return 0; - } - FOREACH_WORD_QUOTED(w, l, line, state) { if (strneq(w, "fsck.mode=auto", l)) diff --git a/src/main.c b/src/main.c index ed317b4..8c765bd 100644 --- a/src/main.c +++ b/src/main.c @@ -690,15 +690,10 @@ static int parse_proc_cmdline(void) { int r; size_t l; - /* Don't read /proc/cmdline if we are in a container, since - * that is only relevant for the host system */ - if (detect_container(NULL) > 0) - return 0; - - if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) { - log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + if ((r = read_cmdline(&line)) < 0) + goto finish; + if (!line) return 0; - } FOREACH_WORD_QUOTED(w, l, line, state) { char *word; diff --git a/src/quotacheck.c b/src/quotacheck.c index b6648b8..4673e3b 100644 --- a/src/quotacheck.c +++ b/src/quotacheck.c @@ -36,14 +36,11 @@ static int parse_proc_cmdline(void) { int r; size_t l; - if (detect_container(NULL) > 0) + if ((r = read_cmdline(&line)) < 0) + return r; + if (!line) return 0; - if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) { - log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); - return 0; - } - FOREACH_WORD_QUOTED(w, l, line, state) { if (strneq(w, "quotacheck.mode=auto", l)) diff --git a/src/util.c b/src/util.c index e9869ea..d6e3d22 100644 --- a/src/util.c +++ b/src/util.c @@ -66,6 +66,7 @@ #include "label.h" #include "exit-status.h" #include "hashmap.h" +#include "virt.h" int saved_argc = 0; char **saved_argv = NULL; @@ -806,6 +807,30 @@ finish: return r; } +int read_cmdline(char **line) +{ + int r; + *line = NULL; + /* Don't read /proc/cmdline if we are in a container, since + * that is only relevant for the host system */ + if (detect_container(NULL) > 0) { + char *v = getenv("LIBVIRT_LXC_CMDLINE"); + if (v && + !(*line = strdup(v))) { + r = -ENOMEM; + goto finish; + } + } else { + if ((r = read_one_line_file("/proc/cmdline", line)) < 0) { + log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + r = 0; + } + } + r = 0; + finish: + return r; +} + int parse_env_file( const char *fname, const char *separator, ...) { diff --git a/src/util.h b/src/util.h index 890a3b5..01ad46a 100644 --- a/src/util.h +++ b/src/util.h @@ -210,6 +210,8 @@ int write_one_line_file_atomic(const char *fn, const char *line); int read_one_line_file(const char *fn, char **line); int read_full_file(const char *fn, char **contents, size_t *size); +int read_cmdline(char **line); + int parse_env_file(const char *fname, const char *separator, ...) _sentinel_; int load_env_file(const char *fname, char ***l); int write_env_file(const char *fname, char **l);