1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
23 #include "extract-word.h"
26 #include "parse-util.h"
27 #include "proc-cmdline.h"
28 #include "process-util.h"
29 //#include "special.h"
30 #include "string-util.h"
34 int proc_cmdline(char **ret) {
37 if (detect_container() > 0)
38 return get_process_cmdline(1, 0, false, ret);
40 return read_one_line_file("/proc/cmdline", ret);
43 int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) {
44 _cleanup_free_ char *line = NULL;
50 r = proc_cmdline(&line);
56 _cleanup_free_ char *word = NULL;
59 r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
65 /* Filter out arguments that are intended only for the
67 if (!in_initrd() && startswith(word, "rd."))
70 value = strchr(word, '=');
74 r = parse_item(word, value);
82 int get_proc_cmdline_key(const char *key, char **value) {
83 _cleanup_free_ char *line = NULL, *ret = NULL;
90 r = proc_cmdline(&line);
96 _cleanup_free_ char *word = NULL;
99 r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
105 /* Filter out arguments that are intended only for the
107 if (!in_initrd() && startswith(word, "rd."))
111 e = startswith(word, key);
115 r = free_and_strdup(&ret, e);
121 if (streq(word, key))
135 #if 0 /// UNNEEDED by elogind
136 int shall_restore_state(void) {
137 _cleanup_free_ char *value = NULL;
140 r = get_proc_cmdline_key("systemd.restore_state=", &value);
146 return parse_boolean(value);
149 static const char * const rlmap[] = {
150 "emergency", SPECIAL_EMERGENCY_TARGET,
151 "-b", SPECIAL_EMERGENCY_TARGET,
152 "rescue", SPECIAL_RESCUE_TARGET,
153 "single", SPECIAL_RESCUE_TARGET,
154 "-s", SPECIAL_RESCUE_TARGET,
155 "s", SPECIAL_RESCUE_TARGET,
156 "S", SPECIAL_RESCUE_TARGET,
157 "1", SPECIAL_RESCUE_TARGET,
158 "2", SPECIAL_MULTI_USER_TARGET,
159 "3", SPECIAL_MULTI_USER_TARGET,
160 "4", SPECIAL_MULTI_USER_TARGET,
161 "5", SPECIAL_GRAPHICAL_TARGET,
164 const char* runlevel_to_target(const char *word) {
170 for (i = 0; i < ELEMENTSOF(rlmap); i += 2)
171 if (streq(word, rlmap[i]))