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:
committed by
Zbigniew Jędrzejewski-Szmek
parent
19279652c0
commit
201423d801
@@ -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;
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef enum ProcessCmdlineFlags {
|
||||
|
||||
int get_process_comm(pid_t pid, char **ret);
|
||||
int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret);
|
||||
int get_process_cmdline_strv(pid_t pid, ProcessCmdlineFlags flags, char ***ret);
|
||||
int get_process_exe(pid_t pid, char **ret);
|
||||
int get_process_uid(pid_t pid, uid_t *ret);
|
||||
int get_process_gid(pid_t pid, gid_t *ret);
|
||||
|
||||
Reference in New Issue
Block a user