Re: rdate gets pledge error with -c option

David Leadbeater <[email protected]> Tue, 28 Apr 2026 13:45:34 +1000
Newsgroups gmane.os.openbsd.bugs
Message-ID <[email protected]>
On Sun, Apr 26, 2026 at 09:21:34AM -0600, Todd C. Miller wrote:
> On Sun, 26 Apr 2026 13:10:44 +1000, David Leadbeater wrote:
> 
> > I have left ntpleaps.h here, two macros from it are needed. I think
> > this could be cleaned up, but this diff keeps the removal simple
> > as a candidate for release.
> 
> No need for ntpleaps.h anyore.  Instead of using SEC_TO_TAI64 and
> then TAI64_TO_SEC, we can just use tv_sec as-is.
> 
> Removing the -c option entirely seems like the safer thing to do.

ok dgl@ (with usage() updated too; maybe worth cherry picking to release
if there's time?)

I finally realised part of my confusion here, the error saying -c isn't
working was hidden by the privsep:

[On a 7.7 system]
$ ktrace -di rdate -pnc pool.ntp.org
Tue Apr 28 13:40:54 AEST 2026
$ kdump | grep -B1 -A2 'Warning: error reading tzfile. You will NOT'
 16343 rdate    GIO   fd 2 wrote 91 bytes
       "Warning: error reading tzfile. You will NOT be
	able to get legal time or posix compliance!
       "
 
>  - todd
> 
> Index: usr.sbin/rdate/Makefile
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rdate/Makefile,v
> diff -u -p -u -r1.8 Makefile
> --- usr.sbin/rdate/Makefile	27 Mar 2026 14:33:58 -0000	1.8
> +++ usr.sbin/rdate/Makefile	26 Apr 2026 15:02:25 -0000
> @@ -1,7 +1,7 @@
>  #	$OpenBSD: Makefile,v 1.8 2026/03/27 14:33:58 deraadt Exp $
>  
>  PROG=	rdate
> -SRCS=	rdate.c ntp.c ntpleaps.c
> +SRCS=	rdate.c ntp.c
>  CFLAGS+=-Wall
>  DPADD+= ${LIBUTIL}
>  LDADD+= -lutil
> Index: usr.sbin/rdate/ntp.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rdate/ntp.c,v
> diff -u -p -u -r1.37 ntp.c
> --- usr.sbin/rdate/ntp.c	12 Nov 2023 18:53:22 -0000	1.37
> +++ usr.sbin/rdate/ntp.c	26 Apr 2026 15:14:04 -0000
> @@ -50,8 +50,6 @@
>  #include <poll.h>
>  #include <unistd.h>
>  
> -#include "ntpleaps.h"
> -
>  /*
>   * NTP definitions.  Note that these assume 8-bit bytes - sigh.  There
>   * is little point in parameterising everything, as it is neither
> @@ -120,7 +118,7 @@ struct ntp_data {
>  	u_int64_t	xmitck;
>  };
>  
> -void	ntp_client(const char *, int, struct timeval *, struct timeval *, int);
> +void	ntp_client(const char *, int, struct timeval *, struct timeval *);
>  int	sync_ntp(int, const struct sockaddr *, double *, double *);
>  int	write_packet(int, struct ntp_data *);
>  int	read_packet(int, struct ntp_data *, double *, double *);
> @@ -132,11 +130,9 @@ void	create_timeval(double, struct timev
>  void	print_packet(const struct ntp_data *);
>  #endif
>  
> -int	corrleaps;
> -
>  void
>  ntp_client(const char *hostname, int family, struct timeval *new,
> -    struct timeval *adjust, int leapflag)
> +    struct timeval *adjust)
>  {
>  	struct addrinfo hints, *res0, *res;
>  	double offset, error;
> @@ -154,10 +150,6 @@ ntp_client(const char *hostname, int fam
>  	if (pledge("stdio inet", NULL) == -1)
>  		err(1, "pledge");
>  
> -	corrleaps = leapflag;
> -	if (corrleaps)
> -		ntpleaps_init();
> -
>  	s = -1;
>  	for (res = res0; res; res = res->ai_next) {
>  		s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
> @@ -447,21 +439,11 @@ double
>  current_time(double offset)
>  {
>  	struct timeval current;
> -	u_int64_t t;
>  
>  	if (gettimeofday(&current, NULL))
>  		err(1, "Could not get local time of day");
>  
> -	/*
> -	 * At this point, current has the current TAI time.
> -	 * Now subtract leap seconds to set the posix tick.
> -	 */
> -
> -	t = SEC_TO_TAI64(current.tv_sec);
> -	if (corrleaps)
> -		ntpleaps_sub(&t);
> -
> -	return (offset + TAI64_TO_SEC(t) + 1.0e-6 * current.tv_usec);
> +	return (offset + current.tv_sec + 1.0e-6 * current.tv_usec);
>  }
>  
>  /*
> Index: usr.sbin/rdate/rdate.8
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rdate/rdate.8,v
> diff -u -p -u -r1.41 rdate.8
> --- usr.sbin/rdate/rdate.8	27 Mar 2026 14:33:58 -0000	1.41
> +++ usr.sbin/rdate/rdate.8	26 Apr 2026 15:15:10 -0000
> @@ -32,7 +32,7 @@
>  .Nd set the system's date from a remote host
>  .Sh SYNOPSIS
>  .Nm rdate
> -.Op Fl 46acnpsv
> +.Op Fl 46anpsv
>  .Ar host
>  .Sh DESCRIPTION
>  .Nm
> @@ -55,10 +55,6 @@ Use the
>  .Xr adjtime 2
>  call to gradually skew the local time to the
>  remote time rather than just hopping.
> -.It Fl c
> -Correct leap seconds.
> -This should be used only when synchronizing to a server
> -which does not correctly account for leap seconds.
>  .It Fl n
>  Use SNTP (RFC 5905).
>  This is the default.
> Index: usr.sbin/rdate/rdate.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rdate/rdate.c,v
> diff -u -p -u -r1.38 rdate.c
> --- usr.sbin/rdate/rdate.c	27 Mar 2026 14:33:58 -0000	1.38
> +++ usr.sbin/rdate/rdate.c	26 Apr 2026 15:14:33 -0000
> @@ -52,7 +52,7 @@
>  #define logwtmp(a,b,c)
>  #endif
>  
> -void ntp_client(const char *, int, struct timeval *, struct timeval *, int);
> +void ntp_client(const char *, int, struct timeval *, struct timeval *);
>  
>  extern char    *__progname;
>  __dead void	usage(void);

usage() needs update.

> @@ -74,12 +74,12 @@ int
>  main(int argc, char **argv)
>  {
>  	int             pr = 0, silent = 0, verbose = 0;
> -	int		slidetime = 0, corrleaps = 0;
> +	int		slidetime = 0;
>  	char           *hname;
>  	int             c, p[2], pid;
>  	int		family = PF_UNSPEC;
>  
> -	while ((c = getopt(argc, argv, "46psanocv")) != -1) {
> +	while ((c = getopt(argc, argv, "46psanov")) != -1) {
>  		switch (c) {
>  		case '4':
>  			family = PF_INET;
> @@ -105,10 +105,6 @@ main(int argc, char **argv)
>  			/* noop */
>  			break;
>  
> -		case 'c':
> -			corrleaps = 1;
> -			break;
> -
>  		case 'v':
>  			verbose = 1;
>  			break;
> @@ -144,8 +140,7 @@ main(int argc, char **argv)
>  		setvbuf(stdout, NULL, _IOFBF, 0);
>  		setvbuf(stderr, NULL, _IOFBF, 0);
>  
> -		ntp_client(hname, family, &pdata.new,
> -		    &pdata.adjust, corrleaps);
> +		ntp_client(hname, family, &pdata.new, &pdata.adjust);
>  
>  		if (write(STDOUT_FILENO, &pdata, sizeof pdata) != sizeof pdata)
>  			exit(1);