23 if (g_inhibit_fd >= 0) {
24 log_debug(
"Keepawake already enabled");
29 if (sd_bus_default_system == NULL) {
30 log_dev(
"systemd not available, keepawake not supported");
35 sd_bus_message *reply = NULL;
36 sd_bus_error error = SD_BUS_ERROR_NULL;
38 if (sd_bus_default_system(&bus) < 0) {
39 return SET_ERRNO(ERROR_PLATFORM_INIT,
"Failed to connect to system bus");
43 return SET_ERRNO(ERROR_PLATFORM_INIT,
"System bus is NULL");
46 int r = sd_bus_call_method(bus,
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
47 "Inhibit", &error, &reply,
"ssss",
50 "Video/audio streaming",
55 sd_bus_error_free(&error);
57 return SET_ERRNO(ERROR_PLATFORM_INIT,
"Failed to inhibit sleep via systemd");
61 sd_bus_error_free(&error);
63 return SET_ERRNO(ERROR_PLATFORM_INIT,
"systemd inhibit reply is NULL");
66 if (sd_bus_message_read(reply,
"h", &g_inhibit_fd) < 0) {
67 sd_bus_message_unref(reply);
68 sd_bus_error_free(&error);
70 return SET_ERRNO(ERROR_PLATFORM_INIT,
"Failed to read inhibit fd from systemd reply");
73 sd_bus_message_unref(reply);
74 sd_bus_error_free(&error);
77 log_debug(
"Keepawake enabled via systemd-inhibit (fd: %d)", g_inhibit_fd);
82 log_debug(
"Keepawake not implemented on this platform");