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",
int pidfd_get_pid(int fd, pid_t *ret);
int setpriority_closest(int priority);
+
+bool invoked_as(char *argv[], const char *token);
if (getpid_cached() == 1)
return;
- if (!strstr(program_invocation_short_name, "init"))
+ if (!invoked_as(argv, "init"))
return;
execv(SYSTEMCTL_BINARY_PATH, argv);
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "sort-util.h"
#include "spawn-polkit-agent.h"
#include "stat-util.h"
assert(argc >= 0);
assert(argv);
- if (strstr(program_invocation_short_name, "systemd-umount"))
- arg_action = ACTION_UMOUNT;
+ if (invoked_as(argv, "systemd-umount"))
+ arg_action = ACTION_UMOUNT;
while ((c = getopt_long(argc, argv, "hqH:M:t:o:p:AuGl", options, NULL)) >= 0)
#include "parse-argument.h"
#include "parse-util.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "resolvconf-compat.h"
#include "resolvectl.h"
#include "resolved-def.h"
setlocale(LC_ALL, "");
log_setup();
- if (streq(program_invocation_short_name, "resolvconf"))
+ if (invoked_as(argv, "resolvconf"))
r = resolvconf_parse_argv(argc, argv);
- else if (streq(program_invocation_short_name, "systemd-resolve"))
+ else if (invoked_as(argv, "systemd-resolve"))
r = compat_parse_argv(argc, argv);
else
r = native_parse_argv(argc, argv);
#include "parse-argument.h"
#include "path-util.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "rlimit-util.h"
#include "sigbus.h"
#include "signal-util.h"
assert(argc >= 0);
assert(argv);
- if (strstr_ptr(argv[0], "halt")) {
+ if (invoked_as(argv, "halt")) {
arg_action = ACTION_HALT;
return halt_parse_argv(argc, argv);
- } else if (strstr_ptr(argv[0], "poweroff")) {
+ } else if (invoked_as(argv, "poweroff")) {
arg_action = ACTION_POWEROFF;
return halt_parse_argv(argc, argv);
- } else if (strstr_ptr(argv[0], "reboot")) {
+ } else if (invoked_as(argv, "reboot")) {
if (kexec_loaded())
arg_action = ACTION_KEXEC;
else
arg_action = ACTION_REBOOT;
return halt_parse_argv(argc, argv);
- } else if (strstr_ptr(argv[0], "shutdown")) {
+ } else if (invoked_as(argv, "shutdown")) {
arg_action = ACTION_POWEROFF;
return shutdown_parse_argv(argc, argv);
- } else if (strstr_ptr(argv[0], "init")) {
+ } else if (invoked_as(argv, "init")) {
/* Matches invocations as "init" as well as "telinit", which are synonymous when run
* as PID != 1 on SysV.
* for us if you invoke "init" you get "systemd", but it will execve() "systemctl"
* immediately with argv[] unmodified if PID is != 1. If you invoke "telinit" you directly
* get "systemctl". In both cases we shall do the same thing, which is why we do
- * strstr_ptr(argv[0], "init") here, as a quick way to match both.
+ * invoked_as(argv, "init") here, as a quick way to match both.
*
* Also see redirect_telinit() in src/core/main.c. */
return 1;
}
- } else if (strstr_ptr(argv[0], "runlevel")) {
+ } else if (invoked_as(argv, "runlevel")) {
arg_action = ACTION_RUNLEVEL;
return runlevel_parse_argv(argc, argv);
}
#include "alloc-util.h"
#include "main-func.h"
#include "pretty-print.h"
+#include "process-util.h"
#include "selinux-util.h"
#include "string-util.h"
+#include "udev-util.h"
#include "udevadm.h"
#include "udevd.h"
-#include "udev-util.h"
-#include "verbs.h"
#include "util.h"
+#include "verbs.h"
static int help(void) {
static const char *const short_descriptions[][2] = {
static int run(int argc, char *argv[]) {
int r;
- if (strstr(program_invocation_short_name, "udevd"))
+ if (invoked_as(argv, "udevd"))
return run_udevd(argc, argv);
udev_parse_config();