Skip to content

Commit

Permalink
Added support to signal systemd when ready. Fixes NEMO#566
Browse files Browse the repository at this point in the history
Signed-off-by: Pekka Lundstrom <pekka.lundstrom@jollamobile.com>
  • Loading branch information
Pekka Lundstrom committed Nov 9, 2012
1 parent 6efd482 commit dabbaa9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
15 changes: 14 additions & 1 deletion configure.ac
@@ -1,5 +1,5 @@
# Package name and version
AC_INIT(dsme, 0.62.5)
AC_INIT(dsme, 0.62.6)

AM_INIT_AUTOMAKE

Expand Down Expand Up @@ -65,6 +65,19 @@ AS_IF([test "x$enable_upstart" != xno],
[AC_DEFINE([DSME_WANT_LIBUPSTART], [1])])
AM_CONDITIONAL([WANT_UPSTART], [test x$enable_upstart != xno])

#
# systemd
#
AC_ARG_ENABLE([systemd],
[AS_HELP_STRING([--enable-systemd],
[enable systemd start feedback])],
[],
[enable_systemd=no])

AS_IF([test "x$enable_systemd" != xno],
[AC_DEFINE([DSME_SYSTEMD_ENABLE], [1])])
AM_CONDITIONAL([WANT_SYSTEMD], [test x$enable_systemd != xno])

#
# validatorlistener
#
Expand Down
3 changes: 3 additions & 0 deletions dsme/Makefile.am
Expand Up @@ -32,6 +32,9 @@ dsme_SOURCES = dsme-wdd.c \
dsme_CFLAGS = -g -std=c99 -Wall -Wwrite-strings -Wmissing-prototypes -Werror \
$(C_OPTFLAGS)
dsme_LDFLAGS = -Wl,--as-needed
if WANT_SYSTEMD
dsme_LDADD = -L/lib -lsystemd-daemon
endif

#
# dsme-server
Expand Down
26 changes: 24 additions & 2 deletions dsme/dsme-server.c
Expand Up @@ -80,6 +80,10 @@ static void usage(const char * progname)
fprintf(stderr, " -l --logging "
"Logging type (syslog, sti, stderr, stdout, none)\n");
fprintf(stderr, " -v --verbosity Log verbosity (3..7)\n");
#endif
#ifdef DSME_SYSTEMD_ENABLE
fprintf(stderr, " -s --systemd "
"Signal systemd when initialization is done\n");
#endif
fprintf(stderr, " -h --help Help\n");
}
Expand All @@ -104,18 +108,24 @@ void signal_handler(int sig)
static int logging_verbosity = LOG_INFO;
static log_method logging_method = LOG_METHOD_SYSLOG;
#endif
#ifdef DSME_SYSTEMD_ENABLE
static int signal_systemd = 0;
#endif

static void parse_options(int argc, /* in */
char* argv[], /* in */
GSList** module_names) /* out */
{
int next_option;
const char* program_name = argv[0];
const char* short_options = "dhp:l:v:";
const char* short_options = "dhsp:l:v:";
const struct option long_options[] = {
{ "startup-module", 1, NULL, 'p' },
{ "help", 0, NULL, 'h' },
{ "verbosity", 0, NULL, 'v' },
#ifdef DSME_SYSTEMD_ENABLE
{ "systemd", 0, NULL, 's' },
#endif
#ifdef DSME_LOG_ENABLE
{ "logging", 0, NULL, 'l' },
#endif
Expand Down Expand Up @@ -169,6 +179,11 @@ static void parse_options(int argc, /* in */
fprintf(stderr, ME "Logging not compiled in\n");
break;
#endif
#ifdef DSME_SYSTEMD_ENABLE
case 's': /* -s or --systemd */
signal_systemd = 1;
break;
#endif
case 'h': /* -h or --help */
usage(program_name);
exit(EXIT_SUCCESS);
Expand Down Expand Up @@ -289,7 +304,14 @@ int main(int argc, char *argv[])
dsme_log(LOG_CRIT, "chdir failed: %s", strerror(errno));
return EXIT_FAILURE;
}

#ifdef DSME_SYSTEMD_ENABLE
/* Inform main process that we are ready
* Main process will inform systemd
*/
if (signal_systemd) {
kill(getppid(), SIGUSR1);
}
#endif
dsme_log(LOG_DEBUG, "Entering main loop");
dsme_main_loop_run(process_message_queue);
dsme_log(LOG_CRIT, "Exited main loop, quitting");
Expand Down
17 changes: 16 additions & 1 deletion dsme/dsme-wdd.c
Expand Up @@ -44,6 +44,9 @@
#include <sched.h>
#include <sys/mman.h>
#include <sys/wait.h>
#ifdef DSME_SYSTEMD_ENABLE
#include <systemd/sd-daemon.h>
#endif

#define STRINGIFY(x) STRINGIFY2(x)
#define STRINGIFY2(x) #x
Expand Down Expand Up @@ -174,6 +177,12 @@ void signal_handler(int sig)
case SIGTERM:
run = false;
break;
#ifdef DSME_SYSTEMD_ENABLE
case SIGUSR1:
/* Inform systemd that server is initialized */
sd_notify(0, "READY=1");
break;
#endif
}
}

Expand All @@ -188,10 +197,13 @@ static void parse_options(int argc, /* in */
{
int next_option;
const char* program_name = argv[0];
const char* short_options = "dhp:l:v:";
const char* short_options = "dhsp:l:v:";
const struct option long_options[] = {
{ "help", 0, NULL, 'h' },
{ "verbosity", 0, NULL, 'v' },
#ifdef DSME_SYSTEMD_ENABLE
{ "systemd", 0, NULL, 's' },
#endif
#ifdef DSME_LOG_ENABLE
{ "logging", 0, NULL, 'l' },
#endif
Expand Down Expand Up @@ -354,6 +366,9 @@ int main(int argc, char *argv[])
signal(SIGTERM, signal_handler);
signal(SIGPIPE, signal_handler);
signal(SIGCHLD, signal_handler);
#ifdef DSME_SYSTEMD_ENABLE
signal(SIGUSR1, signal_handler);
#endif


// protect from oom
Expand Down

0 comments on commit dabbaa9

Please sign in to comment.