From 59740d8fee66f3326b30ac25882b52ffada4bac2 Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Fri, 6 Jun 2014 15:29:49 +0400 Subject: epmd: Added systemd notify support to EPMD Signed-off-by: Peter Lemenkov --- erts/configure.in | 3 +++ erts/epmd/src/epmd.c | 8 +++++--- erts/epmd/src/epmd_srv.c | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'erts') diff --git a/erts/configure.in b/erts/configure.in index 9864d03cde..a594d59355 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -1691,10 +1691,13 @@ systemd_daemon_save_LIBS=$LIBS LIBS= AC_SEARCH_LIBS(sd_listen_fds,[systemd systemd-daemon], [have_sd_listen_fds=yes],[have_sd_listen_fds=no],$systemd_daemon_save_LIBS) +AC_SEARCH_LIBS(sd_notify,[systemd systemd-daemon], + [have_sd_notify=yes],[have_sd_notify=no],$systemd_daemon_save_LIBS) AC_CHECK_HEADERS(systemd/sd-daemon.h, [have_systemd_sd_daemon_h=yes],[have_systemd_sd_daemon_h=no]) if test x"$have_sd_listen_fds" = x"yes" && \ + test x"$have_sd_notify" = x"yes" && \ test x"$have_systemd_sd_daemon_h" = x"yes"; then AC_DEFINE([HAVE_SYSTEMD_DAEMON],[1],[Define if you have systemd daemon]) SYSTEMD_DAEMON_LIBS=$LIBS diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c index 9630e0cdf0..dff9bc64de 100644 --- a/erts/epmd/src/epmd.c +++ b/erts/epmd/src/epmd.c @@ -593,9 +593,11 @@ void epmd_cleanup_exit(EpmdVars *g, int exitval) for(i=0; g->argv[i] != NULL; ++i) free(g->argv[i]); free(g->argv); - } - - + } +#ifdef HAVE_SYSTEMD_SD_DAEMON_H + sd_notifyf(0, "STATUS=Exited.\n" + "ERRNO=%i", exitval); +#endif // HAVE_SYSTEMD_SD_DAEMON_H exit(exitval); } diff --git a/erts/epmd/src/epmd_srv.c b/erts/epmd/src/epmd_srv.c index 48fd7a5f9c..18d898a915 100644 --- a/erts/epmd/src/epmd_srv.c +++ b/erts/epmd/src/epmd_srv.c @@ -399,8 +399,11 @@ void run(EpmdVars *g) } select_fd_set(g, listensock[i]); } -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_SD_DAEMON_H } + sd_notifyf(0, "READY=1\n" + "STATUS=Processing port mapping requests...\n" + "MAINPID=%lu", (unsigned long) getpid()); #endif dbg_tty_printf(g,2,"entering the main select() loop"); -- cgit v1.2.3 From 5db2345baa3bb9c835f91aafac3dde6e595debc7 Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Sun, 2 Nov 2014 18:06:21 +0300 Subject: epmd: Unify systemd autoconf macros usage Don't use both HAVE_SYSTEMD_DAEMON and HAVE_SYSTEMD_SD_DAEMON - use only the former one and remove the latter one entirely. Signed-off-by: Peter Lemenkov --- erts/epmd/src/epmd.c | 16 ++++++++-------- erts/epmd/src/epmd_int.h | 8 ++++---- erts/epmd/src/epmd_srv.c | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'erts') diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c index dff9bc64de..9699491526 100644 --- a/erts/epmd/src/epmd.c +++ b/erts/epmd/src/epmd.c @@ -175,9 +175,9 @@ int main(int argc, char** argv) g->nodes.reg = g->nodes.unreg = g->nodes.unreg_tail = NULL; g->nodes.unreg_count = 0; g->active_conn = 0; -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON g->is_systemd = 0; -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ for (i = 0; i < MAX_LISTEN_SOCKETS; i++) g->listenfd[i] = -1; @@ -251,11 +251,11 @@ int main(int argc, char** argv) else usage(g); epmd_cleanup_exit(g,0); -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON } else if (strcmp(argv[0], "-systemd") == 0) { g->is_systemd = 1; argv++; argc--; -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ } else usage(g); } @@ -461,11 +461,11 @@ static void usage(EpmdVars *g) fprintf(stderr, " Forcibly unregisters a name with epmd\n"); fprintf(stderr, " (only allowed if -relaxed_command_check was given when \n"); fprintf(stderr, " epmd was started).\n"); -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON fprintf(stderr, " -systemd\n"); fprintf(stderr, " Wait for socket from systemd. The option makes sense\n"); fprintf(stderr, " when started from .socket unit.\n"); -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ epmd_cleanup_exit(g,1); } @@ -594,10 +594,10 @@ void epmd_cleanup_exit(EpmdVars *g, int exitval) free(g->argv[i]); free(g->argv); } -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON sd_notifyf(0, "STATUS=Exited.\n" "ERRNO=%i", exitval); -#endif // HAVE_SYSTEMD_SD_DAEMON_H +#endif /* HAVE_SYSTEMD_DAEMON */ exit(exitval); } diff --git a/erts/epmd/src/epmd_int.h b/erts/epmd/src/epmd_int.h index c8f2192f7f..52badd7086 100644 --- a/erts/epmd/src/epmd_int.h +++ b/erts/epmd/src/epmd_int.h @@ -125,9 +125,9 @@ # include "sys/select.h" #endif -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON # include -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ /* ************************************************************************ */ /* Replace some functions by others by making the function name a macro */ @@ -340,9 +340,9 @@ typedef struct { int listenfd[MAX_LISTEN_SOCKETS]; char *addresses; char **argv; -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON int is_systemd; -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ } EpmdVars; void dbg_printf(EpmdVars*,int,const char*,...); diff --git a/erts/epmd/src/epmd_srv.c b/erts/epmd/src/epmd_srv.c index 18d898a915..26e42adb19 100644 --- a/erts/epmd/src/epmd_srv.c +++ b/erts/epmd/src/epmd_srv.c @@ -244,7 +244,7 @@ void run(EpmdVars *g) } else { -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ dbg_printf(g,2,"try to initiate listening port %d", g->port); @@ -312,7 +312,7 @@ void run(EpmdVars *g) } #ifdef HAVE_SYSTEMD_DAEMON } -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ #if !defined(__WIN32__) && !defined(__OSE__) /* We ignore the SIGPIPE signal that is raised when we call write @@ -330,13 +330,13 @@ void run(EpmdVars *g) FD_ZERO(&g->orig_read_mask); g->select_fd_top = 0; -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON if (g->is_systemd) for (i = 0; i < num_sockets; i++) select_fd_set(g, listensock[i]); else { -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ for (i = 0; i < num_sockets; i++) { if ((listensock[i] = socket(FAMILY,SOCK_STREAM,0)) < 0) @@ -399,12 +399,12 @@ void run(EpmdVars *g) } select_fd_set(g, listensock[i]); } -#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#ifdef HAVE_SYSTEMD_DAEMON } sd_notifyf(0, "READY=1\n" "STATUS=Processing port mapping requests...\n" "MAINPID=%lu", (unsigned long) getpid()); -#endif +#endif /* HAVE_SYSTEMD_DAEMON */ dbg_tty_printf(g,2,"entering the main select() loop"); -- cgit v1.2.3