diff options
author | Sven Eden <yamakuzure@gmx.net> | 2018-03-13 19:14:05 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-03-26 18:25:59 +0200 |
commit | 969056d0e1de27ab99946632849b6f965e51f753 (patch) | |
tree | 30a03c74c55ac73d92f35d8d1f60a311cb616575 /src | |
parent | 36fdbc812fbd4cfd9a4c5471107a93bab04b306c (diff) |
Prep v236 : Add missing SPDX-License-Identifier (5/9) src/login
Diffstat (limited to 'src')
43 files changed, 269 insertions, 191 deletions
diff --git a/src/login/70-power-switch.rules b/src/login/70-power-switch.rules index 394a80f1f..d69e65b3d 100644 --- a/src/login/70-power-switch.rules +++ b/src/login/70-power-switch.rules @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it diff --git a/src/login/70-uaccess.rules b/src/login/70-uaccess.rules index e946bf238..f2c838f35 100644 --- a/src/login/70-uaccess.rules +++ b/src/login/70-uaccess.rules @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it diff --git a/src/login/71-seat.rules.in b/src/login/71-seat.rules.in index de55c9a4e..0db46adc8 100644 --- a/src/login/71-seat.rules.in +++ b/src/login/71-seat.rules.in @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it diff --git a/src/login/73-seat-late.rules.in b/src/login/73-seat-late.rules.in index a44976b6d..e75881960 100644 --- a/src/login/73-seat-late.rules.in +++ b/src/login/73-seat-late.rules.in @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it diff --git a/src/login/eloginctl.c b/src/login/eloginctl.c index 8adfb62e9..566c339c6 100644 --- a/src/login/eloginctl.c +++ b/src/login/eloginctl.c @@ -313,7 +313,7 @@ static int elogind_reboot(sd_bus *bus, enum elogind_action a) { return -EINVAL; } - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) ) (void) elogind_set_wall_message(bus, table[a]); @@ -477,22 +477,6 @@ static int parse_shutdown_time_spec(const char *t, usec_t *_u) { } /* Original: - * systemctl/systemctl.c:270:polkit_agent_open_if_enabled() - */ -void polkit_agent_open_if_enabled(void) { - - /* Open the polkit agent as a child process if necessary */ - - if (!arg_ask_password) - return; - - if (arg_transport != BUS_TRANSPORT_LOCAL) - return; - - polkit_agent_open(); -} - -/* Original: * systemctl/systemctl.c:3482:start_special() * However, this elogind variant is very different from the original. */ diff --git a/src/login/eloginctl.h b/src/login/eloginctl.h index b6e96930b..cf8ce8334 100644 --- a/src/login/eloginctl.h +++ b/src/login/eloginctl.h @@ -41,7 +41,6 @@ typedef enum elogind_action { int elogind_cancel_shutdown(sd_bus *bus); void elogind_cleanup(void); -void polkit_agent_open_if_enabled(void); int start_special(int argc, char *argv[], void *userdata); diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 896fd570a..7c48e7cee 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 7343fecaa..11bd99069 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -37,8 +38,9 @@ #include "pager.h" #include "parse-util.h" #include "process-util.h" +#include "sigbus.h" #include "signal-util.h" -//#include "spawn-polkit-agent.h" +#include "spawn-polkit-agent.h" #include "strv.h" #include "sysfs-show.h" #include "terminal-util.h" @@ -75,29 +77,13 @@ extern bool arg_ignore_inhibitors; extern elogind_action arg_action; #endif // 0 -#if 0 /// UNNEEDED by elogind -static void polkit_agent_open_if_enabled(void) { - - /* Open the polkit agent as a child process if necessary */ - - if (!arg_ask_password) - return; - - if (arg_transport != BUS_TRANSPORT_LOCAL) - return; - - polkit_agent_open(); -} - static OutputFlags get_output_flags(void) { return arg_all * OUTPUT_SHOW_ALL | - arg_full * OUTPUT_FULL_WIDTH | - (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH | + (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH | colors_enabled() * OUTPUT_COLOR; } -#endif // 0 static int get_session_path(sd_bus *bus, const char *session_id, sd_bus_error *error, char **path) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; @@ -749,7 +735,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line) printf("\t Devices:\n"); - show_sysfs(i.id, "\t\t ", c); + show_sysfs(i.id, "\t\t ", c, get_output_flags()); } return 0; @@ -1103,7 +1089,7 @@ static int activate(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); if (argc < 2) { /* No argument? Let's either use $XDG_SESSION_ID (if specified), or an empty @@ -1147,7 +1133,7 @@ static int kill_session(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); if (!arg_kill_who) arg_kill_who = "all"; @@ -1181,7 +1167,7 @@ static int enable_linger(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); b = streq(argv[0], "enable-linger"); @@ -1232,7 +1218,7 @@ static int terminate_user(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); for (i = 1; i < argc; i++) { uid_t uid; @@ -1266,7 +1252,7 @@ static int kill_user(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); if (!arg_kill_who) arg_kill_who = "all"; @@ -1303,7 +1289,7 @@ static int attach(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); for (i = 2; i < argc; i++) { @@ -1333,7 +1319,7 @@ static int flush_devices(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); r = sd_bus_call_method( bus, @@ -1357,7 +1343,7 @@ static int lock_sessions(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); r = sd_bus_call_method( bus, @@ -1381,7 +1367,7 @@ static int terminate_seat(int argc, char *argv[], void *userdata) { assert(bus); assert(argv); - polkit_agent_open_if_enabled(); + polkit_agent_open_if_enabled(arg_transport, arg_ask_password); for (i = 1; i < argc; i++) { @@ -1688,13 +1674,14 @@ static int loginctl_main(int argc, char *argv[], sd_bus *bus) { } int main(int argc, char *argv[]) { - sd_bus *bus = NULL; + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); elogind_set_program_name(argv[0]); log_parse_environment(); log_open(); + sigbus_install(); r = parse_argv(argc, argv); if (r <= 0) @@ -1711,8 +1698,6 @@ int main(int argc, char *argv[]) { r = loginctl_main(argc, argv, bus); finish: - sd_bus_flush_close_unref(bus); - pager_close(); #if 0 /// elogind does that in elogind_cleanup() polkit_agent_close(); diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c index 1b69f4b9c..d785f67ca 100644 --- a/src/login/logind-acl.c +++ b/src/login/logind-acl.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-acl.h b/src/login/logind-acl.h index df25beca2..d50b887bc 100644 --- a/src/login/logind-acl.h +++ b/src/login/logind-acl.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 48d9fb856..bae42db99 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-action.h b/src/login/logind-action.h index fb40ae48d..8c31ec42b 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-button.c b/src/login/logind-button.c index e53dd63c2..94945f0bc 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-button.h b/src/login/logind-button.h index f30cba295..b47eb4757 100644 --- a/src/login/logind-button.h +++ b/src/login/logind-button.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 95e2363dd..71b9c76d3 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 0ac16de2d..aff699674 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -52,28 +53,47 @@ /// Additional includes needed by elogind #include "elogind-dbus.h" +static int get_sender_session(Manager *m, sd_bus_message *message, sd_bus_error *error, Session **ret) { -int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; + const char *name; Session *session; int r; + /* Get client login session. This is not what you are looking for these days, + * as apps may instead belong to a user service unit. This includes terminal + * emulators and hence command-line apps. */ + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_SESSION|SD_BUS_CREDS_AUGMENT, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_session(creds, &name); + if (r == -ENXIO) + goto err_no_session; + if (r < 0) + return r; + + session = hashmap_get(m->sessions, name); + if (!session) + goto err_no_session; + + *ret = session; + return 0; + +err_no_session: + return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, + "Caller does not belong to any known session"); +} + +int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) { + Session *session; + assert(m); assert(message); assert(ret); - if (isempty(name)) { - r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_SESSION|SD_BUS_CREDS_AUGMENT, &creds); - if (r < 0) - return r; - - r = sd_bus_creds_get_session(creds, &name); - if (r == -ENXIO) - return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, - "Caller does not belong to any known session"); - if (r < 0) - return r; - } + if (isempty(name)) + return get_sender_session(m, message, error, ret); session = hashmap_get(m->sessions, name); if (!session) @@ -83,30 +103,48 @@ int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const ch return 0; } -int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret) { +static int get_sender_user(Manager *m, sd_bus_message *message, sd_bus_error *error, User **ret) { + + _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; + uid_t uid; User *user; int r; + /* Note that we get the owner UID of the session, not the actual client UID here! */ + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_OWNER_UID|SD_BUS_CREDS_AUGMENT, &creds); + if (r < 0) + return r; + + r = sd_bus_creds_get_owner_uid(creds, &uid); + if (r == -ENXIO) + goto err_no_user; + if (r < 0) + return r; + + user = hashmap_get(m->users, UID_TO_PTR(uid)); + if (!user) + goto err_no_user; + + *ret = user; + return 0; + +err_no_user: + return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "Caller does not belong to any logged in user or lingering user"); +} + +int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret) { + User *user; + assert(m); assert(message); assert(ret); - if (!uid_is_valid(uid)) { - _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; - - /* Note that we get the owner UID of the session, not the actual client UID here! */ - r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_OWNER_UID|SD_BUS_CREDS_AUGMENT, &creds); - if (r < 0) - return r; - - r = sd_bus_creds_get_owner_uid(creds, &uid); - if (r < 0) - return r; - } + if (!uid_is_valid(uid)) + return get_sender_user(m, message, error, ret); user = hashmap_get(m->users, UID_TO_PTR(uid)); if (!user) - return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user "UID_FMT" known or logged in", uid); + return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "User ID "UID_FMT" is not logged in or lingering", uid); *ret = user; return 0; @@ -332,6 +370,9 @@ static int method_get_session(sd_bus_message *message, void *userdata, sd_bus_er return sd_bus_reply_method_return(message, "o", p); } +/* Get login session of a process. This is not what you are looking for these days, + * as apps may instead belong to a user service unit. This includes terminal + * emulators and hence command-line apps. */ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_free_ char *p = NULL; Session *session = NULL; @@ -422,7 +463,9 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu if (r < 0) return r; if (!user) - return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "PID "PID_FMT" does not belong to any known or logged in user", pid); + return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, + "PID "PID_FMT" does not belong to any logged in user or lingering user", + pid); } p = user_bus_path(user); @@ -1186,7 +1229,7 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu mkdir_p_label("/var/lib/systemd", 0755); - r = mkdir_safe_label("/var/lib/systemd/linger", 0755, 0, 0); + r = mkdir_safe_label("/var/lib/elogind/linger", 0755, 0, 0, false); if (r < 0) return r; @@ -1946,7 +1989,7 @@ static int update_schedule_file(Manager *m) { assert(m); - r = mkdir_safe_label("/run/systemd/shutdown", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/shutdown", 0755, 0, 0, false); if (r < 0) return log_error_errno(r, "Failed to create shutdown subdirectory: %m"); @@ -2417,7 +2460,7 @@ static int property_get_reboot_to_firmware_setup( r = efi_get_reboot_to_firmware(); if (r < 0 && r != -EOPNOTSUPP) - return r; + log_warning_errno(r, "Failed to determine reboot-to-firmware state: %m"); return sd_bus_message_append(reply, "b", r > 0); #else @@ -2477,10 +2520,12 @@ static int method_can_reboot_to_firmware_setup( assert(m); r = efi_reboot_to_firmware_supported(); - if (r == -EOPNOTSUPP) + if (r < 0) { + if (r != -EOPNOTSUPP) + log_warning_errno(errno, "Failed to determine whether reboot to firmware is supported: %m"); + return sd_bus_reply_method_return(message, "s", "na"); - else if (r < 0) - return r; + } r = bus_test_polkit(message, CAP_SYS_ADMIN, diff --git a/src/login/logind-device.c b/src/login/logind-device.c index 6537fa04b..758ba73c2 100644 --- a/src/login/logind-device.c +++ b/src/login/logind-device.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-device.h b/src/login/logind-device.h index 927068e00..d0911560d 100644 --- a/src/login/logind-device.h +++ b/src/login/logind-device.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 1e6f38373..9bfde30ab 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -86,7 +87,7 @@ int inhibitor_save(Inhibitor *i) { assert(i); - r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/inhibit", 0755, 0, 0, false); if (r < 0) goto fail; @@ -290,7 +291,7 @@ int inhibitor_create_fifo(Inhibitor *i) { /* Create FIFO */ if (!i->fifo_path) { - r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/inhibit", 0755, 0, 0, false); if (r < 0) return r; @@ -357,6 +358,8 @@ static int pid_is_active(Manager *m, pid_t pid) { Session *s; int r; + /* Get client session. This is not what you are looking for these days. + * FIXME #6852 */ r = manager_get_session_by_pid(m, pid, &s); if (r < 0) return r; diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index 70de199c6..cc6c62ab1 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 2154b878d..8e4e4efc8 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index eacea3c39..0301d670a 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -19,6 +20,7 @@ #include <errno.h> #include <fcntl.h> +#include <stdio_ext.h> #include <string.h> #include <unistd.h> @@ -93,7 +95,7 @@ int seat_save(Seat *s) { if (!s->started) return 0; - r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/seats", 0755, 0, 0, false); if (r < 0) goto fail; @@ -101,7 +103,8 @@ int seat_save(Seat *s) { if (r < 0) goto fail; - fchmod(fileno(f), 0644); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + (void) fchmod(fileno(f), 0644); fprintf(f, "# This is private data. Do not parse.\n" @@ -127,7 +130,7 @@ int seat_save(Seat *s) { if (s->sessions) { Session *i; - fputs_unlocked("SESSIONS=", f); + fputs("SESSIONS=", f); LIST_FOREACH(sessions_by_seat, i, s->sessions) { fprintf(f, "%s%c", @@ -135,7 +138,7 @@ int seat_save(Seat *s) { i->sessions_by_seat_next ? ' ' : '\n'); } - fputs_unlocked("UIDS=", f); + fputs("UIDS=", f); LIST_FOREACH(sessions_by_seat, i, s->sessions) fprintf(f, UID_FMT"%c", diff --git a/src/login/logind-seat.h b/src/login/logind-seat.h index d7096a5e3..caf9708c1 100644 --- a/src/login/logind-seat.h +++ b/src/login/logind-seat.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index 4e3162d8f..b49b8b92d 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index c48889c3e..9d1256dca 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-session-device.h b/src/login/logind-session-device.h index 84b1e6ad2..a1cf17af9 100644 --- a/src/login/logind-session-device.h +++ b/src/login/logind-session-device.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-session.c b/src/login/logind-session.c index e9834c9bd..6ae45f45a 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -184,7 +185,7 @@ int session_save(Session *s) { if (!s->started) return 0; - r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/sessions", 0755, 0, 0, false); if (r < 0) goto fail; @@ -1006,7 +1007,7 @@ int session_create_fifo(Session *s) { /* Create FIFO */ if (!s->fifo_path) { - r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/sessions", 0755, 0, 0, false); if (r < 0) return r; diff --git a/src/login/logind-session.h b/src/login/logind-session.h index 1e7f3ad49..d53975acc 100644 --- a/src/login/logind-session.h +++ b/src/login/logind-session.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 921f1e0f9..9fca5ce0c 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 3bbd9644c..ab6aef514 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -21,6 +22,7 @@ #include <string.h> #include <sys/mount.h> #include <unistd.h> +#include <stdio_ext.h> #include "alloc-util.h" #include "bus-common-errors.h" @@ -146,7 +148,7 @@ static int user_save_internal(User *u) { assert(u); assert(u->state_file); - r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0); + r = mkdir_safe_label("/run/elogind/users", 0755, 0, 0, false); if (r < 0) goto fail; @@ -154,7 +156,8 @@ static int user_save_internal(User *u) { if (r < 0) goto fail; - fchmod(fileno(f), 0644); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + (void) fchmod(fileno(f), 0644); fprintf(f, "# This is private data. Do not parse.\n" @@ -189,18 +192,18 @@ static int user_save_internal(User *u) { Session *i; bool first; - fputs_unlocked("SESSIONS=", f); + fputs("SESSIONS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (first) first = false; else - fputc_unlocked(' ', f); + fputc(' ', f); - fputs_unlocked(i->id, f); + fputs(i->id, f); } - fputs_unlocked("\nSEATS=", f); + fputs("\nSEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (!i->seat) @@ -209,12 +212,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc_unlocked(' ', f); + fputc(' ', f); - fputs_unlocked(i->seat->id, f); + fputs(i->seat->id, f); } - fputs_unlocked("\nACTIVE_SESSIONS=", f); + fputs("\nACTIVE_SESSIONS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (!session_is_active(i)) @@ -223,12 +226,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc_unlocked(' ', f); + fputc(' ', f); - fputs_unlocked(i->id, f); + fputs(i->id, f); } - fputs_unlocked("\nONLINE_SESSIONS=", f); + fputs("\nONLINE_SESSIONS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (session_get_state(i) == SESSION_CLOSING) @@ -237,12 +240,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc_unlocked(' ', f); + fputc(' ', f); - fputs_unlocked(i->id, f); + fputs(i->id, f); } - fputs_unlocked("\nACTIVE_SEATS=", f); + fputs("\nACTIVE_SEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (!session_is_active(i) || !i->seat) @@ -251,12 +254,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc_unlocked(' ', f); + fputc(' ', f); - fputs_unlocked(i->seat->id, f); + fputs(i->seat->id, f); } - fputs_unlocked("\nONLINE_SEATS=", f); + fputs("\nONLINE_SEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (session_get_state(i) == SESSION_CLOSING || !i->seat) @@ -265,11 +268,11 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc_unlocked(' ', f); + fputc(' ', f); - fputs_unlocked(i->seat->id, f); + fputs(i->seat->id, f); } - fputc_unlocked('\n', f); + fputc('\n', f); } r = fflush_and_check(f); @@ -343,7 +346,7 @@ static int user_mkdir_runtime_path(User *u) { assert(u); - r = mkdir_safe_label("/run/user", 0755, 0, 0); + r = mkdir_safe_label("/run/user", 0755, 0, 0, false); if (r < 0) return log_error_errno(r, "Failed to create /run/user: %m"); @@ -441,12 +444,11 @@ static int user_start_service(User *u) { u->service, &error, &job); - if (r < 0) { + if (r < 0) /* we don't fail due to this, let's try to continue */ log_error_errno(r, "Failed to start user service, ignoring: %s", bus_error_message(&error, r)); - } else { + else u->service_job = job; - } #else assert(u); diff --git a/src/login/logind-user.h b/src/login/logind-user.h index 043870b24..cc8fb26b4 100644 --- a/src/login/logind-user.h +++ b/src/login/logind-user.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 2185db4b2..f6667609f 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/logind.c b/src/login/logind.c index d711c9d89..b76100bfc 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -1113,7 +1114,6 @@ static int manager_parse_config_file(Manager *m) { CONF_PATHS_NULSTR("systemd/logind.conf.d"), "Login\0", config_item_perf_lookup, logind_gperf_lookup, - false, m); #else const char* logind_conf = getenv("ELOGIND_CONF_FILE"); @@ -1124,8 +1124,8 @@ static int manager_parse_config_file(Manager *m) { return config_parse(NULL, logind_conf, NULL, "Login\0Sleep\0", config_item_perf_lookup, logind_gperf_lookup, - false, false, true, m); #endif // 0 + CONFIG_PARSE_WARN, m); } static int manager_dispatch_reload_signal(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) { diff --git a/src/login/logind.h b/src/login/logind.h index 9b90049ab..95de51a65 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** diff --git a/src/login/org.freedesktop.login1.conf b/src/login/org.freedesktop.login1.conf index f1d8cce53..a25eb4401 100644 --- a/src/login/org.freedesktop.login1.conf +++ b/src/login/org.freedesktop.login1.conf @@ -4,8 +4,10 @@ <!-- This file is part of elogind. + SPDX-License-Identifier: LGPL-2.1+ elogind is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. diff --git a/src/login/org.freedesktop.login1.policy.in b/src/login/org.freedesktop.login1.policy.in index b0825a33f..997a7d70f 100644 --- a/src/login/org.freedesktop.login1.policy.in +++ b/src/login/org.freedesktop.login1.policy.in @@ -4,8 +4,10 @@ <!-- This file is part of elogind. + SPDX-License-Identifier: LGPL-2.1+ elogind is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. @@ -21,8 +23,8 @@ <!-- // 0 --> <action id="org.freedesktop.login1.inhibit-block-shutdown"> - <_description>Allow applications to inhibit system shutdown</_description> - <_message>Authentication is required for an application to inhibit system shutdown.</_message> + <description>Allow applications to inhibit system shutdown</description> + <message>Authentication is required for an application to inhibit system shutdown.</message> <defaults> <allow_any>no</allow_any> <allow_inactive>yes</allow_inactive> @@ -32,8 +34,8 @@ </action> <action id="org.freedesktop.login1.inhibit-delay-shutdown"> - <_description>Allow applications to delay system shutdown</_description> - <_message>Authentication is required for an application to delay system shutdown.</_message> + <description>Allow applications to delay system shutdown</description> + <message>Authentication is required for an application to delay system shutdown.</message> <defaults> <allow_any>yes</allow_any> <allow_inactive>yes</allow_inactive> @@ -43,8 +45,8 @@ </action> <action id="org.freedesktop.login1.inhibit-block-sleep"> - <_description>Allow applications to inhibit system sleep</_description> - <_message>Authentication is required for an application to inhibit system sleep.</_message> + <description>Allow applications to inhibit system sleep</description> + <message>Authentication is required for an application to inhibit system sleep.</message> <defaults> <allow_any>no</allow_any> <allow_inactive>yes</allow_inactive> @@ -54,8 +56,8 @@ </action> <action id="org.freedesktop.login1.inhibit-delay-sleep"> - <_description>Allow applications to delay system sleep</_description> - <_message>Authentication is required for an application to delay system sleep.</_message> + <description>Allow applications to delay system sleep</description> + <message>Authentication is required for an application to delay system sleep.</message> <defaults> <allow_any>yes</allow_any> <allow_inactive>yes</allow_inactive> @@ -64,8 +66,8 @@ </action> <action id="org.freedesktop.login1.inhibit-block-idle"> - <_description>Allow applications to inhibit automatic system suspend</_description> - <_message>Authentication is required for an application to inhibit automatic system suspend.</_message> + <description>Allow applications to inhibit automatic system suspend</description> + <message>Authentication is required for an application to inhibit automatic system suspend.</message> <defaults> <allow_any>yes</allow_any> <allow_inactive>yes</allow_inactive> @@ -74,8 +76,8 @@ </action> <action id="org.freedesktop.login1.inhibit-handle-power-key"> - <_description>Allow applications to inhibit system handling of the power key</_description> - <_message>Authentication is required for an application to inhibit system handling of the power key.</_message> + <description>Allow applications to inhibit system handling of the power key</description> + <message>Authentication is required for an application to inhibit system handling of the power key.</message> <defaults> <allow_any>no</allow_any> <allow_inactive>yes</allow_inactive> @@ -85,8 +87,8 @@ </action> <action id="org.freedesktop.login1.inhibit-handle-suspend-key"> - <_description>Allow applications to inhibit system handling of the suspend key</_description> - <_message>Authentication is required for an application to inhibit system handling of the suspend key.</_message> + <description>Allow applications to inhibit system handling of the suspend key</description> + <message>Authentication is required for an application to inhibit system handling of the suspend key.</message> <defaults> <allow_any>no</allow_any> <allow_inactive>yes</allow_inactive> @@ -96,8 +98,8 @@ </action> <action id="org.freedesktop.login1.inhibit-handle-hibernate-key"> - <_description>Allow applications to inhibit system handling of the hibernate key</_description> - <_message>Authentication is required for an application to inhibit system handling of the hibernate key.</_message> + <description>Allow applications to inhibit system handling of the hibernate key</description> + <message>Authentication is required for an application to inhibit system handling of the hibernate key.</message> <defaults> <allow_any>no</allow_any> <allow_inactive>yes</allow_inactive> @@ -106,8 +108,8 @@ </action> <action id="org.freedesktop.login1.inhibit-handle-lid-switch"> - <_description>Allow applications to inhibit system handling of the lid switch</_description> - <_message>Authentication is required for an application to inhibit system handling of the lid switch.</_message> + <description>Allow applications to inhibit system handling of the lid switch</description> + <message>Authentication is required for an application to inhibit system handling of the lid switch.</message> <defaults> <allow_any>no</allow_any> <allow_inactive>yes</allow_inactive> @@ -116,8 +118,8 @@ </action> <action id="org.freedesktop.login1.set-self-linger"> - <_description>Allow non-logged-in user to run programs</_description> - <_message>Explicit request is required to run programs as a non-logged-in user.</_message> + <description>Allow non-logged-in user to run programs</description> + <message>Explicit request is required to run programs as a non-logged-in user.</message> <defaults> <allow_any>yes</allow_any> <allow_inactive>yes</allow_inactive> @@ -126,8 +128,8 @@ </action> <action id="org.freedesktop.login1.set-user-linger"> - <_description>Allow non-logged-in users to run programs</_description> - <_message>Authentication is required to run programs as a non-logged-in user.</_message> + <description>Allow non-logged-in users to run programs</description> + <message>Authentication is required to run programs as a non-logged-in user.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -136,8 +138,8 @@ </action> <action id="org.freedesktop.login1.attach-device"> - <_description>Allow attaching devices to seats</_description> - <_message>Authentication is required for attaching a device to a seat.</_message> + <description>Allow attaching devices to seats</description> + <message>Authentication is required for attaching a device to a seat.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -147,8 +149,8 @@ </action> <action id="org.freedesktop.login1.flush-devices"> - <_description>Flush device to seat attachments</_description> - <_message>Authentication is required for resetting how devices are attached to seats.</_message> + <description>Flush device to seat attachments</description> + <message>Authentication is required for resetting how devices are attached to seats.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -157,8 +159,8 @@ </action> <action id="org.freedesktop.login1.power-off"> - <_description>Power off the system</_description> - <_message>Authentication is required for powering off the system.</_message> + <description>Power off the system</description> + <message>Authentication is required for powering off the system.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -168,8 +170,8 @@ </action> <action id="org.freedesktop.login1.power-off-multiple-sessions"> - <_description>Power off the system while other users are logged in</_description> - <_message>Authentication is required for powering off the system while other users are logged in.</_message> + <description>Power off the system while other users are logged in</description> + <message>Authentication is required for powering off the system while other users are logged in.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -179,8 +181,8 @@ </action> <action id="org.freedesktop.login1.power-off-ignore-inhibit"> - <_description>Power off the system while an application asked to inhibit it</_description> - <_message>Authentication is required for powering off the system while an application asked to inhibit it.</_message> + <description>Power off the system while an application asked to inhibit it</description> + <message>Authentication is required for powering off the system while an application asked to inhibit it.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -190,8 +192,8 @@ </action> <action id="org.freedesktop.login1.reboot"> - <_description>Reboot the system</_description> - <_message>Authentication is required for rebooting the system.</_message> + <description>Reboot the system</description> + <message>Authentication is required for rebooting the system.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -201,8 +203,8 @@ </action> <action id="org.freedesktop.login1.reboot-multiple-sessions"> - <_description>Reboot the system while other users are logged in</_description> - <_message>Authentication is required for rebooting the system while other users are logged in.</_message> + <description>Reboot the system while other users are logged in</description> + <message>Authentication is required for rebooting the system while other users are logged in.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -212,8 +214,8 @@ </action> <action id="org.freedesktop.login1.reboot-ignore-inhibit"> - <_description>Reboot the system while an application asked to inhibit it</_description> - <_message>Authentication is required for rebooting the system while an application asked to inhibit it.</_message> + <description>Reboot the system while an application asked to inhibit it</description> + <message>Authentication is required for rebooting the system while an application asked to inhibit it.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -223,8 +225,8 @@ </action> <action id="org.freedesktop.login1.halt"> - <_description>Halt the system</_description> - <_message>Authentication is required for halting the system.</_message> + <description>Halt the system</description> + <message>Authentication is required for halting the system.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -234,8 +236,8 @@ </action> <action id="org.freedesktop.login1.halt-multiple-sessions"> - <_description>Halt the system while other users are logged in</_description> - <_message>Authentication is required for halting the system while other users are logged in.</_message> + <description>Halt the system while other users are logged in</description> + <message>Authentication is required for halting the system while other users are logged in.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -245,8 +247,8 @@ </action> <action id="org.freedesktop.login1.halt-ignore-inhibit"> - <_description>Halt the system while an application asked to inhibit it</_description> - <_message>Authentication is required for halting the system while an application asked to inhibit it.</_message> + <description>Halt the system while an application asked to inhibit it</description> + <message>Authentication is required for halting the system while an application asked to inhibit it.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -256,8 +258,8 @@ </action> <action id="org.freedesktop.login1.suspend"> - <_description>Suspend the system</_description> - <_message>Authentication is required for suspending the system.</_message> + <description>Suspend the system</description> + <message>Authentication is required for suspending the system.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -266,8 +268,8 @@ </action> <action id="org.freedesktop.login1.suspend-multiple-sessions"> - <_description>Suspend the system while other users are logged in</_description> - <_message>Authentication is required for suspending the system while other users are logged in.</_message> + <description>Suspend the system while other users are logged in</description> + <message>Authentication is required for suspending the system while other users are logged in.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -277,8 +279,8 @@ </action> <action id="org.freedesktop.login1.suspend-ignore-inhibit"> - <_description>Suspend the system while an application asked to inhibit it</_description> - <_message>Authentication is required for suspending the system while an application asked to inhibit it.</_message> + <description>Suspend the system while an application asked to inhibit it</description> + <message>Authentication is required for suspending the system while an application asked to inhibit it.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -288,8 +290,8 @@ </action> <action id="org.freedesktop.login1.hibernate"> - <_description>Hibernate the system</_description> - <_message>Authentication is required for hibernating the system.</_message> + <description>Hibernate the system</description> + <message>Authentication is required for hibernating the system.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -298,8 +300,8 @@ </action> <action id="org.freedesktop.login1.hibernate-multiple-sessions"> - <_description>Hibernate the system while other users are logged in</_description> - <_message>Authentication is required for hibernating the system while other users are logged in.</_message> + <description>Hibernate the system while other users are logged in</description> + <message>Authentication is required for hibernating the system while other users are logged in.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -309,8 +311,8 @@ </action> <action id="org.freedesktop.login1.hibernate-ignore-inhibit"> - <_description>Hibernate the system while an application asked to inhibit it</_description> - <_message>Authentication is required for hibernating the system while an application asked to inhibit it.</_message> + <description>Hibernate the system while an application asked to inhibit it</description> + <message>Authentication is required for hibernating the system while an application asked to inhibit it.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -320,8 +322,8 @@ </action> <action id="org.freedesktop.login1.manage"> - <_description>Manage active sessions, users and seats</_description> - <_message>Authentication is required for managing active sessions, users and seats.</_message> + <description>Manage active sessions, users and seats</description> + <message>Authentication is required for managing active sessions, users and seats.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -330,8 +332,8 @@ </action> <action id="org.freedesktop.login1.lock-sessions"> - <_description>Lock or unlock active sessions</_description> - <_message>Authentication is required to lock or unlock active sessions.</_message> + <description>Lock or unlock active sessions</description> + <message>Authentication is required to lock or unlock active sessions.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -340,8 +342,8 @@ </action> <action id="org.freedesktop.login1.set-reboot-to-firmware-setup"> - <_description>Allow indication to the firmware to boot to setup interface</_description> - <_message>Authentication is required to indicate to the firmware to boot to setup interface.</_message> + <description>Allow indication to the firmware to boot to setup interface</description> + <message>Authentication is required to indicate to the firmware to boot to setup interface.</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> @@ -350,8 +352,8 @@ </action> <action id="org.freedesktop.login1.set-wall-message"> - <_description>Set a wall message</_description> - <_message>Authentication is required to set a wall message</_message> + <description>Set a wall message</description> + <message>Authentication is required to set a wall message</message> <defaults> <allow_any>auth_admin_keep</allow_any> <allow_inactive>auth_admin_keep</allow_inactive> diff --git a/src/login/pam_elogind.c b/src/login/pam_elogind.c index 221badce6..80b737694 100644 --- a/src/login/pam_elogind.c +++ b/src/login/pam_elogind.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/pam_elogind.sym b/src/login/pam_elogind.sym index 23ff75f68..d48b9e8cc 100644 --- a/src/login/pam_elogind.sym +++ b/src/login/pam_elogind.sym @@ -1,4 +1,6 @@ /*** + SPDX-License-Identifier: LGPL-2.1+ + This file is part of systemd. systemd is free software; you can redistribute it and/or modify it diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index cb5bb5e5f..16bb5118b 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. @@ -41,13 +42,23 @@ static int show_sysfs_one( struct udev_list_entry **item, const char *sub, const char *prefix, - unsigned n_columns) { + unsigned n_columns, + OutputFlags flags) { + + size_t max_width; assert(udev); assert(seat); assert(item); assert(prefix); + if (flags & OUTPUT_FULL_WIDTH) + max_width = (size_t) -1; + else if (n_columns < 10) + max_width = 10; + else + max_width = n_columns; + while (*item) { _cleanup_udev_device_unref_ struct udev_device *d = NULL; struct udev_list_entry *next, *lookahead; @@ -110,7 +121,7 @@ static int show_sysfs_one( lookahead = udev_list_entry_get_next(lookahead); } - k = ellipsize(sysfs, n_columns, 20); + k = ellipsize(sysfs, max_width, 20); if (!k) return -ENOMEM; @@ -124,7 +135,7 @@ static int show_sysfs_one( return -ENOMEM; free(k); - k = ellipsize(l, n_columns, 70); + k = ellipsize(l, max_width, 70); if (!k) return -ENOMEM; @@ -138,14 +149,16 @@ static int show_sysfs_one( if (!p) return -ENOMEM; - show_sysfs_one(udev, seat, item, sysfs, p, n_columns - 2); + show_sysfs_one(udev, seat, item, sysfs, p, + n_columns == (unsigned) -1 || n_columns < 2 ? n_columns : n_columns - 2, + flags); } } return 0; } -int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { +int show_sysfs(const char *seat, const char *prefix, unsigned n_columns, OutputFlags flags) { _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL; _cleanup_udev_unref_ struct udev *udev = NULL; struct udev_list_entry *first = NULL; @@ -154,8 +167,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { if (n_columns <= 0) n_columns = columns(); - if (!prefix) - prefix = ""; + prefix = strempty(prefix); if (isempty(seat)) seat = "seat0"; @@ -185,7 +197,7 @@ int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { first = udev_enumerate_get_list_entry(e); if (first) - show_sysfs_one(udev, seat, &first, "/", prefix, n_columns); + show_sysfs_one(udev, seat, &first, "/", prefix, n_columns, flags); else printf("%s%s%s\n", prefix, special_glyph(TREE_RIGHT), "(none)"); diff --git a/src/login/sysfs-show.h b/src/login/sysfs-show.h index 3e94bc3ed..15c902cc3 100644 --- a/src/login/sysfs-show.h +++ b/src/login/sysfs-show.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once /*** @@ -19,4 +20,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -int show_sysfs(const char *seat, const char *prefix, unsigned columns); +#include <sys/types.h> + +#include "output-mode.h" + +int show_sysfs(const char *seat, const char *prefix, unsigned columns, OutputFlags flags); diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index a3cf9d293..ad4700f32 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/test-login-shared.c b/src/login/test-login-shared.c index 47d8bf077..5f1e46323 100644 --- a/src/login/test-login-shared.c +++ b/src/login/test-login-shared.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. diff --git a/src/login/test-login-tables.c b/src/login/test-login-tables.c index 4fbc893a9..7772f4b85 100644 --- a/src/login/test-login-tables.c +++ b/src/login/test-login-tables.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd |