Ignore $SYSTEMD_INVOKED_AS if empty

Let's treat unset SYSTEMD_INVOKED_AS and SYSTEMD_INVOKED_AS='' the same.
I encountered this when testing various --help outputs. It is often
more convenient to override a variable with VAR= instead of removing it,
in particular on the commandline. But we'd then print help with the
program name missing. We look at the variable in two places, so adjust
both as in $subject.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-28 14:50:10 +02:00
parent d04d0b0627
commit 05fb4c6e27
2 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ void save_argc_argv(int argc, char **argv) {
}
bool invoked_as(char *argv[], const char *token) {
const char *progname = secure_getenv("SYSTEMD_INVOKED_AS");
const char *progname = empty_to_null(secure_getenv("SYSTEMD_INVOKED_AS"));
if (!progname && argv)
progname = argv[0];
+4 -4
View File
@@ -514,12 +514,12 @@ static const Verb* verbs_find_cmd_verbs(const Verb *cmdverb, const Verb verbs_en
}
static void help_cmdline(const char *arguments) {
const char *progname =
last_path_component(secure_getenv("SYSTEMD_INVOKED_AS"))
?: program_invocation_short_name;
assert(arguments);
const char *progname =
empty_to_null(last_path_component(secure_getenv("SYSTEMD_INVOKED_AS")))
?: program_invocation_short_name;
printf("%s>%s %s %s\n",
ansi_grey(),
ansi_normal(),