aboutsummaryrefslogtreecommitdiffstats
path: root/erts/epmd/src/epmd_srv.c
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2014-03-27 10:23:28 +0100
committerLukas Larsson <[email protected]>2014-03-27 10:23:28 +0100
commitbe5ad8be918b803d4224e8d6b17a508d2559b8a1 (patch)
treeb2ff548843c6abc9b2ada2cc0fdc4ef5f0ce4525 /erts/epmd/src/epmd_srv.c
parent70d60cb4d825464149ca48fdeeb350ac4689cc00 (diff)
parentb7c95eabf6017ddb352fb8ce2b3749af108ebf29 (diff)
downloadotp-be5ad8be918b803d4224e8d6b17a508d2559b8a1.tar.gz
otp-be5ad8be918b803d4224e8d6b17a508d2559b8a1.tar.bz2
otp-be5ad8be918b803d4224e8d6b17a508d2559b8a1.zip
Merge branch 'matwey/systemd/OTP-11829'
* matwey/systemd/OTP-11829: Add systemd socket activation for epmd. Conflicts: erts/epmd/src/epmd_int.h Extra ticket: OTP-11828
Diffstat (limited to 'erts/epmd/src/epmd_srv.c')
-rw-r--r--erts/epmd/src/epmd_srv.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/erts/epmd/src/epmd_srv.c b/erts/epmd/src/epmd_srv.c
index 247fd34d5a..93982c2f60 100644
--- a/erts/epmd/src/epmd_srv.c
+++ b/erts/epmd/src/epmd_srv.c
@@ -213,6 +213,39 @@ void run(EpmdVars *g)
node_init(g);
g->conn = conn_init(g);
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
+ if (g->is_systemd)
+ {
+ int n;
+
+ dbg_printf(g,2,"try to obtain sockets from systemd");
+
+ n = sd_listen_fds(0);
+ if (n < 0)
+ {
+ dbg_perror(g,"cannot obtain sockets from systemd");
+ epmd_cleanup_exit(g,1);
+ }
+ else if (n == 0)
+ {
+ dbg_tty_printf(g,0,"systemd provides no sockets");
+ epmd_cleanup_exit(g,1);
+ }
+ else if (n > MAX_LISTEN_SOCKETS)
+ {
+ dbg_tty_printf(g,0,"cannot listen on more than %d IP addresses", MAX_LISTEN_SOCKETS);
+ epmd_cleanup_exit(g,1);
+ }
+ num_sockets = n;
+ for (i = 0; i < num_sockets; i++)
+ {
+ g->listenfd[i] = listensock[i] = SD_LISTEN_FDS_START + i;
+ }
+ }
+ else
+ {
+#endif
+
dbg_printf(g,2,"try to initiate listening port %d", g->port);
if (g->addresses != NULL && /* String contains non-separator characters if: */
@@ -277,6 +310,9 @@ void run(EpmdVars *g)
SET_ADDR(iserv_addr[0],EPMD_ADDR_ANY,sport);
num_sockets = 1;
}
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
+ }
+#endif
#if !defined(__WIN32__) && !defined(__OSE__)
/* We ignore the SIGPIPE signal that is raised when we call write
@@ -294,6 +330,13 @@ void run(EpmdVars *g)
FD_ZERO(&g->orig_read_mask);
g->select_fd_top = 0;
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
+ if (g->is_systemd)
+ for (i = 0; i < num_sockets; i++)
+ select_fd_set(g, listensock[i]);
+ else
+ {
+#endif
for (i = 0; i < num_sockets; i++)
{
if ((listensock[i] = socket(FAMILY,SOCK_STREAM,0)) < 0)
@@ -356,6 +399,9 @@ void run(EpmdVars *g)
}
select_fd_set(g, listensock[i]);
}
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
+ }
+#endif
dbg_tty_printf(g,2,"entering the main select() loop");