summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/machines.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp/machines.c')
-rw-r--r--contrib/ntp/libntp/machines.c106
1 files changed, 56 insertions, 50 deletions
diff --git a/contrib/ntp/libntp/machines.c b/contrib/ntp/libntp/machines.c
index c8e4e07..43944f9 100644
--- a/contrib/ntp/libntp/machines.c
+++ b/contrib/ntp/libntp/machines.c
@@ -8,10 +8,13 @@
#include "config.h"
#endif
+#include "ntp.h"
#include "ntp_machine.h"
#include "ntp_syslog.h"
#include "ntp_stdlib.h"
#include "ntp_unixtime.h"
+#include "lib_strbuf.h"
+#include "ntp_debug.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -409,7 +412,20 @@ return 0;
}
#endif /* MPE */
-const char *set_tod_using = "UNKNOWN";
+#define SET_TOD_UNDETERMINED 0
+#define SET_TOD_CLOCK_SETTIME 1
+#define SET_TOD_SETTIMEOFDAY 2
+#define SET_TOD_STIME 3
+
+const char * const set_tod_used[] = {
+ "undetermined",
+ "clock_settime",
+ "settimeofday",
+ "stime"
+};
+
+pset_tod_using set_tod_using = NULL;
+
int
ntp_set_tod(
@@ -417,37 +433,35 @@ ntp_set_tod(
void *tzp
)
{
- int rc = -1;
+ static int tod;
+ int rc;
+ int saved_errno;
-#ifdef DEBUG
- if (debug)
- printf("In ntp_set_tod\n");
-#endif
+ TRACE(1, ("In ntp_set_tod\n"));
+ rc = -1;
+ saved_errno = 0;
#ifdef HAVE_CLOCK_SETTIME
- if (rc) {
+ if (rc && (SET_TOD_CLOCK_SETTIME == tod || !tod)) {
struct timespec ts;
- set_tod_using = "clock_settime";
/* Convert timeval to timespec */
ts.tv_sec = tvp->tv_sec;
ts.tv_nsec = 1000 * tvp->tv_usec;
errno = 0;
rc = clock_settime(CLOCK_REALTIME, &ts);
-#ifdef DEBUG
- if (debug) {
- printf("ntp_set_tod: %s: %d: %s\n",
- set_tod_using, rc, strerror(errno));
- }
-#endif
+ saved_errno = errno;
+ TRACE(1, ("ntp_set_tod: clock_settime: %d %m\n", rc));
+ if (!tod && !rc)
+ tod = SET_TOD_CLOCK_SETTIME;
+
}
#endif /* HAVE_CLOCK_SETTIME */
#ifdef HAVE_SETTIMEOFDAY
- if (rc) {
+ if (rc && (SET_TOD_SETTIMEOFDAY == tod || !tod)) {
struct timeval adjtv;
- set_tod_using = "settimeofday";
/*
* Some broken systems don't reset adjtime() when the
* clock is stepped.
@@ -456,37 +470,39 @@ ntp_set_tod(
adjtime(&adjtv, NULL);
errno = 0;
rc = SETTIMEOFDAY(tvp, tzp);
-#ifdef DEBUG
- if (debug) {
- printf("ntp_set_tod: %s: %d: %s\n",
- set_tod_using, rc, strerror(errno));
- }
-#endif
+ saved_errno = errno;
+ TRACE(1, ("ntp_set_tod: settimeofday: %d %m\n", rc));
+ if (!tod && !rc)
+ tod = SET_TOD_SETTIMEOFDAY;
}
#endif /* HAVE_SETTIMEOFDAY */
#ifdef HAVE_STIME
- if (rc) {
+ if (rc && (SET_TOD_STIME == tod || !tod)) {
long tp = tvp->tv_sec;
- set_tod_using = "stime";
errno = 0;
rc = stime(&tp); /* lie as bad as SysVR4 */
-#ifdef DEBUG
- if (debug) {
- printf("ntp_set_tod: %s: %d: %s\n",
- set_tod_using, rc, strerror(errno));
- }
-#endif
+ saved_errno = errno;
+ TRACE(1, ("ntp_set_tod: stime: %d %m\n", rc));
+ if (!tod && !rc)
+ tod = SET_TOD_STIME;
}
#endif /* HAVE_STIME */
- if (rc)
- set_tod_using = "Failed!";
-#ifdef DEBUG
- if (debug) {
- printf("ntp_set_tod: Final result: %s: %d: %s\n",
- set_tod_using, rc, strerror(errno));
+
+ errno = saved_errno; /* for %m below */
+ TRACE(1, ("ntp_set_tod: Final result: %s: %d %m\n",
+ set_tod_used[tod], rc));
+ /*
+ * Say how we're setting the time of day
+ */
+ if (!rc && NULL != set_tod_using) {
+ (*set_tod_using)(set_tod_used[tod]);
+ set_tod_using = NULL;
}
-#endif
+
+ if (rc)
+ errno = saved_errno;
+
return rc;
}
@@ -509,19 +525,9 @@ getpass(const char * prompt)
}
password[i] = '\0';
+ fputc('\n', stderr);
+ fflush(stderr);
+
return password;
}
#endif /* SYS_WINNT */
-
-#if !defined(HAVE_MEMSET)
-void
-ntp_memset(
- char *a,
- int x,
- int c
- )
-{
- while (c-- > 0)
- *a++ = (char) x;
-}
-#endif /*POSIX*/
OpenPOWER on IntegriCloud