Subject: bin/3519: xntpd should use sysctl to get clockrate info.
To: None <gnats-bugs@gnats.netbsd.org>
From: Brad Spencer <brad@anduin.eldar.org>
List: netbsd-bugs
Date: 04/20/1997 18:59:55
>Number:         3519
>Category:       bin
>Synopsis:       xntpd should use sysctl to get clockrate info.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 20 16:05:01 1997
>Last-Modified:
>Originator:     Brad Spencer
>Organization:
	Sitting at home
>Release:        1.2C/1.2D
>Environment:
	
NetBSD valinor.eldar.org 1.2D NetBSD 1.2D (VALINOR) #5: Sat Apr 19 21:27:29 EDT 1997     brad@valinor.eldar.org:/usr/src/sys/arch/alpha/compile/VALINOR alpha


>Description:

The xntpd reads the kernel to find the values of tickadj and tick.
The method used does not work on the Alpha, at the very least.  One
should not have to do this with NetBSD, as these bits of information
are available with the sysctl interface.  This should work on all
ports and should not require xntpd to be linked with libkvm.

>How-To-Repeat:

Try using xntpd in the tree on the Alpha.

>Fix:

Here is a patch which adds a USE_SYSCTL define and removes the linking
of libkvm.  I don't know if there is anything else wrong with xntpd on
the Alpha, but at least this gives it a chance of working.  [It
appears to function fine, here]


diff -cr xntp/Makefile.inc ../new/xntp/Makefile.inc
*** xntp/Makefile.inc	Sat Apr 19 07:27:23 1997
--- ../new/xntp/Makefile.inc	Sun Apr 20 18:33:27 1997
***************
*** 1,5 ****
  #	$NetBSD: Makefile.inc,v 1.2 1997/04/18 14:06:15 christos Exp $
  CFLAGS += -I${.CURDIR}/../include -DHAVE_CONFIG_H
! LDADD += -lntp -lkvm
! DPADD += ${LIBNTP} ${LIBKVM}
  BINDIR=/usr/sbin
--- 1,5 ----
  #	$NetBSD: Makefile.inc,v 1.2 1997/04/18 14:06:15 christos Exp $
  CFLAGS += -I${.CURDIR}/../include -DHAVE_CONFIG_H
! LDADD += -lntp
! DPADD += ${LIBNTP}
  BINDIR=/usr/sbin
diff -cr xntp/xntpd/Makefile ../new/xntp/xntpd/Makefile
*** xntp/xntpd/Makefile	Sat Apr 19 07:27:31 1997
--- ../new/xntp/xntpd/Makefile	Sun Apr 20 18:30:16 1997
***************
*** 1,5 ****
--- 1,6 ----
  #	$NetBSD: Makefile,v 1.1.1.1 1997/04/18 13:29:14 christos Exp $
  
+ CFLAGS+= -DUSE_SYSCTL
  PROG= xntpd
  SRCS=	map_vme.c ntp_config.c ntp_control.c ntp_filegen.c ntp_intres.c ntp_io.c \
  ntp_leap.c ntp_loopfilter.c ntp_monitor.c ntp_peer.c ntp_proto.c ntp_refclock.c \
diff -cr xntp/xntpd/ntp_unixclock.c ../new/xntp/xntpd/ntp_unixclock.c
*** xntp/xntpd/ntp_unixclock.c	Sat Apr 19 07:27:36 1997
--- ../new/xntp/xntpd/ntp_unixclock.c	Sun Apr 20 18:28:32 1997
***************
*** 59,64 ****
--- 59,70 ----
  # undef hz
  #endif /* hz */
  
+ #ifdef USE_SYSCTL
+ #include <sys/param.h>
+ #include <sys/sysctl.h>
+ #include <sys/time.h>
+ #endif
+ 
  extern int debug;
  /*
   * These routines (init_systime, get_systime, step_systime, adj_systime)
***************
*** 267,272 ****
--- 273,304 ----
   * clock_parms - return the local clock tickadj and tick parameters
   *
   */
+ 
+ #ifdef USE_SYSCTL
+ static void
+ clock_parms(ptickadj, ptick)
+      u_long *ptickadj;
+      u_long *ptick;
+ {
+   int mib[2];
+   size_t len;
+   struct clockinfo c;
+   int e;
+ 
+   mib[0]=CTL_KERN;
+   mib[1]=KERN_CLOCKRATE;
+   len=sizeof(c);
+   e=sysctl(mib,2,&c,&len,NULL,0);
+   if (e != 0) {
+     NLOG(NLOG_SYSINFO) /* conditional if clause for conditional syslog */
+       syslog(LOG_NOTICE, "Could not find clockrate with sysctl\n");
+       exit(1);
+   }
+   *ptickadj=c.tickadj;
+   *ptick=c.tick;
+ }
+ #else
+ 
  static void
  clock_parms(ptickadj, ptick)
       u_long *ptickadj;
***************
*** 704,707 ****
--- 736,740 ----
      printf("tick = %ld, tickadj = %ld, hz = %d\n", *ptick, *ptickadj, hz);
  #endif
  }
+ #endif
  #endif /* not VMS */

>Audit-Trail:
>Unformatted: