[Git][NTPsec/ntpsec][master] Fix stats dir argument "-s PATH" & change default

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Wed Nov 12 08:40:53 UTC 2025



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
5bdffcbc by James Browning at 2025-11-12T00:37:15-08:00
Fix stats dir argument "-s PATH" & change default

- - - - -


3 changed files:

- ntpd/ntp_config.c
- ntpd/ntp_util.c
- ntpd/ntpd.c


Changes:

=====================================
ntpd/ntp_config.c
=====================================
@@ -1288,8 +1288,7 @@ config_monitor(
 	int filegen_flag;
 
 	/* Set the statistics directory */
-	if (ptree->stats_dir)
-		stats_config(STATS_STATSDIR, ptree->stats_dir);
+	stats_config(STATS_STATSDIR, ptree->stats_dir);
 
 	/* NOTE:
 	 * Calling filegen_get is brain dead. Doing a string


=====================================
ntpd/ntp_util.c
=====================================
@@ -296,6 +296,9 @@ stats_config(
 	 * Specify statistics directory.
 	 */
 	case STATS_STATSDIR:
+		if ((NULL == value) || ('\0' == *value)) {
+			break;
+		}
 
 		/* - 1 since value may be missing the DIR_SEP. */
 		if (strlen(value) >= sizeof(statsdir) - 1) {
@@ -303,23 +306,17 @@ stats_config(
 			    "LOG: statsdir too long (>%d, sigh)",
 			    (int)sizeof(statsdir) - 2);
 		} else {
-			bool add_dir_sep;
 			size_t value_l;
 
-			/* Add a DIR_SEP unless we already have one. */
 			value_l = strlen(value);
-			if (0 == value_l)
-				add_dir_sep = false;
-			else
-				add_dir_sep = (DIR_SEP !=
-				    value[value_l - 1]);
-
-			if (add_dir_sep)
-				snprintf(statsdir, sizeof(statsdir),
-				    "%s%c", value, DIR_SEP);
-			else
-				snprintf(statsdir, sizeof(statsdir),
-				    "%s", value);
+			strlcpy(statsdir, value, sizeof(statsdir) - 1);
+
+			/* Add a DIR_SEP unless we already have one. */
+			if (DIR_SEP != value[value_l - 1]) {
+				statsdir[value_l + 1] = '\0';
+				statsdir[value_l] = DIR_SEP;
+			}
+
 			filegen_statsdir();
 		}
 		break;


=====================================
ntpd/ntpd.c
=====================================
@@ -323,8 +323,7 @@ parse_cmdline_opts(
 		nofork = true;
 		break;
 	    case 's':
-		if (ntp_optarg != NULL)
-			strlcpy(statsdir, ntp_optarg, sizeof(statsdir));
+		/* defer */
 		break;
 	    case 't':
 		/* defer */
@@ -703,7 +702,7 @@ main(
                 /* handled elsewhere */
                 break;
 	    case 's':
-		stats_config(STATS_STATSDIR, statsdir);
+		stats_config(STATS_STATSDIR, ntp_optarg);
 		break;
 	    case 't':
 		if (ntp_optarg != NULL)
@@ -873,7 +872,7 @@ main(
 #endif
 
 	if (access(statsdir, W_OK) != 0) {
-	    msyslog(LOG_ERR, "statistics directory %s does not exist or is unwriteable, error %s", statsdir, strerror(errno));
+	    msyslog(LOG_ERR, "statistics directory '%s' does not exist or is unwriteable, error %s", statsdir, strerror(errno));
 	}
 
 	mainloop();



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/5bdffcbc093f890b4274d5987197a681bb902b27

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/5bdffcbc093f890b4274d5987197a681bb902b27
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20251112/546d9a36/attachment-0001.htm>


More information about the vc mailing list