summaryrefslogtreecommitdiff
path: root/dev-lang/erlang/files/erlang-add-epmd-pid-file-creation-for-openrc.patch
blob: 56e3946c93fa185f1d1ebdae8d983f89a04919ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From 04ace92c33a699f75445dc99c30d521311aba826 Mon Sep 17 00:00:00 2001
From: Steve Arnold <nerdboy@gentoo.org>
Date: Mon, 6 Aug 2018 16:38:30 -0700
Subject: [PATCH] Add daemon-mode pid file creation when not configured for
 systemd

Signed-off-by: Steve Arnold <nerdboy@gentoo.org>
---
 erts/epmd/src/epmd.c | 39 ++++++++++++++++++++++++++++++++++++++-
 erts/epmd/src/epmd.h |  3 +++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c
index 44e997e609..c74888a1ee 100644
--- a/erts/epmd/src/epmd.c
+++ b/erts/epmd/src/epmd.c
@@ -40,6 +40,37 @@ static int check_relaxed(void);
 #ifdef __WIN32__
 static int has_console(void);
 #endif
+#ifndef HAVE_SYSTEMD_DAEMON
+static int create_pidfile(void);
+static const char *pidfile = EPMD_PIDFILE;
+#endif
+
+#ifndef HAVE_SYSTEMD_DAEMON
+static int create_pidfile(void)
+{
+    int fd;
+
+    unlink(pidfile);
+
+    /* open the pidfile */
+    fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644);
+    if (fd >= 0) {
+        FILE *f;
+
+        /* write our pid to it */
+        f = fdopen(fd, "w");
+        if (f != NULL) {
+            fprintf(f, "%d\n", getpid());
+            fclose(f);
+            /* leave the fd open */
+            return 0;
+        }
+        close(fd);
+    }
+
+    return -1;
+}
+#endif    /* (no) HAVE_SYSTEMD_DAEMON */
 
 #ifdef DONT_USE_MAIN
 
@@ -340,6 +371,13 @@ static void run_daemon(EpmdVars *g)
     
     umask(0);
 
+#ifndef HAVE_SYSTEMD_DAEMON
+    if (create_pidfile() < 0) {
+        dbg_perror(g,"could not create pidfile %s", pidfile);
+        epmd_cleanup_exit(g,1);
+    }
+#endif /* HAVE_SYSTEMD_DAEMON */
+
     for (fd = 0; fd < g->max_conn ; fd++) /* close all files ... */
         close(fd);
     /* Syslog on linux will try to write to whatever if we dont
@@ -614,4 +652,3 @@ static int check_relaxed(void)
     char* port_str = getenv("ERL_EPMD_RELAXED_COMMAND_CHECK");
     return (port_str != NULL) ? 1 : 0;
 }
-
diff --git a/erts/epmd/src/epmd.h b/erts/epmd/src/epmd.h
index cffcd4ae7a..e53322acf5 100644
--- a/erts/epmd/src/epmd.h
+++ b/erts/epmd/src/epmd.h
@@ -20,6 +20,9 @@
 
 /* The port number is defined in a makefile */
 
+/* The name and path to the pid file */
+#define EPMD_PIDFILE "/var/run/epmd.pid"
+
 /* Definitions of message codes */
 
 /* Registration and queries */
-- 
2.17.0