Skip to content

Commit

Permalink
Notify systemd when mce has started up
Browse files Browse the repository at this point in the history
If started with --systemd option, mce sends "READY=1" notification
to systemd just before entering mainloop.

[init] Notification sent to systemd when mce has started up
  • Loading branch information
spiiroin committed Aug 29, 2013
1 parent d76e49a commit 90dae1d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -273,6 +273,7 @@ MCE_PKG_NAMES += dbus-1
MCE_PKG_NAMES += dbus-glib-1
MCE_PKG_NAMES += gconf-2.0
MCE_PKG_NAMES += dsme
MCE_PKG_NAMES += libsystemd-daemon

MCE_PKG_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(MCE_PKG_NAMES))
MCE_PKG_LDLIBS := $(shell $(PKG_CONFIG) --libs $(MCE_PKG_NAMES))
Expand Down
17 changes: 16 additions & 1 deletion mce.c
Expand Up @@ -134,6 +134,8 @@
# include "libwakelock.h"
#endif

#include <systemd/sd-daemon.h>

/** Path to the lockfile */
#define MCE_LOCKFILE "/var/run/mce.pid"
/** Name shown by --help etc. */
Expand Down Expand Up @@ -169,6 +171,7 @@ static const char usage_fmt[] =
"Usage: %s [OPTION]...\n"
"Mode Control Entity\n"
"\n"
" -n, --systemd notify systemd when started up\n"
" -d, --daemonflag run MCE as a daemon\n"
" -s, --force-syslog log to syslog even when not daemonized\n"
" -T, --force-stderr log to stderr even when daemonized\n"
Expand Down Expand Up @@ -753,10 +756,12 @@ int main(int argc, char **argv)
gboolean daemonflag = FALSE;
gboolean systembus = TRUE;
gboolean debugmode = FALSE;
gboolean systemd_notify = FALSE;

const char optline[] = "dsTSMDqvhVt:";
const char optline[] = "dsTSMDqvhVt:n";

struct option const options[] = {
{ "systemd", no_argument, 0, 'n' },
{ "daemonflag", no_argument, 0, 'd' },
{ "force-syslog", no_argument, 0, 's' },
{ "force-stderr", no_argument, 0, 'T' },
Expand All @@ -779,6 +784,10 @@ int main(int argc, char **argv)
while ((optc = getopt_long(argc, argv, optline,
options, &opt_index)) != -1) {
switch (optc) {
case 'n':
systemd_notify = TRUE;
break;

case 'd':
daemonflag = TRUE;
break;
Expand Down Expand Up @@ -1015,6 +1024,12 @@ int main(int argc, char **argv)
/* MCE startup succeeded */
status = EXIT_SUCCESS;

/* Tell systemd that we have started up */
if( systemd_notify ) {
mce_log(LL_NOTICE, "notifying systemd");
sd_notify(0, "READY=1");
}

/* Run the main loop */
g_main_loop_run(mainloop);

Expand Down
1 change: 1 addition & 0 deletions rpm/mce.spec
Expand Up @@ -18,6 +18,7 @@ BuildRequires: pkgconfig(dsme) >= 0.58
BuildRequires: pkgconfig(gconf-2.0)
BuildRequires: pkgconfig(glib-2.0) >= 2.18.0
BuildRequires: pkgconfig(mce) >= 1.12.3
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: kernel-headers >= 2.6.32
BuildRequires: systemd
# systemd has /etc/rpm/macros.systemd
Expand Down
3 changes: 2 additions & 1 deletion systemd/mce.service
Expand Up @@ -8,7 +8,8 @@ After=dsme.service
# Before=systemd-user-sessions.service

[Service]
ExecStart=/usr/sbin/mce
Type=notify
ExecStart=/usr/sbin/mce --systemd
Restart=always

[Install]
Expand Down

0 comments on commit 90dae1d

Please sign in to comment.