From cb18fdd6edbb3ff8d59d69fdcf9857da061ff4c0 Mon Sep 17 00:00:00 2001 From: henning <> Date: Fri, 9 Jul 2004 15:02:15 +0000 Subject: [PATCH] don't panic when sendto() fails; for the client part just re-schedule noticed & fix tested by fries@ --- src/usr.sbin/ntpd/client.c | 10 +++++++--- src/usr.sbin/ntpd/ntp_msg.c | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c index 873056c5..7c2503e1 100644 --- a/src/usr.sbin/ntpd/client.c +++ b/src/usr.sbin/ntpd/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.18 2004/07/09 10:53:33 henning Exp $ */ +/* $OpenBSD: client.c,v 1.19 2004/07/09 15:02:15 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -104,8 +104,12 @@ client_query(struct ntp_peer *p) p->query->msg.xmttime.fraction = arc4random(); p->query->xmttime = gettime(); - ntp_sendmsg(p->query->fd, (struct sockaddr *)&p->addr->ss, - &p->query->msg, NTP_MSGSIZE_NOAUTH, 0); + if (ntp_sendmsg(p->query->fd, (struct sockaddr *)&p->addr->ss, + &p->query->msg, NTP_MSGSIZE_NOAUTH, 0) == -1) { + p->next = time(NULL) + INTERVAL_QUERY_PATHETIC; + return (-1); + } + p->state = STATE_QUERY_SENT; p->next = 0; p->deadline = time(NULL) + QUERYTIME_MAX; diff --git a/src/usr.sbin/ntpd/ntp_msg.c b/src/usr.sbin/ntpd/ntp_msg.c index a053678a..eee25694 100644 --- a/src/usr.sbin/ntpd/ntp_msg.c +++ b/src/usr.sbin/ntpd/ntp_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp_msg.c,v 1.2 2004/07/07 07:32:05 alexander Exp $ */ +/* $OpenBSD: ntp_msg.c,v 1.3 2004/07/09 15:02:15 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -135,8 +135,10 @@ ntp_sendmsg(int fd, struct sockaddr *sa, struct ntp_msg *msg, ssize_t len, /* XXX */ } - if (sendto(fd, &buf, len, 0, sa, sa->sa_len) != len) - fatal("sendto"); + if (sendto(fd, &buf, len, 0, sa, sa->sa_len) != len) { + log_warn("sendto"); + return (-1); + } return (0); }