diff options
author | Sven Eden <yamakuzure@gmx.net> | 2017-04-06 14:56:03 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-04-26 12:59:13 +0200 |
commit | da4b83e77bc603745cf4a365d7f013301ef7fa89 (patch) | |
tree | 293d9508eeb1f841c71b0b0517287fd398aded82 /src/login | |
parent | eaca07ccfdf5d7dabc50afc7e539c2413dd69d3e (diff) |
Prep v228: Add remaining updates from upstream (3/3)
Apply remaining fixes and the performed move of utility functions
into their own foo-util.[hc] files on the rest of elogind.
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/inhibit.c | 18 | ||||
-rw-r--r-- | src/login/loginctl.c | 37 | ||||
-rw-r--r-- | src/login/logind-acl.c | 11 | ||||
-rw-r--r-- | src/login/logind-action.c | 22 | ||||
-rw-r--r-- | src/login/logind-action.h | 3 | ||||
-rw-r--r-- | src/login/logind-button.c | 8 | ||||
-rw-r--r-- | src/login/logind-core.c | 22 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 307 | ||||
-rw-r--r-- | src/login/logind-device.c | 3 | ||||
-rw-r--r-- | src/login/logind-inhibit.c | 13 | ||||
-rw-r--r-- | src/login/logind-seat-dbus.c | 10 | ||||
-rw-r--r-- | src/login/logind-seat.c | 14 | ||||
-rw-r--r-- | src/login/logind-session-dbus.c | 13 | ||||
-rw-r--r-- | src/login/logind-session-device.c | 9 | ||||
-rw-r--r-- | src/login/logind-session.c | 55 | ||||
-rw-r--r-- | src/login/logind-user-dbus.c | 8 | ||||
-rw-r--r-- | src/login/logind-user.c | 285 | ||||
-rw-r--r-- | src/login/logind-user.h | 11 | ||||
-rw-r--r-- | src/login/logind-utmp.c | 21 | ||||
-rw-r--r-- | src/login/logind.c | 94 | ||||
-rw-r--r-- | src/login/logind.h | 19 | ||||
-rw-r--r-- | src/login/pam_elogind.c | 41 | ||||
-rw-r--r-- | src/login/sysfs-show.c | 12 | ||||
-rw-r--r-- | src/login/test-inhibit.c | 6 |
24 files changed, 629 insertions, 413 deletions
diff --git a/src/login/inhibit.c b/src/login/inhibit.c index bfee1ca06..a8328592f 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -19,21 +19,27 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <fcntl.h> #include <getopt.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> -#include <fcntl.h> #include "sd-bus.h" -#include "bus-util.h" + +#include "alloc-util.h" #include "bus-error.h" -#include "util.h" -#include "build.h" -#include "strv.h" +#include "bus-util.h" +#include "fd-util.h" #include "formats-util.h" #include "process-util.h" #include "signal-util.h" +#include "strv.h" +#include "user-util.h" +#include "util.h" + +/// Additional includes needed by elogind +#include "musl_missing.h" static const char* arg_what = "idle:sleep:shutdown"; static const char* arg_who = NULL; diff --git a/src/login/loginctl.c b/src/login/loginctl.c index ce0adc45c..fec9fe58b 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -19,33 +19,40 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <unistd.h> #include <errno.h> -#include <string.h> #include <getopt.h> #include <locale.h> +#include <string.h> +#include <unistd.h> #include "sd-bus.h" -#include "sd-login.h" -#include "bus-util.h" + +#include "alloc-util.h" #include "bus-error.h" +#include "bus-util.h" +//#include "cgroup-show.h" +#include "cgroup-util.h" #include "log.h" -#include "util.h" +//#include "logs-show.h" #include "macro.h" #include "pager.h" -#include "build.h" +#include "parse-util.h" +#include "process-util.h" +#include "signal-util.h" +#include "spawn-polkit-agent.h" #include "strv.h" -#include "unit-name.h" #include "sysfs-show.h" -//#include "logs-show.h" -//#include "cgroup-show.h" -#include "cgroup-util.h" -#include "spawn-polkit-agent.h" -#include "verbs.h" -#include "process-util.h" #include "terminal-util.h" -#include "signal-util.h" +#include "unit-name.h" +#include "user-util.h" +#include "util.h" +#include "verbs.h" + +/// Additional includes for elogind #include "logind-action.h" +#include "musl_missing.h" +#include "sd-login.h" +#include "virt.h" static char **arg_property = NULL; static bool arg_all = false; @@ -1694,7 +1701,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hp:als:H:M:ci", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "hp:als:H:M:n:o:ci", options, NULL)) >= 0) switch (c) { diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c index 466225d69..d0dd569a0 100644 --- a/src/login/logind-acl.c +++ b/src/login/logind-acl.c @@ -22,12 +22,17 @@ #include <errno.h> #include <string.h> -#include "util.h" -#include "formats-util.h" #include "acl-util.h" -#include "set.h" +#include "alloc-util.h" +#include "dirent-util.h" +#include "escape.h" +#include "fd-util.h" +#include "formats-util.h" #include "logind-acl.h" +#include "set.h" +#include "string-util.h" #include "udev-util.h" +#include "util.h" static int flush_acl(acl_t acl) { acl_entry_t i; diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 9b2ec6e24..474b69628 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -21,19 +21,25 @@ #include <unistd.h> -#include "sd-messages.h" -#include "util.h" -#include "strv.h" -#include "fileio.h" -#include "conf-parser.h" -// #include "special.h" -#include "sleep-config.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" +#include "conf-parser.h" +#include "formats-util.h" #include "logind-action.h" -// #include "formats-util.h" #include "process-util.h" +#include "sleep-config.h" +//#include "special.h" +#include "string-table.h" #include "terminal-util.h" +#include "user-util.h" + +// Additional includes needed by elogind +#include "fd-util.h" +#include "fileio.h" +#include "sd-messages.h" +#include "strv.h" + int manager_handle_action( Manager *m, diff --git a/src/login/logind-action.h b/src/login/logind-action.h index 6b63b92d3..2fcad0397 100644 --- a/src/login/logind-action.h +++ b/src/login/logind-action.h @@ -22,7 +22,7 @@ ***/ typedef enum HandleAction { - HANDLE_IGNORE = 0, + HANDLE_IGNORE, HANDLE_POWEROFF, HANDLE_REBOOT, HANDLE_HALT, @@ -36,6 +36,7 @@ typedef enum HandleAction { } HandleAction; #include "logind.h" +#include "logind-inhibit.h" int manager_handle_action( Manager *m, diff --git a/src/login/logind-button.c b/src/login/logind-button.c index f40e35a8c..b08b69dbf 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -19,16 +19,20 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <string.h> #include <errno.h> #include <fcntl.h> +#include <string.h> #include <sys/ioctl.h> #include <unistd.h> #include <linux/input.h> #include "sd-messages.h" -#include "util.h" + +#include "alloc-util.h" +#include "fd-util.h" #include "logind-button.h" +#include "string-util.h" +#include "util.h" Button* button_new(Manager *m, const char *name) { Button *b; diff --git a/src/login/logind-core.c b/src/login/logind-core.c index fe97c1de0..4ab66cd9b 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -19,19 +19,22 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <sys/types.h> -#include <sys/ioctl.h> #include <fcntl.h> #include <pwd.h> +#include <sys/ioctl.h> +#include <sys/types.h> #include <linux/vt.h> -#include "strv.h" -#include "cgroup-util.h" -#include "bus-util.h" +#include "alloc-util.h" #include "bus-error.h" -#include "udev-util.h" +#include "bus-util.h" +#include "cgroup-util.h" +#include "fd-util.h" #include "logind.h" +#include "strv.h" #include "terminal-util.h" +#include "udev-util.h" +#include "user-util.h" int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) { Device *d; @@ -95,15 +98,16 @@ int manager_add_session(Manager *m, const char *id, Session **_session) { int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user) { User *u; + int r; assert(m); assert(name); u = hashmap_get(m->users, UID_TO_PTR(uid)); if (!u) { - u = user_new(m, uid, gid, name); - if (!u) - return -ENOMEM; + r = user_new(&u, m, uid, gid, name); + if (r < 0) + return r; } if (_user) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index d88636f74..0c25d1f6f 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -20,29 +20,36 @@ ***/ #include <errno.h> +#include <pwd.h> #include <string.h> #include <unistd.h> -#include <pwd.h> #include "sd-messages.h" -#include "strv.h" -#include "mkdir.h" -#include "path-util.h" -// #include "special.h" -#include "sleep-config.h" -#include "fileio-label.h" -#include "unit-name.h" -#include "audit.h" -#include "bus-util.h" -#include "bus-error.h" + +#include "alloc-util.h" +#include "audit-util.h" #include "bus-common-errors.h" -#include "udev-util.h" -#include "selinux-util.h" +#include "bus-error.h" +#include "bus-util.h" +#include "dirent-util.h" #include "efivars.h" -#include "logind.h" +#include "escape.h" +#include "fd-util.h" +#include "fileio-label.h" #include "formats-util.h" +#include "fs-util.h" +#include "logind.h" +#include "mkdir.h" +#include "path-util.h" #include "process-util.h" +#include "selinux-util.h" +#include "sleep-config.h" +//#include "special.h" +#include "strv.h" #include "terminal-util.h" +#include "udev-util.h" +#include "unit-name.h" +#include "user-util.h" #include "utmp-wtmp.h" int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) { @@ -301,8 +308,10 @@ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd r = sd_bus_message_read(message, "u", &pid); if (r < 0) return r; + if (pid < 0) + return -EINVAL; - if (pid <= 0) { + if (pid == 0) { r = manager_get_session_from_creds(m, message, NULL, error, &session); if (r < 0) return r; @@ -362,8 +371,10 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu r = sd_bus_message_read(message, "u", &pid); if (r < 0) return r; + if (pid < 0) + return -EINVAL; - if (pid <= 0) { + if (pid == 0) { r = manager_get_user_from_creds(m, message, UID_INVALID, error, &user); if (r < 0) return r; @@ -566,12 +577,14 @@ static int method_list_inhibitors(sd_bus_message *message, void *userdata, sd_bu static int method_create_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *desktop; - uint32_t uid, leader, audit_id = 0; + uint32_t audit_id = 0; _cleanup_free_ char *id = NULL; Session *session = NULL; Manager *m = userdata; User *user = NULL; Seat *seat = NULL; + pid_t leader; + uid_t uid; int remote; uint32_t vtnr = 0; SessionType t; @@ -581,11 +594,16 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus assert(message); assert(m); + assert_cc(sizeof(pid_t) == sizeof(uint32_t)); + assert_cc(sizeof(uid_t) == sizeof(uint32_t)); + r = sd_bus_message_read(message, "uusssssussbss", &uid, &leader, &service, &type, &class, &desktop, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host); if (r < 0) return r; - if (leader == 1) + if (!uid_is_valid(uid)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UID"); + if (leader < 0 || leader == 1) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID"); if (isempty(type)) @@ -677,7 +695,7 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus c = SESSION_USER; } - if (leader <= 0) { + if (leader == 0) { _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); @@ -1092,7 +1110,9 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu r = sd_bus_creds_get_owner_uid(creds, &uid); if (r < 0) return r; - } + + } else if (!uid_is_valid(uid)) + return -EINVAL; errno = 0; pw = getpwuid(uid); @@ -1347,39 +1367,70 @@ static int have_multiple_sessions( static int bus_manager_log_shutdown( Manager *m, InhibitWhat w, - HandleAction action) { +/// elogind does not support systemd units +#if 0 + const char *unit_name) { const char *p, *q; assert(m); + assert(unit_name); if (w != INHIBIT_SHUTDOWN) return 0; - switch (action) { - case HANDLE_POWEROFF: - p = "MESSAGE=System is powering down."; + if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) { + p = "MESSAGE=System is powering down"; q = "SHUTDOWN=power-off"; - break; - case HANDLE_HALT: - p = "MESSAGE=System is halting."; + } else if (streq(unit_name, SPECIAL_HALT_TARGET)) { + p = "MESSAGE=System is halting"; q = "SHUTDOWN=halt"; - break; - case HANDLE_REBOOT: - p = "MESSAGE=System is rebooting."; + } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) { + p = "MESSAGE=System is rebooting"; q = "SHUTDOWN=reboot"; - break; - case HANDLE_KEXEC: - p = "MESSAGE=System is rebooting with kexec."; + } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) { + p = "MESSAGE=System is rebooting with kexec"; q = "SHUTDOWN=kexec"; - break; - default: - p = "MESSAGE=System is shutting down."; + } else { + p = "MESSAGE=System is shutting down"; q = NULL; } - - if (!isempty(m->wall_message)) - p = strjoina(p, " (", m->wall_message, ")"); +#else + HandleAction action) { + + const char *p, *q; + + assert(m); + + if (w != INHIBIT_SHUTDOWN) + return 0; + + switch (action) { + case HANDLE_POWEROFF: + p = "MESSAGE=System is powering down."; + q = "SHUTDOWN=power-off"; + break; + case HANDLE_HALT: + p = "MESSAGE=System is halting."; + q = "SHUTDOWN=halt"; + break; + case HANDLE_REBOOT: + p = "MESSAGE=System is rebooting."; + q = "SHUTDOWN=reboot"; + break; + case HANDLE_KEXEC: + p = "MESSAGE=System is rebooting with kexec."; + q = "SHUTDOWN=kexec"; + break; + default: + p = "MESSAGE=System is shutting down."; + q = NULL; + } +#endif // 0 + if (isempty(m->wall_message)) + p = strjoina(p, "."); + else + p = strjoina(p, " (", m->wall_message, ")."); return log_struct(LOG_NOTICE, LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN), @@ -1433,26 +1484,18 @@ int manager_set_lid_switch_ignore(Manager *m, usec_t until) { return r; } -static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) { - - static const char * const signal_name[_INHIBIT_WHAT_MAX] = { - [INHIBIT_SHUTDOWN] = "PrepareForShutdown", - [INHIBIT_SLEEP] = "PrepareForSleep" - }; - - int active = _active; - - assert(m); - assert(w >= 0); - assert(w < _INHIBIT_WHAT_MAX); - assert(signal_name[w]); +static void reset_scheduled_shutdown(Manager *m) { + m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source); + m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source); + m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source); + m->scheduled_shutdown_type = mfree(m->scheduled_shutdown_type); + m->scheduled_shutdown_timeout = 0; + m->shutdown_dry_run = false; - return sd_bus_emit_signal(m->bus, - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - signal_name[w], - "b", - active); + if (m->unlink_nologin) { + (void) unlink("/run/nologin"); + m->unlink_nologin = false; + } } static int execute_shutdown_or_sleep( @@ -1464,8 +1507,8 @@ static int execute_shutdown_or_sleep( /// elogind does not need these, we do it ourselves #if 0 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; + char *c = NULL; const char *p; - char *c; #endif // 0 int r; @@ -1477,6 +1520,10 @@ static int execute_shutdown_or_sleep( /// elogind does it directly without depending on systemd running the system #if 0 + if (m->shutdown_dry_run) { + log_info("Running in dry run, suppressing action."); + reset_scheduled_shutdown(m); + } else { r = sd_bus_call_method( m->bus, "org.freedesktop.systemd1", @@ -1501,6 +1548,7 @@ static int execute_shutdown_or_sleep( c = strdup(p); if (!c) return -ENOMEM; + } m->action_unit = unit_name; free(m->action_job); @@ -1508,12 +1556,6 @@ static int execute_shutdown_or_sleep( m->action_what = w; #endif // 0 - if (w == INHIBIT_SLEEP) - /* And we're back. */ - send_prepare_for(m, w, false); - - m->action_what = 0; - /* Make sure the lid switch is ignored for a while */ manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec); @@ -1608,6 +1650,28 @@ static int delay_shutdown_or_sleep( return 0; } +static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) { + + static const char * const signal_name[_INHIBIT_WHAT_MAX] = { + [INHIBIT_SHUTDOWN] = "PrepareForShutdown", + [INHIBIT_SLEEP] = "PrepareForSleep" + }; + + int active = _active; + + assert(m); + assert(w >= 0); + assert(w < _INHIBIT_WHAT_MAX); + assert(signal_name[w]); + + return sd_bus_emit_signal(m->bus, + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + signal_name[w], + "b", + active); +} + int bus_manager_shutdown_or_sleep_now_or_later( Manager *m, HandleAction action, @@ -1911,6 +1975,11 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ if (r < 0) return r; + if (startswith(type, "dry-")) { + type += 4; + m->shutdown_dry_run = true; + } + if (streq(type, "reboot")) { action = "org.freedesktop.login1.reboot"; action_multiple_sessions = "org.freedesktop.login1.reboot-multiple-sessions"; @@ -2005,17 +2074,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd assert(message); cancelled = m->scheduled_shutdown_type != NULL; - - m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source); - m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source); - m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source); - m->scheduled_shutdown_type = mfree(m->scheduled_shutdown_type); - m->scheduled_shutdown_timeout = 0; - - if (m->unlink_nologin) { - (void) unlink("/run/nologin"); - m->unlink_nologin = false; - } + reset_scheduled_shutdown(m); if (cancelled) { _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; @@ -2030,7 +2089,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd } utmp_wall("The system shutdown has been cancelled", - lookup_uid(uid), tty, logind_wall_tty_filter, m); + uid_to_name(uid), tty, logind_wall_tty_filter, m); } return sd_bus_reply_method_return(message, "b", cancelled); @@ -2743,13 +2802,101 @@ int manager_send_changed(Manager *manager, const char *property, ...) { /// UNNEEDED by elogind #if 0 +int manager_start_slice( + Manager *manager, + const char *slice, + const char *description, + const char *after, + const char *after2, + uint64_t tasks_max, + sd_bus_error *error, + char **job) { + + _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; + int r; + + assert(manager); + assert(slice); + + r = sd_bus_message_new_method_call( + manager->bus, + &m, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "StartTransientUnit"); + if (r < 0) + return r; + + r = sd_bus_message_append(m, "ss", strempty(slice), "fail"); + if (r < 0) + return r; + + r = sd_bus_message_open_container(m, 'a', "(sv)"); + if (r < 0) + return r; + + if (!isempty(description)) { + r = sd_bus_message_append(m, "(sv)", "Description", "s", description); + if (r < 0) + return r; + } + + if (!isempty(after)) { + r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after); + if (r < 0) + return r; + } + + if (!isempty(after2)) { + r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after2); + if (r < 0) + return r; + } + + r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", tasks_max); + if (r < 0) + return r; + + r = sd_bus_message_close_container(m); + if (r < 0) + return r; + + r = sd_bus_message_append(m, "a(sa(sv))", 0); + if (r < 0) + return r; + + r = sd_bus_call(manager->bus, m, 0, error, &reply); + if (r < 0) + return r; + + if (job) { + const char *j; + char *copy; + + r = sd_bus_message_read(reply, "o", &j); + if (r < 0) + return r; + + copy = strdup(j); + if (!copy) + return -ENOMEM; + + *job = copy; + } + + return 1; +} + int manager_start_scope( Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, - const char *after, const char *after2, + const char *after, + const char *after2, + uint64_t tasks_max, sd_bus_error *error, char **job) { @@ -2817,6 +2964,10 @@ int manager_start_scope( if (r < 0) return r; + r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", tasks_max); + if (r < 0) + return r; + r = sd_bus_message_close_container(m); if (r < 0) return r; diff --git a/src/login/logind-device.c b/src/login/logind-device.c index ee4c45fb8..ffb9162e5 100644 --- a/src/login/logind-device.c +++ b/src/login/logind-device.c @@ -21,8 +21,9 @@ #include <string.h> -#include "util.h" +#include "alloc-util.h" #include "logind-device.h" +#include "util.h" Device* device_new(Manager *m, const char *sysfs, bool master) { Device *d; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 0c9c1e5e9..33fbdde55 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -24,11 +24,18 @@ #include <string.h> #include <unistd.h> -#include "util.h" -#include "mkdir.h" -#include "logind-inhibit.h" +#include "alloc-util.h" +#include "escape.h" +#include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "logind-inhibit.h" +#include "mkdir.h" +#include "parse-util.h" +#include "string-table.h" +#include "string-util.h" +#include "user-util.h" +#include "util.h" Inhibitor* inhibitor_new(Manager *m, const char* id) { Inhibitor *i; diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 346e1d2ce..43b578f36 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -22,13 +22,15 @@ #include <errno.h> #include <string.h> -#include "util.h" -#include "bus-util.h" -#include "strv.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-label.h" -#include "logind.h" +#include "bus-util.h" #include "logind-seat.h" +#include "logind.h" +#include "strv.h" +#include "user-util.h" +#include "util.h" static int property_get_active_session( sd_bus *bus, diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 1be871375..6838d3699 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -20,17 +20,23 @@ ***/ #include <errno.h> -#include <unistd.h> #include <fcntl.h> #include <string.h> +#include <unistd.h> #include "sd-messages.h" -#include "logind-seat.h" + +#include "alloc-util.h" +#include "fd-util.h" +#include "fileio.h" +#include "formats-util.h" #include "logind-acl.h" -#include "util.h" +#include "logind-seat.h" #include "mkdir.h" -#include "formats-util.h" +#include "parse-util.h" +#include "string-util.h" #include "terminal-util.h" +#include "util.h" Seat *seat_new(Manager *m, const char *id) { Seat *s; diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index 5d3fec411..0be2f8abe 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -22,15 +22,16 @@ #include <errno.h> #include <string.h> -#include "util.h" -#include "strv.h" -#include "bus-util.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-label.h" - -#include "logind.h" -#include "logind-session.h" +#include "bus-util.h" +#include "fd-util.h" #include "logind-session-device.h" +#include "logind-session.h" +#include "logind.h" +#include "strv.h" +#include "util.h" static int property_get_user( sd_bus *bus, diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 656f268db..9bf3ca099 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -20,16 +20,19 @@ ***/ #include <fcntl.h> -#include <libudev.h> #include <linux/input.h> #include <string.h> #include <sys/ioctl.h> #include <sys/types.h> -#include "util.h" -#include "missing.h" +#include "libudev.h" + +#include "alloc-util.h" #include "bus-util.h" +#include "fd-util.h" #include "logind-session-device.h" +#include "missing.h" +#include "util.h" enum SessionDeviceNotifications { SESSION_DEVICE_RESUME, diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 9b6f46b6f..c53e9f9a5 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -21,24 +21,32 @@ #include <errno.h> #include <fcntl.h> -#include <linux/vt.h> #include <linux/kd.h> +#include <linux/vt.h> #include <signal.h> #include <string.h> #include <sys/ioctl.h> #include <unistd.h> #include "sd-messages.h" -#include "util.h" -#include "mkdir.h" -#include "path-util.h" -#include "fileio.h" -#include "audit.h" -#include "bus-util.h" + +#include "alloc-util.h" +#include "audit-util.h" #include "bus-error.h" -#include "logind-session.h" +#include "bus-util.h" +#include "escape.h" +#include "fd-util.h" +#include "fileio.h" #include "formats-util.h" +#include "io-util.h" +#include "logind-session.h" +#include "mkdir.h" +#include "parse-util.h" +#include "path-util.h" +#include "string-table.h" #include "terminal-util.h" +#include "user-util.h" +#include "util.h" // #define RELEASE_USEC (20*USEC_PER_SEC) @@ -511,28 +519,35 @@ int session_activate(Session *s) { /// UNNEEDED by elogind #if 0 static int session_start_scope(Session *s) { - int r = 0; + int r; assert(s); assert(s->user); if (!s->scope) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_free_ char *description = NULL; - char *scope = NULL; //, *job = NULL; - - description = strjoin("Session ", s->id, " of user ", s->user->name, NULL); - if (!description) - return log_oom(); + char *scope, *job = NULL; + const char *description; scope = strjoin("session-", s->id, ".scope", NULL); if (!scope) return log_oom(); - r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", "systemd-user-sessions.service", &error, &job); + description = strjoina("Session ", s->id, " of user ", s->user->name, NULL); + + r = manager_start_scope( + s->manager, + scope, + s->leader, + s->user->slice, + description, + "systemd-logind.service", + "systemd-user-sessions.service", + (uint64_t) -1, /* disable TasksMax= for the scope, rely on the slice setting for it */ + &error, + &job); if (r < 0) { - log_error("Failed to start session scope %s: %s %s", - scope, bus_error_message(&error, r), error.name); + log_error_errno(r, "Failed to start session scope %s: %s", scope, bus_error_message(&error, r)); free(scope); return r; } else { @@ -544,7 +559,7 @@ static int session_start_scope(Session *s) { } if (s->scope) - hashmap_put(s->manager->session_units, s->scope, s); + (void) hashmap_put(s->manager->session_units, s->scope, s); return 0; } @@ -1091,7 +1106,7 @@ static int session_open_vt(Session *s) { sprintf(path, "/dev/tty%u", s->vtnr); s->vtfd = open_terminal(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY); if (s->vtfd < 0) - return log_error_errno(errno, "cannot open VT %s of session %s: %m", path, s->id); + return log_error_errno(s->vtfd, "cannot open VT %s of session %s: %m", path, s->id); return s->vtfd; } diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 20ea2fbdc..df901f655 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -22,11 +22,13 @@ #include <errno.h> #include <string.h> -#include "strv.h" +#include "alloc-util.h" #include "bus-util.h" -#include "logind.h" -#include "logind-user.h" #include "formats-util.h" +#include "logind-user.h" +#include "logind.h" +#include "strv.h" +#include "user-util.h" static int property_get_display( sd_bus *bus, diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 27f737000..ecc61080a 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -19,64 +19,94 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <sys/mount.h> +#include <errno.h> #include <string.h> +#include <sys/mount.h> #include <unistd.h> -#include <errno.h> -#include "util.h" -#include "mkdir.h" -#include "rm-rf.h" -#include "hashmap.h" -#include "fileio.h" -#include "path-util.h" -// #include "special.h" -#include "unit-name.h" -#include "bus-util.h" +#include "alloc-util.h" +#include "bus-common-errors.h" #include "bus-error.h" -#include "conf-parser.h" +#include "bus-util.h" #include "clean-ipc.h" -#include "smack-util.h" +#include "conf-parser.h" +#include "escape.h" +#include "fd-util.h" +#include "fileio.h" #include "formats-util.h" +#include "fs-util.h" +#include "hashmap.h" #include "label.h" #include "logind-user.h" +#include "mkdir.h" +#include "mount-util.h" +#include "parse-util.h" +#include "path-util.h" +#include "rm-rf.h" +#include "smack-util.h" +//#include "special.h" +#include "stdio-util.h" +#include "string-table.h" +#include "unit-name.h" +#include "user-util.h" +#include "util.h" -User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) { - User *u; +int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) { + _cleanup_(user_freep) User *u = NULL; + char lu[DECIMAL_STR_MAX(uid_t) + 1]; + int r; + assert(out); assert(m); assert(name); u = new0(User, 1); if (!u) - return NULL; + return -ENOMEM; + + u->manager = m; + u->uid = uid; + u->gid = gid; + xsprintf(lu, UID_FMT, uid); u->name = strdup(name); if (!u->name) - goto fail; + return -ENOMEM; if (asprintf(&u->state_file, "/run/systemd/users/"UID_FMT, uid) < 0) - goto fail; + return -ENOMEM; - if (hashmap_put(m->users, UID_TO_PTR(uid), u) < 0) - goto fail; + if (asprintf(&u->runtime_path, "/run/user/"UID_FMT, uid) < 0) + return -ENOMEM; - u->manager = m; - u->uid = uid; - u->gid = gid; + r = slice_build_subslice("user.slice", lu, &u->slice); + if (r < 0) + return r; - return u; + r = unit_name_build("user", lu, ".service", &u->service); + if (r < 0) + return r; -fail: - free(u->state_file); - free(u->name); - free(u); + r = hashmap_put(m->users, UID_TO_PTR(uid), u); + if (r < 0) + return r; + + r = hashmap_put(m->user_units, u->slice, u); + if (r < 0) + return r; + + r = hashmap_put(m->user_units, u->service, u); + if (r < 0) + return r; - return NULL; + *out = u; + u = NULL; + return 0; } -void user_free(User *u) { - assert(u); +User *user_free(User *u) { + if (!u) + return NULL; if (u->in_gc_queue) LIST_REMOVE(gc_queue, u->manager->user_gc_queue, u); @@ -84,29 +114,26 @@ void user_free(User *u) { while (u->sessions) session_free(u->sessions); - if (u->slice) { - hashmap_remove(u->manager->user_units, u->slice); - free(u->slice); - } + if (u->service) + hashmap_remove_value(u->manager->user_units, u->service, u); - if (u->service) { - hashmap_remove(u->manager->user_units, u->service); - free(u->service); - } + if (u->slice) + hashmap_remove_value(u->manager->user_units, u->slice, u); + + hashmap_remove_value(u->manager->users, UID_TO_PTR(u->uid), u); -/// elogind does not support slice and service jobs +/// elogind neither supports slice nor service jobs. #if 0 - free(u->slice_job); - free(u->service_job); + u->slice_job = mfree(u->slice_job); + u->service_job = mfree(u->service_job); #endif // 0 + u->service = mfree(u->service); + u->slice = mfree(u->slice); + u->runtime_path = mfree(u->runtime_path); + u->state_file = mfree(u->state_file); + u->name = mfree(u->name); - free(u->runtime_path); - - hashmap_remove(u->manager->users, UID_TO_PTR(u->uid)); - - free(u->name); - free(u->state_file); - free(u); + return mfree(u); } static int user_save_internal(User *u) { @@ -134,21 +161,15 @@ static int user_save_internal(User *u) { u->name, user_state_to_string(user_get_state(u))); + /* LEGACY: no-one reads RUNTIME= anymore, drop it at some point */ if (u->runtime_path) fprintf(f, "RUNTIME=%s\n", u->runtime_path); - if (u->service) - fprintf(f, "SERVICE=%s\n", u->service); -/// elogind does not support service jobs +/// elogind neither supports service nor slice jobs #if 0 if (u->service_job) fprintf(f, "SERVICE_JOB=%s\n", u->service_job); -#endif // 0 - if (u->slice) - fprintf(f, "SLICE=%s\n", u->slice); -/// elogind does not support slice jobs -#if 0 if (u->slice_job) fprintf(f, "SLICE_JOB=%s\n", u->slice_job); #endif // 0 @@ -287,15 +308,9 @@ int user_load(User *u) { assert(u); r = parse_env_file(u->state_file, NEWLINE, - "RUNTIME", &u->runtime_path, - "SERVICE", &u->service, -/// elogind does not support service jobs +/// elogind neither supports service nor slice jobs #if 0 "SERVICE_JOB", &u->service_job, -#endif // 0 - "SLICE", &u->slice, -/// elogind does not support slice jobs -#if 0 "SLICE_JOB", &u->slice_job, #endif // 0 "DISPLAY", &display, @@ -332,7 +347,6 @@ int user_load(User *u) { } static int user_mkdir_runtime_path(User *u) { - char *p; int r; assert(u); @@ -341,16 +355,10 @@ static int user_mkdir_runtime_path(User *u) { if (r < 0) return log_error_errno(r, "Failed to create /run/user: %m"); - if (!u->runtime_path) { - if (asprintf(&p, "/run/user/" UID_FMT, u->uid) < 0) - return log_oom(); - } else - p = u->runtime_path; - - if (path_is_mount_point(p, 0) <= 0) { + if (path_is_mount_point(u->runtime_path, 0) <= 0) { _cleanup_free_ char *t = NULL; - (void) mkdir_label(p, 0700); + (void) mkdir_label(u->runtime_path, 0700); if (mac_smack_use()) r = asprintf(&t, "mode=0700,smackfsroot=*,uid=" UID_FMT ",gid=" GID_FMT ",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size); @@ -361,10 +369,10 @@ static int user_mkdir_runtime_path(User *u) { goto fail; } - r = mount("tmpfs", p, "tmpfs", MS_NODEV|MS_NOSUID, t); + r = mount("tmpfs", u->runtime_path, "tmpfs", MS_NODEV|MS_NOSUID, t); if (r < 0) { if (errno != EPERM) { - r = log_error_errno(errno, "Failed to mount per-user tmpfs directory %s: %m", p); + r = log_error_errno(errno, "Failed to mount per-user tmpfs directory %s: %m", u->runtime_path); goto fail; } @@ -372,106 +380,91 @@ static int user_mkdir_runtime_path(User *u) { * CAP_SYS_ADMIN-less container? In this case, * just use a normal directory. */ - r = chmod_and_chown(p, 0700, u->uid, u->gid); + r = chmod_and_chown(u->runtime_path, 0700, u->uid, u->gid); if (r < 0) { log_error_errno(r, "Failed to change runtime directory ownership and mode: %m"); goto fail; } } - r = label_fix(p, false, false); + r = label_fix(u->runtime_path, false, false); if (r < 0) - log_warning_errno(r, "Failed to fix label of '%s', ignoring: %m", p); + log_warning_errno(r, "Failed to fix label of '%s', ignoring: %m", u->runtime_path); } - u->runtime_path = p; return 0; fail: - if (p) { /* Try to clean up, but ignore errors */ - (void) rmdir(p); - free(p); - } - - u->runtime_path = NULL; + (void) rmdir(u->runtime_path); return r; } static int user_start_slice(User *u) { - // char *job; +/// elogind can not ask systemd via dbus to start user services +#if 0 + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + const char *description; + char *job; int r; assert(u); - if (!u->slice) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - char lu[DECIMAL_STR_MAX(uid_t) + 1], *slice; - sprintf(lu, UID_FMT, u->uid); - - r = slice_build_subslice("user.slice", lu, &slice); - if (r < 0) - return r; - -/// elogind : Do not try to use dbus to ask systemd -#if 0 - r = manager_start_unit(u->manager, slice, &error, &job); + u->slice_job = mfree(u->slice_job); + description = strjoina("User Slice of ", u->name); + + r = manager_start_slice( + u->manager, + u->slice, + description, + "systemd-logind.service", + "systemd-user-sessions.service", + u->manager->user_tasks_max, + &error, + &job); if (r < 0) { - log_error("Failed to start user slice: %s", bus_error_message(&error, r)); - free(slice); + /* we don't fail due to this, let's try to continue */ + if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS)) + log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)", u->slice, bus_error_message(&error, r), error.name); } else { -#endif // 0 - u->slice = slice; - -/// elogind does not support slice jobs -#if 0 - free(u->slice_job); u->slice_job = job; } -#endif // 0 - } +#else + assert(u); - if (u->slice) - hashmap_put(u->manager->user_units, u->slice, u); + hashmap_put(u->manager->user_units, u->slice, u); +#endif // 0 return 0; } static int user_start_service(User *u) { +/// elogind can not ask systemd via dbus to start user services +#if 0 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - // char *job; + char *job; int r; assert(u); - if (!u->service) { - char lu[DECIMAL_STR_MAX(uid_t) + 1], *service; - sprintf(lu, UID_FMT, u->uid); - - r = unit_name_build("user", lu, ".service", &service); - if (r < 0) - return log_error_errno(r, "Failed to build service name: %m"); + u->service_job = mfree(u->service_job); -/// elogind : Do not try to use dbus to ask systemd -#if 0 - r = manager_start_unit(u->manager, service, &error, &job); -#endif // 0 + r = manager_start_unit( + u->manager, + u->service, + &error, + &job); if (r < 0) { - log_error("Failed to start user service: %s", bus_error_message(&error, r)); - free(service); + /* 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 { - u->service = service; - -/// elogind does not support service jobs -#if 0 - free(u->service_job); u->service_job = job; -#endif // 0 - } } +#else + assert(u); - if (u->service) - hashmap_put(u->manager->user_units, u->service, u); + hashmap_put(u->manager->user_units, u->service, u); +#endif // 0 return 0; } @@ -541,14 +534,11 @@ int user_start(User *u) { #if 0 static int user_stop_slice(User *u) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - // char *job; - int r = 0; + char *job; + int r; assert(u); - if (!u->slice) - return 0; - r = manager_stop_unit(u->manager, u->slice, &error, &job); if (r < 0) { log_error("Failed to stop user slice: %s", bus_error_message(&error, r)); @@ -563,14 +553,11 @@ static int user_stop_slice(User *u) { static int user_stop_service(User *u) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - // char *job; - int r = 0; + char *job; + int r; assert(u); - if (!u->service) - return 0; - r = manager_stop_unit(u->manager, u->service, &error, &job); if (r < 0) { log_error("Failed to stop user service: %s", bus_error_message(&error, r)); @@ -589,9 +576,6 @@ static int user_remove_runtime_path(User *u) { assert(u); - if (!u->runtime_path) - return 0; - r = rm_rf(u->runtime_path, 0); if (r < 0) log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path); @@ -607,8 +591,6 @@ static int user_remove_runtime_path(User *u) { if (r < 0) log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path); - u->runtime_path = mfree(u->runtime_path); - return r; } @@ -748,7 +730,7 @@ bool user_check_gc(User *u, bool drop_not_started) { if (user_check_linger_file(u) > 0) return true; -/// elogind does not support systemd services and slices +/// elogind neither supports service nor slice jobs #if 0 if (u->slice_job && manager_job_is_active(u->manager, u->slice_job)) return true; @@ -778,7 +760,7 @@ UserState user_get_state(User *u) { if (u->stopping) return USER_CLOSING; -/// elogind does not support slice and service jobs +/// elogind neither supports service nor slice jobs. #if 0 if (!u->started || u->slice_job || u->service_job) #else @@ -813,9 +795,6 @@ int user_kill(User *u, int signo) { #if 0 assert(u); - if (!u->slice) - return -ESRCH; - return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL); #else Session *s; diff --git a/src/login/logind-user.h b/src/login/logind-user.h index b30e7d60c..a59b11b2a 100644 --- a/src/login/logind-user.h +++ b/src/login/logind-user.h @@ -39,19 +39,17 @@ typedef enum UserState { struct User { Manager *manager; - uid_t uid; gid_t gid; char *name; - char *state_file; char *runtime_path; /* These are always NULL, and here just for logind-user-dbus.c to easily provide a NULL value for the user's service and slice properties. */ - char *service; char *slice; + char *service; /// UNNEEDED (and unsupported) by elogind #if 0 @@ -71,8 +69,11 @@ struct User { LIST_FIELDS(User, gc_queue); }; -User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name); -void user_free(User *u); +int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name); +User *user_free(User *u); + +DEFINE_TRIVIAL_CLEANUP_FUNC(User *, user_free); + bool user_check_gc(User *u, bool drop_not_started); void user_add_to_gc_queue(User *u); int user_start(User *u); diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index faa4fc733..8c2bfb07a 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -20,20 +20,23 @@ ***/ #include <errno.h> +#include <pwd.h> #include <string.h> #include <unistd.h> -#include <pwd.h> #include "sd-messages.h" -#include "strv.h" -// #include "special.h" -#include "unit-name.h" -#include "audit.h" -#include "bus-util.h" -#include "bus-error.h" + +#include "alloc-util.h" +#include "audit-util.h" #include "bus-common-errors.h" -#include "logind.h" +#include "bus-error.h" +#include "bus-util.h" #include "formats-util.h" +#include "logind.h" +//#include "special.h" +#include "strv.h" +#include "unit-name.h" +#include "user-util.h" #include "utmp-wtmp.h" _const_ static usec_t when_wall(usec_t n, usec_t elapse) { @@ -94,7 +97,7 @@ static int warn_wall(Manager *m, usec_t n) { return 0; } - utmp_wall(l, lookup_uid(m->scheduled_shutdown_uid), + utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid), m->scheduled_shutdown_tty, logind_wall_tty_filter, m); return 1; diff --git a/src/login/logind.c b/src/login/logind.c index 2e4342b0a..8693627f2 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -20,24 +20,31 @@ ***/ #include <errno.h> -#include <libudev.h> #include <fcntl.h> #include <string.h> #include <unistd.h> +#include "libudev.h" #include "sd-daemon.h" -#include "strv.h" -#include "conf-parser.h" -#include "bus-util.h" + +#include "alloc-util.h" #include "bus-error.h" -#include "udev-util.h" +#include "bus-util.h" +#include "conf-parser.h" +#include "def.h" +#include "dirent-util.h" +#include "fd-util.h" #include "formats-util.h" +#include "logind.h" #include "signal-util.h" +#include "strv.h" +#include "udev-util.h" + +/// additional includes elogind needs +#include "cgroup.h" // From src/core/ #include "label.h" -#include "logind.h" -#include "cgroup.h" -#include "mount-setup.h" -#include "virt.h" +#include "mount-setup.h" // From src/core +#include "musl_missing.h" static void manager_free(Manager *m); @@ -75,6 +82,7 @@ static Manager *manager_new(void) { m->idle_action_not_before_usec = now(CLOCK_MONOTONIC); m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */ + m->user_tasks_max = UINT64_C(4096); m->devices = hashmap_new(&string_hash_ops); m->seats = hashmap_new(&string_hash_ops); @@ -215,12 +223,6 @@ static void manager_free(Manager *m) { safe_close(m->reserve_vt_fd); #endif // 0 - /* Avoid the creation of new processes forked by the - * kernel; at this point, we will not listen to the - * signals anyway */ - if (detect_container() <= 0) - (void) cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER); - manager_shutdown_cgroup(m, true); strv_free(m->kill_only_users); @@ -352,8 +354,7 @@ static int manager_enumerate_seats(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/seats: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/seats: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -389,8 +390,7 @@ static int manager_enumerate_linger_users(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -425,8 +425,7 @@ static int manager_enumerate_users(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/users: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/users: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -466,8 +465,7 @@ static int manager_enumerate_sessions(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/sessions: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/sessions: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -513,8 +511,7 @@ static int manager_enumerate_inhibitors(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -729,7 +726,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_job_removed, m); if (r < 0) - log_warning_errno(r, "Failed to add match for JobRemoved: %m"); + return log_error_errno(r, "Failed to add match for JobRemoved: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -740,7 +737,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_unit_removed, m); if (r < 0) - log_warning_errno(r, "Failed to add match for UnitRemoved: %m"); + return log_error_errno(r, "Failed to add match for UnitRemoved: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -750,7 +747,7 @@ static int manager_connect_bus(Manager *m) { "member='PropertiesChanged'", match_properties_changed, m); if (r < 0) - log_warning_errno(r, "Failed to add match for PropertiesChanged: %m"); + return log_error_errno(r, "Failed to add match for PropertiesChanged: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -761,7 +758,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_reloading, m); if (r < 0) - log_warning_errno(r, "Failed to add match for Reloading: %m"); + return log_error_errno(r, "Failed to add match for Reloading: %m"); r = sd_bus_call_method( m->bus, @@ -771,8 +768,10 @@ static int manager_connect_bus(Manager *m) { "Subscribe", &error, NULL, NULL); - if (r < 0) - log_notice("Failed to enable subscription: %s", bus_error_message(&error, r)); + if (r < 0) { + log_error("Failed to enable subscription: %s", bus_error_message(&error, r)); + return r; + } #endif // 0 r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0); @@ -847,8 +846,7 @@ static int manager_connect_console(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m"); } r = sd_event_add_io(m->event, &m->console_active_event_source, m->console_active_fd, 0, manager_dispatch_console, m); @@ -1210,20 +1208,22 @@ static int manager_run(Manager *m) { } static int manager_parse_config_file(Manager *m) { - const char *unit = NULL, *logind_conf, *sections; - FILE *file = NULL; - bool relaxed = false, allow_include = false, warn = true; +/// elogind parses its own config file +#if 0 assert(m); -/// elogind parses its own config file -#if 0 - return config_parse_many("/etc/systemd/logind.conf", - CONF_DIRS_NULSTR("systemd/logind.conf"), + return config_parse_many(PKGSYSCONFDIR "/logind.conf", + CONF_PATHS_NULSTR("systemd/logind.conf.d"), "Login\0", config_item_perf_lookup, logind_gperf_lookup, false, m); -#endif // 0 +#else + const char *unit = NULL, *logind_conf, *sections; + FILE *file = NULL; + bool relaxed = false, allow_include = false, warn = true; + + assert(m); logind_conf = getenv("ELOGIND_CONF_FILE"); if (!logind_conf) @@ -1233,6 +1233,7 @@ static int manager_parse_config_file(Manager *m) { return config_parse(unit, logind_conf, file, sections, config_item_perf_lookup, logind_gperf_lookup, relaxed, allow_include, warn, m); +#endif // 0 } int main(int argc, char *argv[]) { @@ -1262,6 +1263,12 @@ int main(int argc, char *argv[]) { * existence of /run/systemd/seats/ to determine whether * logind is available, so please always make sure this check * stays in. */ +/// elogind can not rely on systemd to help, so we need a bit more effort than this +#if 0 + mkdir_label("/run/systemd/seats", 0755); + mkdir_label("/run/systemd/users", 0755); + mkdir_label("/run/systemd/sessions", 0755); +#else r = mkdir_label("/run/systemd", 0755); if ( (r < 0) && (-EEXIST != r) ) return log_error_errno(r, "Failed to create /run/systemd : %m"); @@ -1277,6 +1284,7 @@ int main(int argc, char *argv[]) { r = mkdir_label("/run/systemd/machines", 0755); if ( r < 0 && (-EEXIST != r) ) return log_error_errno(r, "Failed to create /run/systemd/machines : %m"); +#endif // 0 m = manager_new(); if (!m) { @@ -1292,7 +1300,7 @@ int main(int argc, char *argv[]) { goto finish; } - log_debug("logind running as pid "PID_FMT, getpid()); + log_debug("elogind running as pid "PID_FMT, getpid()); sd_notify(false, "READY=1\n" @@ -1300,7 +1308,7 @@ int main(int argc, char *argv[]) { r = manager_run(m); - log_debug("logind stopped as pid "PID_FMT, getpid()); + log_debug("elogind stopped as pid "PID_FMT, getpid()); finish: sd_notify(false, diff --git a/src/login/logind.h b/src/login/logind.h index 4783ea3b2..b57e8d0a2 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -22,23 +22,23 @@ ***/ #include <stdbool.h> -#include <libudev.h> -#include "config.h" -#include "sd-event.h" +#include "libudev.h" #include "sd-bus.h" +#include "sd-event.h" + #include "cgroup-util.h" -#include "path-lookup.h" -#include "list.h" #include "hashmap.h" +#include "list.h" +#include "path-lookup.h" #include "set.h" typedef struct Manager Manager; +#include "logind-action.h" +#include "logind-button.h" #include "logind-device.h" #include "logind-inhibit.h" -#include "logind-button.h" -#include "logind-action.h" struct Manager { sd_event *event; @@ -134,6 +134,8 @@ struct Manager { unsigned enable_wall_messages; sd_event_source *wall_message_timeout_source; + bool shutdown_dry_run; + sd_event_source *idle_action_event_source; usec_t idle_action_usec; usec_t idle_action_not_before_usec; @@ -162,6 +164,7 @@ struct Manager { sd_event_source *lid_switch_ignore_event_source; size_t runtime_dir_size; + uint64_t user_tasks_max; }; int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device); @@ -204,7 +207,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action, int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_; -// UNNEEDED int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, sd_bus_error *error, char **job); +// UNNEEDED int manager_start_slice(Manager *manager, const char *slice, const char *description, const char *after, const char *after2, uint64_t tasks_max, sd_bus_error *error, char **job);// UNNEEDED int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, sd_bus_error *error, char **job); // UNNEEDED int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job); // UNNEEDED int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job); // UNNEEDED int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error); diff --git a/src/login/pam_elogind.c b/src/login/pam_elogind.c index f66f1ce84..50c4483ed 100644 --- a/src/login/pam_elogind.c +++ b/src/login/pam_elogind.c @@ -19,31 +19,34 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <endian.h> #include <errno.h> #include <fcntl.h> -#include <sys/file.h> #include <pwd.h> -#include <endian.h> - -#include <security/pam_modules.h> #include <security/_pam_macros.h> -#include <security/pam_modutil.h> #include <security/pam_ext.h> #include <security/pam_misc.h> +#include <security/pam_modules.h> +#include <security/pam_modutil.h> +#include <sys/file.h> +#include "alloc-util.h" +#include "audit-util.h" #include "bus-common-errors.h" -#include "util.h" -#include "audit.h" -#include "macro.h" -#include "strv.h" +#include "bus-error.h" #include "bus-util.h" #include "def.h" -#include "socket-util.h" +#include "fd-util.h" #include "fileio.h" -#include "bus-error.h" #include "formats-util.h" -#include "terminal-util.h" #include "hostname-util.h" +#include "login-util.h" +#include "macro.h" +#include "parse-util.h" +#include "socket-util.h" +#include "strv.h" +#include "terminal-util.h" +#include "util.h" static int parse_argv( pam_handle_t *handle, @@ -264,18 +267,11 @@ _public_ PAM_EXTERN int pam_sm_open_session( pam_get_item(handle, PAM_SERVICE, (const void**) &service); if (streq_ptr(service, "systemd-user")) { - _cleanup_free_ char *p = NULL, *rt = NULL; + _cleanup_free_ char *rt = NULL; - if (asprintf(&p, "/run/systemd/users/"UID_FMT, pw->pw_uid) < 0) + if (asprintf(&rt, "/run/user/"UID_FMT, pw->pw_uid) < 0) return PAM_BUF_ERR; - r = parse_env_file(p, NEWLINE, - "RUNTIME", &rt, - NULL); - if (r < 0 && r != -ENOENT) - return PAM_SESSION_ERR; - - if (rt) { r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0); if (r != PAM_SUCCESS) { pam_syslog(handle, LOG_ERR, "Failed to set runtime dir."); @@ -285,7 +281,6 @@ _public_ PAM_EXTERN int pam_sm_open_session( r = export_legacy_dbus_address(handle, pw->pw_uid, rt); if (r != PAM_SUCCESS) return r; - } return PAM_SUCCESS; } @@ -498,7 +493,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( return PAM_SESSION_ERR; } - r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL); + r = pam_set_data(handle, "systemd.session-fd", FD_TO_PTR(session_fd), NULL); if (r != PAM_SUCCESS) { pam_syslog(handle, LOG_ERR, "Failed to install session fd."); safe_close(session_fd); diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index f38f06baf..e9ca4bb03 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -21,13 +21,17 @@ #include <errno.h> #include <string.h> -#include <libudev.h> -#include "util.h" -#include "sysfs-show.h" +#include "libudev.h" + +#include "alloc-util.h" +#include "locale-util.h" #include "path-util.h" -#include "udev-util.h" +#include "string-util.h" +#include "sysfs-show.h" #include "terminal-util.h" +#include "udev-util.h" +#include "util.h" static int show_sysfs_one( struct udev *udev, diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index 03516de91..d0727ff7c 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -21,10 +21,12 @@ #include <unistd.h> -#include "macro.h" -#include "util.h" #include "sd-bus.h" + #include "bus-util.h" +#include "fd-util.h" +#include "macro.h" +#include "util.h" static int inhibit(sd_bus *bus, const char *what) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; |