]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
privops: refactor initialisation/finalisation
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 8 Dec 2015 13:10:29 +0000 (14:10 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 8 Dec 2015 17:02:05 +0000 (18:02 +0100)
Rename PRV_Initialise() to PRV_StartHelper() and add a new
initialisation function, which just sets the helper fd to -1. Move
the initialision/finalisation calls from the system drivers to main.c.
If privops is not included in the build, define empty macros for the
function names, so their calls don't have to be wrapped in #ifdefs.

main.c
privops.c
privops.h
sys_macosx.c

diff --git a/main.c b/main.c
index e2cf4705d9089acf8360d8261f1348b46cb4185f..c2c33f568cee04c2ff4269b3563be1880e32b9d9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -49,6 +49,7 @@
 #include "refclock.h"
 #include "clientlog.h"
 #include "nameserv.h"
+#include "privops.h"
 #include "smooth.h"
 #include "tempcomp.h"
 #include "util.h"
@@ -111,6 +112,7 @@ MAI_CleanupAndExit(void)
   NCR_Finalise();
   NIO_Finalise();
   CAM_Finalise();
+  PRV_Finalise();
   KEY_Finalise();
   RCL_Finalise();
   SRC_Finalise();
@@ -484,6 +486,7 @@ int main
   SRC_Initialise();
   RCL_Initialise();
   KEY_Initialise();
+  PRV_Initialise();
 
   /* Open privileged ports before dropping root */
   CAM_Initialise(address_family);
index e0967ab6a6e644bc7f148a0ceef6fbd91362510c..49fecbbeef2f75c24de6a66c40ebdc611a94b638 100644 (file)
--- a/privops.c
+++ b/privops.c
@@ -91,7 +91,7 @@ typedef struct {
   } u;
 } PrvResponse;
 
-static int helper_fd = -1;
+static int helper_fd;
 static pid_t helper_pid;
 
 static int
@@ -477,11 +477,19 @@ PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len)
 
 /* ======================================================================= */
 
+void
+PRV_Initialise(void)
+{
+  helper_fd = -1;
+}
+
+/* ======================================================================= */
+
 /* DAEMON - setup socket(s) then fork to run the helper */
 /* must be called before privileges are dropped */
 
 void
-PRV_Initialise(void)
+PRV_StartHelper(void)
 {
   pid_t pid;
   int fd, sock_pair[2];
index b3737e41df63a436f7f678a0eb91869e6a7c37ed..a513ee99f0a5e07a40aa2f6c7ef32420a0829a36 100644 (file)
--- a/privops.h
+++ b/privops.h
@@ -48,7 +48,12 @@ int PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len);
 
 #ifdef PRIVOPS_HELPER
 void PRV_Initialise(void);
+void PRV_StartHelper(void);
 void PRV_Finalise(void);
+#else
+#define PRV_Initialise()
+#define PRV_StartHelper()
+#define PRV_Finalise()
 #endif
 
 #endif
index 266d2ad8121eaf8e80a7a0b7a0e88cfe8f612ea7..c1592ddd864d947845b9360036d8a0510ceac6cb 100644 (file)
@@ -417,7 +417,7 @@ SYS_MacOSX_SetScheduler(int SchedPriority)
 #ifdef FEAT_PRIVDROP
 void SYS_MacOSX_DropRoot(uid_t uid, gid_t gid)
 {
-  PRV_Initialise();
+  PRV_StartHelper();
 
   if (setgroups(0, NULL))
     LOG_FATAL(LOGF_SysMacOSX, "setgroups() failed : %s", strerror(errno));
@@ -457,9 +457,6 @@ SYS_MacOSX_Finalise(void)
   SCH_RemoveTimeout(drift_removal_id);
 
   clock_finalise();
-#ifdef FEAT_PRIVDROP
-  PRV_Finalise();
-#endif
 }
 
 /* ================================================== */