]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: replace empty strings with NULL
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 20 May 2020 14:20:43 +0000 (16:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 21 May 2020 10:42:18 +0000 (12:42 +0200)
Avoid mixing empty strings with NULLs in configuration strings to make
the handling of default or disabled values consistent.

cmdmon.c
conf.c
logging.c
main.c
sources.c

index f3f6f29877e006e3db90f105371c05d988ec96ba..5dac63683215f2ade096c85f0a648553ee62556f 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -291,7 +291,7 @@ CAM_OpenUnixSocket(void)
 {
   /* This is separated from CAM_Initialise() as it needs to be called when
      the process has already dropped the root privileges */
-  if (CNF_GetBindCommandPath()[0])
+  if (CNF_GetBindCommandPath())
     sock_fdu = open_socket(IPADDR_UNSPEC);
 }
 
diff --git a/conf.c b/conf.c
index d931ef9e6d0dd313f4bd3a0ead8bc3757f710996..d41f85f5173527ae59b13c091897fb3bd798e609 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -114,8 +114,8 @@ static int do_log_rtc = 0;
 static int do_log_refclocks = 0;
 static int do_log_tempcomp = 0;
 static int log_banner = 32;
-static char *logdir;
-static char *dumpdir;
+static char *logdir = NULL;
+static char *dumpdir = NULL;
 
 static int enable_local=0;
 static int local_stratum;
@@ -190,14 +190,14 @@ static IPAddr bind_acq_address4, bind_acq_address6;
 static IPAddr bind_cmd_address4, bind_cmd_address6;
 
 /* Path to the Unix domain command socket. */
-static char *bind_cmd_path;
+static char *bind_cmd_path = NULL;
 
 /* Path to Samba (ntp_signd) socket. */
 static char *ntp_signd_socket = NULL;
 
 /* Filename to use for storing pid of running chronyd, to prevent multiple
  * chronyds being started. */
-static char *pidfile;
+static char *pidfile = NULL;
 
 /* Rate limiting parameters */
 static int ntp_ratelimit_enabled = 0;
@@ -370,16 +370,12 @@ CNF_Initialise(int r, int client_only)
   ntp_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
   cmd_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
 
-  dumpdir = Strdup("");
-  logdir = Strdup("");
   rtc_device = Strdup(DEFAULT_RTC_DEVICE);
   hwclock_file = Strdup(DEFAULT_HWCLOCK_FILE);
   user = Strdup(DEFAULT_USER);
 
   if (client_only) {
     cmd_port = ntp_port = 0;
-    bind_cmd_path = Strdup("");
-    pidfile = Strdup("");
   } else {
     bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
     pidfile = Strdup(DEFAULT_PID_FILE);
@@ -1233,8 +1229,10 @@ parse_bindcmdaddress(char *line)
   if (line[0] == '/') {
     parse_string(line, &bind_cmd_path);
     /* / disables the socket */
-    if (!strcmp(bind_cmd_path, "/"))
-        bind_cmd_path[0] = '\0';
+    if (strcmp(bind_cmd_path, "/") == 0) {
+      Free(bind_cmd_path);
+      bind_cmd_path = NULL;
+    }
   } else if (UTI_StringToIP(line, &ip)) {
     if (ip.family == IPADDR_INET4)
       bind_cmd_address4 = ip;
@@ -1537,7 +1535,7 @@ CNF_CreateDirs(uid_t uid, gid_t gid)
   char *dir;
 
   /* Create a directory for the Unix domain command socket */
-  if (bind_cmd_path[0]) {
+  if (bind_cmd_path) {
     dir = UTI_PathToDir(bind_cmd_path);
     UTI_CreateDirAndParents(dir, 0770, uid, gid);
 
@@ -1546,15 +1544,16 @@ CNF_CreateDirs(uid_t uid, gid_t gid)
        domain sockets are ignored on some systems (e.g. Solaris). */
     if (!UTI_CheckDirPermissions(dir, 0770, uid, gid)) {
       LOG(LOGS_WARN, "Disabled command socket %s", bind_cmd_path);
-      bind_cmd_path[0] = '\0';
+      Free(bind_cmd_path);
+      bind_cmd_path = NULL;
     }
 
     Free(dir);
   }
 
-  if (logdir[0])
+  if (logdir)
     UTI_CreateDirAndParents(logdir, 0755, uid, gid);
-  if (dumpdir[0])
+  if (dumpdir)
     UTI_CreateDirAndParents(dumpdir, 0755, uid, gid);
 }
 
index 9bcc0c5f7c8987ea49aab8db81939a8bb2c11f0d..d5440a183af9b01f0c39fa9a44731f52c051ebd6 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -267,7 +267,7 @@ LOG_FileWrite(LOG_FileID id, const char *format, ...)
   if (!logfiles[id].file) {
     char *logdir = CNF_GetLogDir();
 
-    if (logdir[0] == '\0') {
+    if (!logdir) {
       LOG(LOGS_WARN, "logdir not specified");
       logfiles[id].name = NULL;
       return;
diff --git a/main.c b/main.c
index 99f06c0f94612cc90791e0914a4eeef21df27ed8..5701d410cfe876fe9f717c976552b0cdafca1210 100644 (file)
--- a/main.c
+++ b/main.c
@@ -91,7 +91,7 @@ delete_pidfile(void)
 {
   const char *pidfile = CNF_GetPidFile();
 
-  if (!pidfile[0])
+  if (!pidfile)
     return;
 
   if (!UTI_RemoveFile(NULL, pidfile, NULL))
@@ -105,9 +105,7 @@ MAI_CleanupAndExit(void)
 {
   if (!initialised) exit(exit_status);
   
-  if (CNF_GetDumpDir()[0] != '\0') {
-    SRC_DumpSources();
-  }
+  SRC_DumpSources();
 
   /* Don't update clock when removing sources */
   REF_SetMode(REF_ModeIgnore);
@@ -261,7 +259,7 @@ check_pidfile(void)
   FILE *in;
   int pid, count;
   
-  if (!pidfile[0])
+  if (!pidfile)
     return;
 
   in = UTI_OpenFile(NULL, pidfile, NULL, 'r', 0);
@@ -289,7 +287,7 @@ write_pidfile(void)
   const char *pidfile = CNF_GetPidFile();
   FILE *out;
 
-  if (!pidfile[0])
+  if (!pidfile)
     return;
 
   out = UTI_OpenFile(NULL, pidfile, NULL, 'W', 0644);
index bd16ea4f24d0ddef4e28e67a13e116089b6bac62..ad2b225c27d506781ba891a0d93418cf9967b606 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -1284,9 +1284,8 @@ FILE *open_dumpfile(SRC_Instance inst, char mode)
   char filename[64], *dumpdir;
 
   dumpdir = CNF_GetDumpDir();
-  if (dumpdir[0] == '\0') {
+  if (!dumpdir)
     return NULL;
-  }
 
   /* Include IP address in the name for NTP sources, or reference ID in hex */
   if (inst->type == SRC_NTP && UTI_IsIPReal(inst->ip_addr))
@@ -1350,7 +1349,7 @@ SRC_RemoveDumpFiles(void)
   size_t i;
 
   dumpdir = CNF_GetDumpDir();
-  if (dumpdir[0] == '\0' ||
+  if (!dumpdir ||
       snprintf(pattern, sizeof (pattern), "%s/*.dat", dumpdir) >= sizeof (pattern))
     return;