]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemctl/systemctl-whoami.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "format-util.h"
4 #include "parse-util.h"
6 #include "systemctl-util.h"
7 #include "systemctl-whoami.h"
9 int verb_whoami(int argc
, char *argv
[], void *userdata
) {
13 r
= acquire_bus(BUS_FULL
, &bus
);
18 _cleanup_free_
char *unit
= NULL
;
20 if (arg_transport
!= BUS_TRANSPORT_LOCAL
)
21 return log_error_errno(SYNTHETIC_ERRNO(EREMOTE
),
22 "Refusing to look up our local PID on remote host.");
24 /* Our own process can never go away while querying, hence no need to go through pidfd. */
26 r
= get_unit_by_pid(bus
, 0, &unit
, /* ret_path = */ NULL
);
34 STRV_FOREACH(pidstr
, strv_skip(argv
, 1)) {
35 _cleanup_free_
char *unit
= NULL
;
38 r
= parse_pid(*pidstr
, &pid
);
40 return log_error_errno(r
, "Invalid PID specified: %s", *pidstr
);
42 r
= lookup_unit_by_pidref(bus
, pid
, &unit
, /* ret_path = */ NULL
);