basic/proc-cmdline: allow parsing of cmdline from a string

Comes with tests.

Also add direct test for $SYSTEMD_PROC_CMDLINE.

In test-proc-cmdline, "true" was masquerading as PROC_CMDLINE_STRIP_RD_PREFIX,
fix that. Also, reorder functions to match call order.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-10-08 17:05:19 +02:00
parent 1af294fc82
commit 9a135c084a
3 changed files with 95 additions and 20 deletions
+14 -6
View File
@@ -39,17 +39,12 @@ int proc_cmdline(char **ret) {
return read_one_line_file("/proc/cmdline", ret);
}
int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, unsigned flags) {
_cleanup_free_ char *line = NULL;
int proc_cmdline_parse_given(const char *line, proc_cmdline_parse_t parse_item, void *data, unsigned flags) {
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;
@@ -85,6 +80,19 @@ int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, unsigned fla
return 0;
}
int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, unsigned flags) {
_cleanup_free_ char *line = NULL;
int r;
assert(parse_item);
r = proc_cmdline(&line);
if (r < 0)
return r;
return proc_cmdline_parse_given(line, parse_item, data, flags);
}
static bool relaxed_equal_char(char a, char b) {
return a == b ||
(a == '_' && b == '-') ||