]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: move /proc/cmdline parsing code to proc-cmdline.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 23:06:29 +0000 (00:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:57 +0000 (13:25 +0100)
24 files changed:
Makefile.am
src/backlight/backlight.c
src/basic/cgroup-util.c
src/basic/log.c
src/basic/proc-cmdline.c [new file with mode: 0644]
src/basic/proc-cmdline.h [new file with mode: 0644]
src/basic/util.c
src/basic/util.h
src/core/main.c
src/cryptsetup/cryptsetup-generator.c
src/debug-generator/debug-generator.c
src/fsck/fsck.c
src/fstab-generator/fstab-generator.c
src/gpt-auto-generator/gpt-auto-generator.c
src/hibernate-resume/hibernate-resume-generator.c
src/journal/journald-server.c
src/modules-load/modules-load.c
src/quotacheck/quotacheck.c
src/rfkill/rfkill.c
src/shared/bus-util.c
src/shared/condition.c
src/test/test-util.c
src/udev/net/link-config.c
src/udev/udevd.c

index d435141492c6966d3477898653c79109e36175ce..549ac014e3d5c0db7b19c57c20c7f9afe1b14b65 100644 (file)
@@ -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 \
index 6a2d04ef13f88cfe34f5b064ea1b43e5a10009b0..9112ed328d9f8fd2d486d53e905efe5718391105 100644 (file)
 #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;
index d416b0b41e2ff39f6db63fd248b3d4dbe32e0575..cfbeab741104862ed73d1b4f94b544083704fe26 100644 (file)
@@ -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;
index dcb24cfab78e41db00792ae98dcd850eb78ce2fe..d0db77eca0ab978b8b069e963a24cd10f96e6ff5 100644 (file)
@@ -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 (file)
index 0000000..dd0e18e
--- /dev/null
@@ -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 (file)
index 0000000..ea8277b
--- /dev/null
@@ -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);
index 6fe4f47018f8f3fc2ea7e9646cde2ac5372682f3..66bb00b98264373aeb8433387b93c30cbff3e120 100644 (file)
@@ -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;
index 96be6ecaa855bdc7f35702d4bb454d511ec912ef..2ebb2754943434df77b57610a89005ed1c28f3cd 100644 (file)
@@ -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);
index fd8ad0c0eacc54eabff04c96227b1937086c81c2..dbe774b14d24563e69ca6139122303d46b0a2ebe 100644 (file)
@@ -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"
index 768d59c8df238d0b5a41499ec2f606a25ba40922..54a89452a356e94eb38856281092e71261751b3a 100644 (file)
@@ -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"
index 115f99e68caf14d841eaa6bcb5bb9690b5a3cc85..1a98cbaef872985471d0bfc0e09d710ece79ec1c 100644 (file)
   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;
index 590ffafef68bc8bb692bc6ab5567743a6aab0b59..45c24b2fcf6ea95f814aaed05fea9e9c64f14b35 100644 (file)
@@ -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"
index 64aa6db01a53aa1f0d96be1aeb25bdb729f575fc..a51ecd9f7a5ed6ebb13d6c4d5585acf72ad34db4 100644 (file)
@@ -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"
index 8bdb6c7548158e31c26c82ae31709962729b20fe..cc1bd3f50eb29046102c7abe43e5c0aa6b9389ad 100644 (file)
@@ -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"
index da7d33508dc2de9af5dbccf6ad433a181777e039..8c3a09501f00befba09a7a1c622ccb309ffd247e 100644 (file)
@@ -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"
index 442fbb8ecd3258a6f482c0ddc2f052713ca6b8c1..32d1f36821052e618d9ef6b976bc39d88f5d8018 100644 (file)
@@ -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"
index 5627e63938af4ab859793302b42640ba2b88695a..830ca7b89d13bc6dec7990102dcfc7c7644737aa 100644 (file)
@@ -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"
index a2a035f4f1e92eb5f658d8f69d9d07a72015a0df..dc2911e4e8b2558b8f779462838eb8f95be5ef60 100644 (file)
@@ -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;
index c08b746f2c8dd9019d9916990798c16d912f9856..5ba1e3d4a8c21b68c509d1cda519b951989aea8d 100644 (file)
@@ -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"
index 724103fc3f85b4bf4a35f0d447a5cb1e1760fc1b..9fcc61dbd22c730ab52fef37e8cac58b4e663fa6 100644 (file)
@@ -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;
index a11054e31662f40ec9087e307fdbe108b8667e04..d06120f0d754d23532575cb51d3c7a48f32f6407 100644 (file)
@@ -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"
index d339bc686f61517f5db39856c61c1b849bf7f471..a020b33e7509d803361be60dd8229635b33cbc21 100644 (file)
@@ -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"
index db4fe0c855353cd0d8ca575688c466aa5249856d..972841b6d9bb617b309026a7263421caa473bad9 100644 (file)
@@ -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"
index 90e1de7b7af846c475c295a075595260b9dcd8a7..2dcdef9918a99ac29a3c9a035138b16b6e1b7bd7 100644 (file)
@@ -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"