1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-03-09 23:38:56 +00:00

miracle-dispd: notify systemd about the service readiness

This commit is contained in:
Derek Dai 2017-03-30 13:06:49 +08:00
parent 4ec5e11c07
commit f46617383d
No known key found for this signature in database
GPG key ID: E109CC97553EF009

View file

@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <systemd/sd-event.h> #include <systemd/sd-event.h>
#include <systemd/sd-daemon.h>
#include <glib.h> #include <glib.h>
#include <gst/gst.h> #include <gst/gst.h>
#include "ctl.h" #include "ctl.h"
@ -515,6 +516,7 @@ int main(int argc, char **argv)
r = sd_event_set_watchdog(event, true); r = sd_event_set_watchdog(event, true);
if (0 > r) { if (0 > r) {
log_warning("unable to start automatic watchdog support: %s", strerror(errno));
goto unref_event; goto unref_event;
} }
@ -531,13 +533,13 @@ int main(int argc, char **argv)
r = sd_bus_default_system(&bus); r = sd_bus_default_system(&bus);
if(0 > r) { if(0 > r) {
log_warning("unabled to connect to system DBus: %s", strerror(errno)); log_warning("unable to connect to system DBus: %s", strerror(errno));
goto unref_source; goto unref_source;
} }
r = sd_bus_attach_event(bus, event, 0); r = sd_bus_attach_event(bus, event, 0);
if(0 > r) { if(0 > r) {
log_warning("unabled to attache DBus event source to loop: %s", log_warning("unable to attache DBus event source to loop: %s",
strerror(errno)); strerror(errno));
goto unref_bus; goto unref_bus;
} }
@ -554,12 +556,21 @@ int main(int argc, char **argv)
r = wfd_dbus_expose(wfd_dbus); r = wfd_dbus_expose(wfd_dbus);
if(0 > r) { if(0 > r) {
log_warning("unabled to publish WFD service: %s", strerror(errno)); log_warning("unable to publish WFD service: %s", strerror(errno));
goto free_wfd_dbus;
}
r = sd_notify(false, "READY=1\n"
"STATUS=Running..");
if (0 > r) {
log_warning("unable to notify systemd that we are ready: %s", strerror(errno));
goto free_wfd_dbus; goto free_wfd_dbus;
} }
g_main_loop_run(loop); g_main_loop_run(loop);
sd_notify(false, "STATUS=Exiting..");
free_wfd_dbus: free_wfd_dbus:
wfd_dbus_free(wfd_dbus); wfd_dbus_free(wfd_dbus);
wfd_dbus = NULL; wfd_dbus = NULL;
@ -580,6 +591,7 @@ unref_loop:
g_main_loop_unref(loop); g_main_loop_unref(loop);
deinit_gst: deinit_gst:
gst_deinit(); gst_deinit();
sd_event_set_watchdog(event, false);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }