From 1ca04b87979b2add53ebb8a7fdf13c34fb6c2743 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 14 Jan 2013 21:40:38 +0100 Subject: logind: ignore non-tty/non-x11 session when checking if there are other sessions before shutting down https://bugzilla.redhat.com/show_bug.cgi?id=890827 --- src/login/logind-dbus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 77a06f2ce4..d64debe51f 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -979,9 +979,12 @@ static int have_multiple_sessions( assert(m); - /* Check for other users' sessions. Greeter sessions do not count. */ + /* Check for other users' sessions. Greeter sessions do not + * count, and non-login sessions do not count either. */ HASHMAP_FOREACH(session, m->sessions, i) - if (session->class == SESSION_USER && session->user->uid != uid) + if (session->class == SESSION_USER && + (session->type == SESSION_TTY || session->type == SESSION_X11) && + session->user->uid != uid) return true; return false; -- cgit v1.2.1 From c84f5e4a825f17163ead0f60308d548b415334a5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 15 Jan 2013 03:00:33 +0100 Subject: login: introduce sd_session_get_tty() --- src/login/libsystemd-login.sym | 5 +++++ src/login/sd-login.c | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'src/login') diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index ff51be729b..272b0e2b52 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -53,3 +53,8 @@ global: sd_seat_can_tty; sd_seat_can_graphical; } LIBSYSTEMD_LOGIN_43; + +LIBSYSTEMD_LOGIN_198 { +global: + sd_session_get_tty; +} LIBSYSTEMD_LOGIN_186; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 45e3bb8dcd..4bc51e71a2 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -409,6 +409,10 @@ _public_ int sd_session_get_seat(const char *session, char **seat) { return session_get_string(session, "SEAT", seat); } +_public_ int sd_session_get_tty(const char *session, char **tty) { + return session_get_string(session, "TTY", tty); +} + _public_ int sd_session_get_service(const char *session, char **service) { return session_get_string(session, "SERVICE", service); } -- cgit v1.2.1 From 0762eaa3272b8c6d900737d610c9314c8610ef75 Mon Sep 17 00:00:00 2001 From: Michal Sekletar Date: Fri, 11 Jan 2013 17:06:23 +0100 Subject: logind: remove unused variable --- src/login/logind-session.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-session.c b/src/login/logind-session.c index b64a5d302d..b981e147c9 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -772,7 +772,6 @@ static int get_process_ctty_atime(pid_t pid, usec_t *atime) { } int session_get_idle_hint(Session *s, dual_timestamp *t) { - _cleanup_free_ char *p = NULL; usec_t atime = 0, n; int r; @@ -786,7 +785,7 @@ int session_get_idle_hint(Session *s, dual_timestamp *t) { return s->idle_hint; } - /* Graphical sessions really should really implement a real + /* Graphical sessions should really implement a real * idle hint logic */ if (s->display) goto dont_know; -- cgit v1.2.1 From 9bdbc2e2ec523dbefe1c1c7e164b5544aff0b185 Mon Sep 17 00:00:00 2001 From: Lukas Nykryn Date: Mon, 14 Jan 2013 18:16:50 +0100 Subject: systemctl,loginctl,cgls: do not ellipsize cgroup members when --full is specified New file output.h with output flags and modes. --full parameter also for cgls and loginctl. Include 'all' parameter in flags (show_cgroup_by_path, show_cgroup, show_cgroup_and_extra, show_cgroup_and_extra_by_spec). get_process_cmdline with max_length == 0 will not ellipsize output. Replace LINE_MAX with 0 in some calls of get_process_cmdline. [zj: Default to --full when under pager for clgs. Drop '-f' since it wasn't documented and didn't actually work. Reindent a bit. ] --- src/login/loginctl.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/login') diff --git a/src/login/loginctl.c b/src/login/loginctl.c index e2b33a626c..0e57e0828e 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -40,6 +40,7 @@ static char **arg_property = NULL; static bool arg_all = false; +static bool arg_full = false; static bool arg_no_pager = false; static const char *arg_kill_who = NULL; static int arg_signal = SIGTERM; @@ -402,6 +403,9 @@ static void print_session_status_info(SessionStatusInfo *i) { if (i->default_control_group) { unsigned c; + int output_flags = + arg_all * OUTPUT_SHOW_ALL | + arg_full * OUTPUT_FULL_WIDTH; printf("\t CGroup: %s\n", i->default_control_group); @@ -412,7 +416,10 @@ static void print_session_status_info(SessionStatusInfo *i) { else c = 0; - show_cgroup_and_extra_by_spec(i->default_control_group, "\t\t ", c, false, arg_all, &i->leader, i->leader > 0 ? 1 : 0); + show_cgroup_and_extra_by_spec(i->default_control_group, + "\t\t ", c, false, &i->leader, + i->leader > 0 ? 1 : 0, + output_flags); } } } @@ -454,6 +461,9 @@ static void print_user_status_info(UserStatusInfo *i) { if (i->default_control_group) { unsigned c; + int output_flags = + arg_all * OUTPUT_SHOW_ALL | + arg_full * OUTPUT_FULL_WIDTH; printf("\t CGroup: %s\n", i->default_control_group); @@ -464,7 +474,8 @@ static void print_user_status_info(UserStatusInfo *i) { else c = 0; - show_cgroup_by_path(i->default_control_group, "\t\t ", c, false, arg_all); + show_cgroup_by_path(i->default_control_group, "\t\t ", + c, false, output_flags); } } } @@ -1323,6 +1334,7 @@ static int help(void) { " -p --property=NAME Show only properties by this name\n" " -a --all Show all properties, including empty ones\n" " --kill-who=WHO Who to send signal to\n" + " --full Do not ellipsize output\n" " -s --signal=SIGNAL Which signal to send\n" " --no-ask-password Don't prompt for password\n" " -H --host=[USER@]HOST Show information for remote host\n" @@ -1362,7 +1374,8 @@ static int parse_argv(int argc, char *argv[]) { ARG_VERSION = 0x100, ARG_NO_PAGER, ARG_KILL_WHO, - ARG_NO_ASK_PASSWORD + ARG_NO_ASK_PASSWORD, + ARG_FULL, }; static const struct option options[] = { @@ -1376,6 +1389,7 @@ static int parse_argv(int argc, char *argv[]) { { "host", required_argument, NULL, 'H' }, { "privileged", no_argument, NULL, 'P' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD }, + { "full", no_argument, NULL, ARG_FULL }, { NULL, 0, NULL, 0 } }; @@ -1447,6 +1461,10 @@ static int parse_argv(int argc, char *argv[]) { arg_host = optarg; break; + case ARG_FULL: + arg_full = true; + break; + case '?': return -EINVAL; -- cgit v1.2.1 From af9792ac7f39354f80e9006c42c2400c5e41c447 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Jan 2013 04:56:44 +0100 Subject: logind: only allow one shutdown/sleep action to be queued at the same time This should make sure that closing the lid while shutting down won't suspend the machine but will simply cause the shutdown to complete. --- src/login/logind-action.c | 9 ++++++- src/login/logind-dbus.c | 65 +++++++++++++++++++++++++++++++++++++++-------- src/login/logind.c | 2 ++ src/login/logind.h | 4 ++- 4 files changed, 67 insertions(+), 13 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-action.c b/src/login/logind-action.c index e1517d6ac2..a796ebe9ec 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -56,10 +56,15 @@ int manager_handle_action( DBusError error; int r; InhibitWhat inhibit_operation; - bool supported = true; + bool supported; assert(m); + if (m->action_job || m->delayed_unit) { + log_debug("Action already in progress, ignoring."); + return -EALREADY; + } + /* If the key handling is turned off, don't do anything */ if (handle == HANDLE_IGNORE) { log_debug("Refusing operation, as it is turned off."); @@ -74,6 +79,8 @@ int manager_handle_action( supported = can_sleep("disk") > 0 && can_sleep_disk("suspend") > 0; else if (handle == HANDLE_KEXEC) supported = access("/sbin/kexec", X_OK) >= 0; + else + supported = true; if (!supported) { log_warning("Requested operation not supported, ignoring."); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index d64debe51f..0ff20fabd5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -990,22 +990,44 @@ static int have_multiple_sessions( return false; } -static int send_start_unit(DBusConnection *connection, const char *unit_name, DBusError *error) { - const char *mode = "replace"; +static int send_start_unit(Manager *m, const char *unit_name, DBusError *error) { + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; + const char *mode = "replace", *p; + int r; + char *c; + assert(m); assert(unit_name); - return bus_method_call_with_reply ( - connection, + r = bus_method_call_with_reply( + m->bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnit", - NULL, - NULL, + &reply, + error, DBUS_TYPE_STRING, &unit_name, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID); + if (r < 0) + return r; + + if (!dbus_message_get_args( + reply, + error, + DBUS_TYPE_OBJECT_PATH, &p, + DBUS_TYPE_INVALID)) + return -EINVAL; + + c = strdup(p); + if (!c) + return -ENOMEM; + + free(m->action_job); + m->action_job = c; + + return 0; } static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) { @@ -1226,6 +1248,7 @@ int bus_manager_shutdown_or_sleep_now_or_later( assert(unit_name); assert(w >= 0); assert(w <= _INHIBIT_WHAT_MAX); + assert(!m->action_job); delayed = m->inhibit_delay_max > 0 && @@ -1240,7 +1263,7 @@ int bus_manager_shutdown_or_sleep_now_or_later( /* Shutdown is not delayed, execute it * immediately */ - r = send_start_unit(m->bus, unit_name, error); + r = send_start_unit(m, unit_name, error); } return r; @@ -1278,6 +1301,9 @@ static int bus_manager_do_shutdown_or_sleep( assert(error); assert(_reply); + if (m->action_job || m->delayed_unit) + return -EALREADY; + if (!dbus_message_get_args( message, error, @@ -2327,6 +2353,23 @@ DBusHandlerResult bus_message_filter( log_error("Failed to parse Released message: %s", bus_error_message(&error)); else manager_cgroup_notify_empty(m, cgroup); + + } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "JobRemoved")) { + uint32_t id; + const char *path, *result, *unit; + + if (!dbus_message_get_args(message, &error, + DBUS_TYPE_UINT32, &id, + DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_STRING, &unit, + DBUS_TYPE_STRING, &result, + DBUS_TYPE_INVALID)) + log_error("Failed to parse JobRemoved message: %s", bus_error_message(&error)); + else if (m->action_job && streq(m->action_job, path)) { + log_info("Action is complete, result is '%s'.", result); + free(m->action_job); + m->action_job = NULL; + } } dbus_error_free(&error); @@ -2376,21 +2419,21 @@ int manager_dispatch_delayed(Manager *manager) { bus_manager_log_shutdown(manager, manager->delayed_what, manager->delayed_unit); + /* Tell people about it */ + send_prepare_for(manager, manager->delayed_what, false); + /* Reset delay data */ unit_name = manager->delayed_unit; manager->delayed_unit = NULL; /* Actually do the shutdown */ dbus_error_init(&error); - r = send_start_unit(manager->bus, unit_name, &error); + r = send_start_unit(manager, unit_name, &error); if (r < 0) { log_warning("Failed to send delayed message: %s", bus_error_message_or_strerror(&error, -r)); dbus_error_free(&error); return r; } - /* Tell people about it */ - send_prepare_for(manager, manager->delayed_what, false); - return 1; } diff --git a/src/login/logind.c b/src/login/logind.c index 6776229ee7..ed0b7489b9 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -187,6 +187,8 @@ void manager_free(Manager *m) { strv_free(m->kill_only_users); strv_free(m->kill_exclude_users); + free(m->action_job); + free(m->cgroup_path); free(m); } diff --git a/src/login/logind.h b/src/login/logind.h index 816635dcfc..fe6ea0fd34 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -100,7 +100,9 @@ struct Manager { usec_t inhibit_delay_max; - int idle_action_fd; + char* action_job; + + int idle_action_fd; /* the timer_fd */ usec_t idle_action_usec; usec_t idle_action_not_before_usec; HandleAction idle_action; -- cgit v1.2.1 From ee17c9281d3c208ca3f4fadd800990e61e8fd4f2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Jan 2013 05:15:36 +0100 Subject: logind: send Resumed() signal after we come back from suspend/hibernate/hybrid-sleep This allows clients to get asynchronous notifications for user-requested suspend/hibernate cycles. Kernel-triggered automatic suspending is not covered. --- src/login/logind-dbus.c | 24 ++++++++++++++++-------- src/login/logind.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 0ff20fabd5..1717584e8e 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -197,6 +197,7 @@ " \n" \ " \n" \ " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -990,7 +991,7 @@ static int have_multiple_sessions( return false; } -static int send_start_unit(Manager *m, const char *unit_name, DBusError *error) { +static int send_start_unit(Manager *m, const char *unit_name, bool send_resumed, DBusError *error) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; const char *mode = "replace", *p; int r; @@ -1026,6 +1027,7 @@ static int send_start_unit(Manager *m, const char *unit_name, DBusError *error) free(m->action_job); m->action_job = c; + m->send_resumed_after_action_job = send_resumed; return 0; } @@ -1037,8 +1039,7 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) { }; dbus_bool_t active = _active; - DBusMessage *message; - int r = 0; + _cleanup_dbus_message_unref_ DBusMessage *message = NULL; assert(m); assert(w >= 0); @@ -1051,10 +1052,9 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) { if (!dbus_message_append_args(message, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID) || !dbus_connection_send(m->bus, message, NULL)) - r = -ENOMEM; + return -ENOMEM; - dbus_message_unref(message); - return r; + return 0; } static int delay_shutdown_or_sleep(Manager *m, InhibitWhat w, const char *unit_name) { @@ -1263,7 +1263,7 @@ int bus_manager_shutdown_or_sleep_now_or_later( /* Shutdown is not delayed, execute it * immediately */ - r = send_start_unit(m, unit_name, error); + r = send_start_unit(m, unit_name, w & INHIBIT_SLEEP, error); } return r; @@ -2369,6 +2369,14 @@ DBusHandlerResult bus_message_filter( log_info("Action is complete, result is '%s'.", result); free(m->action_job); m->action_job = NULL; + + if (m->send_resumed_after_action_job) { + _cleanup_dbus_message_unref_ DBusMessage *s = NULL; + + s = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Resumed"); + if (s) + dbus_connection_send(m->bus, s, NULL); + } } } @@ -2428,7 +2436,7 @@ int manager_dispatch_delayed(Manager *manager) { /* Actually do the shutdown */ dbus_error_init(&error); - r = send_start_unit(manager, unit_name, &error); + r = send_start_unit(manager, unit_name, manager->delayed_what & INHIBIT_SLEEP, &error); if (r < 0) { log_warning("Failed to send delayed message: %s", bus_error_message_or_strerror(&error, -r)); dbus_error_free(&error); diff --git a/src/login/logind.h b/src/login/logind.h index fe6ea0fd34..7a0f8f25b0 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -101,6 +101,7 @@ struct Manager { usec_t inhibit_delay_max; char* action_job; + bool send_resumed_after_action_job; int idle_action_fd; /* the timer_fd */ usec_t idle_action_usec; -- cgit v1.2.1 From b61600291e3bbc51482bbb9823ccd48f03c130da Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Jan 2013 05:29:37 +0100 Subject: logind: add UnlockSessions() clal to complement LockSessions() --- src/login/loginctl.c | 6 +++++- src/login/logind-dbus.c | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/login') diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 0e57e0828e..473c77b92d 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1287,6 +1287,8 @@ static int flush_devices(DBusConnection *bus, char **args, unsigned n) { } static int lock_sessions(DBusConnection *bus, char **args, unsigned n) { + assert(args); + polkit_agent_open_if_enabled(); return bus_method_call_with_reply ( @@ -1294,7 +1296,7 @@ static int lock_sessions(DBusConnection *bus, char **args, unsigned n) { "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", - "LockSessions", + streq(args[0], "lock-sessions") ? "LockSessions" : "UnlockSessions", NULL, NULL, DBUS_TYPE_INVALID); @@ -1348,6 +1350,7 @@ static int help(void) { " lock-session [ID...] Screen lock one or more sessions\n" " unlock-session [ID...] Screen unlock one or more sessions\n" " lock-sessions Screen lock all current sessions\n" + " unlock-sessions Screen unlock all current sessions\n" " terminate-session [ID...] Terminate one or more sessions\n" " kill-session [ID...] Send signal to processes of a session\n" " list-users List users\n" @@ -1496,6 +1499,7 @@ static int loginctl_main(DBusConnection *bus, int argc, char *argv[], DBusError { "lock-session", MORE, 2, activate }, { "unlock-session", MORE, 2, activate }, { "lock-sessions", EQUAL, 1, lock_sessions }, + { "unlock-sessions", EQUAL, 1, lock_sessions }, { "terminate-session", MORE, 2, activate }, { "kill-session", MORE, 2, kill_session }, { "list-users", EQUAL, 1, list_users }, diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 1717584e8e..0960aab634 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -102,6 +102,7 @@ " \n" \ " \n" \ " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -1853,8 +1854,10 @@ static DBusHandlerResult manager_message_handler( if (!reply) goto oom; - } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSessions")) { - r = session_send_lock_all(m, true); + } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSessions") || + dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "UnlockSessions")) { + + r = session_send_lock_all(m, streq(dbus_message_get_member(message), "LockSessions")); if (r < 0) bus_send_error_reply(connection, message, NULL, r); -- cgit v1.2.1 From d239d84aa384a532e1056ec1d09fef16d843b8eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Jan 2013 05:47:37 +0100 Subject: loginctl: show seat master and uaccess devices in seat-status output --- src/login/sysfs-show.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/login') diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index d113ec3e43..da34c3ade8 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -45,6 +45,7 @@ static int show_sysfs_one( struct udev_device *d; const char *sn, *name, *sysfs, *subsystem, *sysname; char *l, *k; + bool is_master, uaccess; sysfs = udev_list_entry_get_name(*item); if (!path_startswith(sysfs, sub)) @@ -60,13 +61,16 @@ static int show_sysfs_one( if (isempty(sn)) sn = "seat0"; - /* fixme, also check for tag 'seat' here */ + /* Explicitly also check for tag 'seat' here */ if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) { udev_device_unref(d); *item = udev_list_entry_get_next(*item); continue; } + is_master = udev_device_has_tag(d, "seat-master"); + uaccess = udev_device_has_tag(d, "uaccess"); + name = udev_device_get_sysattr_value(d, "name"); if (!name) name = udev_device_get_sysattr_value(d, "id"); @@ -110,7 +114,8 @@ static int show_sysfs_one( free(k); if (asprintf(&l, - "(%s:%s)%s%s%s", + "%s%s%s:%s%s%s%s", + is_master ? "[MASTER] " : "", uaccess ? "[ACL] " : "", subsystem, sysname, name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) { udev_device_unref(d); -- cgit v1.2.1 From 5d1fb81b2c602abd2605f6e50810ac7fcb06c024 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 25 Jan 2013 04:48:34 +0100 Subject: loginctl: don't show [UACCESS] info in device tree As the tree doesn't really necessarily show all device node devices and only those are marked for uaccess it's kinda pointless showing this at all, since it would give a pretty incomplete impression of the uaccess information. --- src/login/sysfs-show.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/login') diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index da34c3ade8..fc3af75876 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -45,7 +45,7 @@ static int show_sysfs_one( struct udev_device *d; const char *sn, *name, *sysfs, *subsystem, *sysname; char *l, *k; - bool is_master, uaccess; + bool is_master; sysfs = udev_list_entry_get_name(*item); if (!path_startswith(sysfs, sub)) @@ -69,7 +69,6 @@ static int show_sysfs_one( } is_master = udev_device_has_tag(d, "seat-master"); - uaccess = udev_device_has_tag(d, "uaccess"); name = udev_device_get_sysattr_value(d, "name"); if (!name) @@ -114,8 +113,8 @@ static int show_sysfs_one( free(k); if (asprintf(&l, - "%s%s%s:%s%s%s%s", - is_master ? "[MASTER] " : "", uaccess ? "[ACL] " : "", + "%s%s:%s%s%s%s", + is_master ? "[MASTER] " : "", subsystem, sysname, name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) { udev_device_unref(d); -- cgit v1.2.1 From 314b4b0a68d9ab35de981923a088fc8c8820caa5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 25 Jan 2013 06:30:23 +0100 Subject: logind: rework delay inhibition logic - Don't allow any locks to be taken while we are in the process of executing the specific operation, so that apps are not surprised if a suspend/shutdown happens while they rely on their inhibitor. - Get rid of the Resumed signal, it was a bad idea, and redundant due to PrepareForSleep(false), see below. - Always send out PrepareFor{Shutdown,Sleep} signals, instead of only if a delay lock is taken. - Move PrepareForSleep(false) after we come back from the suspend, so that apps can use this as "Resumed" notification. This also has the benefit that apps know when to take a new lock. --- src/login/logind-action.c | 2 +- src/login/logind-dbus.c | 218 +++++++++++++++++++++++++--------------------- src/login/logind.c | 4 +- src/login/logind.h | 22 +++-- 4 files changed, 133 insertions(+), 113 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-action.c b/src/login/logind-action.c index a796ebe9ec..1e529e1c98 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -60,7 +60,7 @@ int manager_handle_action( assert(m); - if (m->action_job || m->delayed_unit) { + if (m->action_what) { log_debug("Action already in progress, ignoring."); return -EALREADY; } diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 0960aab634..f35185971b 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -198,7 +198,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -298,9 +297,9 @@ static int bus_manager_append_preparing(DBusMessageIter *i, const char *property assert(property); if (streq(property, "PreparingForShutdown")) - b = !!(m->delayed_what & INHIBIT_SHUTDOWN); + b = !!(m->action_what & INHIBIT_SHUTDOWN); else - b = !!(m->delayed_what & INHIBIT_SLEEP); + b = !!(m->action_what & INHIBIT_SLEEP); dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b); return 0; @@ -697,7 +696,13 @@ fail: return r; } -static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessage *message, DBusError *error, DBusMessage **_reply) { +static int bus_manager_inhibit( + Manager *m, + DBusConnection *connection, + DBusMessage *message, + DBusError *error, + DBusMessage **_reply) { + Inhibitor *i = NULL; char *id = NULL; const char *who, *why, *what, *mode; @@ -744,6 +749,15 @@ static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessa goto fail; } + /* Don't allow taking delay locks while we are already + * executing the operation. We shouldn't create the impression + * that the lock was successful if the machine is about to go + * down/suspend any moment. */ + if (m->action_what & w) { + r = -EALREADY; + goto fail; + } + r = verify_polkit(connection, message, w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") : w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") : @@ -992,15 +1006,59 @@ static int have_multiple_sessions( return false; } -static int send_start_unit(Manager *m, const char *unit_name, bool send_resumed, DBusError *error) { +static int bus_manager_log_shutdown( + Manager *m, + InhibitWhat w, + const char *unit_name) { + + const char *p, *q; + + assert(m); + assert(unit_name); + + if (w != INHIBIT_SHUTDOWN) + return 0; + + if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) { + p = "MESSAGE=System is powering down."; + q = "SHUTDOWN=power-off"; + } else if (streq(unit_name, SPECIAL_HALT_TARGET)) { + p = "MESSAGE=System is halting."; + q = "SHUTDOWN=halt"; + } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) { + p = "MESSAGE=System is rebooting."; + q = "SHUTDOWN=reboot"; + } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) { + p = "MESSAGE=System is rebooting with kexec."; + q = "SHUTDOWN=kexec"; + } else { + p = "MESSAGE=System is shutting down."; + q = NULL; + } + + return log_struct(LOG_NOTICE, MESSAGE_ID(SD_MESSAGE_SHUTDOWN), + p, + q, NULL); +} + +static int execute_shutdown_or_sleep( + Manager *m, + InhibitWhat w, + const char *unit_name, + DBusError *error) { + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; const char *mode = "replace", *p; int r; char *c; assert(m); + assert(w >= 0); + assert(w < _INHIBIT_WHAT_MAX); assert(unit_name); + bus_manager_log_shutdown(m, w, unit_name); + r = bus_method_call_with_reply( m->bus, "org.freedesktop.systemd1", @@ -1026,54 +1084,27 @@ static int send_start_unit(Manager *m, const char *unit_name, bool send_resumed, if (!c) return -ENOMEM; + m->action_unit = unit_name; free(m->action_job); m->action_job = c; - m->send_resumed_after_action_job = send_resumed; + m->action_what = w; 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" - }; - - dbus_bool_t active = _active; - _cleanup_dbus_message_unref_ DBusMessage *message = NULL; - - assert(m); - assert(w >= 0); - assert(w < _INHIBIT_WHAT_MAX); - assert(signal_name[w]); - - message = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", signal_name[w]); - if (!message) - return -ENOMEM; - - if (!dbus_message_append_args(message, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID) || - !dbus_connection_send(m->bus, message, NULL)) - return -ENOMEM; - - return 0; -} +static int delay_shutdown_or_sleep( + Manager *m, + InhibitWhat w, + const char *unit_name) { -static int delay_shutdown_or_sleep(Manager *m, InhibitWhat w, const char *unit_name) { assert(m); assert(w >= 0); assert(w < _INHIBIT_WHAT_MAX); + assert(unit_name); - /* Tell everybody to prepare for shutdown/sleep */ - send_prepare_for(m, w, true); - - /* Update timestamp for timeout */ - if (!m->delayed_unit) - m->delayed_timestamp = now(CLOCK_MONOTONIC); - - /* Remember what we want to do, possibly overriding what kind - * of unit we previously queued. */ - m->delayed_unit = unit_name; - m->delayed_what = w; + m->action_timestamp = now(CLOCK_MONOTONIC); + m->action_unit = unit_name; + m->action_what = w; return 0; } @@ -1201,39 +1232,29 @@ finish: return 0; } -static int bus_manager_log_shutdown( - Manager *m, - InhibitWhat w, - const char *unit_name) { +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" + }; - const char *p, *q; + dbus_bool_t active = _active; + _cleanup_dbus_message_unref_ DBusMessage *message = NULL; assert(m); - assert(unit_name); + assert(w >= 0); + assert(w < _INHIBIT_WHAT_MAX); + assert(signal_name[w]); - if (w != INHIBIT_SHUTDOWN) - return 0; + message = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", signal_name[w]); + if (!message) + return -ENOMEM; - if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) { - p = "MESSAGE=System is powering down."; - q = "SHUTDOWN=power-off"; - } else if (streq(unit_name, SPECIAL_HALT_TARGET)) { - p = "MESSAGE=System is halting."; - q = "SHUTDOWN=halt"; - } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) { - p = "MESSAGE=System is rebooting."; - q = "SHUTDOWN=reboot"; - } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) { - p = "MESSAGE=System is rebooting with kexec."; - q = "SHUTDOWN=kexec"; - } else { - p = "MESSAGE=System is shutting down."; - q = NULL; - } + if (!dbus_message_append_args(message, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID) || + !dbus_connection_send(m->bus, message, NULL)) + return -ENOMEM; - return log_struct(LOG_NOTICE, MESSAGE_ID(SD_MESSAGE_SHUTDOWN), - p, - q, NULL); + return 0; } int bus_manager_shutdown_or_sleep_now_or_later( @@ -1251,6 +1272,9 @@ int bus_manager_shutdown_or_sleep_now_or_later( assert(w <= _INHIBIT_WHAT_MAX); assert(!m->action_job); + /* Tell everybody to prepare for shutdown/sleep */ + send_prepare_for(m, w, true); + delayed = m->inhibit_delay_max > 0 && manager_is_inhibited(m, w, INHIBIT_DELAY, NULL, false, false, 0); @@ -1259,13 +1283,10 @@ int bus_manager_shutdown_or_sleep_now_or_later( /* Shutdown is delayed, keep in mind what we * want to do, and start a timeout */ r = delay_shutdown_or_sleep(m, w, unit_name); - else { - bus_manager_log_shutdown(m, w, unit_name); - + else /* Shutdown is not delayed, execute it * immediately */ - r = send_start_unit(m, unit_name, w & INHIBIT_SLEEP, error); - } + r = execute_shutdown_or_sleep(m, w, unit_name, error); return r; } @@ -1302,7 +1323,8 @@ static int bus_manager_do_shutdown_or_sleep( assert(error); assert(_reply); - if (m->action_job || m->delayed_unit) + /* Don't allow multiple jobs being executed at the same time */ + if (m->action_what) return -EALREADY; if (!dbus_message_get_args( @@ -2368,18 +2390,18 @@ DBusHandlerResult bus_message_filter( DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID)) log_error("Failed to parse JobRemoved message: %s", bus_error_message(&error)); + else if (m->action_job && streq(m->action_job, path)) { - log_info("Action is complete, result is '%s'.", result); - free(m->action_job); - m->action_job = NULL; - if (m->send_resumed_after_action_job) { - _cleanup_dbus_message_unref_ DBusMessage *s = NULL; + log_info("Operation finished."); - s = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Resumed"); - if (s) - dbus_connection_send(m->bus, s, NULL); - } + /* Tell people that they now may take a lock again */ + send_prepare_for(m, m->action_what, false); + + free(m->action_job); + m->action_job = NULL; + m->action_unit = NULL; + m->action_what = 0; } } @@ -2411,38 +2433,32 @@ finish: } int manager_dispatch_delayed(Manager *manager) { - const char *unit_name; DBusError error; - bool delayed; int r; assert(manager); - if (!manager->delayed_unit) + if (!manager->action_unit || manager->action_job) return 0; /* Continue delay? */ - delayed = - manager->delayed_timestamp + manager->inhibit_delay_max > now(CLOCK_MONOTONIC) && - manager_is_inhibited(manager, manager->delayed_what, INHIBIT_DELAY, NULL, false, false, 0); - if (delayed) - return 0; + if (manager_is_inhibited(manager, manager->action_what, INHIBIT_DELAY, NULL, false, false, 0)) { - bus_manager_log_shutdown(manager, manager->delayed_what, manager->delayed_unit); - - /* Tell people about it */ - send_prepare_for(manager, manager->delayed_what, false); + if (manager->action_timestamp + manager->inhibit_delay_max > now(CLOCK_MONOTONIC)) + return 0; - /* Reset delay data */ - unit_name = manager->delayed_unit; - manager->delayed_unit = NULL; + log_info("Delay lock is active but inhibitor timeout is reached."); + } - /* Actually do the shutdown */ + /* Actually do the operation */ dbus_error_init(&error); - r = send_start_unit(manager, unit_name, manager->delayed_what & INHIBIT_SLEEP, &error); + r = execute_shutdown_or_sleep(manager, manager->action_what, manager->action_unit, &error); if (r < 0) { log_warning("Failed to send delayed message: %s", bus_error_message_or_strerror(&error, -r)); dbus_error_free(&error); + + manager->action_unit = NULL; + manager->action_what = 0; return r; } diff --git a/src/login/logind.c b/src/login/logind.c index ed0b7489b9..be793e2a93 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1628,11 +1628,11 @@ int manager_run(Manager *m) { manager_gc(m, true); - if (m->delayed_unit) { + if (m->action_what != 0) { usec_t x, y; x = now(CLOCK_MONOTONIC); - y = m->delayed_timestamp + m->inhibit_delay_max; + y = m->action_timestamp + m->inhibit_delay_max; msec = x >= y ? 0 : (int) ((y - x) / USEC_PER_MSEC); } diff --git a/src/login/logind.h b/src/login/logind.h index 7a0f8f25b0..904dc20467 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -91,17 +91,21 @@ struct Manager { Hashmap *inhibitor_fds; Hashmap *button_fds; - /* If a shutdown was delayed due to a inhibitor this contains - the unit name we are supposed to start after the delay is - over */ - const char *delayed_unit; - InhibitWhat delayed_what; - usec_t delayed_timestamp; - usec_t inhibit_delay_max; - char* action_job; - bool send_resumed_after_action_job; + /* If an action is currently being executed or is delayed, + * this is != 0 and encodes what is being done */ + InhibitWhat action_what; + + /* If a shutdown/suspend was delayed due to a inhibitor this + contains the unit name we are supposed to start after the + delay is over */ + const char *action_unit; + + /* If a shutdown/suspend is currently executed, then this is + * the job of it */ + char *action_job; + usec_t action_timestamp; int idle_action_fd; /* the timer_fd */ usec_t idle_action_usec; -- cgit v1.2.1 From c485437f50450c0087bae3df4aed462e4a86ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 27 Jan 2013 21:14:14 -0500 Subject: logind: add MESSAGE_IDs to interesting events --- src/login/logind-button.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-button.c b/src/login/logind-button.c index dbf3d3c446..cbb067aa55 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -33,6 +33,7 @@ #include "logind-button.h" #include "special.h" #include "dbus-common.h" +#include "sd-messages.h" Button* button_new(Manager *m, const char *name) { Button *b; @@ -188,7 +189,10 @@ int button_process(Button *b) { case KEY_POWER: case KEY_POWER2: - log_info("Power key pressed."); + log_struct(LOG_INFO, + "MESSAGE=Power key pressed.", + MESSAGE_ID(SD_MESSAGE_POWER_KEY), + NULL); return button_handle(b, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true); /* The kernel is a bit confused here: @@ -198,11 +202,17 @@ int button_process(Button *b) { */ case KEY_SLEEP: - log_info("Suspend key pressed."); + log_struct(LOG_INFO, + "MESSAGE=Suspend key pressed.", + MESSAGE_ID(SD_MESSAGE_SUSPEND_KEY), + NULL); return button_handle(b, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true); case KEY_SUSPEND: - log_info("Hibernate key pressed."); + log_struct(LOG_INFO, + "MESSAGE=Hibernate key pressed.", + MESSAGE_ID(SD_MESSAGE_HIBERNATE_KEY), + NULL); return button_handle(b, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true); } @@ -211,7 +221,10 @@ int button_process(Button *b) { switch (ev.code) { case SW_LID: - log_info("Lid closed."); + log_struct(LOG_INFO, + "MESSAGE=Lid closed.", + MESSAGE_ID(SD_MESSAGE_LID_CLOSED), + NULL); b->lid_close_queued = true; return button_handle(b, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, true); @@ -222,7 +235,10 @@ int button_process(Button *b) { switch (ev.code) { case SW_LID: - log_info("Lid opened."); + log_struct(LOG_INFO, + "MESSAGE=Lid opened.", + MESSAGE_ID(SD_MESSAGE_LID_OPENED), + NULL); b->lid_close_queued = false; break; } -- cgit v1.2.1 From 2d96536dd7ef371c94be70cd9fb0fcbc0e5a0329 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Feb 2013 01:25:55 +0100 Subject: logind: rename "seat-master" tag to "master-of-seat" We currently enforce that seats are to be named in the form of "seatXXX", i.e. need to begin with the 4 characters "seat". Thus, "seat-master" would qualify as a seat name. As seat names are frequently used as tags on devices, the "seat-master" tag might hence confuse logind if the user decides to name a seat "seat-master". Hence, avoid any ambuigity: let's rename the "seat-master" tag to "master-of-seat". --- src/login/71-seat.rules.in | 2 +- src/login/logind.c | 4 ++-- src/login/sysfs-show.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/login') diff --git a/src/login/71-seat.rules.in b/src/login/71-seat.rules.in index 4f1a9a59a1..a064de4b5e 100644 --- a/src/login/71-seat.rules.in +++ b/src/login/71-seat.rules.in @@ -10,7 +10,7 @@ ACTION=="remove", GOTO="seat_end" TAG=="uaccess", SUBSYSTEM!="sound", TAG+="seat" SUBSYSTEM=="sound", KERNEL=="card*", TAG+="seat" SUBSYSTEM=="input", KERNEL=="input*", TAG+="seat" -SUBSYSTEM=="graphics", KERNEL=="fb[0-9]*", TAG+="seat", TAG+="seat-master" +SUBSYSTEM=="graphics", KERNEL=="fb[0-9]*", TAG+="seat", TAG+="master-of-seat" SUBSYSTEM=="usb", ATTR{bDeviceClass}=="09", TAG+="seat" # 'Plugable' USB hub, sound, network, graphics adapter diff --git a/src/login/logind.c b/src/login/logind.c index be793e2a93..680bc1fcdf 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -461,7 +461,7 @@ int manager_enumerate_devices(Manager *m) { goto finish; } - r = udev_enumerate_add_match_tag(e, "seat-master"); + r = udev_enumerate_add_match_tag(e, "master-of-seat"); if (r < 0) goto finish; @@ -1293,7 +1293,7 @@ static int manager_connect_udev(Manager *m) { if (!m->udev_seat_monitor) return -ENOMEM; - r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, "seat-master"); + r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, "master-of-seat"); if (r < 0) return r; diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index fc3af75876..3c03bd1f2e 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -68,7 +68,7 @@ static int show_sysfs_one( continue; } - is_master = udev_device_has_tag(d, "seat-master"); + is_master = udev_device_has_tag(d, "master-of-seat"); name = udev_device_get_sysattr_value(d, "name"); if (!name) -- cgit v1.2.1 From eb6d233862f33575b6a3e6c21ffaafa3f686248c Mon Sep 17 00:00:00 2001 From: Adel Gadllah Date: Wed, 6 Feb 2013 14:24:56 +0100 Subject: logind: Allow active sessions to always shutdown by default Currently local user are being asked for an admin password when another user is logged into the system. This does not make sense as the user has the power to shut down the system anyway regardless if he/she knows the password or not (by pulling the plug, battery or whatever). So only require the admin authentification for remote sessions. https://bugzilla.gnome.org/show_bug.cgi?id=693385 --- src/login/org.freedesktop.login1.policy.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/org.freedesktop.login1.policy.in b/src/login/org.freedesktop.login1.policy.in index b5f5db4f6a..0c551d4f9b 100644 --- a/src/login/org.freedesktop.login1.policy.in +++ b/src/login/org.freedesktop.login1.policy.in @@ -158,7 +158,7 @@ auth_admin_keep auth_admin_keep - auth_admin_keep + yes org.freedesktop.login1.power-off -- cgit v1.2.1 From 641906e9366891e0ad3e6e38b7396a427678c4cf Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Tue, 12 Feb 2013 21:47:36 +0100 Subject: use strneq instead of strncmp --- src/login/logind-inhibit.c | 14 +++++++------- src/login/sd-login.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index f1b9cca834..2c1a412e55 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -439,19 +439,19 @@ InhibitWhat inhibit_what_from_string(const char *s) { size_t l; FOREACH_WORD_SEPARATOR(w, l, s, ":", state) { - if (l == 8 && strncmp(w, "shutdown", l) == 0) + if (l == 8 && strneq(w, "shutdown", l)) what |= INHIBIT_SHUTDOWN; - else if (l == 5 && strncmp(w, "sleep", l) == 0) + else if (l == 5 && strneq(w, "sleep", l)) what |= INHIBIT_SLEEP; - else if (l == 4 && strncmp(w, "idle", l) == 0) + else if (l == 4 && strneq(w, "idle", l)) what |= INHIBIT_IDLE; - else if (l == 16 && strncmp(w, "handle-power-key", l) == 0) + else if (l == 16 && strneq(w, "handle-power-key", l)) what |= INHIBIT_HANDLE_POWER_KEY; - else if (l == 18 && strncmp(w, "handle-suspend-key", l) == 0) + else if (l == 18 && strneq(w, "handle-suspend-key", l)) what |= INHIBIT_HANDLE_SUSPEND_KEY; - else if (l == 20 && strncmp(w, "handle-hibernate-key", l) == 0) + else if (l == 20 && strneq(w, "handle-hibernate-key", l)) what |= INHIBIT_HANDLE_HIBERNATE_KEY; - else if (l == 17 && strncmp(w, "handle-lid-switch", l) == 0) + else if (l == 17 && strneq(w, "handle-lid-switch", l)) what |= INHIBIT_HANDLE_LID_SWITCH; else return _INHIBIT_WHAT_INVALID; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 4bc51e71a2..b81dddf86b 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -196,7 +196,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat) } FOREACH_WORD(w, l, s, state) { - if (strncmp(t, w, l) == 0) { + if (strneq(t, w, l)) { free(s); free(t); -- cgit v1.2.1 From 2826d14091e43ed3397d862dee79d09d0115c84e Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 13 Feb 2013 15:09:36 +0100 Subject: log_error() if inotify_add_watch() fails [zj: Reworded message s/to watch/to add watch on/ to make it clear that it was the watch init action that failed, and not the "process of watching". I think this way it'll be clearer to people who don't know what inotify does.] --- src/login/sd-login.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/login') diff --git a/src/login/sd-login.c b/src/login/sd-login.c index b81dddf86b..865527f8dd 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -733,6 +733,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "seat")) { k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); if (k < 0) { + log_error("Failed to add watch on /run/systemd/seats/: %m"); close_nointr_nofail(fd); return -errno; } @@ -743,6 +744,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "session")) { k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE); if (k < 0) { + log_error("Failed to add watch on /run/systemd/sessions/: %m"); close_nointr_nofail(fd); return -errno; } @@ -753,6 +755,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "uid")) { k = inotify_add_watch(fd, "/run/systemd/users/", IN_MOVED_TO|IN_DELETE); if (k < 0) { + log_error("Failed to add watch on /run/systemd/users/: %m"); close_nointr_nofail(fd); return -errno; } -- cgit v1.2.1 From 092c4c437f30bb030deae89cc81109a624898b36 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Feb 2013 16:25:33 +0100 Subject: Revert "log_error() if inotify_add_watch() fails" This reverts commit 2826d14091e43ed3397d862dee79d09d0115c84e. We never should generate log messages from a library. --- src/login/sd-login.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/login') diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 865527f8dd..b81dddf86b 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -733,7 +733,6 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "seat")) { k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); if (k < 0) { - log_error("Failed to add watch on /run/systemd/seats/: %m"); close_nointr_nofail(fd); return -errno; } @@ -744,7 +743,6 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "session")) { k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE); if (k < 0) { - log_error("Failed to add watch on /run/systemd/sessions/: %m"); close_nointr_nofail(fd); return -errno; } @@ -755,7 +753,6 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "uid")) { k = inotify_add_watch(fd, "/run/systemd/users/", IN_MOVED_TO|IN_DELETE); if (k < 0) { - log_error("Failed to add watch on /run/systemd/users/: %m"); close_nointr_nofail(fd); return -errno; } -- cgit v1.2.1 From a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 14 Feb 2013 12:26:13 +0100 Subject: honor SELinux labels, when creating and writing config files Also split out some fileio functions to fileio.c and provide a SELinux aware pendant in fileio-label.c see https://bugzilla.redhat.com/show_bug.cgi?id=881577 --- src/login/logind-dbus.c | 5 ++++- src/login/logind-inhibit.c | 1 + src/login/logind-session.c | 1 + src/login/logind-user.c | 1 + src/login/pam-module.c | 1 + src/login/sd-login.c | 1 + src/login/user-sessions.c | 1 + 7 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index f35185971b..d235474a23 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -33,6 +33,8 @@ #include "special.h" #include "systemd/sd-id128.h" #include "systemd/sd-messages.h" +#include "fileio-label.h" +#include "label.h" #define BUS_MANAGER_INTERFACE \ " \n" \ @@ -937,7 +939,8 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { } mkdir_p_label("/etc/udev/rules.d", 0755); - r = write_one_line_file_atomic(file, rule); + label_init("/etc"); + r = write_one_line_file_atomic_label(file, rule); if (r < 0) goto finish; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 2c1a412e55..9994084f93 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -30,6 +30,7 @@ #include "mkdir.h" #include "path-util.h" #include "logind-inhibit.h" +#include "fileio.h" Inhibitor* inhibitor_new(Manager *m, const char* id) { Inhibitor *i; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index b981e147c9..71c79127e9 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -33,6 +33,7 @@ #include "path-util.h" #include "cgroup-util.h" #include "logind-session.h" +#include "fileio.h" Session* session_new(Manager *m, User *u, const char *id) { Session *s; diff --git a/src/login/logind-user.c b/src/login/logind-user.c index b692b533e2..411215a925 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -29,6 +29,7 @@ #include "cgroup-util.h" #include "hashmap.h" #include "strv.h" +#include "fileio.h" User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) { User *u; diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 88b0ef9e45..702095e5e6 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -41,6 +41,7 @@ #include "dbus-common.h" #include "def.h" #include "socket-util.h" +#include "fileio.h" static int parse_argv(pam_handle_t *handle, int argc, const char **argv, diff --git a/src/login/sd-login.c b/src/login/sd-login.c index b81dddf86b..8867e8c8eb 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -29,6 +29,7 @@ #include "macro.h" #include "sd-login.h" #include "strv.h" +#include "fileio.h" _public_ int sd_pid_get_session(pid_t pid, char **session) { int r; diff --git a/src/login/user-sessions.c b/src/login/user-sessions.c index 91531e8f38..c6f8fa79e2 100644 --- a/src/login/user-sessions.c +++ b/src/login/user-sessions.c @@ -26,6 +26,7 @@ #include "log.h" #include "util.h" #include "cgroup-util.h" +#include "fileio.h" int main(int argc, char*argv[]) { int ret = EXIT_FAILURE; -- cgit v1.2.1 From 39ccc87c8a70cbe8a02e681cda280baee91b2907 Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Thu, 14 Feb 2013 22:16:58 +0100 Subject: update TODO --- src/login/logind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/logind.c b/src/login/logind.c index 680bc1fcdf..bb34a7f362 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1463,7 +1463,7 @@ int manager_dispatch_idle_action(Manager *m) { r = manager_get_idle_hint(m, &since); if (r <= 0) - /* Not idle. Let's check if after a timeout it it might be idle then. */ + /* Not idle. Let's check if after a timeout it might be idle then. */ timespec_store(&its.it_value, n + m->idle_action_usec); else { /* Idle! Let's see if it's time to do something, or if -- cgit v1.2.1 From b85bdddafb321fa870b9250a2ff17040d6996061 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Fri, 22 Feb 2013 11:21:47 +0100 Subject: systemctl: make shutdown operations use irreversible jobs Occasionally people report problem with reboot/poweroff operations hanging in the middle. One known cause is when a new transaction to start a unit is enqueued while the shutdown is going on. The start of the unit conflicts with the shutdown jobs, so they get cancelled. The failure case can be quite unpleasant, becase getty and sshd may already be stopped. Fix it by using irreversible jobs for shutdown (reboot/poweroff/...) actions. This applies to commands like "reboot", "telinit 6", "systemctl reboot". Should someone desire to use reversible jobs, they can say "systemctl start reboot.target".` --- src/login/logind-dbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index d235474a23..818f2fa808 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1051,7 +1051,7 @@ static int execute_shutdown_or_sleep( DBusError *error) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - const char *mode = "replace", *p; + const char *mode = "replace-irreversibly", *p; int r; char *c; -- cgit v1.2.1 From 41330ddb033f2cbeeb565e43708be91d5df28fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Mikul=C4=97nas?= Date: Sun, 17 Feb 2013 21:00:34 +0200 Subject: inhibit: make the output more readable The columnar output can become pretty horrible. When GNOME inhibits power/suspend/hibernate keys, the "WHAT" column's text extends to "WHO" and even "WHY". At the same time, all texts in "WHY" are of the form GNOME handlin...sses Receiving sle...ions GNOME needs t...reen This patch splits each inhibit entry into four lines, allowing the full text to fit in a normal-width terminal. --- src/login/inhibit.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/login') diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 9b6613340f..586582190e 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -99,18 +99,9 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) { goto finish; } - printf("%-21s %-20s %-20s %-5s %6s %6s\n", - "WHAT", - "WHO", - "WHY", - "MODE", - "UID", - "PID"); - dbus_message_iter_recurse(&iter, &sub); while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { const char *what, *who, *why, *mode; - char *ewho, *ewhy; dbus_uint32_t uid, pid; if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) { @@ -130,21 +121,21 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) { goto finish; } - ewho = ellipsize(who, 20, 66); - ewhy = ellipsize(why, 20, 66); - - printf("%-21s %-20s %-20s %-5s %6lu %6lu\n", - what, ewho ? ewho : who, ewhy ? ewhy : why, mode, (unsigned long) uid, (unsigned long) pid); - - free(ewho); - free(ewhy); + printf(" Who: %s (UID %lu, PID %lu)\n" + " What: %s\n" + " Why: %s\n" + " Mode: %s\n\n", + who, (unsigned long) uid, (unsigned long) pid, + what, + why, + mode); dbus_message_iter_next(&sub); n++; } - printf("\n%u inhibitors listed.\n", n); + printf("%u inhibitors listed.\n", n); r = 0; finish: -- cgit v1.2.1 From 954449b82df7fc2d37a8d854977a1a73a65edfbd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Mar 2013 03:29:54 +0100 Subject: logind: when registering a new session always use previous session info from cgroup path rather than audit Previously for cases like "su" or "sudo" where a session is attempted to be created from within an existing one we used the audit session ID to detect this and in such a case we simple returned the session data of the original session a second time. With this change we will now use the cgroup path of the calling path to determine the old session, i.e. we only rely on our own session identification scheme, instead of audits. We will continue to keep the audit session ID and ours in sync however, to avoid unnecessary confusion. --- src/login/logind-dbus.c | 173 ++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 87 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 818f2fa808..1dcdf04b29 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -308,21 +308,21 @@ static int bus_manager_append_preparing(DBusMessageIter *i, const char *property } static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMessage **_reply) { - Session *session = NULL; - User *user = NULL; - const char *type, *class, *seat, *tty, *display, *remote_user, *remote_host, *service; + const char *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *service; uint32_t uid, leader, audit_id = 0; dbus_bool_t remote, kill_processes, exists; - char **controllers = NULL, **reset_controllers = NULL; + _cleanup_strv_free_ char **controllers = NULL, **reset_controllers = NULL; + _cleanup_free_ char *cgroup = NULL, *id = NULL, *p = NULL; SessionType t; SessionClass c; - Seat *s; DBusMessageIter iter; int r; - char *id = NULL, *p; uint32_t vtnr = 0; - int fifo_fd = -1; + _cleanup_close_ int fifo_fd = -1; DBusMessage *reply = NULL; + Session *session = NULL; + User *user = NULL; + Seat *seat = NULL; bool b; assert(m); @@ -371,13 +371,13 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return -EINVAL; - dbus_message_iter_get_basic(&iter, &seat); + dbus_message_iter_get_basic(&iter, &cseat); - if (isempty(seat)) - s = NULL; + if (isempty(cseat)) + seat = NULL; else { - s = hashmap_get(m->seats, seat); - if (!s) + seat = hashmap_get(m->seats, cseat); + if (!seat) return -ENOENT; } @@ -396,9 +396,9 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess if (tty_is_vc(tty)) { int v; - if (!s) - s = m->vtconsole; - else if (s != m->vtconsole) + if (!seat) + seat = m->vtconsole; + else if (seat != m->vtconsole) return -EINVAL; v = vtnr_from_tty(tty); @@ -412,18 +412,17 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess return -EINVAL; } else if (tty_is_console(tty)) { - if (!s) - s = m->vtconsole; - else if (s != m->vtconsole) + if (!seat) + seat = m->vtconsole; + else if (seat != m->vtconsole) return -EINVAL; if (vtnr != 0) return -EINVAL; - } - if (s) { - if (seat_can_multi_session(s)) { + if (seat) { + if (seat_can_multi_session(seat)) { if (vtnr > 63) return -EINVAL; } else { @@ -486,78 +485,83 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess dbus_message_iter_get_basic(&iter, &kill_processes); - r = manager_add_user_by_uid(m, uid, &user); + r = cg_pid_get_cgroup(leader, NULL, &cgroup); if (r < 0) goto fail; - audit_session_from_pid(leader, &audit_id); - - if (audit_id > 0) { - asprintf(&id, "%lu", (unsigned long) audit_id); + r = manager_get_session_by_cgroup(m, cgroup, &session); + if (r < 0) + goto fail; - if (!id) { - r = -ENOMEM; + if (session) { + fifo_fd = session_create_fifo(session); + if (fifo_fd < 0) { + r = fifo_fd; goto fail; } - session = hashmap_get(m->sessions, id); + /* Session already exists, client is probably + * something like "su" which changes uid but + * is still the same audit session */ - if (session) { - free(id); + reply = dbus_message_new_method_return(message); + if (!reply) { + r = -ENOMEM; + goto fail; + } - fifo_fd = session_create_fifo(session); - if (fifo_fd < 0) { - r = fifo_fd; - goto fail; - } + p = session_bus_path(session); + if (!p) { + r = -ENOMEM; + goto fail; + } - /* Session already exists, client is probably - * something like "su" which changes uid but - * is still the same audit session */ + cseat = session->seat ? session->seat->id : ""; + vtnr = session->vtnr; + exists = true; - reply = dbus_message_new_method_return(message); - if (!reply) { - r = -ENOMEM; - goto fail; - } + b = dbus_message_append_args( + reply, + DBUS_TYPE_STRING, &session->id, + DBUS_TYPE_OBJECT_PATH, &p, + DBUS_TYPE_STRING, &session->user->runtime_path, + DBUS_TYPE_UNIX_FD, &fifo_fd, + DBUS_TYPE_STRING, &cseat, + DBUS_TYPE_UINT32, &vtnr, + DBUS_TYPE_BOOLEAN, &exists, + DBUS_TYPE_INVALID); + if (!b) { + r = -ENOMEM; + goto fail; + } - p = session_bus_path(session); - if (!p) { - r = -ENOMEM; - goto fail; - } + *_reply = reply; - seat = session->seat ? session->seat->id : ""; - vtnr = session->vtnr; - exists = true; - - b = dbus_message_append_args( - reply, - DBUS_TYPE_STRING, &session->id, - DBUS_TYPE_OBJECT_PATH, &p, - DBUS_TYPE_STRING, &session->user->runtime_path, - DBUS_TYPE_UNIX_FD, &fifo_fd, - DBUS_TYPE_STRING, &seat, - DBUS_TYPE_UINT32, &vtnr, - DBUS_TYPE_BOOLEAN, &exists, - DBUS_TYPE_INVALID); - free(p); + return 0; + } - if (!b) { - r = -ENOMEM; - goto fail; - } + audit_session_from_pid(leader, &audit_id); + if (audit_id > 0) { + /* Keep our session IDs and the audit session IDs in sync */ - close_nointr_nofail(fifo_fd); - *_reply = reply; + if (asprintf(&id, "%lu", (unsigned long) audit_id) < 0) { + r = -ENOMEM; + goto fail; + } - strv_free(controllers); - strv_free(reset_controllers); + /* Wut? There's already a session by this name and we + * didn't find it above? Weird, then let's not trust + * the audit data and let's better register a new + * ID */ + if (hashmap_get(m->sessions, id)) { + audit_id = 0; - return 0; + free(id); + id = NULL; } + } - } else { + if (!id) { do { free(id); id = NULL; @@ -570,8 +574,11 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess } while (hashmap_get(m->sessions, id)); } + r = manager_add_user_by_uid(m, uid, &user); + if (r < 0) + goto fail; + r = manager_add_session(m, user, id, &session); - free(id); if (r < 0) goto fail; @@ -633,8 +640,8 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess goto fail; } - if (s) { - r = seat_attach_session(s, session); + if (seat) { + r = seat_attach_session(seat, session); if (r < 0) goto fail; } @@ -655,7 +662,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess goto fail; } - seat = s ? s->id : ""; + cseat = seat ? seat->id : ""; exists = false; b = dbus_message_append_args( reply, @@ -663,35 +670,27 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_STRING, &session->user->runtime_path, DBUS_TYPE_UNIX_FD, &fifo_fd, - DBUS_TYPE_STRING, &seat, + DBUS_TYPE_STRING, &cseat, DBUS_TYPE_UINT32, &vtnr, DBUS_TYPE_BOOLEAN, &exists, DBUS_TYPE_INVALID); - free(p); if (!b) { r = -ENOMEM; goto fail; } - close_nointr_nofail(fifo_fd); *_reply = reply; return 0; fail: - strv_free(controllers); - strv_free(reset_controllers); - if (session) session_add_to_gc_queue(session); if (user) user_add_to_gc_queue(user); - if (fifo_fd >= 0) - close_nointr_nofail(fifo_fd); - if (reply) dbus_message_unref(reply); -- cgit v1.2.1 From 2f2343c6b15ec5495eb5032ae36b937fe36177cc Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 5 Mar 2013 19:32:36 +0100 Subject: inhibit: print --list if no argument is given --- src/login/inhibit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 586582190e..a812195cae 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -230,7 +230,10 @@ static int parse_argv(int argc, char *argv[]) { } } - if (arg_action == ACTION_INHIBIT && optind >= argc) { + if (arg_action == ACTION_INHIBIT && argc == 1) + arg_action = ACTION_LIST; + + else if (arg_action == ACTION_INHIBIT && optind >= argc) { log_error("Missing command line to execute."); return -EINVAL; } -- cgit v1.2.1 From c30a0c62fdbf6f11902be9db64ade99fb508adfd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Mar 2013 16:48:14 +0100 Subject: logind: don't hit an assert if an close() on an input device fd fails with ENODEV because the device is gone https://bugzilla.redhat.com/show_bug.cgi?id=907890 --- src/login/logind-button.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-button.c b/src/login/logind-button.c index cbb067aa55..ea45c28eef 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -71,7 +71,11 @@ void button_free(Button *b) { if (b->fd >= 0) { hashmap_remove(b->manager->button_fds, INT_TO_PTR(b->fd + 1)); assert_se(epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_DEL, b->fd, NULL) == 0); - close_nointr_nofail(b->fd); + + /* If the device has been unplugged close() returns + * ENODEV, let's ignore this, hence we don't use + * close_nointr_nofail() */ + close(b->fd); } free(b->name); @@ -103,7 +107,7 @@ int button_open(Button *b) { assert(b); if (b->fd >= 0) { - close_nointr_nofail(b->fd); + close(b->fd); b->fd = -1; } @@ -146,7 +150,7 @@ int button_open(Button *b) { return 0; fail: - close_nointr_nofail(b->fd); + close(b->fd); b->fd = -1; return r; } -- cgit v1.2.1 From 1b12a7b5896f94bdf33b3a6661ebabd761ea6adc Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 7 Mar 2013 20:44:35 +0100 Subject: pager: introduce "jump to end" option $ journalctl -be is what you want :) https://bugzilla.redhat.com/show_bug.cgi?id=867841 --- src/login/loginctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 473c77b92d..fe27003a92 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -58,7 +58,7 @@ static void pager_open_if_enabled(void) { if (arg_no_pager) return; - pager_open(); + pager_open(false); } static void polkit_agent_open_if_enabled(void) { -- cgit v1.2.1 From f432bb914499e2c28b43f592bb273f0a8664f352 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Mon, 11 Mar 2013 07:17:39 +0100 Subject: Move udevadm to rootbindir The udevadm utility is needed during early boot, so move it to rootbindir to support split-/usr configurations. --- src/login/71-seat.rules.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/71-seat.rules.in b/src/login/71-seat.rules.in index a064de4b5e..ad26acbbb3 100644 --- a/src/login/71-seat.rules.in +++ b/src/login/71-seat.rules.in @@ -38,7 +38,7 @@ SUBSYSTEM=="usb", ATTR{idVendor}=="17e9", ATTR{idProduct}=="401a", ATTR{product} SUBSYSTEM=="usb", ATTR{idVendor}=="17e9", ATTR{idProduct}=="401a", ATTR{product}=="mimo inc", \ ATTR{../idVendor}=="058f", ATTR{../idProduct}=="6254", \ ENV{ID_AVOID_LOOP}=="", \ - RUN+="@bindir@/udevadm trigger --parent-match=%p/.." + RUN+="@rootbindir@/udevadm trigger --parent-match=%p/.." TAG=="seat", ENV{ID_PATH}=="", IMPORT{builtin}="path_id" TAG=="seat", ENV{ID_FOR_SEAT}=="", ENV{ID_PATH_TAG}!="", ENV{ID_FOR_SEAT}="$env{SUBSYSTEM}-$env{ID_PATH_TAG}" -- cgit v1.2.1 From bb27ff6672573727488b5b4826e27ac9cb8a2c94 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Mar 2013 16:46:35 +0100 Subject: logind: explicitly create state directories during early initialization Strictly speaking this isn't necessary for the /run/systemd/seats/ directory, since that is created anyway as the first seat is found, and seat0 is always found. But let's be explicit here, and also create the sessions/ and users/ directories, so that people can always install inotify watches from very early on, even when nobody logged in yet. --- src/login/logind.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/login') diff --git a/src/login/logind.c b/src/login/logind.c index bb34a7f362..f72aac5e61 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -37,6 +37,7 @@ #include "dbus-loop.h" #include "strv.h" #include "conf-parser.h" +#include "mkdir.h" Manager *manager_new(void) { Manager *m; @@ -1727,6 +1728,15 @@ int main(int argc, char *argv[]) { goto finish; } + /* Always create the directories people can create inotify + * watches in. Note that some applications might check for the + * existance of /run/systemd/seats/ to determine whether + * logind is available, so please always make sure this check + * stays in. */ + mkdir_label("/run/systemd/seats", 0755); + mkdir_label("/run/systemd/users", 0755); + mkdir_label("/run/systemd/sessions", 0755); + m = manager_new(); if (!m) { r = log_oom(); -- cgit v1.2.1 From c6a818c82035da91e7987920510f0dda61d8781a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 18 Mar 2013 14:38:24 -0400 Subject: Use bus_maybe_send_reply() where applicable This is a followup to: commit 1a37b9b9043ef83e9900e460a9a1fccced3acf89 It will fix denial messages from dbus-daemon between gdm and systemd-logind on logging into GNOME due to this. See the previous commit for more details. --- src/login/logind-seat-dbus.c | 2 +- src/login/logind-session-dbus.c | 2 +- src/login/logind-user-dbus.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 7833d70a03..4da076e369 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -310,7 +310,7 @@ static DBusHandlerResult seat_message_dispatch( } if (reply) { - if (!dbus_connection_send(connection, reply, NULL)) + if (!bus_maybe_send_reply(connection, message, reply)) goto oom; dbus_message_unref(reply); diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index ef73cd434a..c4db315530 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -412,7 +412,7 @@ static DBusHandlerResult session_message_dispatch( } if (reply) { - if (!dbus_connection_send(connection, reply, NULL)) + if (!bus_maybe_send_reply(connection, message, reply)) goto oom; dbus_message_unref(reply); diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index ddf9d9d5cf..5951c38cb7 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -304,7 +304,7 @@ static DBusHandlerResult user_message_dispatch( } if (reply) { - if (!dbus_connection_send(connection, reply, NULL)) + if (!bus_maybe_send_reply(connection, message, reply)) goto oom; dbus_message_unref(reply); -- cgit v1.2.1 From ce0fc5f5f6debc6e37ac3ab0a3ea1c9c35b3ed99 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 18 Mar 2013 14:38:48 -0400 Subject: logind: Make more use of cleanup macros --- src/login/inhibit.c | 9 ++------- src/login/loginctl.c | 23 ++++------------------- src/login/logind-dbus.c | 29 +++++++++-------------------- src/login/logind-seat-dbus.c | 22 +++++----------------- src/login/logind-session-dbus.c | 29 +++++++---------------------- src/login/logind-user-dbus.c | 22 +++++----------------- 6 files changed, 32 insertions(+), 102 deletions(-) (limited to 'src/login') diff --git a/src/login/inhibit.c b/src/login/inhibit.c index a812195cae..e94843be7f 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -42,7 +42,7 @@ static enum { } arg_action = ACTION_INHIBIT; static int inhibit(DBusConnection *bus, DBusError *error) { - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; r = bus_method_call_with_reply( @@ -66,13 +66,11 @@ static int inhibit(DBusConnection *bus, DBusError *error) { DBUS_TYPE_INVALID)) r = -EIO; - dbus_message_unref(reply); - return r; } static int print_inhibitors(DBusConnection *bus, DBusError *error) { - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; unsigned n = 0; DBusMessageIter iter, sub, sub2; int r; @@ -139,9 +137,6 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) { r = 0; finish: - if (reply) - dbus_message_unref(reply); - return r; } diff --git a/src/login/loginctl.c b/src/login/loginctl.c index fe27003a92..387095361d 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -72,7 +72,7 @@ static void polkit_agent_open_if_enabled(void) { } static int list_sessions(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; DBusMessageIter iter, sub, sub2; unsigned k = 0; @@ -139,14 +139,11 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) { r = 0; finish: - if (reply) - dbus_message_unref(reply); - return r; } static int list_users(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; DBusMessageIter iter, sub, sub2; unsigned k = 0; @@ -211,14 +208,11 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) { r = 0; finish: - if (reply) - dbus_message_unref(reply); - return r; } static int list_seats(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; DBusMessageIter iter, sub, sub2; unsigned k = 0; @@ -281,9 +275,6 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) { r = 0; finish: - if (reply) - dbus_message_unref(reply); - return r; } @@ -961,7 +952,7 @@ finish: } static int show(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r, ret = 0; DBusError error; unsigned i; @@ -1048,15 +1039,9 @@ static int show(DBusConnection *bus, char **args, unsigned n) { r = show_one(args[0], bus, path, show_properties, &new_line); if (r != 0) ret = r; - - dbus_message_unref(reply); - reply = NULL; } finish: - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 1dcdf04b29..ed2ce97156 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -319,7 +319,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess int r; uint32_t vtnr = 0; _cleanup_close_ int fifo_fd = -1; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; Session *session = NULL; User *user = NULL; Seat *seat = NULL; @@ -536,6 +536,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess } *_reply = reply; + reply = NULL; return 0; } @@ -681,6 +682,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess } *_reply = reply; + reply = NULL; return 0; @@ -691,9 +693,6 @@ fail: if (user) user_add_to_gc_queue(user); - if (reply) - dbus_message_unref(reply); - return r; } @@ -712,7 +711,7 @@ static int bus_manager_inhibit( InhibitMode mm; unsigned long ul; int r, fifo_fd = -1; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; assert(m); assert(connection); @@ -833,6 +832,7 @@ static int bus_manager_inhibit( close_nointr_nofail(fifo_fd); *_reply = reply; + reply = NULL; inhibitor_start(i); @@ -845,9 +845,6 @@ fail: if (fifo_fd >= 0) close_nointr_nofail(fifo_fd); - if (reply) - dbus_message_unref(reply); - return r; } @@ -1126,7 +1123,7 @@ static int bus_manager_can_shutdown_or_sleep( bool multiple_sessions, challenge, blocked, b; const char *result; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; unsigned long ul; @@ -1226,11 +1223,11 @@ finish: DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID); if (!b) { - dbus_message_unref(reply); return -ENOMEM; } *_reply = reply; + reply = NULL; return 0; } @@ -1430,7 +1427,7 @@ static DBusHandlerResult manager_message_handler( Manager *m = userdata; DBusError error; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; assert(connection); @@ -2338,16 +2335,11 @@ static DBusHandlerResult manager_message_handler( if (reply) { if (!bus_maybe_send_reply(connection, message, reply)) goto oom; - - dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; oom: - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -2413,7 +2405,7 @@ DBusHandlerResult bus_message_filter( } int manager_send_changed(Manager *manager, const char *properties) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; assert(manager); @@ -2428,9 +2420,6 @@ int manager_send_changed(Manager *manager, const char *properties) { r = 0; finish: - if (m) - dbus_message_unref(m); - return r; } diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 4da076e369..585e0c15c3 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -260,7 +260,7 @@ static DBusHandlerResult seat_message_dispatch( DBusMessage *message) { DBusError error; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; assert(s); @@ -312,16 +312,11 @@ static DBusHandlerResult seat_message_dispatch( if (reply) { if (!bus_maybe_send_reply(connection, message, reply)) goto oom; - - dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; oom: - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -376,9 +371,9 @@ char *seat_bus_path(Seat *s) { } int seat_send_signal(Seat *s, bool new_seat) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; - char *p = NULL; + _cleanup_free_ char *p = NULL; assert(s); @@ -406,16 +401,13 @@ int seat_send_signal(Seat *s, bool new_seat) { r = 0; finish: - dbus_message_unref(m); - free(p); - return r; } int seat_send_changed(Seat *s, const char *properties) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; - char *p = NULL; + _cleanup_free_ char *p = NULL; assert(s); @@ -436,9 +428,5 @@ int seat_send_changed(Seat *s, const char *properties) { r = 0; finish: - if (m) - dbus_message_unref(m); - free(p); - return r; } diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index c4db315530..1f64c44e2a 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -307,7 +307,7 @@ static DBusHandlerResult session_message_dispatch( DBusMessage *message) { DBusError error; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; assert(s); @@ -414,16 +414,11 @@ static DBusHandlerResult session_message_dispatch( if (reply) { if (!bus_maybe_send_reply(connection, message, reply)) goto oom; - - dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; oom: - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -478,9 +473,9 @@ char *session_bus_path(Session *s) { } int session_send_signal(Session *s, bool new_session) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; - char *p = NULL; + _cleanup_free_ char *p = NULL; assert(s); @@ -508,16 +503,13 @@ int session_send_signal(Session *s, bool new_session) { r = 0; finish: - dbus_message_unref(m); - free(p); - return r; } int session_send_changed(Session *s, const char *properties) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; - char *p = NULL; + _cleanup_free_ char *p = NULL; assert(s); @@ -538,17 +530,13 @@ int session_send_changed(Session *s, const char *properties) { r = 0; finish: - if (m) - dbus_message_unref(m); - free(p); - return r; } int session_send_lock(Session *s, bool lock) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; bool b; - char *p; + _cleanup_free_ char *p = NULL; assert(s); @@ -557,14 +545,11 @@ int session_send_lock(Session *s, bool lock) { return -ENOMEM; m = dbus_message_new_signal(p, "org.freedesktop.login1.Session", lock ? "Lock" : "Unlock"); - free(p); if (!m) return -ENOMEM; b = dbus_connection_send(s->manager->bus, m, NULL); - dbus_message_unref(m); - if (!b) return -ENOMEM; diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 5951c38cb7..32f4062ac5 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -257,7 +257,7 @@ static DBusHandlerResult user_message_dispatch( DBusMessage *message) { DBusError error; - DBusMessage *reply = NULL; + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; int r; assert(u); @@ -306,16 +306,11 @@ static DBusHandlerResult user_message_dispatch( if (reply) { if (!bus_maybe_send_reply(connection, message, reply)) goto oom; - - dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; oom: - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -366,9 +361,9 @@ char *user_bus_path(User *u) { } int user_send_signal(User *u, bool new_user) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; - char *p = NULL; + _cleanup_free_ char *p = NULL; uint32_t uid; assert(u); @@ -399,16 +394,13 @@ int user_send_signal(User *u, bool new_user) { r = 0; finish: - dbus_message_unref(m); - free(p); - return r; } int user_send_changed(User *u, const char *properties) { - DBusMessage *m; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL; int r = -ENOMEM; - char *p = NULL; + _cleanup_free_ char *p = NULL; assert(u); @@ -429,9 +421,5 @@ int user_send_changed(User *u, const char *properties) { r = 0; finish: - if (m) - dbus_message_unref(m); - free(p); - return r; } -- cgit v1.2.1 From 4654e558a3c297a71f05c3b2db6a2744fcf3cdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 18 Mar 2013 20:31:21 -0400 Subject: logind: exploit previous cleanups and simplify returns --- src/login/inhibit.c | 38 ++---- src/login/loginctl.c | 263 ++++++++++++++++++---------------------- src/login/logind-dbus.c | 26 ++-- src/login/logind-seat-dbus.c | 46 ++----- src/login/logind-session-dbus.c | 47 ++----- src/login/logind-user-dbus.c | 34 ++---- 6 files changed, 178 insertions(+), 276 deletions(-) (limited to 'src/login') diff --git a/src/login/inhibit.c b/src/login/inhibit.c index e94843be7f..9cb321fc8f 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -64,7 +64,7 @@ static int inhibit(DBusConnection *bus, DBusError *error) { if (!dbus_message_get_args(reply, error, DBUS_TYPE_UNIX_FD, &r, DBUS_TYPE_INVALID)) - r = -EIO; + return -EIO; return r; } @@ -85,27 +85,21 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) { NULL, DBUS_TYPE_INVALID); if (r < 0) - goto finish; + return r; - if (!dbus_message_iter_init(reply, &iter)) { - r = -ENOMEM; - goto finish; - } + if (!dbus_message_iter_init(reply, &iter)) + return -ENOMEM; - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { - r = -EIO; - goto finish; - } + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) + return -EIO; dbus_message_iter_recurse(&iter, &sub); while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { const char *what, *who, *why, *mode; dbus_uint32_t uid, pid; - if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) { - r = -EIO; - goto finish; - } + if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) + return -EIO; dbus_message_iter_recurse(&sub, &sub2); @@ -114,10 +108,8 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) { bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &why, true) < 0 || bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &mode, true) < 0 || bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &uid, true) < 0 || - bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &pid, false) < 0) { - r = -EIO; - goto finish; - } + bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &pid, false) < 0) + return -EIO; printf(" Who: %s (UID %lu, PID %lu)\n" " What: %s\n" @@ -134,10 +126,7 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) { } printf("%u inhibitors listed.\n", n); - r = 0; - -finish: - return r; + return 0; } static int help(void) { @@ -240,7 +229,7 @@ int main(int argc, char *argv[]) { int r, exit_code = 0; DBusConnection *bus = NULL; DBusError error; - int fd = -1; + int _cleanup_close_ fd = -1; dbus_error_init(&error); @@ -313,8 +302,5 @@ finish: dbus_error_free(&error); - if (fd >= 0) - close_nointr_nofail(fd); - return r < 0 ? EXIT_FAILURE : exit_code; } diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 387095361d..6c229c64e3 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -89,14 +89,13 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) { NULL, DBUS_TYPE_INVALID); if (r) - goto finish; + return r; if (!dbus_message_iter_init(reply, &iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } dbus_message_iter_recurse(&iter, &sub); @@ -110,8 +109,7 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) { if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } dbus_message_iter_recurse(&sub, &sub2); @@ -122,8 +120,7 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) { bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &seat, true) < 0 || bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } printf("%10s %10u %-16s %-16s\n", id, (unsigned) uid, user, seat); @@ -136,10 +133,7 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) { if (on_tty()) printf("\n%u sessions listed.\n", k); - r = 0; - -finish: - return r; + return 0; } static int list_users(DBusConnection *bus, char **args, unsigned n) { @@ -160,14 +154,13 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) { NULL, DBUS_TYPE_INVALID); if (r) - goto finish; + return r; if (!dbus_message_iter_init(reply, &iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } dbus_message_iter_recurse(&iter, &sub); @@ -181,8 +174,7 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) { if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } dbus_message_iter_recurse(&sub, &sub2); @@ -191,8 +183,7 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) { bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &user, true) < 0 || bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } printf("%10u %-16s\n", (unsigned) uid, user); @@ -205,10 +196,7 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) { if (on_tty()) printf("\n%u users listed.\n", k); - r = 0; - -finish: - return r; + return 0; } static int list_seats(DBusConnection *bus, char **args, unsigned n) { @@ -229,14 +217,13 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) { NULL, DBUS_TYPE_INVALID); if (r) - goto finish; + return r; if (!dbus_message_iter_init(reply, &iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } dbus_message_iter_recurse(&iter, &sub); @@ -249,8 +236,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) { if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } dbus_message_iter_recurse(&sub, &sub2); @@ -258,8 +244,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) { if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &seat, true) < 0 || bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) { log_error("Failed to parse reply."); - r = -EIO; - goto finish; + return -EIO; } printf("%-16s\n", seat); @@ -272,10 +257,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) { if (on_tty()) printf("\n%u seats listed.\n", k); - r = 0; - -finish: - return r; + return 0; } typedef struct SessionStatusInfo { @@ -1077,7 +1059,6 @@ finish: } static int kill_session(DBusConnection *bus, char **args, unsigned n) { - int ret = 0; unsigned i; assert(args); @@ -1086,28 +1067,28 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) { arg_kill_who = "all"; for (i = 1; i < n; i++) { - ret = bus_method_call_with_reply ( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "KillSession", - NULL, - NULL, - DBUS_TYPE_STRING, &args[i], - DBUS_TYPE_STRING, &arg_kill_who, - DBUS_TYPE_INT32, &arg_signal, - DBUS_TYPE_INVALID); - if (ret) - goto finish; + int r; + + r = bus_method_call_with_reply ( + bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "KillSession", + NULL, + NULL, + DBUS_TYPE_STRING, &args[i], + DBUS_TYPE_STRING, &arg_kill_who, + DBUS_TYPE_INT32, &arg_signal, + DBUS_TYPE_INVALID); + if (r) + return r; } -finish: - return ret; + return 0; } static int enable_linger(DBusConnection *bus, char **args, unsigned n) { - int ret = 0; unsigned i; dbus_bool_t b, interactive = true; @@ -1120,36 +1101,35 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) { for (i = 1; i < n; i++) { uint32_t u; uid_t uid; + int r; - ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (ret < 0) { - log_error("Failed to resolve user %s: %s", args[i], strerror(-ret)); - goto finish; + r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); + if (r < 0) { + log_error("Failed to resolve user %s: %s", args[i], strerror(-r)); + return r; } u = (uint32_t) uid; - ret = bus_method_call_with_reply ( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "SetUserLinger", - NULL, - NULL, - DBUS_TYPE_UINT32, &u, - DBUS_TYPE_BOOLEAN, &b, - DBUS_TYPE_BOOLEAN, &interactive, - DBUS_TYPE_INVALID); - if (ret) - goto finish; + r = bus_method_call_with_reply ( + bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "SetUserLinger", + NULL, + NULL, + DBUS_TYPE_UINT32, &u, + DBUS_TYPE_BOOLEAN, &b, + DBUS_TYPE_BOOLEAN, &interactive, + DBUS_TYPE_INVALID); + if (r) + return r; } -finish: - return ret; + return 0; } static int terminate_user(DBusConnection *bus, char **args, unsigned n) { - int ret = 0; unsigned i; assert(args); @@ -1157,34 +1137,33 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) { for (i = 1; i < n; i++) { uint32_t u; uid_t uid; + int r; - ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (ret < 0) { - log_error("Failed to look up user %s: %s", args[i], strerror(-ret)); - goto finish; + r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); + if (r < 0) { + log_error("Failed to look up user %s: %s", args[i], strerror(-r)); + return r; } u = (uint32_t) uid; - ret = bus_method_call_with_reply ( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "TerminateUser", - NULL, - NULL, - DBUS_TYPE_UINT32, &u, - DBUS_TYPE_INVALID); - if (ret) - goto finish; + r = bus_method_call_with_reply ( + bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "TerminateUser", + NULL, + NULL, + DBUS_TYPE_UINT32, &u, + DBUS_TYPE_INVALID); + if (r) + return r; } -finish: - return ret; + return 0; } static int kill_user(DBusConnection *bus, char **args, unsigned n) { - int ret = 0; unsigned i; assert(args); @@ -1195,35 +1174,34 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) { for (i = 1; i < n; i++) { uid_t uid; uint32_t u; + int r; - ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (ret < 0) { - log_error("Failed to look up user %s: %s", args[i], strerror(-ret)); - goto finish; + r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); + if (r < 0) { + log_error("Failed to look up user %s: %s", args[i], strerror(-r)); + return r; } u = (uint32_t) uid; - ret = bus_method_call_with_reply ( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "KillUser", - NULL, - NULL, - DBUS_TYPE_UINT32, &u, - DBUS_TYPE_INT32, &arg_signal, - DBUS_TYPE_INVALID); - if (ret) - goto finish; + r = bus_method_call_with_reply ( + bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "KillUser", + NULL, + NULL, + DBUS_TYPE_UINT32, &u, + DBUS_TYPE_INT32, &arg_signal, + DBUS_TYPE_INVALID); + if (r) + return r; } -finish: - return ret; + return 0; } static int attach(DBusConnection *bus, char **args, unsigned n) { - int ret = 0; unsigned i; dbus_bool_t interactive = true; @@ -1232,24 +1210,25 @@ static int attach(DBusConnection *bus, char **args, unsigned n) { polkit_agent_open_if_enabled(); for (i = 2; i < n; i++) { - ret = bus_method_call_with_reply ( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "AttachDevice", - NULL, - NULL, - DBUS_TYPE_STRING, &args[1], - DBUS_TYPE_STRING, &args[i], - DBUS_TYPE_BOOLEAN, &interactive, - DBUS_TYPE_INVALID); - if (ret) - goto finish; + int r; + + r = bus_method_call_with_reply ( + bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "AttachDevice", + NULL, + NULL, + DBUS_TYPE_STRING, &args[1], + DBUS_TYPE_STRING, &args[i], + DBUS_TYPE_BOOLEAN, &interactive, + DBUS_TYPE_INVALID); + if (r) + return r; } -finish: - return ret; + return 0; } static int flush_devices(DBusConnection *bus, char **args, unsigned n) { @@ -1288,28 +1267,28 @@ static int lock_sessions(DBusConnection *bus, char **args, unsigned n) { } static int terminate_seat(DBusConnection *bus, char **args, unsigned n) { - int ret = 0; unsigned i; assert(args); for (i = 1; i < n; i++) { - ret = bus_method_call_with_reply ( - bus, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "TerminateSeat", - NULL, - NULL, - DBUS_TYPE_STRING, &args[i], - DBUS_TYPE_INVALID); - if (ret) - goto finish; + int r; + + r = bus_method_call_with_reply ( + bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "TerminateSeat", + NULL, + NULL, + DBUS_TYPE_STRING, &args[i], + DBUS_TYPE_INVALID); + if (r) + return r; } -finish: - return ret; + return 0; } static int help(void) { diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index ed2ce97156..4ae8362211 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -901,7 +901,7 @@ finish: static int attach_device(Manager *m, const char *seat, const char *sysfs) { struct udev_device *d; - char *rule = NULL, *file = NULL; + char _cleanup_free_ *rule = NULL, *file = NULL; const char *id_for_seat; int r; @@ -943,9 +943,6 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { r = trigger_device(m, d); finish: - free(rule); - free(file); - if (d) udev_device_unref(d); @@ -953,7 +950,7 @@ finish: } static int flush_devices(Manager *m) { - DIR *d; + DIR _cleanup_closedir_ *d; assert(m); @@ -978,8 +975,6 @@ static int flush_devices(Manager *m) { if (unlinkat(dirfd(d), de->d_name, 0) < 0) log_warning("Failed to unlink %s: %m", de->d_name); } - - closedir(d); } return trigger_device(m, NULL); @@ -1222,9 +1217,8 @@ finish: reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID); - if (!b) { + if (!b) return -ENOMEM; - } *_reply = reply; reply = NULL; @@ -2406,21 +2400,19 @@ DBusHandlerResult bus_message_filter( int manager_send_changed(Manager *manager, const char *properties) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; assert(manager); - m = bus_properties_changed_new("/org/freedesktop/login1", "org.freedesktop.login1.Manager", properties); + m = bus_properties_changed_new("/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + properties); if (!m) - goto finish; + return -ENOMEM; if (!dbus_connection_send(manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } int manager_dispatch_delayed(Manager *manager) { diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 585e0c15c3..82f25a0d1c 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -61,7 +61,7 @@ static int bus_seat_append_active(DBusMessageIter *i, const char *property, void DBusMessageIter sub; Seat *s = data; const char *id, *path; - char *p = NULL; + char _cleanup_free_ *p = NULL; assert(i); assert(property); @@ -82,12 +82,8 @@ static int bus_seat_append_active(DBusMessageIter *i, const char *property, void } if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) || - !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) { - free(p); + !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) return -ENOMEM; - } - - free(p); if (!dbus_message_iter_close_container(i, &sub)) return -ENOMEM; @@ -108,7 +104,7 @@ static int bus_seat_append_sessions(DBusMessageIter *i, const char *property, vo return -ENOMEM; LIST_FOREACH(sessions_by_seat, session, s->sessions) { - char *p; + char _cleanup_free_ *p = NULL; if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2)) return -ENOMEM; @@ -118,12 +114,8 @@ static int bus_seat_append_sessions(DBusMessageIter *i, const char *property, vo return -ENOMEM; if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->id) || - !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) { - free(p); + !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) return -ENOMEM; - } - - free(p); if (!dbus_message_iter_close_container(&sub, &sub2)) return -ENOMEM; @@ -356,7 +348,7 @@ const DBusObjectPathVTable bus_seat_vtable = { }; char *seat_bus_path(Seat *s) { - char *t, *r; + char _cleanup_free_ *t; assert(s); @@ -364,15 +356,11 @@ char *seat_bus_path(Seat *s) { if (!t) return NULL; - r = strappend("/org/freedesktop/login1/seat/", t); - free(t); - - return r; + return strappend("/org/freedesktop/login1/seat/", t); } int seat_send_signal(Seat *s, bool new_seat) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; _cleanup_free_ char *p = NULL; assert(s); @@ -380,33 +368,28 @@ int seat_send_signal(Seat *s, bool new_seat) { m = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", new_seat ? "SeatNew" : "SeatRemoved"); - if (!m) return -ENOMEM; p = seat_bus_path(s); if (!p) - goto finish; + return -ENOMEM; if (!dbus_message_append_args( m, DBUS_TYPE_STRING, &s->id, DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_INVALID)) - goto finish; + return -ENOMEM; if (!dbus_connection_send(s->manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } int seat_send_changed(Seat *s, const char *properties) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; _cleanup_free_ char *p = NULL; assert(s); @@ -420,13 +403,10 @@ int seat_send_changed(Seat *s, const char *properties) { m = bus_properties_changed_new(p, "org.freedesktop.login1.Seat", properties); if (!m) - goto finish; + return -ENOMEM; if (!dbus_connection_send(s->manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index 1f64c44e2a..0e425e48d3 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -108,12 +108,8 @@ static int bus_session_append_seat(DBusMessageIter *i, const char *property, voi } if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) || - !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) { - free(p); + !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) return -ENOMEM; - } - - free(p); if (!dbus_message_iter_close_container(i, &sub)) return -ENOMEM; @@ -124,7 +120,7 @@ static int bus_session_append_seat(DBusMessageIter *i, const char *property, voi static int bus_session_append_user(DBusMessageIter *i, const char *property, void *data) { DBusMessageIter sub; User *u = data; - char *p = NULL; + char _cleanup_free_ *p = NULL; assert(i); assert(property); @@ -138,12 +134,8 @@ static int bus_session_append_user(DBusMessageIter *i, const char *property, voi return -ENOMEM; if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &u->uid) || - !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) { - free(p); + !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) return -ENOMEM; - } - - free(p); if (!dbus_message_iter_close_container(i, &sub)) return -ENOMEM; @@ -205,7 +197,7 @@ static int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *pr static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) { Session *s = data; - char *t; + char _cleanup_free_ *t = NULL; int r; bool success; @@ -218,8 +210,6 @@ static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *pro return r; success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t); - free(t); - return success ? 0 : -ENOMEM; } @@ -458,7 +448,7 @@ const DBusObjectPathVTable bus_session_vtable = { }; char *session_bus_path(Session *s) { - char *t, *r; + char _cleanup_free_ *t; assert(s); @@ -466,15 +456,11 @@ char *session_bus_path(Session *s) { if (!t) return NULL; - r = strappend("/org/freedesktop/login1/session/", t); - free(t); - - return r; + return strappend("/org/freedesktop/login1/session/", t); } int session_send_signal(Session *s, bool new_session) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; _cleanup_free_ char *p = NULL; assert(s); @@ -488,27 +474,23 @@ int session_send_signal(Session *s, bool new_session) { p = session_bus_path(s); if (!p) - goto finish; + return -ENOMEM; if (!dbus_message_append_args( m, DBUS_TYPE_STRING, &s->id, DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_INVALID)) - goto finish; + return -ENOMEM; if (!dbus_connection_send(s->manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } int session_send_changed(Session *s, const char *properties) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; _cleanup_free_ char *p = NULL; assert(s); @@ -522,15 +504,12 @@ int session_send_changed(Session *s, const char *properties) { m = bus_properties_changed_new(p, "org.freedesktop.login1.Session", properties); if (!m) - goto finish; + return -ENOMEM; if (!dbus_connection_send(s->manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } int session_send_lock(Session *s, bool lock) { diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 32f4062ac5..8cc1dd49fd 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -65,7 +65,7 @@ static int bus_user_append_display(DBusMessageIter *i, const char *property, voi DBusMessageIter sub; User *u = data; const char *id, *path; - char *p = NULL; + char _cleanup_free_ *p = NULL; assert(i); assert(property); @@ -86,12 +86,8 @@ static int bus_user_append_display(DBusMessageIter *i, const char *property, voi } if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) || - !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) { - free(p); + !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) return -ENOMEM; - } - - free(p); if (!dbus_message_iter_close_container(i, &sub)) return -ENOMEM; @@ -191,7 +187,7 @@ static int bus_user_append_idle_hint_since(DBusMessageIter *i, const char *prope static int bus_user_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) { User *u = data; - char *t; + char _cleanup_free_ *t = NULL; int r; bool success; @@ -204,8 +200,6 @@ static int bus_user_append_default_cgroup(DBusMessageIter *i, const char *proper return r; success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t); - free(t); - return success ? 0 : -ENOMEM; } @@ -362,7 +356,6 @@ char *user_bus_path(User *u) { int user_send_signal(User *u, bool new_user) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; _cleanup_free_ char *p = NULL; uint32_t uid; @@ -377,7 +370,7 @@ int user_send_signal(User *u, bool new_user) { p = user_bus_path(u); if (!p) - goto finish; + return -ENOMEM; uid = u->uid; @@ -386,20 +379,16 @@ int user_send_signal(User *u, bool new_user) { DBUS_TYPE_UINT32, &uid, DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_INVALID)) - goto finish; + return -ENOMEM; if (!dbus_connection_send(u->manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } int user_send_changed(User *u, const char *properties) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL; - int r = -ENOMEM; _cleanup_free_ char *p = NULL; assert(u); @@ -413,13 +402,10 @@ int user_send_changed(User *u, const char *properties) { m = bus_properties_changed_new(p, "org.freedesktop.login1.User", properties); if (!m) - goto finish; + return -ENOMEM; if (!dbus_connection_send(u->manager->bus, m, NULL)) - goto finish; - - r = 0; + return -ENOMEM; -finish: - return r; + return 0; } -- cgit v1.2.1 From bb06e0f85cf337dfaea92dc1c24d7c84249b1433 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 23 Mar 2013 16:26:49 +0100 Subject: uaccess: remove needless usb_id call from udev rules --- src/login/70-uaccess.rules | 1 - 1 file changed, 1 deletion(-) (limited to 'src/login') diff --git a/src/login/70-uaccess.rules b/src/login/70-uaccess.rules index d1275f2ca9..a118f8e887 100644 --- a/src/login/70-uaccess.rules +++ b/src/login/70-uaccess.rules @@ -9,7 +9,6 @@ ACTION=="remove", GOTO="uaccess_end" ENV{MAJOR}=="", GOTO="uaccess_end" # PTP/MTP protocol devices, cameras, portable media players -SUBSYSTEM=="usb", ENV{ID_USB_INTERFACES}=="", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id" SUBSYSTEM=="usb", ENV{ID_USB_INTERFACES}=="*:060101:*", TAG+="uaccess" # Digicams with proprietary protocol -- cgit v1.2.1 From 9717120e593fde25332e919b9d7406925261a1b1 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 26 Mar 2013 11:35:17 +0100 Subject: Drop src/login/uaccess.c, dead code This moved to src/udev/udev-builtin-uaccess.c a while ago. --- src/login/uaccess.c | 91 ----------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 src/login/uaccess.c (limited to 'src/login') diff --git a/src/login/uaccess.c b/src/login/uaccess.c deleted file mode 100644 index 2c530c8f39..0000000000 --- a/src/login/uaccess.c +++ /dev/null @@ -1,91 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2011 Lennart Poettering - - systemd 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. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . -***/ - -#include -#include - -#include -#include - -#include "logind-acl.h" -#include "util.h" -#include "log.h" - -int main(int argc, char *argv[]) { - int r; - const char *path = NULL, *seat; - bool changed_acl = false; - uid_t uid; - - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); - - umask(0022); - - if (argc < 2 || argc > 3) { - log_error("This program expects one or two arguments."); - r = -EINVAL; - goto finish; - } - - /* Make sure we don't muck around with ACLs the system is not - * running systemd. */ - if (!sd_booted()) - return 0; - - path = argv[1]; - seat = argc < 3 || isempty(argv[2]) ? "seat0" : argv[2]; - - r = sd_seat_get_active(seat, NULL, &uid); - if (r == -ENOENT) { - /* No active session on this seat */ - r = 0; - goto finish; - } else if (r < 0) { - log_error("Failed to determine active user on seat %s.", seat); - goto finish; - } - - r = devnode_acl(path, true, false, 0, true, uid); - if (r < 0) { - log_error("Failed to apply ACL on %s: %s", path, strerror(-r)); - goto finish; - } - - changed_acl = true; - r = 0; - -finish: - if (path && !changed_acl) { - int k; - /* Better be safe that sorry and reset ACL */ - - k = devnode_acl(path, true, false, 0, false, 0); - if (k < 0) { - log_error("Failed to apply ACL on %s: %s", path, strerror(-k)); - if (r >= 0) - r = k; - } - } - - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; -} -- cgit v1.2.1 From 574d5f2dfc25226afc718aa5ba1a145fe5cad221 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Apr 2013 20:31:42 +0200 Subject: util: rename write_one_line_file() to write_string_file() You can write much more than just one line with this call (and we frequently do), so let's correct the naming. --- src/login/logind-dbus.c | 4 ++-- src/login/user-sessions.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 4ae8362211..aa212d1fed 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -886,7 +886,7 @@ static int trigger_device(Manager *m, struct udev_device *d) { goto finish; } - write_one_line_file(t, "change"); + write_string_file(t, "change"); free(t); } @@ -936,7 +936,7 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { mkdir_p_label("/etc/udev/rules.d", 0755); label_init("/etc"); - r = write_one_line_file_atomic_label(file, rule); + r = write_string_file_atomic_label(file, rule); if (r < 0) goto finish; diff --git a/src/login/user-sessions.c b/src/login/user-sessions.c index c6f8fa79e2..41d32044e9 100644 --- a/src/login/user-sessions.c +++ b/src/login/user-sessions.c @@ -70,7 +70,7 @@ int main(int argc, char*argv[]) { int r, q; char *cgroup_user_tree = NULL; - r = write_one_line_file_atomic("/run/nologin", "System is going down."); + r = write_string_file_atomic("/run/nologin", "System is going down."); if (r < 0) log_error("Failed to create /run/nologin: %s", strerror(-r)); -- cgit v1.2.1 From 7f602784de4fd378120e8ebfe6d830862b9cae03 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Apr 2013 20:38:16 +0200 Subject: util: rename parse_usec() to parse_sec() sinds the default unit is seconds Internally we store all time values in usec_t, however parse_usec() actually was used mostly to parse values in seconds (unless explicit units were specified to define a different unit). Hence, be clear about this and name the function about what we pass into it, not what we get out of it. --- src/login/logind-gperf.gperf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index 076d116161..735d2dbc9c 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -21,7 +21,7 @@ Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manag Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users) Login.Controllers, config_parse_strv, 0, offsetof(Manager, controllers) Login.ResetControllers, config_parse_strv, 0, offsetof(Manager, reset_controllers) -Login.InhibitDelayMaxSec, config_parse_usec, 0, offsetof(Manager, inhibit_delay_max) +Login.InhibitDelayMaxSec, config_parse_sec, 0, offsetof(Manager, inhibit_delay_max) Login.HandlePowerKey, config_parse_handle_action, 0, offsetof(Manager, handle_power_key) Login.HandleSuspendKey, config_parse_handle_action, 0, offsetof(Manager, handle_suspend_key) Login.HandleHibernateKey, config_parse_handle_action, 0, offsetof(Manager, handle_hibernate_key) @@ -31,4 +31,4 @@ Login.SuspendKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manag Login.HibernateKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, hibernate_key_ignore_inhibited) Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited) Login.IdleAction, config_parse_handle_action, 0, offsetof(Manager, idle_action) -Login.IdleActionSec, config_parse_usec, 0, offsetof(Manager, idle_action_usec) +Login.IdleActionSec, config_parse_sec, 0, offsetof(Manager, idle_action_usec) -- cgit v1.2.1 From dace83cbd0c2212fc0e25d36d50711b19f14b1b6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 4 Apr 2013 17:38:08 +0200 Subject: login: add new public API call sd_login_monitor_get_events() to get poll() flags to wait for We should keep our options open, so that we can watch for POLLOUT later on if we wish to. CUrrently this call will always return POLLIN however. --- src/login/libsystemd-login.sym | 5 +++++ src/login/sd-login.c | 9 +++++++++ src/login/test-login.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index 272b0e2b52..55a828773b 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -58,3 +58,8 @@ LIBSYSTEMD_LOGIN_198 { global: sd_session_get_tty; } LIBSYSTEMD_LOGIN_186; + +LIBSYSTEMD_LOGIN_201 { +global: + sd_login_monitor_get_events; +} LIBSYSTEMD_LOGIN_198; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 8867e8c8eb..861a57166d 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "util.h" #include "cgroup-util.h" @@ -797,3 +798,11 @@ _public_ int sd_login_monitor_get_fd(sd_login_monitor *m) { return MONITOR_TO_FD(m); } + +_public_ int sd_login_monitor_get_events(sd_login_monitor *m) { + + if (!m) + return -EINVAL; + + return POLLIN; +} diff --git a/src/login/test-login.c b/src/login/test-login.c index 159ff3efc5..f639129636 100644 --- a/src/login/test-login.c +++ b/src/login/test-login.c @@ -185,7 +185,7 @@ int main(int argc, char* argv[]) { zero(pollfd); pollfd.fd = sd_login_monitor_get_fd(m); - pollfd.events = POLLIN; + pollfd.events = sd_login_monitor_get_events(m); for (n = 0; n < 5; n++) { r = poll(&pollfd, 1, -1); -- cgit v1.2.1 From 667c24a6a86a5a26a906b7477ae81dcf4c73e64e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 4 Apr 2013 18:31:22 +0200 Subject: login: add sd_login_monitor_get_timeout() public api call We don't need this right now, but we should keep our options open, in case we need more than just an fd for waking up. --- src/login/libsystemd-login.sym | 1 + src/login/sd-login.c | 18 ++++++++++++++++++ src/login/test-login.c | 19 +++++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/login') diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index 55a828773b..ce2304a1ba 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -62,4 +62,5 @@ global: LIBSYSTEMD_LOGIN_201 { global: sd_login_monitor_get_events; + sd_login_monitor_get_timeout; } LIBSYSTEMD_LOGIN_198; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 861a57166d..7513f76cb3 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -804,5 +804,23 @@ _public_ int sd_login_monitor_get_events(sd_login_monitor *m) { if (!m) return -EINVAL; + /* For now we will only return POLLIN here, since we don't + * need anything else ever for inotify. However, let's have + * this API to keep our options open should we later on need + * it. */ return POLLIN; } + +_public_ int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *timeout_usec) { + + if (!m) + return -EINVAL; + if (!timeout_usec) + return -EINVAL; + + /* For now we will only return (uint64_t) -1, since we don't + * need any timeout. However, let's have this API to keep our + * options open should we later on need it. */ + *timeout_usec = (uint64_t) -1; + return 0; +} diff --git a/src/login/test-login.c b/src/login/test-login.c index f639129636..e4d0c93378 100644 --- a/src/login/test-login.c +++ b/src/login/test-login.c @@ -183,12 +183,23 @@ int main(int argc, char* argv[]) { r = sd_login_monitor_new("session", &m); assert_se(r >= 0); - zero(pollfd); - pollfd.fd = sd_login_monitor_get_fd(m); - pollfd.events = sd_login_monitor_get_events(m); for (n = 0; n < 5; n++) { - r = poll(&pollfd, 1, -1); + usec_t timeout, nw; + + zero(pollfd); + assert_se((pollfd.fd = sd_login_monitor_get_fd(m)) >= 0); + assert_se((pollfd.events = sd_login_monitor_get_events(m)) >= 0); + + assert_se(sd_login_monitor_get_timeout(m, &timeout) >= 0); + + nw = now(CLOCK_MONOTONIC); + + r = poll(&pollfd, 1, + timeout == (uint64_t) -1 ? -1 : + timeout > nw ? (int) ((timeout - nw) / 1000) : + 0); + assert_se(r >= 0); sd_login_monitor_flush(m); -- cgit v1.2.1 From 79d860fe78ff9e53fe3150fb55a8a8b03c4f6470 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 26 Mar 2013 11:36:31 +0100 Subject: PAM, uaccess: check for logind, not for systemd It is possible to build systemd without logind or run logind without systemd init. Commit 66e41181 fixed sd_booted() to only succeed for systemd init; with that, testing for systemd init is wrong in the parts that talk to logind. In particular, this affects the PAM module and the "uaccess" udev builtin. Change sd_booted() to a new logind_running() which tests for /run/systemd/seats/. For details, see: https://bugs.freedesktop.org/show_bug.cgi?id=62754 --- src/login/pam-module.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/login') diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 702095e5e6..0d4f7991e7 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -32,8 +32,6 @@ #include #include -#include - #include "util.h" #include "audit.h" #include "macro.h" @@ -348,8 +346,8 @@ _public_ PAM_EXTERN int pam_sm_open_session( /* pam_syslog(handle, LOG_INFO, "pam-systemd initializing"); */ - /* Make this a NOP on non-systemd systems */ - if (sd_booted() <= 0) + /* Make this a NOP on non-logind systems */ + if (!logind_running()) return PAM_SUCCESS; if (parse_argv(handle, -- cgit v1.2.1 From 2c4f86c1298f402220965682ab0e7729e150a562 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 5 Apr 2013 18:57:58 +0200 Subject: logind: consider key inhibitors that are taken by non-session processes as global This should allow system services to take over key handling for all sessions, globally. --- src/login/logind-inhibit.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 9994084f93..c43ae23acf 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -354,9 +354,14 @@ static int pid_is_active(Manager *m, pid_t pid) { int r; r = manager_get_session_by_pid(m, pid, &s); - if (r <= 0) + if (r < 0) return r; + /* If there's no session assigned to it, then it's globally + * active on all ttys */ + if (r == 0) + return 1; + return session_is_active(s); } -- cgit v1.2.1 From b92bea5d2a9481de69bb627a7b442a9f58fca43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 24 Mar 2013 19:59:00 -0400 Subject: Use initalization instead of explicit zeroing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, we would initialize many fields twice: first by filling the structure with zeros, and then a second time with the real values. We can let the compiler do the job for us, avoiding one copy. A downside of this patch is that text gets slightly bigger. This is because all zero() calls are effectively inlined: $ size build/.libs/systemd text data bss dec hex filename before 897737 107300 2560 1007597 f5fed build/.libs/systemd after 897873 107300 2560 1007733 f6075 build/.libs/systemd … actually less than 1‰. A few asserts that the parameter is not null had to be removed. I don't think this changes much, because first, it is quite unlikely for the assert to fail, and second, an immediate SEGV is almost as good as an assert. --- src/login/loginctl.c | 10 +++------- src/login/logind-inhibit.c | 3 +-- src/login/logind-session.c | 3 +-- src/login/logind.c | 38 +++++++++++++++++--------------------- src/login/pam-module.c | 28 +++++++++------------------- 5 files changed, 31 insertions(+), 51 deletions(-) (limited to 'src/login') diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 6c229c64e3..36c65bc8d0 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -834,17 +834,13 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo const char *interface = ""; int r; DBusMessageIter iter, sub, sub2, sub3; - SessionStatusInfo session_info; - UserStatusInfo user_info; - SeatStatusInfo seat_info; + SessionStatusInfo session_info = {}; + UserStatusInfo user_info = {}; + SeatStatusInfo seat_info = {}; assert(path); assert(new_line); - zero(session_info); - zero(user_info); - zero(seat_info); - r = bus_method_call_with_reply( bus, "org.freedesktop.login1", diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index c43ae23acf..e77088364a 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -292,7 +292,7 @@ int inhibitor_create_fifo(Inhibitor *i) { /* Open reading side */ if (i->fifo_fd < 0) { - struct epoll_event ev; + struct epoll_event ev = {}; i->fifo_fd = open(i->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY); if (i->fifo_fd < 0) @@ -302,7 +302,6 @@ int inhibitor_create_fifo(Inhibitor *i) { if (r < 0) return r; - zero(ev); ev.events = 0; ev.data.u32 = FD_OTHER_BASE + i->fifo_fd; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 71c79127e9..97c24d094b 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -898,7 +898,7 @@ int session_create_fifo(Session *s) { /* Open reading side */ if (s->fifo_fd < 0) { - struct epoll_event ev; + struct epoll_event ev = {}; s->fifo_fd = open(s->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY); if (s->fifo_fd < 0) @@ -908,7 +908,6 @@ int session_create_fifo(Session *s) { if (r < 0) return r; - zero(ev); ev.events = 0; ev.data.u32 = FD_OTHER_BASE + s->fifo_fd; diff --git a/src/login/logind.c b/src/login/logind.c index f72aac5e61..c9e492fc4f 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1174,7 +1174,10 @@ static void manager_dispatch_other(Manager *m, int fd) { static int manager_connect_bus(Manager *m) { DBusError error; int r; - struct epoll_event ev; + struct epoll_event ev = { + .events = EPOLLIN, + .data.u32 = FD_BUS, + }; assert(m); assert(!m->bus); @@ -1230,10 +1233,6 @@ static int manager_connect_bus(Manager *m) { goto fail; } - zero(ev); - ev.events = EPOLLIN; - ev.data.u32 = FD_BUS; - if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->bus_fd, &ev) < 0) goto fail; @@ -1246,7 +1245,10 @@ fail: } static int manager_connect_console(Manager *m) { - struct epoll_event ev; + struct epoll_event ev = { + .events = 0, + .data.u32 = FD_CONSOLE, + }; assert(m); assert(m->console_active_fd < 0); @@ -1271,10 +1273,6 @@ static int manager_connect_console(Manager *m) { return -errno; } - zero(ev); - ev.events = 0; - ev.data.u32 = FD_CONSOLE; - if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->console_active_fd, &ev) < 0) return -errno; @@ -1282,8 +1280,11 @@ static int manager_connect_console(Manager *m) { } static int manager_connect_udev(Manager *m) { - struct epoll_event ev; int r; + struct epoll_event ev = { + .events = EPOLLIN, + .data.u32 = FD_SEAT_UDEV, + }; assert(m); assert(!m->udev_seat_monitor); @@ -1304,9 +1305,6 @@ static int manager_connect_udev(Manager *m) { m->udev_seat_fd = udev_monitor_get_fd(m->udev_seat_monitor); - zero(ev); - ev.events = EPOLLIN; - ev.data.u32 = FD_SEAT_UDEV; if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->udev_seat_fd, &ev) < 0) return -errno; @@ -1447,7 +1445,7 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) { int manager_dispatch_idle_action(Manager *m) { struct dual_timestamp since; - struct itimerspec its; + struct itimerspec its = {}; int r; usec_t n; @@ -1459,7 +1457,6 @@ int manager_dispatch_idle_action(Manager *m) { goto finish; } - zero(its); n = now(CLOCK_MONOTONIC); r = manager_get_idle_hint(m, &since); @@ -1482,7 +1479,10 @@ int manager_dispatch_idle_action(Manager *m) { } if (m->idle_action_fd < 0) { - struct epoll_event ev; + struct epoll_event ev = { + .events = EPOLLIN, + .data.u32 = FD_IDLE_ACTION, + }; m->idle_action_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC); if (m->idle_action_fd < 0) { @@ -1491,10 +1491,6 @@ int manager_dispatch_idle_action(Manager *m) { goto finish; } - zero(ev); - ev.events = EPOLLIN; - ev.data.u32 = FD_IDLE_ACTION; - if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->idle_action_fd, &ev) < 0) { log_error("Failed to add idle action timer to epoll: %m"); r = -errno; diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 0d4f7991e7..c8f4dae77e 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -256,13 +256,15 @@ static bool check_user_lists( } static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) { - char *p = NULL; + char _cleanup_free_ *p = NULL; int r; - int fd; - union sockaddr_union sa; + int _cleanup_close_ fd = -1; + union sockaddr_union sa = { + .un.sun_family = AF_UNIX, + }; struct ucred ucred; socklen_t l; - char *tty; + char _cleanup_free_ *tty = NULL; int v; assert(display); @@ -277,27 +279,17 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ r = socket_from_display(display, &p); if (r < 0) return r; + strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1); fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); - if (fd < 0) { - free(p); + if (fd < 0) return -errno; - } - - zero(sa); - sa.un.sun_family = AF_UNIX; - strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1); - free(p); - if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) { - close_nointr_nofail(fd); + if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) return -errno; - } l = sizeof(ucred); r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l); - close_nointr_nofail(fd); - if (r < 0) return -errno; @@ -306,8 +298,6 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_ return r; v = vtnr_from_tty(tty); - free(tty); - if (v < 0) return v; else if (v == 0) -- cgit v1.2.1 From e2acb67baaa1d63685dcaf80becf10291f13d086 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Apr 2013 22:18:16 +0200 Subject: logind: introduce an explicit session class for cronjobs and similar cronjobs are neither interactive user session, nor lock screens, nor login screens, hence they should get their own class. --- src/login/logind-dbus.c | 38 ++++++++++++++++++++++++++++++-------- src/login/logind-session.c | 3 ++- src/login/logind-session.h | 17 +++++++++-------- src/login/pam-module.c | 9 +++++---- 4 files changed, 46 insertions(+), 21 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index aa212d1fed..230dd2b4b5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -353,21 +353,28 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess return -EINVAL; dbus_message_iter_get_basic(&iter, &type); - t = session_type_from_string(type); + if (isempty(type)) + t = _SESSION_TYPE_INVALID; + else { + t = session_type_from_string(type); + if (t < 0) + return -EINVAL; + } - if (t < 0 || - !dbus_message_iter_next(&iter) || + if (!dbus_message_iter_next(&iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return -EINVAL; dbus_message_iter_get_basic(&iter, &class); if (isempty(class)) - c = SESSION_USER; - else + c = _SESSION_CLASS_INVALID; + else { c = session_class_from_string(class); + if (c < 0) + return -EINVAL; + } - if (c < 0 || - !dbus_message_iter_next(&iter) || + if (!dbus_message_iter_next(&iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return -EINVAL; @@ -441,6 +448,22 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN) return -EINVAL; + if (t == _SESSION_TYPE_INVALID) { + if (!isempty(display)) + t = SESSION_X11; + else if (!isempty(tty)) + t = SESSION_TTY; + else + t = SESSION_UNSPECIFIED; + } + + if (c == _SESSION_CLASS_INVALID) { + if (!isempty(display) || !isempty(tty)) + c = SESSION_USER; + else + c = SESSION_BACKGROUND; + } + dbus_message_iter_get_basic(&iter, &remote); if (!dbus_message_iter_next(&iter) || @@ -993,7 +1016,6 @@ static int have_multiple_sessions( * count, and non-login sessions do not count either. */ HASHMAP_FOREACH(session, m->sessions, i) if (session->class == SESSION_USER && - (session->type == SESSION_TTY || session->type == SESSION_X11) && session->user->uid != uid) return true; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 97c24d094b..508336d4d3 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1056,7 +1056,8 @@ DEFINE_STRING_TABLE_LOOKUP(session_type, SessionType); static const char* const session_class_table[_SESSION_CLASS_MAX] = { [SESSION_USER] = "user", [SESSION_GREETER] = "greeter", - [SESSION_LOCK_SCREEN] = "lock-screen" + [SESSION_LOCK_SCREEN] = "lock-screen", + [SESSION_BACKGROUND] = "background" }; DEFINE_STRING_TABLE_LOOKUP(session_class, SessionClass); diff --git a/src/login/logind-session.h b/src/login/logind-session.h index 7598afa618..c8dd181e7b 100644 --- a/src/login/logind-session.h +++ b/src/login/logind-session.h @@ -37,22 +37,23 @@ typedef enum SessionState { _SESSION_STATE_INVALID = -1 } SessionState; -typedef enum SessionType { - SESSION_UNSPECIFIED, - SESSION_TTY, - SESSION_X11, - _SESSION_TYPE_MAX, - _SESSION_TYPE_INVALID = -1 -} SessionType; - typedef enum SessionClass { SESSION_USER, SESSION_GREETER, SESSION_LOCK_SCREEN, + SESSION_BACKGROUND, _SESSION_CLASS_MAX, _SESSION_CLASS_INVALID = -1 } SessionClass; +typedef enum SessionType { + SESSION_UNSPECIFIED, + SESSION_TTY, + SESSION_X11, + _SESSION_TYPE_MAX, + _SESSION_TYPE_INVALID = -1 +} SessionType; + typedef enum KillWho { KILL_LEADER, KILL_ALL, diff --git a/src/login/pam-module.c b/src/login/pam-module.c index c8f4dae77e..609317e9dd 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -440,9 +440,10 @@ _public_ PAM_EXTERN int pam_sm_open_session( seat = strempty(seat); if (strchr(tty, ':')) { - /* A tty with a colon is usually an X11 display, place - * there to show up in utmp. We rearrange things and - * don't pretend that an X display was a tty */ + /* A tty with a colon is usually an X11 display, + * placed there to show up in utmp. We rearrange + * things and don't pretend that an X display was a + * tty. */ if (isempty(display)) display = tty; @@ -482,7 +483,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( if (isempty(class)) class = class_pam; if (isempty(class)) - class = "user"; + class = streq(type, "unspecified") ? "background" : "user"; remote = !isempty(remote_host) && !streq(remote_host, "localhost") && -- cgit v1.2.1 From 50fb97935d689a520251b2d543599be14bdfd0ed Mon Sep 17 00:00:00 2001 From: Fedora systemd team Date: Wed, 10 Apr 2013 09:49:24 +0200 Subject: logind: avoid creating stale session state files There were old session state files accumulating in /run/systemd/session. They confused e.g. "reboot", which thought there were still users logged in. The files got created like this: session_stop(Session *s) -> ... unlink(s->state_file); ... seat_set_active(s->seat, NULL) -> session_save(...); /* re-creates the state file we just unlinked */ Fix it simply by clearing the s->started flag earlier to prevent any further writes of the state file (session_save() checks the flag). --- src/login/logind-session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 508336d4d3..e2f41d3e57 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -710,6 +710,8 @@ int session_stop(Session *s) { if (s->started) session_send_signal(s, false); + s->started = false; + if (s->seat) { if (s->seat->active == s) seat_set_active(s->seat, NULL); @@ -721,8 +723,6 @@ int session_stop(Session *s) { user_send_changed(s->user, "Sessions\0"); user_save(s->user); - s->started = false; - return r; } -- cgit v1.2.1 From bcb161b0230fdd1faf9176f95fee76a7db6afd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 11 Apr 2013 18:57:42 -0400 Subject: errno is positive Make sure we compare errno against positive error codes. The ones in hwclock.c and install.c can have an impact, the rest are unlikely to be hit or in code that isn't widely used. Also check that errno > 0, to help gcc know that we are returning a negative error code. --- src/login/sd-login.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/login') diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 7513f76cb3..f433e3e80b 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -730,7 +730,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC); if (fd < 0) - return errno; + return -errno; if (!category || streq(category, "seat")) { k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); -- cgit v1.2.1 From 97e13058170c7759dbbc239d264b9a31b0c81079 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Apr 2013 14:16:45 +0200 Subject: sd-login: add a sd_pid_get_user_unit() call --- src/login/libsystemd-login.sym | 5 +++++ src/login/sd-login.c | 11 +++++++++++ 2 files changed, 16 insertions(+) (limited to 'src/login') diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index ce2304a1ba..9048de86a9 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -64,3 +64,8 @@ global: sd_login_monitor_get_events; sd_login_monitor_get_timeout; } LIBSYSTEMD_LOGIN_198; + +LIBSYSTEMD_LOGIN_202 { +global: + sd_pid_get_user_unit; +} LIBSYSTEMD_LOGIN_201; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index f433e3e80b..4c918f2105 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -84,6 +84,17 @@ _public_ int sd_pid_get_unit(pid_t pid, char **unit) { return cg_pid_get_unit(pid, unit); } +_public_ int sd_pid_get_user_unit(pid_t pid, char **unit) { + + if (pid < 0) + return -EINVAL; + + if (!unit) + return -EINVAL; + + return cg_pid_get_user_unit(pid, unit); +} + _public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) { int r; char *root, *cgroup, *p, *cc; -- cgit v1.2.1 From ab06eef8101866dd1337c4759002f7360a9db416 Mon Sep 17 00:00:00 2001 From: Anatol Pomozov Date: Sun, 14 Apr 2013 19:37:54 -0700 Subject: Fix spelling errors using 'codespell' tool --- src/login/logind-dbus.c | 2 +- src/login/logind.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 230dd2b4b5..4a8ffe5eda 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -66,7 +66,7 @@ " \n" \ " \n" \ " \n" \ - " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ diff --git a/src/login/logind.c b/src/login/logind.c index c9e492fc4f..63422f4c32 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1726,7 +1726,7 @@ int main(int argc, char *argv[]) { /* Always create the directories people can create inotify * watches in. Note that some applications might check for the - * existance of /run/systemd/seats/ to determine whether + * existence of /run/systemd/seats/ to determine whether * logind is available, so please always make sure this check * stays in. */ mkdir_label("/run/systemd/seats", 0755); -- cgit v1.2.1 From a32360f1a5a85c12f00e9dfb7353280067cccb5b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Apr 2013 21:52:56 +0200 Subject: core: always create /user and /machine top-level cgroup dirs This allows clients to put inotify watches on these trees to watch for state changes, without having to wait until these dirs are created. This introduces the new top-level /machine cgroup dir as canonical location where OS containers and VMs shall be located (as discussed with the libvirt folks). --- src/login/logind-session.c | 4 ++-- src/login/logind-user.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-session.c b/src/login/logind-session.c index e2f41d3e57..da7ce42015 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -442,9 +442,9 @@ static int session_create_one_group(Session *s, const char *controller, const ch if (s->leader > 0) { r = cg_create_and_attach(controller, path, s->leader); if (r < 0) - r = cg_create(controller, path); + r = cg_create(controller, path, NULL); } else - r = cg_create(controller, path); + r = cg_create(controller, path, NULL); if (r < 0) return r; diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 411215a925..4b0ac5e737 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -320,7 +320,7 @@ static int user_create_cgroup(User *u) { } else p = u->cgroup_path; - r = cg_create(SYSTEMD_CGROUP_CONTROLLER, p); + r = cg_create(SYSTEMD_CGROUP_CONTROLLER, p, NULL); if (r < 0) { log_error("Failed to create cgroup "SYSTEMD_CGROUP_CONTROLLER":%s: %s", p, strerror(-r)); free(p); @@ -335,7 +335,7 @@ static int user_create_cgroup(User *u) { if (strv_contains(u->manager->reset_controllers, *k)) continue; - r = cg_create(*k, p); + r = cg_create(*k, p, NULL); if (r < 0) log_warning("Failed to create cgroup %s:%s: %s", *k, p, strerror(-r)); } -- cgit v1.2.1 From 54b758dd1422f6a907b04ce309c764c5c91b2e59 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 Apr 2013 03:52:59 +0200 Subject: logind: when looking for cgroup prefixes, allocate from stack --- src/login/logind.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/login') diff --git a/src/login/logind.c b/src/login/logind.c index 63422f4c32..aa3e5f0914 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1041,16 +1041,13 @@ int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **sess return 1; } - p = strdup(cgroup); - if (!p) - return log_oom(); + p = strdupa(cgroup); for (;;) { char *e; e = strrchr(p, '/'); if (!e || e == p) { - free(p); *session = NULL; return 0; } @@ -1059,7 +1056,6 @@ int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **sess s = hashmap_get(m->session_cgroups, p); if (s) { - free(p); *session = s; return 1; } @@ -1080,7 +1076,7 @@ int manager_get_user_by_cgroup(Manager *m, const char *cgroup, User **user) { return 1; } - p = strdup(cgroup); + p = strdupa(cgroup); if (!p) return log_oom(); @@ -1089,7 +1085,6 @@ int manager_get_user_by_cgroup(Manager *m, const char *cgroup, User **user) { e = strrchr(p, '/'); if (!e || e == p) { - free(p); *user = NULL; return 0; } @@ -1098,7 +1093,6 @@ int manager_get_user_by_cgroup(Manager *m, const char *cgroup, User **user) { u = hashmap_get(m->user_cgroups, p); if (u) { - free(p); *user = u; return 1; } -- cgit v1.2.1 From ed85d9a58d8e404877ec4bc2f2e9d31d16b98c47 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 Apr 2013 03:54:53 +0200 Subject: logind: filter configured cgroup controller lists --- src/login/logind-dbus.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/login') diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 4a8ffe5eda..d957bd7de5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -487,8 +487,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess if (r < 0) return -EINVAL; - if (strv_contains(controllers, "systemd") || - !dbus_message_iter_next(&iter) || + if (!dbus_message_iter_next(&iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING) { r = -EINVAL; @@ -499,8 +498,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess if (r < 0) goto fail; - if (strv_contains(reset_controllers, "systemd") || - !dbus_message_iter_next(&iter) || + if (!dbus_message_iter_next(&iter) || dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN) { r = -EINVAL; goto fail; @@ -611,11 +609,11 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess session->type = t; session->class = c; session->remote = remote; - session->controllers = controllers; - session->reset_controllers = reset_controllers; session->kill_processes = kill_processes; session->vtnr = vtnr; + session->controllers = cg_shorten_controllers(controllers); + session->reset_controllers = cg_shorten_controllers(reset_controllers); controllers = reset_controllers = NULL; if (!isempty(tty)) { -- cgit v1.2.1 From 7027ff61a34a12487712b382a061c654acc3a679 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 Apr 2013 04:36:06 +0200 Subject: nspawn: introduce the new /machine/ tree in the cgroup tree and move containers there Containers will now carry a label (normally derived from the root directory name, but configurable by the user), and the container's root cgroup is /machine/