#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;
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);
}
_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;
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 */
}
}
-#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);
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;
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);
}
return sd_bus_message_append(reply, "b", r > 0);
#else
- return sd_bus_message_append(reply, "b", -EOPNOTSUPP);
+ return sd_bus_message_append(reply, "b", false);
#endif // 0
}
return sd_bus_reply_method_return(message, "s", result);
#else
- return sd_bus_reply_method_return(message, "s", "na");
+ return sd_bus_reply_method_return(message, "s", "no");
#endif // 0
}