-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <getopt.h>
#include "main-func.h"
#include "memory-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "verbs.h"
static char **arg_property = NULL;
-static bool arg_all = false;
-static bool arg_value = false;
+static BusPrintPropertyFlags arg_print_flags = 0;
static bool arg_full = false;
static PagerFlags arg_pager_flags = 0;
static bool arg_legend = true;
static OutputFlags get_output_flags(void) {
return
- arg_all * OUTPUT_SHOW_ALL |
+ FLAGS_SET(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) * OUTPUT_SHOW_ALL |
(arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR;
}
assert(word);
if (table_get_rows(table) > 1 || OUTPUT_MODE_IS_JSON(arg_output)) {
- r = table_set_sort(table, (size_t) 0, (size_t) -1);
+ r = table_set_sort(table, (size_t) 0);
if (r < 0)
return table_log_sort_error(r);
assert(bus);
assert(argv);
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL);
if (r < 0)
assert(bus);
assert(argv);
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_login_mgr, "ListUsers", &error, &reply, NULL);
if (r < 0)
assert(bus);
assert(argv);
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_login_mgr, "ListSeats", &error, &reply, NULL);
if (r < 0)
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
- char since2[FORMAT_TIMESTAMP_MAX];
- const char *s1, *s2;
SessionStatusInfo i = {};
int r;
else
printf("%"PRIu32"\n", i.uid);
- s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
- s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
-
- if (s1)
- printf("\t Since: %s; %s\n", s2, s1);
- else if (s2)
- printf("\t Since: %s\n", s2);
+ if (timestamp_is_set(i.timestamp.realtime))
+ printf("\t Since: %s; %s\n",
+ FORMAT_TIMESTAMP(i.timestamp.realtime),
+ FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime));
if (i.leader > 0) {
_cleanup_free_ char *t = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
- char since2[FORMAT_TIMESTAMP_MAX];
- const char *s1, *s2;
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
int r;
else
printf("%"PRIu32"\n", i.uid);
- s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
- s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
-
- if (s1)
- printf("\t Since: %s; %s\n", s2, s1);
- else if (s2)
- printf("\t Since: %s\n", s2);
+ if (timestamp_is_set(i.timestamp.realtime))
+ printf("\t Since: %s; %s\n",
+ FORMAT_TIMESTAMP(i.timestamp.realtime),
+ FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime));
if (!isempty(i.state))
printf("\t State: %s\n", i.state);
if (!strv_isempty(i.sessions)) {
- char **l;
printf("\tSessions:");
STRV_FOREACH(l, i.sessions)
printf("%s\n", strna(i.id));
if (!strv_isempty(i.sessions)) {
- char **l;
printf("\tSessions:");
STRV_FOREACH(l, i.sessions) {
return 0;
}
-static int print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
+static int print_property(const char *name, const char *expected_value, sd_bus_message *m, BusPrintPropertyFlags flags) {
char type;
const char *contents;
int r;
if (r < 0)
return bus_log_parse_error(r);
- if (all || !isempty(s))
- bus_print_property_value(name, expected_value, value, s);
+ bus_print_property_value(name, expected_value, flags, s);
return 1;
"Invalid user ID: " UID_FMT,
uid);
- bus_print_property_valuef(name, expected_value, value, UID_FMT, uid);
+ bus_print_property_valuef(name, expected_value, flags, UID_FMT, uid);
return 1;
}
break;
if (r < 0)
return bus_log_parse_error(r);
- if (!value)
+ if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("%s=", name);
while ((r = sd_bus_message_read(m, "(so)", &s, NULL)) > 0) {
space = true;
}
- if (space || !value)
+ if (space || !FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE))
printf("\n");
if (r < 0)
path,
print_property,
arg_property,
- arg_value,
- arg_all,
+ arg_print_flags,
NULL);
if (r < 0)
return bus_log_parse_error(r);
properties = !strstr(argv[0], "status");
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
if (argc <= 1) {
/* If no argument is specified inspect the manager itself */
properties = !strstr(argv[0], "status");
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
if (argc <= 1) {
/* If no argument is specified inspect the manager itself */
properties = !strstr(argv[0], "status");
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
if (argc <= 1) {
/* If no argument is specified inspect the manager itself */
for (int i = 1; i < argc; i++) {
uid_t uid;
- r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL, 0);
- if (r < 0)
- return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
+ if (isempty(argv[i]))
+ uid = getuid();
+ else {
+ const char *u = argv[i];
+
+ r = get_user_creds(&u, &uid, NULL, NULL, NULL, 0);
+ if (r < 0)
+ return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
+ }
r = bus_call_method(bus, bus_login_mgr, "TerminateUser", &error, NULL, "u", (uint32_t) uid);
if (r < 0)
for (int i = 1; i < argc; i++) {
uid_t uid;
- r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL, 0);
- if (r < 0)
- return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
+ if (isempty(argv[i]))
+ uid = getuid();
+ else {
+ const char *u = argv[i];
+
+ r = get_user_creds(&u, &uid, NULL, NULL, NULL, 0);
+ if (r < 0)
+ return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
+ }
r = bus_call_method(
bus,
_cleanup_free_ char *link = NULL;
int r;
- (void) pager_open(arg_pager_flags);
+ pager_open(arg_pager_flags);
r = terminal_urlify_man("loginctl", "1", &link);
if (r < 0)
" short-monotonic, short-unix, verbose, export,\n"
" json, json-pretty, json-sse, json-seq, cat,\n"
" with-unit)\n"
- "\nSee the %s for details.\n"
- , program_invocation_short_name
- , ansi_highlight()
- , ansi_normal()
- , link
- );
+ "\nSee the %s for details.\n",
+ program_invocation_short_name,
+ ansi_highlight(),
+ ansi_normal(),
+ link);
return 0;
}
return version();
case 'P':
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
_fallthrough_;
case 'p': {
/* If the user asked for a particular
* property, show it to them, even if it is
* empty. */
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
}
case 'a':
- arg_all = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_SHOW_EMPTY, true);
break;
case ARG_VALUE:
- arg_value = true;
+ SET_FLAG(arg_print_flags, BUS_PRINT_PROPERTY_ONLY_VALUE, true);
break;
case 'l':
arg_output = output_mode_from_string(optarg);
if (arg_output < 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Unknown output '%s'.", optarg);
+ return log_error_errno(arg_output, "Unknown output '%s'.", optarg);
if (OUTPUT_MODE_IS_JSON(arg_output))
arg_legend = false;
break;
case 's':
- if (streq(optarg, "help")) {
- DUMP_STRING_TABLE(signal, int, _NSIG);
- return 0;
- }
-
- arg_signal = signal_from_string(optarg);
- if (arg_signal < 0)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse signal string %s.", optarg);
+ r = parse_signal_argument(optarg, &arg_signal);
+ if (r <= 0)
+ return r;
break;
case 'H':
return -EINVAL;
default:
- assert_not_reached("Unhandled option");
+ assert_not_reached();
}
return 1;
int r;
setlocale(LC_ALL, "");
- log_setup_cli();
+ log_setup();
/* The journal merging logic potentially needs a lot of fds. */
(void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0)
- return bus_log_connect_error(r);
+ return bus_log_connect_error(r, arg_transport);
(void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);