[Git][NTPsec/ntpsec][master] TESTFRAME: Refactoring step, move some complexity out of intercept.c.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Sep 29 13:07:09 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
6c5655cd by Eric S. Raymond at 2016-09-29T09:02:48-04:00
TESTFRAME: Refactoring step, move some complexity out of intercept.c.
- - - - -
2 changed files:
- ntpd/ntp_intercept.c
- ntpd/ntp_util.c
Changes:
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -83,7 +83,6 @@ no mismatches.
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <libgen.h>
#include <sys/socket.h>
#include <netdb.h>
#include <inttypes.h>
@@ -432,6 +431,8 @@ bool intercept_drift_read(const char *drift_file, double *drift)
return true;
}
+extern void drift_write(char *driftfile, double drift);
+
void intercept_drift_write(char *driftfile, double drift)
{
if (mode == replay) {
@@ -448,26 +449,7 @@ void intercept_drift_write(char *driftfile, double drift)
if (df != drift)
replay_fail("expected drift %f but saw %f\n", drift, df);
} else {
- int fd;
- char tmpfile[PATH_MAX], driftcopy[PATH_MAX];
- char driftval[32];
-
- strlcpy(driftcopy, driftfile, PATH_MAX);
- strlcpy(tmpfile, dirname(driftcopy), sizeof(tmpfile));
- strlcat(tmpfile, "/driftXXXXXX", sizeof(tmpfile));
- /* coverity[secure_temp] Warning is bogus on POSIX-compliant systems*/
- if ((fd = mkstemp(tmpfile)) < 0) {
- msyslog(LOG_ERR, "frequency file %s: %m", tmpfile);
- return;
- }
- snprintf(driftval, sizeof(driftval), "%.3f\n", drift);
- IGNORE(write(fd, driftval, strlen(driftval)));
- (void)close(fd);
- /* atomic */
- if (rename(tmpfile, driftfile))
- msyslog(LOG_WARNING,
- "Unable to rename temp drift file %s to %s, %m",
- tmpfile, driftfile);
+ drift_write(driftfile, drift);
if (mode == capture)
printf("drift-write %.3f\n", drift);
=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -14,6 +14,7 @@
#include "lib_strbuf.h"
#include <stdio.h>
+#include <libgen.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
@@ -152,6 +153,30 @@ init_util(void)
/*
* hourly_stats - print some interesting stats
*/
+#define IGNORE(r) do{if(r){}}while(0)
+
+void drift_write(char *driftfile, double drift)
+{
+ int fd;
+ char tmpfile[PATH_MAX], driftcopy[PATH_MAX];
+ char driftval[32];
+ strlcpy(driftcopy, driftfile, PATH_MAX);
+ strlcpy(tmpfile, dirname(driftcopy), sizeof(tmpfile));
+ strlcat(tmpfile, "/driftXXXXXX", sizeof(tmpfile));
+ /* coverity[secure_temp] Warning is bogus on POSIX-compliant systems */
+ if ((fd = mkstemp(tmpfile)) < 0) {
+ msyslog(LOG_ERR, "frequency file %s: %m", tmpfile);
+ return;
+ }
+ snprintf(driftval, sizeof(driftval), "%.3f\n", drift);
+ IGNORE(write(fd, driftval, strlen(driftval)));
+ (void)close(fd);
+ /* atomic */
+ if (rename(tmpfile, driftfile))
+ msyslog(LOG_WARNING,
+ "Unable to rename temp drift file %s to %s, %m",
+ tmpfile, driftfile);
+}
void
write_stats(void)
{
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/6c5655cd3abf4aa7463c976bf6f054569350586e
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160929/a26f46f2/attachment.html>
More information about the vc
mailing list