From ff30424a0526b809bf40f22e6ad58601419da174 Mon Sep 17 00:00:00 2001 From: Sven Eden Date: Wed, 13 Jun 2018 08:08:10 +0200 Subject: [PATCH] Move manager_dispatch_delayed() back to logind-dbus.c --- src/login/elogind-dbus.c | 42 ++-------------------------------------- src/login/elogind-dbus.h | 17 +++++++++------- src/login/logind-dbus.c | 21 +++++++++++++++++++- 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/login/elogind-dbus.c b/src/login/elogind-dbus.c index b07722314..818c3676e 100644 --- a/src/login/elogind-dbus.c +++ b/src/login/elogind-dbus.c @@ -125,7 +125,7 @@ static int shutdown_or_sleep(Manager *m, HandleAction action) { } } -static int execute_shutdown_or_sleep( +int execute_shutdown_or_sleep( Manager *m, InhibitWhat w, HandleAction action, @@ -186,44 +186,6 @@ static int execute_shutdown_or_sleep( return 0; } -int manager_dispatch_delayed(Manager *manager, bool timeout) { - - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - Inhibitor *offending = NULL; - int r; - - assert(manager); - - if ( (0 == manager->action_what) || (HANDLE_IGNORE == manager->pending_action) ) - return 0; - - if (manager_is_inhibited(manager, manager->action_what, INHIBIT_DELAY, NULL, false, false, 0, &offending)) { - _cleanup_free_ char *comm = NULL, *u = NULL; - - if (!timeout) - return 0; - - (void) get_process_comm(offending->pid, &comm); - u = uid_to_name(offending->uid); - - log_notice("Delay lock is active (UID "UID_FMT"/%s, PID "PID_FMT"/%s) but inhibitor timeout is reached.", - offending->uid, strna(u), - offending->pid, strna(comm)); - } - - /* Actually do the operation */ - r = execute_shutdown_or_sleep(manager, manager->action_what, manager->pending_action, &error); - if (r < 0) { - log_warning("Failed to send delayed message: %s", bus_error_message(&error, r)); - - manager->pending_action = HANDLE_IGNORE; - manager->action_what = 0; - /* It is not a critical error for elogind if suspending fails */ - } - - return 1; -} - static int delay_shutdown_or_sleep( Manager *m, InhibitWhat w, @@ -449,7 +411,7 @@ int manager_scheduled_shutdown_handler( * above) for some seconds after our admin has seen the final * wall message. */ - bus_manager_log_shutdown(m, target); + bus_manager_log_shutdown(m, INHIBIT_SHUTDOWN, action); log_info("Running in dry run, suppressing action."); reset_scheduled_shutdown(m); diff --git a/src/login/elogind-dbus.h b/src/login/elogind-dbus.h index 616208316..deac06f73 100644 --- a/src/login/elogind-dbus.h +++ b/src/login/elogind-dbus.h @@ -23,6 +23,8 @@ #include "logind.h" +int execute_shutdown_or_sleep(Manager *m, InhibitWhat w, + HandleAction action, sd_bus_error *error); int manager_scheduled_shutdown_handler(sd_event_source *s, uint64_t usec, void *userdata); int method_halt (sd_bus_message *message, void *userdata, sd_bus_error *error); @@ -34,13 +36,14 @@ int method_suspend (sd_bus_message *message, void *userdata, sd_bus_error *e /* prototypes for former static functions in logind-dbus.c */ -int manager_inhibit_timeout_handler(sd_event_source *s, uint64_t usec, void *userdata); -int send_prepare_for(Manager *m, InhibitWhat w, bool _active); -int verify_shutdown_creds(Manager *m, sd_bus_message *message, InhibitWhat w, - bool interactive, const char *action, - const char *action_multiple_sessions, - const char *action_ignore_inhibit, - sd_bus_error *error); +int manager_inhibit_timeout_handler(sd_event_source *s, uint64_t usec, void *userdata); +void reset_scheduled_shutdown(Manager *m); +int send_prepare_for(Manager *m, InhibitWhat w, bool _active); +int verify_shutdown_creds(Manager *m, sd_bus_message *message, InhibitWhat w, + bool interactive, const char *action, + const char *action_multiple_sessions, + const char *action_ignore_inhibit, + sd_bus_error *error); #endif // ELOGIND_SRC_LOGIN_ELOGIND_DBUS_H_INCLUDED diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 172536d08..3ac67a444 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1635,6 +1635,7 @@ error: return r; } +#endif // 0 int manager_dispatch_delayed(Manager *manager, bool timeout) { @@ -1644,7 +1645,11 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) { assert(manager); +#if 0 /// elogind has no action_job, but a pending_action if (manager->action_what == 0 || manager->action_job) +#else + if ( (0 == manager->action_what) || (HANDLE_IGNORE == manager->pending_action) ) +#endif // 0 return 0; if (manager_is_inhibited(manager, manager->action_what, INHIBIT_DELAY, NULL, false, false, 0, &offending)) { @@ -1662,19 +1667,29 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) { } /* Actually do the operation */ +#if 0 /// elogind has no action_unit but a pending_action r = execute_shutdown_or_sleep(manager, manager->action_what, manager->action_unit, &error); +#else + r = execute_shutdown_or_sleep(manager, manager->action_what, manager->pending_action, &error); +#endif // 0 if (r < 0) { log_warning("Error during inhibitor-delayed operation (already returned success to client): %s", bus_error_message(&error, r)); + +#if 0 /// elogind has no action_unit but a pending_action manager->action_unit = NULL; manager->action_what = 0; return r; +#else + manager->pending_action = HANDLE_IGNORE; + manager->action_what = 0; + /* It is not a critical error for elogind if suspending fails */ +#endif // 0 } return 1; } -#endif // 0 #if 0 /// elogind-dbus.c needs to access this static int manager_inhibit_timeout_handler( @@ -2043,7 +2058,11 @@ fail: return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m"); } +#if 0 /// elogind must access this from elogind-dbus.c static void reset_scheduled_shutdown(Manager *m) { +#else +void reset_scheduled_shutdown(Manager *m) { +#endif // 0 assert(m); m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source); -- 2.30.2