logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

erlang-add-epmd-pid-file-creation-for-openrc.patch (2359B)


  1. From 04ace92c33a699f75445dc99c30d521311aba826 Mon Sep 17 00:00:00 2001
  2. From: Steve Arnold <nerdboy@gentoo.org>
  3. Date: Mon, 6 Aug 2018 16:38:30 -0700
  4. Subject: [PATCH] Add daemon-mode pid file creation when not configured for
  5. systemd
  6. Signed-off-by: Steve Arnold <nerdboy@gentoo.org>
  7. ---
  8. erts/epmd/src/epmd.c | 39 ++++++++++++++++++++++++++++++++++++++-
  9. erts/epmd/src/epmd.h | 3 +++
  10. 2 files changed, 41 insertions(+), 1 deletion(-)
  11. diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c
  12. index 44e997e609..c74888a1ee 100644
  13. --- a/erts/epmd/src/epmd.c
  14. +++ b/erts/epmd/src/epmd.c
  15. @@ -40,6 +40,37 @@ static int check_relaxed(void);
  16. #ifdef __WIN32__
  17. static int has_console(void);
  18. #endif
  19. +#ifndef HAVE_SYSTEMD_DAEMON
  20. +static int create_pidfile(void);
  21. +static const char *pidfile = EPMD_PIDFILE;
  22. +#endif
  23. +
  24. +#ifndef HAVE_SYSTEMD_DAEMON
  25. +static int create_pidfile(void)
  26. +{
  27. + int fd;
  28. +
  29. + unlink(pidfile);
  30. +
  31. + /* open the pidfile */
  32. + fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644);
  33. + if (fd >= 0) {
  34. + FILE *f;
  35. +
  36. + /* write our pid to it */
  37. + f = fdopen(fd, "w");
  38. + if (f != NULL) {
  39. + fprintf(f, "%d\n", getpid());
  40. + fclose(f);
  41. + /* leave the fd open */
  42. + return 0;
  43. + }
  44. + close(fd);
  45. + }
  46. +
  47. + return -1;
  48. +}
  49. +#endif /* (no) HAVE_SYSTEMD_DAEMON */
  50. #ifdef DONT_USE_MAIN
  51. @@ -340,6 +371,13 @@ static void run_daemon(EpmdVars *g)
  52. umask(0);
  53. +#ifndef HAVE_SYSTEMD_DAEMON
  54. + if (create_pidfile() < 0) {
  55. + dbg_perror(g,"could not create pidfile %s", pidfile);
  56. + epmd_cleanup_exit(g,1);
  57. + }
  58. +#endif /* HAVE_SYSTEMD_DAEMON */
  59. +
  60. for (fd = 0; fd < g->max_conn ; fd++) /* close all files ... */
  61. close(fd);
  62. /* Syslog on linux will try to write to whatever if we dont
  63. @@ -614,4 +652,3 @@ static int check_relaxed(void)
  64. char* port_str = getenv("ERL_EPMD_RELAXED_COMMAND_CHECK");
  65. return (port_str != NULL) ? 1 : 0;
  66. }
  67. -
  68. diff --git a/erts/epmd/src/epmd.h b/erts/epmd/src/epmd.h
  69. index cffcd4ae7a..e53322acf5 100644
  70. --- a/erts/epmd/src/epmd.h
  71. +++ b/erts/epmd/src/epmd.h
  72. @@ -20,6 +20,9 @@
  73. /* The port number is defined in a makefile */
  74. +/* The name and path to the pid file */
  75. +#define EPMD_PIDFILE "/var/run/epmd.pid"
  76. +
  77. /* Definitions of message codes */
  78. /* Registration and queries */
  79. --
  80. 2.17.0