diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-02-15 18:08:59 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-02-17 02:26:22 -0500 |
commit | 141a79f491fd4bf5ea0d66039065c9f9649bfc0e (patch) | |
tree | 9e13ad2015007d047b195661d2945c603770bb98 /src/shared/util.c | |
parent | 8fe63cd4f16e1e7cdf528ff053f8eb4da7848455 (diff) |
Extract looping over /proc/cmdline into a shared function
In cryptsetup-generator automatic cleanup had to be replaced
with manual cleanup, and the code gets a bit longer. But existing
code had the issue that it returned negative values from main(),
which was wrong, so should be reworked anyway.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index b1a9db1d46..d95a4b4ab1 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5943,6 +5943,35 @@ int proc_cmdline(char **ret) { return 1; } +int parse_proc_cmdline(int (*parse_word)(const char *word)) { + _cleanup_free_ char *line = NULL; + char *w, *state; + size_t l; + int r; + + r = proc_cmdline(&line); + if (r < 0) + log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + if (r <= 0) + return 0; + + FOREACH_WORD_QUOTED(w, l, line, state) { + _cleanup_free_ char *word; + + word = strndup(w, l); + if (!word) + return log_oom(); + + r = parse_word(word); + if (r < 0) { + log_error("Failed on cmdline argument %s: %s", word, strerror(-r)); + return r; + } + } + + return 0; +} + int container_get_leader(const char *machine, pid_t *pid) { _cleanup_free_ char *s = NULL, *class = NULL; const char *p; |