]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/proc-cmdline.c
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 "string-util.h"
33 int proc_cmdline(char **ret
) {
36 if (detect_container() > 0)
37 return get_process_cmdline(1, 0, false, ret
);
39 return read_one_line_file("/proc/cmdline", ret
);
42 int parse_proc_cmdline(int (*parse_item
)(const char *key
, const char *value
)) {
43 _cleanup_free_
char *line
= NULL
;
49 r
= proc_cmdline(&line
);
55 _cleanup_free_
char *word
= NULL
;
58 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_RELAX
);
64 /* Filter out arguments that are intended only for the
66 if (!in_initrd() && startswith(word
, "rd."))
69 value
= strchr(word
, '=');
73 r
= parse_item(word
, value
);
81 int get_proc_cmdline_key(const char *key
, char **value
) {
82 _cleanup_free_
char *line
= NULL
, *ret
= NULL
;
89 r
= proc_cmdline(&line
);
95 _cleanup_free_
char *word
= NULL
;
98 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_RELAX
);
104 /* Filter out arguments that are intended only for the
106 if (!in_initrd() && startswith(word
, "rd."))
110 e
= startswith(word
, key
);
114 r
= free_and_strdup(&ret
, e
);
120 if (streq(word
, key
))
134 int shall_restore_state(void) {
135 _cleanup_free_
char *value
= NULL
;
138 r
= get_proc_cmdline_key("systemd.restore_state=", &value
);
144 return parse_boolean(value
) != 0;