util: simplify proc_cmdline() to reuse get_process_cmdline()
Also, make all parsing of the kernel cmdline non-fatal.
This commit is contained in:
parent
f2997962ff
commit
b5884878a2
|
@ -47,7 +47,7 @@ static void systemd_kmod_log(
|
||||||
static bool cmdline_check_kdbus(void) {
|
static bool cmdline_check_kdbus(void) {
|
||||||
_cleanup_free_ char *line = NULL;
|
_cleanup_free_ char *line = NULL;
|
||||||
|
|
||||||
if (proc_cmdline(&line) <= 0)
|
if (proc_cmdline(&line) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return strstr(line, "kdbus") != NULL;
|
return strstr(line, "kdbus") != NULL;
|
||||||
|
|
|
@ -1402,9 +1402,11 @@ int main(int argc, char *argv[]) {
|
||||||
if (parse_config_file() < 0)
|
if (parse_config_file() < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
if (arg_running_as == SYSTEMD_SYSTEM)
|
if (arg_running_as == SYSTEMD_SYSTEM) {
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
goto finish;
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
|
}
|
||||||
|
|
||||||
/* Note that this also parses bits from the kernel command
|
/* Note that this also parses bits from the kernel command
|
||||||
* line, including "debug". */
|
* line, including "debug". */
|
||||||
|
|
|
@ -308,7 +308,7 @@ int main(int argc, char *argv[]) {
|
||||||
_cleanup_strv_free_ char **disks_done = NULL;
|
_cleanup_strv_free_ char **disks_done = NULL;
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
unsigned n = 0;
|
unsigned n = 0;
|
||||||
int r = EXIT_FAILURE, r2 = EXIT_FAILURE;
|
int r = EXIT_FAILURE, r2 = EXIT_FAILURE, z;
|
||||||
char **i;
|
char **i;
|
||||||
|
|
||||||
if (argc > 1 && argc != 4) {
|
if (argc > 1 && argc != 4) {
|
||||||
|
@ -325,8 +325,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
z = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
goto cleanup;
|
if (z < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-z));
|
||||||
|
|
||||||
if (!arg_enabled) {
|
if (!arg_enabled) {
|
||||||
r = r2 = EXIT_SUCCESS;
|
r = r2 = EXIT_SUCCESS;
|
||||||
|
|
|
@ -150,8 +150,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
return EXIT_FAILURE;
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
|
|
||||||
if (arg_debug_shell) {
|
if (arg_debug_shell) {
|
||||||
r = strv_extend(&arg_wants, "debug-shell.service");
|
r = strv_extend(&arg_wants, "debug-shell.service");
|
||||||
|
|
|
@ -236,7 +236,10 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
parse_proc_cmdline(parse_proc_cmdline_item);
|
q = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
|
if (q < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-q));
|
||||||
|
|
||||||
test_files();
|
test_files();
|
||||||
|
|
||||||
if (!arg_force && arg_skip)
|
if (!arg_force && arg_skip)
|
||||||
|
|
|
@ -593,8 +593,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
return EXIT_FAILURE;
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
|
|
||||||
/* Always honour root= and usr= in the kernel command line if we are in an initrd */
|
/* Always honour root= and usr= in the kernel command line if we are in an initrd */
|
||||||
if (in_initrd()) {
|
if (in_initrd()) {
|
||||||
|
|
|
@ -772,8 +772,9 @@ int main(int argc, char *argv[]) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
return EXIT_FAILURE;
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
|
|
||||||
if (!arg_enabled) {
|
if (!arg_enabled) {
|
||||||
log_debug("Disabled, exiting.");
|
log_debug("Disabled, exiting.");
|
||||||
|
|
|
@ -45,6 +45,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
|
||||||
static int process_resume(void) {
|
static int process_resume(void) {
|
||||||
_cleanup_free_ char *name = NULL, *lnk = NULL;
|
_cleanup_free_ char *name = NULL, *lnk = NULL;
|
||||||
|
|
||||||
|
if (!arg_resume_dev)
|
||||||
|
return 0;
|
||||||
|
|
||||||
name = unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_dev, ".service");
|
name = unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_dev, ".service");
|
||||||
if (!name)
|
if (!name)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
@ -83,12 +86,11 @@ int main(int argc, char *argv[]) {
|
||||||
if (!in_initrd())
|
if (!in_initrd())
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
return EXIT_FAILURE;
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
if (arg_resume_dev != NULL)
|
|
||||||
r = process_resume();
|
|
||||||
|
|
||||||
|
r = process_resume();
|
||||||
free(arg_resume_dev);
|
free(arg_resume_dev);
|
||||||
|
|
||||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
|
|
|
@ -1310,10 +1310,10 @@ static int server_parse_proc_cmdline(Server *s) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = proc_cmdline(&line);
|
r = proc_cmdline(&line);
|
||||||
if (r < 0)
|
if (r < 0) {
|
||||||
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
||||||
if (r <= 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(w, l, line, state) {
|
FOREACH_WORD_QUOTED(w, l, line, state) {
|
||||||
_cleanup_free_ char *word;
|
_cleanup_free_ char *word;
|
||||||
|
|
|
@ -243,8 +243,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
return EXIT_FAILURE;
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
|
|
||||||
ctx = kmod_new(NULL, NULL);
|
ctx = kmod_new(NULL, NULL);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
|
|
|
@ -74,6 +74,7 @@ int main(int argc, char *argv[]) {
|
||||||
};
|
};
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
log_error("This program takes no arguments.");
|
log_error("This program takes no arguments.");
|
||||||
|
@ -86,7 +87,10 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
umask(0022);
|
umask(0022);
|
||||||
|
|
||||||
parse_proc_cmdline(parse_proc_cmdline_item);
|
r = parse_proc_cmdline(parse_proc_cmdline_item);
|
||||||
|
if (r < 0)
|
||||||
|
log_warning("Failed to parse kernel command line, ignoring: %s", strerror(-r));
|
||||||
|
|
||||||
test_files();
|
test_files();
|
||||||
|
|
||||||
if (!arg_force) {
|
if (!arg_force) {
|
||||||
|
@ -107,5 +111,7 @@ int main(int argc, char *argv[]) {
|
||||||
_exit(1); /* Operational error */
|
_exit(1); /* Operational error */
|
||||||
}
|
}
|
||||||
|
|
||||||
return wait_for_terminate_and_warn("quotacheck", pid) >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
r = wait_for_terminate_and_warn("quotacheck", pid);
|
||||||
|
|
||||||
|
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,8 +93,6 @@ static int condition_test_kernel_command_line(Condition *c) {
|
||||||
r = proc_cmdline(&line);
|
r = proc_cmdline(&line);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
equal = !!strchr(c->parameter, '=');
|
equal = !!strchr(c->parameter, '=');
|
||||||
p = line;
|
p = line;
|
||||||
|
|
|
@ -6153,11 +6153,8 @@ int shall_restore_state(void) {
|
||||||
r = proc_cmdline(&line);
|
r = proc_cmdline(&line);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r == 0) /* Container ... */
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(word, l, line, state) {
|
FOREACH_WORD_QUOTED(word, l, line, state) {
|
||||||
const char *e;
|
const char *e;
|
||||||
char n[l+1];
|
char n[l+1];
|
||||||
|
@ -6179,30 +6176,12 @@ int shall_restore_state(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int proc_cmdline(char **ret) {
|
int proc_cmdline(char **ret) {
|
||||||
int r;
|
assert(ret);
|
||||||
|
|
||||||
if (detect_container(NULL) > 0) {
|
if (detect_container(NULL) > 0)
|
||||||
char *buf = NULL, *p;
|
return get_process_cmdline(1, 0, false, ret);
|
||||||
size_t sz = 0;
|
else
|
||||||
|
return read_one_line_file("/proc/cmdline", ret);
|
||||||
r = read_full_file("/proc/1/cmdline", &buf, &sz);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
for (p = buf; p + 1 < buf + sz; p++)
|
|
||||||
if (*p == 0)
|
|
||||||
*p = ' ';
|
|
||||||
|
|
||||||
*p = 0;
|
|
||||||
*ret = buf;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = read_one_line_file("/proc/cmdline", ret);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) {
|
int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) {
|
||||||
|
@ -6215,9 +6194,7 @@ int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) {
|
||||||
|
|
||||||
r = proc_cmdline(&line);
|
r = proc_cmdline(&line);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
return r;
|
||||||
if (r <= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(w, l, line, state) {
|
FOREACH_WORD_QUOTED(w, l, line, state) {
|
||||||
char word[l+1], *value;
|
char word[l+1], *value;
|
||||||
|
|
|
@ -174,11 +174,10 @@ static bool enable_name_policy(void) {
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
r = proc_cmdline(&line);
|
r = proc_cmdline(&line);
|
||||||
if (r < 0)
|
if (r < 0) {
|
||||||
log_warning("Failed to read /proc/cmdline, ignoring: %s",
|
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
||||||
strerror(-r));
|
|
||||||
if (r <= 0)
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(word, l, line, state)
|
FOREACH_WORD_QUOTED(word, l, line, state)
|
||||||
if (strneq(word, "net.ifnames=0", l))
|
if (strneq(word, "net.ifnames=0", l))
|
||||||
|
|
|
@ -961,10 +961,10 @@ static void kernel_cmdline_options(struct udev *udev) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = proc_cmdline(&line);
|
r = proc_cmdline(&line);
|
||||||
if (r < 0)
|
if (r < 0) {
|
||||||
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
||||||
if (r <= 0)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(word, l, line, state) {
|
FOREACH_WORD_QUOTED(word, l, line, state) {
|
||||||
char *s, *opt, *value;
|
char *s, *opt, *value;
|
||||||
|
|
Loading…
Reference in New Issue