]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
send PID of the main daemon to supervisor
authorTomasz Torcz <tomek@pipebreaker.pl>
Fri, 9 Jan 2015 21:17:50 +0000 (22:17 +0100)
committerNick Mathewson <nickm@torproject.org>
Sun, 11 Jan 2015 16:14:08 +0000 (11:14 -0500)
  If running under systemd, notify the supervisor about current PID
of Tor daemon.  This makes systemd unit simpler and more robust:
it will do the right thing regardless of RunAsDaemon settings.

contrib/dist/tor.service.in
src/or/config.c

index 57409a7b0abb464a2b0d51eb144e2887f81937b4..607615afa2cf884dfc32306c7310542c6b201cd3 100644 (file)
@@ -3,11 +3,10 @@ Description = Anonymizing overlay network for TCP
 After = syslog.target network.target nss-lookup.target
 
 [Service]
-Type = simple
+Type = notify
+NotifyAccess = all
 ExecStartPre = @BINDIR@/tor -f @CONFDIR@/torrc --verify-config
-# A torrc that has "RunAsDaemon 1" won't work with the "simple" service type;
-# let's explicitly override it.
-ExecStart = @BINDIR@/tor -f @CONFDIR@/torrc --RunAsDaemon 0
+ExecStart = @BINDIR@/tor -f @CONFDIR@/torrc 
 ExecReload = /bin/kill -HUP ${MAINPID}
 KillSignal = SIGINT
 TimeoutSec = 30
index a1347b9d7d3d058a82fb802bb0976776cf17851c..781f15a42dfd0db196c6c2afa49574089747c5e5 100644 (file)
 
 #include "procmon.h"
 
+#ifdef HAVE_SYSTEMD
+#   if defined(__COVERITY__) && !defined(__INCLUDE_LEVEL__)
+/* Systemd's use of gcc's __INCLUDE_LEVEL__ extension macro appears to confuse
+ * Coverity. Here's a kludge to unconfuse it.
+ */
+#   define __INCLUDE_LEVEL__ 2
+#   endif
+#include <systemd/sd-daemon.h>
+#endif
+
 /* From main.c */
 extern int quiet_level;
 
@@ -1018,6 +1028,11 @@ options_act_reversible(const or_options_t *old_options, char **msg)
     start_daemon();
   }
 
+#ifdef HAVE_SYSTEMD
+  /* Our PID may have changed, inform supervisor */
+  sd_notifyf(0, "MAINPID=%ld\n", (long int)getpid());
+#endif
+
 #ifndef HAVE_SYS_UN_H
   if (options->ControlSocket || options->ControlSocketsGroupWritable) {
     *msg = tor_strdup("Unix domain sockets (ControlSocket) not supported "