summaryrefslogtreecommitdiff
path: root/src/basic/process-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-19 20:36:45 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-20 14:45:27 +0100
commit2306d1778f2479cb16423d51d82f8f31b15146d1 (patch)
treee8a2f3b310155f1c5a25378a26c58ab1198e4e28 /src/basic/process-util.c
parent27edd36eaa0ff6478f7885a702567841fef2f186 (diff)
downloadsystemd-2306d1778f2479cb16423d51d82f8f31b15146d1.tar.gz
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: d41a9e4fc1e1bcdefc8d358da2744a97aac5820a
Diffstat (limited to 'src/basic/process-util.c')
-rw-r--r--src/basic/process-util.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 0851613fc9..304b03960a 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -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",