summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp')
-rw-r--r--contrib/ntp/libntp/Makefile.am4
-rw-r--r--contrib/ntp/libntp/Makefile.in16
-rw-r--r--contrib/ntp/libntp/a_md5encrypt.c1
-rw-r--r--contrib/ntp/libntp/audio.c36
-rw-r--r--contrib/ntp/libntp/authkeys.c2
-rw-r--r--contrib/ntp/libntp/emalloc.c9
-rw-r--r--contrib/ntp/libntp/libssl_compat.c17
-rw-r--r--contrib/ntp/libntp/ntp_intres.c2
-rw-r--r--contrib/ntp/libntp/recvbuff.c2
-rw-r--r--contrib/ntp/libntp/ssl_init.c53
-rw-r--r--contrib/ntp/libntp/statestr.c9
-rw-r--r--contrib/ntp/libntp/work_fork.c165
12 files changed, 201 insertions, 115 deletions
diff --git a/contrib/ntp/libntp/Makefile.am b/contrib/ntp/libntp/Makefile.am
index 874739a..6f3c0ba 100644
--- a/contrib/ntp/libntp/Makefile.am
+++ b/contrib/ntp/libntp/Makefile.am
@@ -119,10 +119,14 @@ libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS)
EXTRA_libntp_a_SOURCES = adjtimex.c
AM_CFLAGS = $(CFLAGS_NTP)
+AM_CFLAGS += $(NTP_HARD_CFLAGS)
AM_CPPFLAGS = $(NTP_INCS)
AM_CPPFLAGS += $(LIBOPTS_CFLAGS)
AM_CPPFLAGS += $(CPPFLAGS_NTP)
+AM_CPPFLAGS += $(NTP_HARD_CPPFLAGS)
+
+AM_LDFLAGS = $(NTP_HARD_LDFLAGS)
EXTRA_DIST = README
diff --git a/contrib/ntp/libntp/Makefile.in b/contrib/ntp/libntp/Makefile.in
index 46b7926..25718b9 100644
--- a/contrib/ntp/libntp/Makefile.in
+++ b/contrib/ntp/libntp/Makefile.in
@@ -109,6 +109,7 @@ am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
$(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \
$(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \
$(top_srcdir)/sntp/m4/ntp_googletest.m4 \
+ $(top_srcdir)/sntp/m4/ntp_harden.m4 \
$(top_srcdir)/sntp/m4/ntp_ipv6.m4 \
$(top_srcdir)/sntp/m4/ntp_lib_m.m4 \
$(top_srcdir)/sntp/m4/ntp_libevent.m4 \
@@ -366,10 +367,6 @@ CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS_LIBEVENT = @CPPFLAGS_LIBEVENT@
CPPFLAGS_NTP = @CPPFLAGS_NTP@
-CXX = @CXX@
-CXXCPP = @CXXCPP@
-CXXDEPMODE = @CXXDEPMODE@
-CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DCFD = @DCFD@
DEFS = @DEFS@
@@ -422,6 +419,7 @@ LN_S = @LN_S@
LSCF = @LSCF@
LTHREAD_LIBS = @LTHREAD_LIBS@
LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAKEINFO = @MAKEINFO@
MAKE_ADJTIMED = @MAKE_ADJTIMED@
MAKE_CHECK_LAYOUT = @MAKE_CHECK_LAYOUT@
@@ -485,6 +483,9 @@ NTPTRACE_DL = @NTPTRACE_DL@
NTPTRACE_DS = @NTPTRACE_DS@
NTPTRACE_MS = @NTPTRACE_MS@
NTPTRACE_NI = @NTPTRACE_NI@
+NTP_HARD_CFLAGS = @NTP_HARD_CFLAGS@
+NTP_HARD_CPPFLAGS = @NTP_HARD_CPPFLAGS@
+NTP_HARD_LDFLAGS = @NTP_HARD_LDFLAGS@
NTP_KEYGEN_DB = @NTP_KEYGEN_DB@
NTP_KEYGEN_DL = @NTP_KEYGEN_DL@
NTP_KEYGEN_DS = @NTP_KEYGEN_DS@
@@ -558,7 +559,6 @@ abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
-ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
@@ -710,8 +710,10 @@ libntp_a_SRCS = \
libntp_a_SOURCES = systime.c $(libntp_a_SRCS)
libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS)
EXTRA_libntp_a_SOURCES = adjtimex.c
-AM_CFLAGS = $(CFLAGS_NTP)
-AM_CPPFLAGS = $(NTP_INCS) $(LIBOPTS_CFLAGS) $(CPPFLAGS_NTP)
+AM_CFLAGS = $(CFLAGS_NTP) $(NTP_HARD_CFLAGS)
+AM_CPPFLAGS = $(NTP_INCS) $(LIBOPTS_CFLAGS) $(CPPFLAGS_NTP) \
+ $(NTP_HARD_CPPFLAGS)
+AM_LDFLAGS = $(NTP_HARD_LDFLAGS)
EXTRA_DIST = README
NTP_INCS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \
-I$(top_srcdir)/lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/include \
diff --git a/contrib/ntp/libntp/a_md5encrypt.c b/contrib/ntp/libntp/a_md5encrypt.c
index 7edcd2e..7394d0d 100644
--- a/contrib/ntp/libntp/a_md5encrypt.c
+++ b/contrib/ntp/libntp/a_md5encrypt.c
@@ -11,7 +11,6 @@
#include "ntp.h"
#include "ntp_md5.h" /* provides OpenSSL digest API */
#include "isc/string.h"
-#include "libssl_compat.h"
/*
* MD5authencrypt - generate message digest
*
diff --git a/contrib/ntp/libntp/audio.c b/contrib/ntp/libntp/audio.c
index 3b0a0b3..f404cc0 100644
--- a/contrib/ntp/libntp/audio.c
+++ b/contrib/ntp/libntp/audio.c
@@ -46,6 +46,19 @@
# include <ctype.h>
#endif
+
+/*
+ * 4.4BSD-Lite switched to an unsigned long ioctl arg. Detect common
+ * derivatives here, and apply that type. To make the following code
+ * less verbose we make a proper typedef.
+ * The joy of IOCTL programming...
+ */
+# if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__) || defined __OpenBSD__
+typedef unsigned long ioctl_arg_T;
+#else
+typedef int ioctl_arg_T;
+#endif
+
/*
* Global variables
*/
@@ -54,13 +67,14 @@ static struct audio_device device; /* audio device ident */
#endif /* HAVE_SYS_AUDIOIO_H */
#ifdef PCM_STYLE_SOUND
# define INIT_FILE "/etc/ntp.audio"
-int agc = SOUND_MIXER_WRITE_RECLEV; /* or IGAIN or LINE */
-int audiomonitor = SOUND_MIXER_WRITE_VOLUME; /* or OGAIN */
-int devmask = 0;
-int recmask = 0;
-char cf_c_dev[100], cf_i_dev[100], cf_agc[100], cf_monitor[100];
-const char *m_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
+static ioctl_arg_T agc = SOUND_MIXER_WRITE_RECLEV; /* or IGAIN or LINE */
+static ioctl_arg_T audiomonitor = SOUND_MIXER_WRITE_VOLUME; /* or OGAIN */
+static int devmask = 0;
+static int recmask = 0;
+static char cf_c_dev[100], cf_i_dev[100], cf_agc[100], cf_monitor[100];
+
+static const char *m_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
#else /* not PCM_STYLE_SOUND */
static struct audio_info info; /* audio device info */
#endif /* not PCM_STYLE_SOUND */
@@ -347,7 +361,7 @@ audio_init(
# ifdef HAVE_SYS_AUDIOIO_H
info.record.buffer_size = bufsiz;
# endif /* HAVE_SYS_AUDIOIO_H */
- rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info);
+ rval = ioctl(ctl_fd, AUDIO_SETINFO, (char *)&info);
if (rval < 0) {
msyslog(LOG_ERR, "audio: invalid control device parameters");
close(ctl_fd);
@@ -448,7 +462,7 @@ audio_gain(
o_port = port;
}
#else /* not PCM_STYLE_SOUND */
- ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info);
+ ioctl(ctl_fd, AUDIO_GETINFO, (char *)&info);
info.record.encoding = AUDIO_ENCODING_ULAW;
info.record.error = 0;
info.record.gain = gain;
@@ -456,7 +470,7 @@ audio_gain(
o_mongain = info.monitor_gain = mongain;
if (o_port != port)
o_port = info.record.port = port;
- rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info);
+ rval = ioctl(ctl_fd, AUDIO_SETINFO, (char *)&info);
if (rval < 0) {
msyslog(LOG_ERR, "audio_gain: %m");
return (rval);
@@ -485,11 +499,11 @@ audio_show(void)
#else /* not PCM_STYLE_SOUND */
# ifdef HAVE_SYS_AUDIOIO_H
- ioctl(ctl_fd, (int)AUDIO_GETDEV, &device);
+ ioctl(ctl_fd, AUDIO_GETDEV, &device);
printf("audio: name %s, version %s, config %s\n",
device.name, device.version, device.config);
# endif /* HAVE_SYS_AUDIOIO_H */
- ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info);
+ ioctl(ctl_fd, AUDIO_GETINFO, (char *)&info);
printf(
"audio: rate %d, chan %d, prec %d, code %d, gain %d, mon %d, port %d\n",
info.record.sample_rate, info.record.channels,
diff --git a/contrib/ntp/libntp/authkeys.c b/contrib/ntp/libntp/authkeys.c
index 51337d5..b2ff410 100644
--- a/contrib/ntp/libntp/authkeys.c
+++ b/contrib/ntp/libntp/authkeys.c
@@ -250,7 +250,7 @@ auth_moremem(
i = (keycount > 0)
? keycount
: MEMINC;
- sk = emalloc_zero(i * sizeof(*sk) + MOREMEM_EXTRA_ALLOC);
+ sk = eallocarrayxz(i, sizeof(*sk), MOREMEM_EXTRA_ALLOC);
#ifdef DEBUG
base = sk;
#endif
diff --git a/contrib/ntp/libntp/emalloc.c b/contrib/ntp/libntp/emalloc.c
index 8b7ef99..7746b7a 100644
--- a/contrib/ntp/libntp/emalloc.c
+++ b/contrib/ntp/libntp/emalloc.c
@@ -83,10 +83,11 @@ ereallocz(
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
void *
-oreallocarray(
+oreallocarrayxz(
void *optr,
size_t nmemb,
- size_t size
+ size_t size,
+ size_t extra
#ifdef EREALLOC_CALLSITE /* ntp_malloc.h */
,
const char * file,
@@ -106,9 +107,9 @@ oreallocarray(
exit(1);
}
#ifndef EREALLOC_CALLSITE
- return ereallocz(optr, (size * nmemb), 0, FALSE);
+ return ereallocz(optr, extra + (size * nmemb), 0, TRUE);
#else
- return ereallocz(optr, (size * nmemb), 0, FALSE, file, line);
+ return ereallocz(optr, extra + (size * nmemb), 0, TRUE, file, line);
#endif
}
diff --git a/contrib/ntp/libntp/libssl_compat.c b/contrib/ntp/libntp/libssl_compat.c
index ce6acb7..afe4d07 100644
--- a/contrib/ntp/libntp/libssl_compat.c
+++ b/contrib/ntp/libntp/libssl_compat.c
@@ -15,15 +15,18 @@
* ---------------------------------------------------------------------
*/
#include "config.h"
-
-#include <string.h>
-#include <openssl/bn.h>
-#include <openssl/evp.h>
-
#include "ntp_types.h"
/* ----------------------------------------------------------------- */
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#ifdef OPENSSL
+# include <string.h>
+# include <openssl/bn.h>
+# include <openssl/evp.h>
+#endif
+/* ----------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------- */
+#if defined(OPENSSL) && OPENSSL_VERSION_NUMBER < 0x10100000L
/* ----------------------------------------------------------------- */
#include "libssl_compat.h"
@@ -325,7 +328,7 @@ sslshim_X509_get_signature_nid(
}
/* ----------------------------------------------------------------- */
-#else /* OPENSSL_VERSION_NUMBER >= v1.1.0 */
+#else /* OPENSSL && OPENSSL_VERSION_NUMBER >= v1.1.0 */
/* ----------------------------------------------------------------- */
NONEMPTY_TRANSLATION_UNIT
diff --git a/contrib/ntp/libntp/ntp_intres.c b/contrib/ntp/libntp/ntp_intres.c
index 7aa288a..9fc3815 100644
--- a/contrib/ntp/libntp/ntp_intres.c
+++ b/contrib/ntp/libntp/ntp_intres.c
@@ -410,7 +410,7 @@ blocking_getaddrinfo(
cp += sizeof(*ai);
/* transform ai_canonname into offset */
- if (NULL != serialized_ai->ai_canonname) {
+ if (NULL != ai->ai_canonname) {
serialized_ai->ai_canonname = (char *)canons_octets;
canons_octets += strlen(ai->ai_canonname) + 1;
}
diff --git a/contrib/ntp/libntp/recvbuff.c b/contrib/ntp/libntp/recvbuff.c
index f888950..a3c41a0 100644
--- a/contrib/ntp/libntp/recvbuff.c
+++ b/contrib/ntp/libntp/recvbuff.c
@@ -85,7 +85,7 @@ create_buffers(int nbufs)
buffer_shortfall = 0;
#ifndef DEBUG
- bufp = emalloc_zero(abuf * sizeof(*bufp));
+ bufp = eallocarray(abuf, sizeof(*bufp));
#endif
for (i = 0; i < abuf; i++) {
diff --git a/contrib/ntp/libntp/ssl_init.c b/contrib/ntp/libntp/ssl_init.c
index ef0f1c1..bebf6e1 100644
--- a/contrib/ntp/libntp/ssl_init.c
+++ b/contrib/ntp/libntp/ssl_init.c
@@ -13,52 +13,65 @@
#include <lib_strbuf.h>
#ifdef OPENSSL
+#include "openssl/crypto.h"
#include "openssl/err.h"
#include "openssl/evp.h"
+#include "openssl/opensslv.h"
#include "libssl_compat.h"
-void atexit_ssl_cleanup(void);
-
int ssl_init_done;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+
+static void
+atexit_ssl_cleanup(void)
+{
+ if (!ssl_init_done)
+ return;
+
+ ssl_init_done = FALSE;
+ EVP_cleanup();
+ ERR_free_strings();
+}
+
void
ssl_init(void)
{
init_lib();
- if (ssl_init_done)
- return;
-
- ERR_load_crypto_strings();
- OpenSSL_add_all_algorithms();
- atexit(&atexit_ssl_cleanup);
-
- ssl_init_done = TRUE;
+ if ( ! ssl_init_done) {
+ ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ atexit(&atexit_ssl_cleanup);
+ ssl_init_done = TRUE;
+ }
}
+#else /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
void
-atexit_ssl_cleanup(void)
+ssl_init(void)
{
- if (!ssl_init_done)
- return;
-
- ssl_init_done = FALSE;
- EVP_cleanup();
- ERR_free_strings();
+ init_lib();
+ ssl_init_done = TRUE;
}
+#endif /* OPENSSL_VERSION_NUMBER */
+
void
ssl_check_version(void)
{
- if ((SSLeay() ^ OPENSSL_VERSION_NUMBER) & ~0xff0L) {
+ u_long v;
+
+ v = OpenSSL_version_num();
+ if ((v ^ OPENSSL_VERSION_NUMBER) & ~0xff0L) {
msyslog(LOG_WARNING,
"OpenSSL version mismatch. Built against %lx, you have %lx",
- (u_long)OPENSSL_VERSION_NUMBER, SSLeay());
+ (u_long)OPENSSL_VERSION_NUMBER, v);
fprintf(stderr,
"OpenSSL version mismatch. Built against %lx, you have %lx\n",
- (u_long)OPENSSL_VERSION_NUMBER, SSLeay());
+ (u_long)OPENSSL_VERSION_NUMBER, v);
}
INIT_SSL();
diff --git a/contrib/ntp/libntp/statestr.c b/contrib/ntp/libntp/statestr.c
index 313cd46..b8fa53c 100644
--- a/contrib/ntp/libntp/statestr.c
+++ b/contrib/ntp/libntp/statestr.c
@@ -355,13 +355,12 @@ decode_bitflags(
for (b = 0; b < tab_ct; b++) {
if (tab[b].code & bits) {
- rc = snprintf(pch, (lim - pch), "%s%s", sep,
+ size_t avail = lim - pch;
+ rc = snprintf(pch, avail, "%s%s", sep,
tab[b].string);
- if (rc < 0)
- goto toosmall;
- pch += (u_int)rc;
- if (pch >= lim)
+ if ((size_t)rc >= avail)
goto toosmall;
+ pch += rc;
sep = sep2;
}
}
diff --git a/contrib/ntp/libntp/work_fork.c b/contrib/ntp/libntp/work_fork.c
index 8223fdd..2aa2d5c 100644
--- a/contrib/ntp/libntp/work_fork.c
+++ b/contrib/ntp/libntp/work_fork.c
@@ -24,6 +24,8 @@
int worker_process;
addremove_io_fd_func addremove_io_fd;
static volatile int worker_sighup_received;
+int saved_argc = 0;
+char **saved_argv;
/* === function prototypes === */
static void fork_blocking_child(blocking_child *);
@@ -31,6 +33,62 @@ static RETSIGTYPE worker_sighup(int);
static void send_worker_home_atexit(void);
static void cleanup_after_child(blocking_child *);
+/* === I/O helpers === */
+/* Since we have signals enabled, there's a good chance that blocking IO
+ * via pipe suffers from EINTR -- and this goes for both directions.
+ * The next two wrappers will loop until either all the data is written
+ * or read, plus handling the EOF condition on read. They may return
+ * zero if no data was transferred at all, and effectively every return
+ * value that differs from the given transfer length signifies an error
+ * condition.
+ */
+
+static size_t
+netread(
+ int fd,
+ void * vb,
+ size_t l
+ )
+{
+ char * b = vb;
+ ssize_t r;
+
+ while (l) {
+ r = read(fd, b, l);
+ if (r > 0) {
+ l -= r;
+ b += r;
+ } else if (r == 0 || errno != EINTR) {
+ l = 0;
+ }
+ }
+ return (size_t)(b - (char *)vb);
+}
+
+
+static size_t
+netwrite(
+ int fd,
+ const void * vb,
+ size_t l
+ )
+{
+ const char * b = vb;
+ ssize_t w;
+
+ while (l) {
+ w = write(fd, b, l);
+ if (w > 0) {
+ l -= w;
+ b += w;
+ } else if (errno != EINTR) {
+ l = 0;
+ }
+ }
+ return (size_t)(b - (const char *)vb);
+}
+
+
/* === functions === */
/*
* exit_worker()
@@ -200,8 +258,8 @@ send_blocking_req_internal(
void * data
)
{
- int octets;
- int rc;
+ size_t octets;
+ size_t rc;
DEBUG_REQUIRE(hdr != NULL);
DEBUG_REQUIRE(data != NULL);
@@ -213,23 +271,18 @@ send_blocking_req_internal(
}
octets = sizeof(*hdr);
- rc = write(c->req_write_pipe, hdr, octets);
+ rc = netwrite(c->req_write_pipe, hdr, octets);
if (rc == octets) {
octets = hdr->octets - sizeof(*hdr);
- rc = write(c->req_write_pipe, data, octets);
-
+ rc = netwrite(c->req_write_pipe, data, octets);
if (rc == octets)
return 0;
}
- if (rc < 0)
- msyslog(LOG_ERR,
- "send_blocking_req_internal: pipe write: %m");
- else
- msyslog(LOG_ERR,
- "send_blocking_req_internal: short write %d of %d",
- rc, octets);
+ msyslog(LOG_ERR,
+ "send_blocking_req_internal: short write (%zu of %zu), %m",
+ rc, octets);
/* Fatal error. Clean up the child process. */
req_child_exit(c);
@@ -244,41 +297,32 @@ receive_blocking_req_internal(
{
blocking_pipe_header hdr;
blocking_pipe_header * req;
- int rc;
- long octets;
+ size_t rc;
+ size_t octets;
DEBUG_REQUIRE(-1 != c->req_read_pipe);
req = NULL;
+ rc = netread(c->req_read_pipe, &hdr, sizeof(hdr));
- do {
- rc = read(c->req_read_pipe, &hdr, sizeof(hdr));
- } while (rc < 0 && EINTR == errno);
-
- if (rc < 0) {
- msyslog(LOG_ERR,
- "receive_blocking_req_internal: pipe read %m");
- } else if (0 == rc) {
+ if (0 == rc) {
TRACE(4, ("parent closed request pipe, child %d terminating\n",
c->pid));
} else if (rc != sizeof(hdr)) {
msyslog(LOG_ERR,
- "receive_blocking_req_internal: short header read %d of %lu",
- rc, (u_long)sizeof(hdr));
+ "receive_blocking_req_internal: short header read (%zu of %zu), %m",
+ rc, sizeof(hdr));
} else {
INSIST(sizeof(hdr) < hdr.octets && hdr.octets < 4 * 1024);
req = emalloc(hdr.octets);
memcpy(req, &hdr, sizeof(*req));
octets = hdr.octets - sizeof(hdr);
- rc = read(c->req_read_pipe, (char *)req + sizeof(*req),
- octets);
+ rc = netread(c->req_read_pipe, (char *)(req + 1),
+ octets);
- if (rc < 0)
- msyslog(LOG_ERR,
- "receive_blocking_req_internal: pipe data read %m");
- else if (rc != octets)
+ if (rc != octets)
msyslog(LOG_ERR,
- "receive_blocking_req_internal: short read %d of %ld",
+ "receive_blocking_req_internal: short read (%zu of %zu), %m",
rc, octets);
else if (BLOCKING_REQ_MAGIC != req->magic_sig)
msyslog(LOG_ERR,
@@ -301,24 +345,20 @@ send_blocking_resp_internal(
blocking_pipe_header * resp
)
{
- long octets;
- int rc;
+ size_t octets;
+ size_t rc;
DEBUG_REQUIRE(-1 != c->resp_write_pipe);
octets = resp->octets;
- rc = write(c->resp_write_pipe, resp, octets);
+ rc = netwrite(c->resp_write_pipe, resp, octets);
free(resp);
if (octets == rc)
return 0;
- if (rc < 0)
- TRACE(1, ("send_blocking_resp_internal: pipe write %m\n"));
- else
- TRACE(1, ("send_blocking_resp_internal: short write %d of %ld\n",
- rc, octets));
-
+ TRACE(1, ("send_blocking_resp_internal: short write (%zu of %zu), %m\n",
+ rc, octets));
return -1;
}
@@ -330,21 +370,19 @@ receive_blocking_resp_internal(
{
blocking_pipe_header hdr;
blocking_pipe_header * resp;
- int rc;
- long octets;
+ size_t rc;
+ size_t octets;
DEBUG_REQUIRE(c->resp_read_pipe != -1);
resp = NULL;
- rc = read(c->resp_read_pipe, &hdr, sizeof(hdr));
+ rc = netread(c->resp_read_pipe, &hdr, sizeof(hdr));
- if (rc < 0) {
- TRACE(1, ("receive_blocking_resp_internal: pipe read %m\n"));
- } else if (0 == rc) {
+ if (0 == rc) {
/* this is the normal child exited indication */
} else if (rc != sizeof(hdr)) {
- TRACE(1, ("receive_blocking_resp_internal: short header read %d of %lu\n",
- rc, (u_long)sizeof(hdr)));
+ TRACE(1, ("receive_blocking_resp_internal: short header read (%zu of %zu), %m\n",
+ rc, sizeof(hdr)));
} else if (BLOCKING_RESP_MAGIC != hdr.magic_sig) {
TRACE(1, ("receive_blocking_resp_internal: header mismatch (0x%x)\n",
hdr.magic_sig));
@@ -354,24 +392,21 @@ receive_blocking_resp_internal(
resp = emalloc(hdr.octets);
memcpy(resp, &hdr, sizeof(*resp));
octets = hdr.octets - sizeof(hdr);
- rc = read(c->resp_read_pipe,
- (char *)resp + sizeof(*resp),
- octets);
+ rc = netread(c->resp_read_pipe, (char *)(resp + 1),
+ octets);
- if (rc < 0)
- TRACE(1, ("receive_blocking_resp_internal: pipe data read %m\n"));
- else if (rc < octets)
- TRACE(1, ("receive_blocking_resp_internal: short read %d of %ld\n",
+ if (rc != octets)
+ TRACE(1, ("receive_blocking_resp_internal: short read (%zu of %zu), %m\n",
rc, octets));
else
return resp;
}
cleanup_after_child(c);
-
+
if (resp != NULL)
free(resp);
-
+
return NULL;
}
@@ -503,6 +538,22 @@ fork_blocking_child(
worker_process = TRUE;
/*
+ * Change the process name of the child to avoid confusion
+ * about ntpd trunning twice.
+ */
+ if (saved_argc != 0) {
+ int argcc;
+ int argvlen = 0;
+ /* Clear argv */
+ for (argcc = 0; argcc < saved_argc; argcc++) {
+ int l = strlen(saved_argv[argcc]);
+ argvlen += l + 1;
+ memset(saved_argv[argcc], 0, l);
+ }
+ strlcpy(saved_argv[0], "ntpd: asynchronous dns resolver", argvlen);
+ }
+
+ /*
* In the child, close all files except stdin, stdout, stderr,
* and the two child ends of the pipes.
*/
OpenPOWER on IntegriCloud