process-util: introduce get_process_cmdline_strv()

The reason why get_process_cmdline() is so complicated is that we
need to escape and quote arguments for building a single result
string.

That's necessary when we want to log or print the command line.
However, when we want to parse the command line, it is not necessary
that the result is a single string, but can be strv.

This will be used when we parse the command line.
This commit is contained in:
Yu Watanabe
2023-03-28 17:09:15 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 19279652c0
commit 201423d801
3 changed files with 68 additions and 3 deletions
+22
View File
@@ -253,6 +253,28 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
return 0;
}
int get_process_cmdline_strv(pid_t pid, ProcessCmdlineFlags flags, char ***ret) {
_cleanup_free_ char *t = NULL;
char **args;
size_t k;
int r;
assert(pid >= 0);
assert((flags & ~PROCESS_CMDLINE_COMM_FALLBACK) == 0);
assert(ret);
r = get_process_cmdline_nulstr(pid, SIZE_MAX, flags, &t, &k);
if (r < 0)
return r;
args = strv_parse_nulstr_full(t, k, /* drop_trailing_nuls = */ true);
if (!args)
return -ENOMEM;
*ret = args;
return 0;
}
int container_get_leader(const char *machine, pid_t *pid) {
_cleanup_free_ char *s = NULL, *class = NULL;
const char *p;