systemctl: don't search in the full argv[0] for the invocation name

argv[0] might be prefixed by a path, and we shouldn't get confused by
that. Hence provide a simple helper call that abstracts the checking
away, which we can use everywhere, and expose the same behaviour, even
if argv[0] is not set.

(While we are at it, port all other multi-call binaries over to the new
helper, too)

Follow-up for: d41a9e4fc1
This commit is contained in:
Lennart Poettering
2021-02-20 14:45:27 +01:00
committed by Zbigniew Jędrzejewski-Szmek
parent 27edd36eaa
commit 2306d1778f
7 changed files with 31 additions and 15 deletions
+10
View File
@@ -1620,6 +1620,16 @@ int setpriority_closest(int priority) {
return 0;
}
bool invoked_as(char *argv[], const char *token) {
if (!argv || isempty(argv[0]))
return false;
if (isempty(token))
return false;
return strstr(last_path_component(argv[0]), token);
}
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
+2
View File
@@ -199,3 +199,5 @@ assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX);
int pidfd_get_pid(int fd, pid_t *ret);
int setpriority_closest(int priority);
bool invoked_as(char *argv[], const char *token);