[Git][NTPsec/ntpsec][master] 4 commits: Fix shadow warning for time

Hal Murray gitlab at mg.gitlab.com
Tue Apr 11 00:45:17 UTC 2017


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
16bda5a4 by Hal Murray at 2017-04-10T15:27:27-07:00
Fix shadow warning for time

- - - - -
458bcaa0 by Hal Murray at 2017-04-10T15:44:14-07:00
Remove unused num_mcast from __endpt

- - - - -
6b6a5697 by Hal Murray at 2017-04-10T15:45:21-07:00
Name changes to fix shadow warnings.

- - - - -
9d9ccb51 by Hal Murray at 2017-04-10T16:48:03-07:00
Move close_all_beyond/except to ntpd/ntpd.c

- - - - -


10 changed files:

- include/ntp.h
- include/ntp_worker.h
- libntp/ntp_worker.c
- libntp/systime.c
- ntpd/ntp_control.c
- ntpd/ntp_io.c
- ntpd/ntp_util.c
- ntpd/ntpd.c
- tests/libntp/humandate.c
- tests/libntp/prettydate.c


Changes:

=====================================
include/ntp.h
=====================================
--- a/include/ntp.h
+++ b/include/ntp.h
@@ -152,7 +152,6 @@ typedef struct __endpt {
 	uint32_t	flags;		/* interface flags */
 	int		last_ttl;	/* last TTL specified */
 	uint32_t	addr_refid;	/* IPv4 addr or IPv6 hash */
-	int		num_mcast;	/* mcast addrs enabled */
 	u_long		starttime;	/* current_time at creation */
 	volatile long	received;	/* number of incoming packets */
 	long		sent;		/* number of outgoing packets */


=====================================
include/ntp_worker.h
=====================================
--- a/include/ntp_worker.h
+++ b/include/ntp_worker.h
@@ -127,8 +127,6 @@ extern	void	worker_idle_timer_fired(void);
 extern	void	interrupt_worker_sleep(void);
 extern	int	req_child_exit(blocking_child *);
 extern	int	pipe_socketpair(int fds[2], bool *is_pipe);
-extern	void	close_all_beyond(int);
-extern	void	close_all_except(int);
 extern	void	kill_asyncio	(int);
 
 # ifdef USE_WORK_PIPE


=====================================
libntp/ntp_worker.c
=====================================
--- a/libntp/ntp_worker.c
+++ b/libntp/ntp_worker.c
@@ -64,59 +64,6 @@ pipe_socketpair(
 }
 
 
-/*
- * close_all_except()
- *
- * Close all file descriptors except the given keep_fd.
- */
-void
-close_all_except(
-	int keep_fd
-	)
-{
-	int fd;
-
-	for (fd = 0; fd < keep_fd; fd++)
-		close(fd);
-
-	close_all_beyond(keep_fd);
-}
-
-
-/*
- * close_all_beyond()
- *
- * Close all file descriptors after the given keep_fd, which is the
- * highest fd to keep open.  See
- *
- * http://stackoverflow.com/questions/899038/getting-the-highest-allocated-file-descriptor
- */
-void
-close_all_beyond(
-	int keep_fd
-	)
-{
-# ifdef HAVE_CLOSEFROM
-	closefrom(keep_fd + 1);
-# elif defined(F_CLOSEM)
-	/*
-	 * From 'Writing Reliable AIX Daemons,' SG24-4946-00,
-	 * by Eric Agar (saves us from doing 32767 system
-	 * calls)
-	 */
-	if (fcntl(keep_fd + 1, F_CLOSEM, 0) == -1)
-		msyslog(LOG_ERR, "F_CLOSEM(%d): %m", keep_fd + 1);
-# else	/* !HAVE_CLOSEFROM && !F_CLOSEM follows */
-	int fd;
-	int max_fd;
-
-	/* includes POSIX case */
-	max_fd = sysconf(_SC_OPEN_MAX);
-	for (fd = keep_fd + 1; fd < max_fd; fd++)
-		close(fd);
-# endif	/* !HAVE_CLOSEFROM && !F_CLOSEM */
-}
-
 u_int
 available_blocking_child_slot(void)
 {


=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -116,7 +116,7 @@ static	void	normalize_time	(struct timespec, long, l_fp *);
 static void
 normalize_time(
 	struct timespec ts,		/* seconds and nanoseconds */
-	long rand,
+	long randd,
 	l_fp *now		/* system time */
 	)
 {
@@ -173,7 +173,7 @@ normalize_time(
 	/*
 	 * Add in the fuzz.
 	 */
-	dfuzz = rand * 2. / FRAC * sys_fuzz;
+	dfuzz = randd * 2. / FRAC * sys_fuzz;
 	lfpfuzz = dtolfp(dfuzz);
 	result += lfpfuzz;
 


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -3635,7 +3635,6 @@ send_ifstats_entry(
 	const char name_fmt[] =		"name.%u";
 	const char flags_fmt[] =	"flags.%u";
 	const char tl_fmt[] =		"tl.%u";	/* ttl */
-	const char mc_fmt[] =		"mc.%u";	/* mcast count */
 	const char rx_fmt[] =		"rx.%u";
 	const char tx_fmt[] =		"tx.%u";
 	const char txerr_fmt[] =	"txerr.%u";
@@ -3705,31 +3704,26 @@ send_ifstats_entry(
 			break;
 
 		case 6:
-			snprintf(tag, sizeof(tag), mc_fmt, ifnum);
-			ctl_putint(tag, la->num_mcast);
-			break;
-
-		case 7:
 			snprintf(tag, sizeof(tag), rx_fmt, ifnum);
 			ctl_putint(tag, la->received);
 			break;
 
-		case 8:
+		case 7:
 			snprintf(tag, sizeof(tag), tx_fmt, ifnum);
 			ctl_putint(tag, la->sent);
 			break;
 
-		case 9:
+		case 8:
 			snprintf(tag, sizeof(tag), txerr_fmt, ifnum);
 			ctl_putint(tag, la->notsent);
 			break;
 
-		case 10:
+		case 9:
 			snprintf(tag, sizeof(tag), pc_fmt, ifnum);
 			ctl_putuint(tag, la->peercnt);
 			break;
 
-		case 11:
+		case 10:
 			snprintf(tag, sizeof(tag), up_fmt, ifnum);
 			ctl_putuint(tag, current_time - la->starttime);
 			break;


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -439,7 +439,6 @@ interface_dump(const endpt *itf)
 	printf("flags = 0x%08x\n", itf->flags);
 	printf("last_ttl = %d\n", itf->last_ttl);
 	printf("addr_refid = %08x\n", itf->addr_refid);
-	printf("num_mcast = %d\n", itf->num_mcast);
 	printf("received = %ld\n", itf->received);
 	printf("sent = %ld\n", itf->sent);
 	printf("notsent = %ld\n", itf->notsent);


=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -150,24 +150,24 @@ init_util(void)
 static void drift_write(char *driftfile, double drift)
 {
 	int fd;
-	char tmpfile[PATH_MAX], driftcopy[PATH_MAX];
+	char tempfile[PATH_MAX], driftcopy[PATH_MAX];
 	char driftval[32];
 	strlcpy(driftcopy, driftfile, PATH_MAX);
-	strlcpy(tmpfile, dirname(driftcopy), sizeof(tmpfile));
-	strlcat(tmpfile, "/driftXXXXXX", sizeof(tmpfile));
+	strlcpy(tempfile, dirname(driftcopy), sizeof(tempfile));
+	strlcat(tempfile, "/driftXXXXXX", sizeof(tempfile));
 	/* coverity[secure_temp] Warning is bogus on POSIX-compliant systems */
-	if ((fd = mkstemp(tmpfile)) < 0) {
-	    msyslog(LOG_ERR, "frequency file %s: %m", tmpfile);
+	if ((fd = mkstemp(tempfile)) < 0) {
+	    msyslog(LOG_ERR, "frequency file %s: %m", tempfile);
 	    return;
 	}
 	snprintf(driftval, sizeof(driftval), "%.6f\n", drift);
 	IGNORE(write(fd, driftval, strlen(driftval)));
 	(void)close(fd);
 	/* atomic */
-	if (rename(tmpfile, driftfile))
+	if (rename(tempfile, driftfile))
 	    msyslog(LOG_WARNING,
 		    "Unable to rename temp drift file %s to %s, %m",
-		    tmpfile, driftfile);
+		    tempfile, driftfile);
 }
 void
 write_stats(void)
@@ -351,16 +351,16 @@ stats_config(
  */
 
 static char *
-timespec_to_MJDtime(const struct timespec *time)
+timespec_to_MJDtime(const struct timespec *ts)
 {
 	char *buf;
 	u_long	day, sec, msec;
 
 	LIB_GETBUF(buf);
 
-	day = (u_long)time->tv_sec / S_PER_DAY + MJD_1970;
-	sec = (u_long)time->tv_sec % S_PER_DAY;
-	msec = (u_long)time->tv_nsec / NS_PER_MS;  /* nano secs to milli sec */
+	day = (u_long)ts->tv_sec / S_PER_DAY + MJD_1970;
+	sec = (u_long)ts->tv_sec % S_PER_DAY;
+	msec = (u_long)ts->tv_nsec / NS_PER_MS;  /* nano secs to milli sec */
 	snprintf(buf, LIB_BUFLENGTH, "%lu %lu.%03lu", day, sec, msec);
 
 	return buf;


=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -122,6 +122,10 @@ static void	library_unexpected_error(const char *, int,
 					 const char *, va_list)
 					ISC_FORMAT_PRINTF(3, 0);
 
+extern  void    close_all_beyond(int);
+extern  void    close_all_except(int);
+
+
 #define ALL_OPTIONS "46c:dD:f:gGhi:I:k:l:LmnNp:PqRs:t:u:U:Vw:xzZ"
 static const struct option longoptions[] = {
     { "ipv4",		    0, 0, '4' },
@@ -1259,3 +1263,57 @@ no_debug(
 	errno = saved_errno;
 }
 # endif	/* !DEBUG */
+
+/*
+ * close_all_except()
+ *
+ * Close all file descriptors except the given keep_fd.
+ */
+void
+close_all_except(
+	int keep_fd
+	)
+{
+	int fd;
+
+	for (fd = 0; fd < keep_fd; fd++)
+		close(fd);
+
+	close_all_beyond(keep_fd);
+}
+
+
+/*
+ * close_all_beyond()
+ *
+ * Close all file descriptors after the given keep_fd, which is the
+ * highest fd to keep open.  See
+ *
+ * http://stackoverflow.com/questions/899038/getting-the-highest-allocated-file-descriptor
+ */
+void
+close_all_beyond(
+	int keep_fd
+	)
+{
+# ifdef HAVE_CLOSEFROM
+	closefrom(keep_fd + 1);
+# elif defined(F_CLOSEM)
+	/*
+	 * From 'Writing Reliable AIX Daemons,' SG24-4946-00,
+	 * by Eric Agar (saves us from doing 32767 system
+	 * calls)
+	 */
+	if (fcntl(keep_fd + 1, F_CLOSEM, 0) == -1)
+		msyslog(LOG_ERR, "F_CLOSEM(%d): %m", keep_fd + 1);
+# else  /* !HAVE_CLOSEFROM && !F_CLOSEM follows */
+	int fd;
+	int max_fd;
+
+	/* includes POSIX case */
+	max_fd = sysconf(_SC_OPEN_MAX);
+	for (fd = keep_fd + 1; fd < max_fd; fd++)
+		close(fd);
+# endif /* !HAVE_CLOSEFROM && !F_CLOSEM */
+}
+


=====================================
tests/libntp/humandate.c
=====================================
--- a/tests/libntp/humandate.c
+++ b/tests/libntp/humandate.c
@@ -18,11 +18,11 @@ TEST(humandate, RegularTime) {
 
 	struct tm tmbuf;
 
-	struct tm* time;
-	time = localtime_r(&sample, &tmbuf);
-	TEST_ASSERT_TRUE(time != NULL);
+	struct tm* tm;
+	tm = localtime_r(&sample, &tmbuf);
+	TEST_ASSERT_TRUE(tm != NULL);
 
-	snprintf(expected, 255, "%02d:%02d:%02d", time->tm_hour, time->tm_min, time->tm_sec);
+	snprintf(expected, 255, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
 
 	TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
 }
@@ -35,11 +35,11 @@ TEST(humandate, CurrentTime) {
 
 	time(&sample);
 
-	struct tm* time;
-	time = localtime_r(&sample, &tmbuf);
-	TEST_ASSERT_TRUE(time != NULL);
+	struct tm* tm;
+	tm = localtime_r(&sample, &tmbuf);
+	TEST_ASSERT_TRUE(tm != NULL);
 
-	snprintf(expected, 255, "%02d:%02d:%02d", time->tm_hour, time->tm_min, time->tm_sec);
+	snprintf(expected, 255, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
 
 	TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
 }


=====================================
tests/libntp/prettydate.c
=====================================
--- a/tests/libntp/prettydate.c
+++ b/tests/libntp/prettydate.c
@@ -16,9 +16,9 @@ TEST_TEAR_DOWN(prettydate) {}
 static const uint32_t HALF = 2147483648UL;
 
 TEST(prettydate, ConstantDate) {
-    l_fp time = lfpinit(3485080800L, HALF); // 2010-06-09 14:00:00.5
+    l_fp t = lfpinit(3485080800L, HALF); // 2010-06-09 14:00:00.5
 
-	TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(time));
+	TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(t));
 }
 
 TEST_GROUP_RUNNER(prettydate) {



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/2f3e38ba6af6103062092a5f6a2e47bcf67c4c97...9d9ccb515e7a6826f659e80d215f19dbb4bdb192
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170411/636dd9e3/attachment.html>


More information about the vc mailing list