chiark / gitweb /
Prep v231.2: login1.policy vendor is the project, not it's description.
[elogind.git] / src / login / logind-dbus.c
index a6bce0de02b94ad18aedc0e1591739470c99aca3..cb67c668fa9982d262ab68ecf361017b8cc7bcab 100644 (file)
 #include "path-util.h"
 #include "process-util.h"
 #include "selinux-util.h"
-//#include "sleep-config.h"
+#include "sleep-config.h"
 //#include "special.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "udev-util.h"
 #include "unit-name.h"
 #include "user-util.h"
-//#include "utmp-wtmp.h"
+#include "utmp-wtmp.h"
+
+/// Additional includes needed by elogind
+#include "update-utmp.h"
+
+#if 1 /// elogind needs this prototype
+static int send_prepare_for(Manager *m, InhibitWhat w, bool _active);
+#endif // 1
 
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) {
         _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
@@ -915,7 +922,9 @@ static int method_release_session(sd_bus_message *message, void *userdata, sd_bu
         if (r < 0)
                 return r;
 
+#if 1 /// elogind must queue this session
         session_add_to_gc_queue(session);
+#endif // 1
 
         return sd_bus_reply_method_return(message, NULL);
 }
@@ -1548,6 +1557,9 @@ static int execute_shutdown_or_sleep(
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         char *c = NULL;
         const char *p;
+#else
+        /* needed for update-utmp */
+        char** argv_utmp = NULL;
 #endif // 0
         int r;
 
@@ -1588,13 +1600,44 @@ static int execute_shutdown_or_sleep(
                 m->action_what = w;
         }
 #else
+        if (IN_SET(action, HANDLE_HALT, HANDLE_POWEROFF, HANDLE_REBOOT)) {
+
+                /* As we have no systemd update-utmp daemon running, we have to
+                 * set the relevant utmp/wtmp entries ourselves.
+                 */
+
+                if (strv_extend(&argv_utmp, "elogind") < 0)
+                        return log_oom();
+
+                if (HANDLE_REBOOT == action) {
+                        if (strv_extend(&argv_utmp, "reboot") < 0)
+                                return log_oom();
+                } else {
+                        if (strv_extend(&argv_utmp, "shutdown") < 0)
+                                return log_oom();
+                }
+
+                 /* This comes from our patched update-utmp/update-utmp.c */
+                update_utmp(2, argv_utmp, m->bus);
+                strv_free(argv_utmp);
+        }
+
+        /* Now perform the requested action */
         r = shutdown_or_sleep(m, action);
 
         /* no more pending actions, whether this failed or not */
         m->pending_action = HANDLE_IGNORE;
-        m->action_what    = 0;
         if (r < 0)
                 return r;
+
+        /* As elogind can not rely on a systemd manager to call all
+         * sleeping processes to wake up, we have to tell them all
+         * by ourselves. */
+        if (w == INHIBIT_SLEEP) {
+                send_prepare_for(m, w, false);
+                m->action_what = 0;
+        } else
+                m->action_what = w;
 #endif // 0
 
         /* Make sure the lid switch is ignored for a while */
@@ -2093,11 +2136,9 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
                 }
         }
 
-#if 0 /// elogind does not support utmp-wtmp
         r = manager_setup_wall_message_timer(m);
         if (r < 0)
                 return r;
-#endif // 0
 
         if (!isempty(type)) {
                 r = update_schedule_file(m);
@@ -2119,7 +2160,6 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
         cancelled = m->scheduled_shutdown_type != NULL;
         reset_scheduled_shutdown(m);
 
-#if 0 /// elogind does not support utmp-wtmp
         if (cancelled) {
                 _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
                 const char *tty = NULL;
@@ -2135,7 +2175,6 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
                 utmp_wall("The system shutdown has been cancelled",
                           uid_to_name(uid), tty, logind_wall_tty_filter, m);
         }
-#endif // 0
 
         return sd_bus_reply_method_return(message, "b", cancelled);
 }