Add $SYSTEMD_INVOKED_AS

This allows multi-call binaries to be easily invoked with a different
name. After installation, the name is set by creating a symlink. But in
build directories, we don't create the symlinks. (There are also other
ways to achieve the same thing, e.g. zsh supports $ARGV0, and exec -a
can be used, but those are either non-portable or are more complicated
to use.)  The primary use-case for me is to test --help output for
multicall binaries.

Also reorder the help for env vars to group the more generic ones near
the top.

This was initially proposed in https://github.com/systemd/systemd/pull/24054,
but there were some comments about the implementation. I had a branch
with the patch, but I don't think I ever actually submitted it as a
pull request.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-05-25 12:37:36 +02:00
parent 4d18eac5a9
commit 58e7959988
4 changed files with 38 additions and 11 deletions
+8 -1
View File
@@ -1,8 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <stdlib.h>
#include "alloc-util.h"
#include "ansi-color.h"
#include "help-util.h"
#include "path-util.h"
#include "pretty-print.h"
/* These are helpers for putting together --help texts in a uniform way with a common output style. Each
@@ -25,12 +28,16 @@
* options.[ch] APIs. */
void help_cmdline(const char *arguments) {
const char *progname =
last_path_component(secure_getenv("SYSTEMD_INVOKED_AS"))
?: program_invocation_short_name;
assert(arguments);
printf("%s>%s %s %s\n",
ansi_grey(),
ansi_normal(),
program_invocation_short_name,
progname,
arguments);
}