Blame otp-0011-Add-systemd-option-to-empd.-Check-for-include-system.patch

f7eb6d
From: "Matwey V. Kornilov" <matwey.kornilov@gmail.com>
f7eb6d
Date: Tue, 17 Dec 2013 18:16:56 +0400
f7eb6d
Subject: [PATCH] Add -systemd option to empd. Check for include
f7eb6d
 systemd/sd-daemon.h and wrap systemd code into ifdef-s.
f7eb6d
f7eb6d
f7eb6d
diff --git a/erts/configure.in b/erts/configure.in
f7eb6d
index 9ad3671..125e579 100644
f7eb6d
--- a/erts/configure.in
f7eb6d
+++ b/erts/configure.in
f7eb6d
@@ -1565,6 +1565,8 @@ AC_CHECK_MEMBERS([struct ifreq.ifr_enaddr], [], [],
f7eb6d
 	 #endif
f7eb6d
 	])
f7eb6d
 
f7eb6d
+AC_CHECK_HEADERS(systemd/sd-daemon.h)
f7eb6d
+
f7eb6d
 dnl ----------------------------------------------------------------------
f7eb6d
 dnl Check the availability for libdlpi
f7eb6d
 dnl ----------------------------------------------------------------------
f7eb6d
diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c
f7eb6d
index 2d55b37..fc58882 100644
f7eb6d
--- a/erts/epmd/src/epmd.c
f7eb6d
+++ b/erts/epmd/src/epmd.c
f7eb6d
@@ -175,6 +175,9 @@ int main(int argc, char** argv)
f7eb6d
     g->nodes.reg = g->nodes.unreg = g->nodes.unreg_tail = NULL;
f7eb6d
     g->nodes.unreg_count = 0;
f7eb6d
     g->active_conn    = 0;
f7eb6d
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
f7eb6d
+    g->is_systemd     = 0;
f7eb6d
+#endif
f7eb6d
 
f7eb6d
     for (i = 0; i < MAX_LISTEN_SOCKETS; i++)
f7eb6d
 	g->listenfd[i] = -1;
f7eb6d
@@ -248,8 +251,12 @@ int main(int argc, char** argv)
f7eb6d
 	    else
f7eb6d
 		usage(g);
f7eb6d
 	    epmd_cleanup_exit(g,0);
f7eb6d
-	}
f7eb6d
-	else
f7eb6d
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
f7eb6d
+	} else if (strcmp(argv[0], "-systemd") == 0) {
f7eb6d
+            g->is_systemd = 1;
f7eb6d
+            argv++; argc--;
f7eb6d
+#endif
f7eb6d
+	} else
f7eb6d
 	    usage(g);
f7eb6d
     }
f7eb6d
     dbg_printf(g,1,"epmd running - daemon = %d",g->is_daemon);
f7eb6d
@@ -454,6 +461,11 @@ static void usage(EpmdVars *g)
f7eb6d
     fprintf(stderr, "        Forcibly unregisters a name with epmd\n");
f7eb6d
     fprintf(stderr, "        (only allowed if -relaxed_command_check was given when \n");
f7eb6d
     fprintf(stderr, "        epmd was started).\n");
f7eb6d
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
f7eb6d
+    fprintf(stderr, "    -systemd\n");
f7eb6d
+    fprintf(stderr, "        Wait for socket from systemd. The option makes sense\n");
f7eb6d
+    fprintf(stderr, "        when started from .socket unit.\n");
f7eb6d
+#endif
f7eb6d
     epmd_cleanup_exit(g,1);
f7eb6d
 }
f7eb6d
 
f7eb6d
diff --git a/erts/epmd/src/epmd_int.h b/erts/epmd/src/epmd_int.h
f7eb6d
index 656dbd1..bf1ddd8 100644
f7eb6d
--- a/erts/epmd/src/epmd_int.h
f7eb6d
+++ b/erts/epmd/src/epmd_int.h
f7eb6d
@@ -321,6 +321,9 @@ typedef struct {
f7eb6d
   int listenfd[MAX_LISTEN_SOCKETS];
f7eb6d
   char *addresses;
f7eb6d
   char **argv;
f7eb6d
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
f7eb6d
+  int is_systemd;
f7eb6d
+#endif
f7eb6d
 } EpmdVars;
f7eb6d
 
f7eb6d
 void dbg_printf(EpmdVars*,int,const char*,...);