summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c29
-rw-r--r--src/shared/util.h1
2 files changed, 30 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;
diff --git a/src/shared/util.h b/src/shared/util.h
index fcb45b5f5c..4bed5b4842 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -852,6 +852,7 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size,
}
int proc_cmdline(char **ret);
+int parse_proc_cmdline(int (*parse_word)(const char *word));
int container_get_leader(const char *machine, pid_t *pid);