diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-27 00:06:29 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-27 13:25:57 +0100 |
commit | 4e731273edfe852a3eee2949cd20f49fd5b4f6d7 (patch) | |
tree | 3e728dfbf3fdfd51261e4b7c2aa6c7b057f0ced6 | |
parent | util-lib: move is_main_thread() to process-util.[ch] (diff) | |
download | systemd-4e731273edfe852a3eee2949cd20f49fd5b4f6d7.tar.xz systemd-4e731273edfe852a3eee2949cd20f49fd5b4f6d7.zip |
util-lib: move /proc/cmdline parsing code to proc-cmdline.[ch]
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/backlight/backlight.c | 3 | ||||
-rw-r--r-- | src/basic/cgroup-util.c | 1 | ||||
-rw-r--r-- | src/basic/log.c | 3 | ||||
-rw-r--r-- | src/basic/proc-cmdline.c | 144 | ||||
-rw-r--r-- | src/basic/proc-cmdline.h | 28 | ||||
-rw-r--r-- | src/basic/util.c | 114 | ||||
-rw-r--r-- | src/basic/util.h | 6 | ||||
-rw-r--r-- | src/core/main.c | 1 | ||||
-rw-r--r-- | src/cryptsetup/cryptsetup-generator.c | 1 | ||||
-rw-r--r-- | src/debug-generator/debug-generator.c | 9 | ||||
-rw-r--r-- | src/fsck/fsck.c | 1 | ||||
-rw-r--r-- | src/fstab-generator/fstab-generator.c | 1 | ||||
-rw-r--r-- | src/gpt-auto-generator/gpt-auto-generator.c | 1 | ||||
-rw-r--r-- | src/hibernate-resume/hibernate-resume-generator.c | 1 | ||||
-rw-r--r-- | src/journal/journald-server.c | 1 | ||||
-rw-r--r-- | src/modules-load/modules-load.c | 1 | ||||
-rw-r--r-- | src/quotacheck/quotacheck.c | 1 | ||||
-rw-r--r-- | src/rfkill/rfkill.c | 1 | ||||
-rw-r--r-- | src/shared/bus-util.c | 1 | ||||
-rw-r--r-- | src/shared/condition.c | 1 | ||||
-rw-r--r-- | src/test/test-util.c | 1 | ||||
-rw-r--r-- | src/udev/net/link-config.c | 1 | ||||
-rw-r--r-- | src/udev/udevd.c | 1 |
24 files changed, 199 insertions, 126 deletions
diff --git a/Makefile.am b/Makefile.am index d435141492..549ac014e3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -799,6 +799,8 @@ libbasic_la_SOURCES = \ src/basic/xattr-util.h \ src/basic/chattr-util.c \ src/basic/chattr-util.h \ + src/basic/proc-cmdline.c \ + src/basic/proc-cmdline.h \ src/basic/fs-util.c \ src/basic/fs-util.h \ src/basic/stat-util.c \ diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 6a2d04ef13..9112ed328d 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -25,10 +25,11 @@ #include "escape.h" #include "fileio.h" #include "mkdir.h" +#include "parse-util.h" +#include "proc-cmdline.h" #include "string-util.h" #include "udev-util.h" #include "util.h" -#include "parse-util.h" static struct udev_device *find_pci_or_platform_parent(struct udev_device *device) { struct udev_device *parent; diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index d416b0b41e..cfbeab7411 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -49,6 +49,7 @@ #include "unit-name.h" #include "user-util.h" #include "util.h" +#include "proc-cmdline.h" int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) { _cleanup_free_ char *fs = NULL; diff --git a/src/basic/log.c b/src/basic/log.c index dcb24cfab7..d0db77eca0 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -36,6 +36,8 @@ #include "log.h" #include "macro.h" #include "missing.h" +#include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "signal-util.h" #include "socket-util.h" @@ -43,7 +45,6 @@ #include "string-util.h" #include "terminal-util.h" #include "util.h" -#include "parse-util.h" #define SNDBUF_SIZE (8*1024*1024) diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c new file mode 100644 index 0000000000..dd0e18ed6e --- /dev/null +++ b/src/basic/proc-cmdline.c @@ -0,0 +1,144 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include "extract-word.h" +#include "fileio.h" +#include "macro.h" +#include "parse-util.h" +#include "proc-cmdline.h" +#include "process-util.h" +#include "string-util.h" +#include "util.h" +#include "virt.h" + +int proc_cmdline(char **ret) { + assert(ret); + + if (detect_container() > 0) + return get_process_cmdline(1, 0, false, ret); + else + return read_one_line_file("/proc/cmdline", ret); +} + +int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) { + _cleanup_free_ char *line = NULL; + const char *p; + int r; + + assert(parse_item); + + r = proc_cmdline(&line); + if (r < 0) + return r; + + p = line; + for (;;) { + _cleanup_free_ char *word = NULL; + char *value = NULL; + + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); + if (r < 0) + return r; + if (r == 0) + break; + + /* Filter out arguments that are intended only for the + * initrd */ + if (!in_initrd() && startswith(word, "rd.")) + continue; + + value = strchr(word, '='); + if (value) + *(value++) = 0; + + r = parse_item(word, value); + if (r < 0) + return r; + } + + return 0; +} + +int get_proc_cmdline_key(const char *key, char **value) { + _cleanup_free_ char *line = NULL, *ret = NULL; + bool found = false; + const char *p; + int r; + + assert(key); + + r = proc_cmdline(&line); + if (r < 0) + return r; + + p = line; + for (;;) { + _cleanup_free_ char *word = NULL; + const char *e; + + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); + if (r < 0) + return r; + if (r == 0) + break; + + /* Filter out arguments that are intended only for the + * initrd */ + if (!in_initrd() && startswith(word, "rd.")) + continue; + + if (value) { + e = startswith(word, key); + if (!e) + continue; + + r = free_and_strdup(&ret, e); + if (r < 0) + return r; + + found = true; + } else { + if (streq(word, key)) + found = true; + } + } + + if (value) { + *value = ret; + ret = NULL; + } + + return found; + +} + +int shall_restore_state(void) { + _cleanup_free_ char *value = NULL; + int r; + + r = get_proc_cmdline_key("systemd.restore_state=", &value); + if (r < 0) + return r; + if (r == 0) + return true; + + return parse_boolean(value) != 0; +} diff --git a/src/basic/proc-cmdline.h b/src/basic/proc-cmdline.h new file mode 100644 index 0000000000..ea8277b053 --- /dev/null +++ b/src/basic/proc-cmdline.h @@ -0,0 +1,28 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +int proc_cmdline(char **ret); +int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value)); +int get_proc_cmdline_key(const char *parameter, char **value); + +int shall_restore_state(void); diff --git a/src/basic/util.c b/src/basic/util.c index 6fe4f47018..66bb00b982 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -963,120 +963,6 @@ bool id128_is_valid(const char *s) { return true; } -int shall_restore_state(void) { - _cleanup_free_ char *value = NULL; - int r; - - r = get_proc_cmdline_key("systemd.restore_state=", &value); - if (r < 0) - return r; - if (r == 0) - return true; - - return parse_boolean(value) != 0; -} - -int proc_cmdline(char **ret) { - assert(ret); - - if (detect_container() > 0) - return get_process_cmdline(1, 0, false, ret); - else - return read_one_line_file("/proc/cmdline", ret); -} - -int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) { - _cleanup_free_ char *line = NULL; - const char *p; - int r; - - assert(parse_item); - - r = proc_cmdline(&line); - if (r < 0) - return r; - - p = line; - for (;;) { - _cleanup_free_ char *word = NULL; - char *value = NULL; - - r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); - if (r < 0) - return r; - if (r == 0) - break; - - /* Filter out arguments that are intended only for the - * initrd */ - if (!in_initrd() && startswith(word, "rd.")) - continue; - - value = strchr(word, '='); - if (value) - *(value++) = 0; - - r = parse_item(word, value); - if (r < 0) - return r; - } - - return 0; -} - -int get_proc_cmdline_key(const char *key, char **value) { - _cleanup_free_ char *line = NULL, *ret = NULL; - bool found = false; - const char *p; - int r; - - assert(key); - - r = proc_cmdline(&line); - if (r < 0) - return r; - - p = line; - for (;;) { - _cleanup_free_ char *word = NULL; - const char *e; - - r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); - if (r < 0) - return r; - if (r == 0) - break; - - /* Filter out arguments that are intended only for the - * initrd */ - if (!in_initrd() && startswith(word, "rd.")) - continue; - - if (value) { - e = startswith(word, key); - if (!e) - continue; - - r = free_and_strdup(&ret, e); - if (r < 0) - return r; - - found = true; - } else { - if (streq(word, key)) - found = true; - } - } - - if (value) { - *value = ret; - ret = NULL; - } - - return found; - -} - int container_get_leader(const char *machine, pid_t *pid) { _cleanup_free_ char *s = NULL, *class = NULL; const char *p; diff --git a/src/basic/util.h b/src/basic/util.h index 96be6ecaa8..2ebb275494 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -288,8 +288,6 @@ static inline unsigned log2u_round_up(unsigned x) { bool id128_is_valid(const char *s) _pure_; -int shall_restore_state(void); - /** * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. @@ -302,10 +300,6 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_ qsort(base, nmemb, size, compar); } -int proc_cmdline(char **ret); -int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value)); -int get_proc_cmdline_key(const char *parameter, char **value); - int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd); diff --git a/src/core/main.c b/src/core/main.c index fd8ad0c0ea..dbe774b14d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -69,6 +69,7 @@ #include "mount-setup.h" #include "pager.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "rlimit-util.h" #include "selinux-setup.h" diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 768d59c8df..54a89452a3 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -31,6 +31,7 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index 115f99e68c..1a98cbaef8 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -19,12 +19,13 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "util.h" -#include "strv.h" -#include "unit-name.h" #include "mkdir.h" -#include "string-util.h" #include "parse-util.h" +#include "proc-cmdline.h" +#include "string-util.h" +#include "strv.h" +#include "unit-name.h" +#include "util.h" static const char *arg_dest = "/tmp"; static char **arg_mask = NULL; diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 590ffafef6..45c24b2fcf 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -40,6 +40,7 @@ #include "fs-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "signal-util.h" #include "socket-util.h" diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 64aa6db01a..a51ecd9f7a 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -35,6 +35,7 @@ #include "mount-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "special.h" #include "stat-util.h" #include "string-util.h" diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 8bdb6c7548..cc1bd3f50e 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -41,6 +41,7 @@ #include "mount-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "special.h" #include "stat-util.h" #include "string-util.h" diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c index da7d33508d..8c3a09501f 100644 --- a/src/hibernate-resume/hibernate-resume-generator.c +++ b/src/hibernate-resume/hibernate-resume-generator.c @@ -25,6 +25,7 @@ #include "fstab-util.h" #include "log.h" #include "mkdir.h" +#include "proc-cmdline.h" #include "special.h" #include "string-util.h" #include "unit-name.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 442fbb8ecd..32d1f36821 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -58,6 +58,7 @@ #include "missing.h" #include "mkdir.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "rm-rf.h" #include "selinux-util.h" diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 5627e63938..830ca7b89d 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -30,6 +30,7 @@ #include "fd-util.h" #include "fileio.h" #include "log.h" +#include "proc-cmdline.h" #include "string-util.h" #include "strv.h" #include "util.h" diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index a2a035f4f1..dc2911e4e8 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -29,6 +29,7 @@ #include "signal-util.h" #include "string-util.h" #include "util.h" +#include "proc-cmdline.h" static bool arg_skip = false; static bool arg_force = false; diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index c08b746f2c..5ba1e3d4a8 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -31,6 +31,7 @@ #include "io-util.h" #include "mkdir.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "string-table.h" #include "string-util.h" #include "udev-util.h" diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 724103fc3f..9fcc61dbd2 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -47,6 +47,7 @@ #include "unit-name.h" #include "utf8.h" #include "util.h" +#include "proc-cmdline.h" static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { sd_event *e = userdata; diff --git a/src/shared/condition.c b/src/shared/condition.c index a11054e316..d06120f0d7 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -39,6 +39,7 @@ #include "mount-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "selinux-util.h" #include "smack-util.h" #include "stat-util.h" diff --git a/src/test/test-util.c b/src/test/test-util.c index d339bc686f..a020b33e75 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -44,6 +44,7 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "rm-rf.h" #include "signal-util.h" diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index db4fe0c855..972841b6d9 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -36,6 +36,7 @@ #include "network-internal.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "random-util.h" #include "stat-util.h" #include "string-table.h" diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 90e1de7b7a..2dcdef9918 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -55,6 +55,7 @@ #include "io-util.h" #include "netlink-util.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "selinux-util.h" #include "signal-util.h" |