Subject: #219 - #223 introduced a structure name collision (#224)
Index:	new/ntp/*.c,*.h 2.11BSD

Description:
	Updates 219 thru 223 introduced a name collision with the
	'struct clockinfo'.  The sysctl(3) capability added a 
	structure of the same name to sys/time.h.

Repeat-By:
	After applying updates 219 thru 223 attempt to compile the
	programs in /usr/src/new/ntp.  Observe the errors from the
	compiler.

Fix:
	The ntp structure was renamed to 'xclockinfo'.

	Also at this time a bit of cleanup was done.  The comments in
	the changes explain what was done and the rationale behind the
	changes.  By not using 'nlist(3)' to read the kernel 'hz' variable
	the ntpd program shrank by almost 2kb.

	To apply this patch save the indicated portion to a file (/tmp/foo)
	and then:

		patch -p0 < /tmp/foo
		cd /usr/src/new/ntp
		make
		make install
		make clean

	If you are currently running 'ntpd' you will need to kill the
	old process and run /etc/ntpd.

===========================cut here====================
*** /usr/src/new/ntp/ntp.h.old	Tue Jul 25 09:41:00 1989
--- /usr/src/new/ntp/ntp.h	Fri Jan 27 17:33:52 1995
***************
*** 1,7 ****
! /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ $Revision: 3.4.1.7 $ $Date: 89/05/18 18:22:14 $ */
  
  /*
   *  $Log:	ntp.h,v $
   * Revision 3.4.1.7  89/05/18  18:22:14  louie
   * A few extra diddles in ntp.h for the reference clock feature.
   * 
--- 1,11 ----
! /* $Source: /usr/src/new/ntp/ntp.h,v $ $Revision: 3.4.1.8 $ $Date: 95/01/27 17:22:14 $ */
  
  /*
   *  $Log:	ntp.h,v $
+  * Revision 3.4.1.8  95/01/27  17:20:14  sms
+  * Fix name 'struct clockinfo' name collision with sysctl.h by renaming our
+  * structure xclockinfo.
+  *
   * Revision 3.4.1.7  89/05/18  18:22:14  louie
   * A few extra diddles in ntp.h for the reference clock feature.
   * 
***************
*** 367,373 ****
   *  program.  They are unique to this implementation and not part of the
   *  NTP specification.
   */
! struct clockinfo {
  	u_long net_address;
  	u_long my_address;
  	u_short port;
--- 371,377 ----
   *  program.  They are unique to this implementation and not part of the
   *  NTP specification.
   */
! struct xclockinfo {
  	u_long net_address;
  	u_long my_address;
  	u_short port;
*** /usr/src/new/ntp/ntp_adjust.c.old	Fri May 19 10:51:52 1989
--- /usr/src/new/ntp/ntp_adjust.c	Fri Jan 27 17:47:11 1995
***************
*** 1,5 ****
! #ifndef lint
! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntp_adjust.c,v $ $Revision: 3.4.1.4 $ $Date: 89/05/18 18:23:36 $";
  #endif
  
  /*
--- 1,5 ----
! #if !defined(lint) && defined(DOSCCS)
! static char *RCSid = "$Source: /usr/src/new/ntp/ntp_adjust.c,v $ $Revision: 3.4.1.5 $ $Date: 95/01/27 17:23:36 $";
  #endif
  
  /*
***************
*** 7,12 ****
--- 7,15 ----
   * 5. of the NTP specification.
   *
   * $Log:	ntp_adjust.c,v $
+  * Revision 3.4.1.5  95/01/27  17:23:36  sms
+  * Remove SETTICKADJ - see rational in ntpd.c
+  *
   * Revision 3.4.1.4  89/05/18  18:23:36  louie
   * A couple of changes to debug NeXT support in ntp_adjust.c
   * 
***************
*** 87,93 ****
  
  extern int doset;
  extern int debuglevel;
- extern int kern_tickadj;
  extern char *ntoa();
  extern struct sysdata sys;
  
--- 90,95 ----
***************
*** 105,114 ****
  void
  init_logical_clock()
  {
! 	if (kern_tickadj)
! 		adj_precision = kern_tickadj;
! 	else
! 		adj_precision = 1;
  	/*
  	 *  If you have the "fix" for adjtime() installed in you kernel, you'll
  	 *  have to make sure that adj_precision is set to 1 here.
--- 107,113 ----
  void
  init_logical_clock()
  {
! 	adj_precision = 1;
  	/*
  	 *  If you have the "fix" for adjtime() installed in you kernel, you'll
  	 *  have to make sure that adj_precision is set to 1 here.
*** /usr/src/new/ntp/ntpd.c.old	Sun Jul 23 18:59:16 1989
--- /usr/src/new/ntp/ntpd.c	Fri Jan 27 17:41:02 1995
***************
*** 1,9 ****
! #ifndef	lint
! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntpd.c,v $ $Revision: 3.4.1.9 $ $Date: 89/05/18 18:30:17 $";
  #endif	lint
  
  /*
   *  $Log:	ntpd.c,v $
   * Revision 3.4.1.9  89/05/18  18:30:17  louie
   * Changes in ntpd.c for reference clock support.  Also, a few diddles to
   * accomodate the NeXT computer system that has a slightly different nlist.h
--- 1,17 ----
! #if	!defined(lint) && defined(DOSCCS)
! static char *rcsid = "$Source: /usr/src/new/ntp/ntpd.c,v $ $Revision: 3.4.1.10 $ $Date: 95/01/27 17:20:17 $";
  #endif	lint
  
  /*
   *  $Log:	ntpd.c,v $
+  * Revision 3.4.1.10 95/01/27 17:20:17 sms
+  * 2.11BSD - remove SETTICKADJ from ntpd.c.  This was done for several reasons:
+  * 1) tickadj does not (and never has) existed, 2) this is an old version and
+  * not going to be ported to a system with tickadj, 3) with 'securelevel' 
+  * (see sysctl(3), init(8) and sysctl(8)) set to 1 or 2 /dev/{k}mem can not
+  * be written even by root.  If tickadj were ever added it would need an
+  * extension to sysctl(3) to have a chance of working.
+  *
   * Revision 3.4.1.9  89/05/18  18:30:17  louie
   * Changes in ntpd.c for reference clock support.  Also, a few diddles to
   * accomodate the NeXT computer system that has a slightly different nlist.h
***************
*** 106,112 ****
  #include <strings.h>
  #include <errno.h>
  #include <syslog.h>
- #include <nlist.h>
  
  #include "ntp.h"
  #include "patchlevel.h"
--- 114,119 ----
***************
*** 132,142 ****
  int debug = 0;
  #endif
  
- #ifdef	SETTICKADJ
- int	tickadj = 0;
- int	dotickadj = 0;
- #endif
- 
  #ifdef	NOSWAP
  int	noswap = 0;
  #endif
--- 139,144 ----
***************
*** 215,226 ****
  			break;
  
  		case 't':
! #ifdef	SETTICKADJ
! 			dotickadj++;
! #else
! 			fprintf(stderr, "%s: not compiled to set tickadj\n",
  				prog_name);
- #endif
  			break;
  
  		case 'n':
--- 217,224 ----
  			break;
  
  		case 't':
! 			fprintf(stderr, "%s: tickadj not supported\n",
  				prog_name);
  			break;
  
  		case 'n':
***************
*** 793,815 ****
  			if (fscanf(fp, "%d", &precision) != 1)
  				error = TRUE;
  			else sys.precision = (char) precision;
- #ifdef	SETTICKADJ
- 		} else if (strcmp(name, "tickadj") == 0) {
- 			if (fscanf(fp, "%d", &i) != 1)
- 				error = TRUE;
- 			else tickadj = i;
- 		} else if (strcmp(name, "settickadj") == 0) {
- 			if (fscanf(fp, "%s", name) != 1)
- 				error = TRUE;
- 			else {
- 				if (*name == 'Y' || *name == 'y') {
- 					dotickadj = 1;
- 				} else if (*name == 'N' || *name == 'n') {
- 					dotickadj = 0;
- 				} else
- 					dotickadj = atoi(name);
- 			}
- #endif
  #ifdef	NOSWAP
  		} else if (strcmp(name, "noswap") == 0) {
  			noswap = 1;
--- 791,796 ----
***************
*** 1040,1167 ****
  	}
  }
  
! int kern_tickadj, kern_hz, kern_tick;
  
  void
  init_kern_vars() {
! 	int kmem;
! 	static char	*memory = "/dev/kmem";
! 	static struct nlist nl[] = {
! #ifndef	NeXT
! 		{"_tickadj"},
! 		{"_hz"},
! 		{"_tick"},
! 		{""},
! #else
! 		{{"_tickadj"}},
! 		{{"_hz"}},
! 		{{"_tick"}},
! 		{{""}},
! #endif
! 	};
! 	static int *kern_vars[] = {&kern_tickadj, &kern_hz, &kern_tick};
! 	int i;
! 	kmem = open(memory, O_RDONLY);
! 	if (kmem < 0) {
! 		syslog(LOG_ERR, "Can't open %s for reading: %m", memory);
! #ifdef	DEBUG
! 		if (debug)
! 			perror(memory);
! #endif
! 		return;
! 	}
  
! 	nlist("/vmunix", nl);
! 
! 	for (i = 0; i < (sizeof(kern_vars)/sizeof(kern_vars[0])); i++) {
! 		long where;
! 
! 		if ((where = nl[i].n_value) == 0) {
! 			syslog(LOG_ERR, "Unknown kernal var %s",
! #ifdef	NeXT
! 			       nl[i].n_un.n_name
! #else
! 			       nl[i].n_name
! #endif
! 			       );
! 			continue;
  		}
! 		if (lseek(kmem, where, L_SET) == -1) {
! 			syslog(LOG_ERR, "lseek for %s fails: %m",
! #ifdef	NeXT
! 			       nl[i].n_un.n_name
! #else
! 			       nl[i].n_name
! #endif
! 			       );
! 			continue;
! 		}
! 		if (read(kmem, kern_vars[i], sizeof(int)) != sizeof(int)) {
! 			syslog(LOG_ERR, "read for %s fails: %m",
! #ifdef	NeXT
! 			       nl[i].n_un.n_name
! #else
! 			       nl[i].n_name
! #endif
! 			       );
  
- 			*kern_vars[i] = 0;
- 		}
- 	}
- #ifdef	SETTICKADJ
  	/*
- 	 *  If desired value of tickadj is not specified in the configuration
- 	 *  file, compute a "reasonable" value here, based on the assumption 
- 	 *  that we don't have to slew more than 2ms every 4 seconds.
- 	 *
- 	 *  TODO: the 500 needs to be parameterized.
- 	 */
- 	if (tickadj == 0 && kern_hz)
- 		tickadj = 500/kern_hz;
- 
- #ifdef	DEBUG
- 	if (debug) {
- 		printf("kernel vars: tickadj = %d, hz = %d, tick = %d\n",
- 		       kern_tickadj, kern_hz, kern_tick);
- 		printf("desired tickadj = %d, dotickadj = %d\n", tickadj,
- 		       dotickadj);
- 	}
- #endif
- 
- 	if (dotickadj && tickadj && (tickadj != kern_tickadj)) {
- 		close(kmem);
- 		if ((kmem = open(memory, O_RDWR)) >= 0) {
- 			if (lseek(kmem, (long)nl[0].n_value, L_SET) == -1) {
- 				syslog(LOG_ERR, "%s: lseek fails: %m", memory);
- 				close(kmem);
- 				tickadj = 0;
- 			}
- 			if (tickadj && write(kmem, &tickadj, sizeof(tickadj)) !=
- 			    sizeof(tickadj)) {
- 				syslog(LOG_ERR, "%s: tickadj set fails: %m", memory);
- #ifdef	DEBUG
- 				printf("tickadj set fails\n");
- #endif
- 				tickadj = 0;
- 			} 
- 			if (tickadj && tickadj != kern_tickadj)
- 				syslog(LOG_INFO,
- 				       "System tickadj SET to %d",
- 				       tickadj);
- #ifdef	DEBUG
- 			if (tickadj && debug)
- 				printf("System tickadj SET to %d\n",
- 				       tickadj);
- #endif
- 		} else {
- 			syslog(LOG_ERR, "Can't open %s: %m", memory);
- 			printf("Can't open %s\n", memory);
- 		}
- 	}
- #endif	/* SETTICKADJ */
- 	close(kmem);
- 
- 	/*
  	 *  If we have successfully discovered `hz' from the kernel, then we
  	 *  can set sys.precision, if it has not already been specified.  If
  	 *  no value of `hz' is available, then use default (-6)
--- 1021,1045 ----
  	}
  }
  
! int kern_hz;
  
+ #include <sys/sysctl.h>
+ 
  void
  init_kern_vars() {
! 	int size, mib[2];
! 	struct clockinfo cinfo;
  
! 	mib[0] = CTL_KERN;
! 	mib[1] = KERN_CLOCKRATE;
! 	if	(sysctl(mib, 2, &cinfo, &size, NULL, 0) < 0)
! 		{
! 		syslog(LOG_ERR, "sysctl() for kern.clockrate: %m\n");
! 		return;
  		}
! 	kern_hz = cinfo.hz;
  
  	/*
  	 *  If we have successfully discovered `hz' from the kernel, then we
  	 *  can set sys.precision, if it has not already been specified.  If
  	 *  no value of `hz' is available, then use default (-6)
***************
*** 1224,1230 ****
  
  /* number of clocks per packet */
  #define	N_NTP_PKTS \
!       ((PKTBUF_SIZE - sizeof(struct ntpinfo))/(sizeof(struct clockinfo)))
  
  query_mode(dst, ntp, sock)
  	struct sockaddr_in *dst;
--- 1102,1108 ----
  
  /* number of clocks per packet */
  #define	N_NTP_PKTS \
!       ((PKTBUF_SIZE - sizeof(struct ntpinfo))/(sizeof(struct xclockinfo)))
  
  query_mode(dst, ntp, sock)
  	struct sockaddr_in *dst;
***************
*** 1234,1240 ****
  	char packet[PKTBUF_SIZE];
  	register struct ntpinfo *nip = (struct ntpinfo *) packet;
  	register struct ntp_peer *peer = peer_list.head;
! 	struct clockinfo *cip;
  	int seq = 0;
  	int i;
  
--- 1112,1118 ----
  	char packet[PKTBUF_SIZE];
  	register struct ntpinfo *nip = (struct ntpinfo *) packet;
  	register struct ntp_peer *peer = peer_list.head;
! 	struct xclockinfo *cip;
  	int seq = 0;
  	int i;
  
***************
*** 1248,1254 ****
  		nip->npkts++;
  	nip->peers = peer_list.members;
  	nip->count = 0;
! 	cip = (struct clockinfo *)&nip[1];
  
  	while (peer != NULL) {
  		cip->net_address = peer->src.sin_addr.s_addr;
--- 1126,1132 ----
  		nip->npkts++;
  	nip->peers = peer_list.members;
  	nip->count = 0;
! 	cip = (struct xclockinfo *)&nip[1];
  
  	while (peer != NULL) {
  		cip->net_address = peer->src.sin_addr.s_addr;
***************
*** 1296,1302 ****
  			}
  			nip->type = INFO_REPLY;
  			nip->count = 0;
! 			cip = (struct clockinfo *)&nip[1];
  		}
  		peer = peer->next;
  	}
--- 1174,1180 ----
  			}
  			nip->type = INFO_REPLY;
  			nip->count = 0;
! 			cip = (struct xclockinfo *)&nip[1];
  		}
  		peer = peer->next;
  	}
*** /usr/src/new/ntp/ntpdc.c.old	Sat Jul 22 22:10:30 1989
--- /usr/src/new/ntp/ntpdc.c	Fri Jan 27 17:36:26 1995
***************
*** 1,9 ****
! #ifndef	lint
! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpdc.c,v $ $Revision: 3.4.1.7 $ $Date: 89/05/18 18:31:26 $";
  #endif
  
  /*
   * $Log:	ntpdc.c,v $
   * Revision 3.4.1.7  89/05/18  18:31:26  louie
   * A few cosmetic changes for ntpd.c
   * 
--- 1,12 ----
! #if !defined(lint) && defined(DOSCCS)
! static char *RCSid = "$Source: /usr/src/new/ntp/ntpdc.c,v $ $Revision: 3.4.1.8 $ $Date: 95/01/27 17:31:26 $";
  #endif
  
  /*
   * $Log:	ntpdc.c,v $
+  * Revision 3.4.1.8  95/01/27  17:31:26  sms
+  * Fix name clockinfo name collision with sysctl.h
+  *
   * Revision 3.4.1.7  89/05/18  18:31:26  louie
   * A few cosmetic changes for ntpd.c
   * 
***************
*** 182,188 ****
  	char *host;
  {
  	register struct ntpinfo *msg = (struct ntpinfo *) packet;
! 	register struct clockinfo *n;
  	struct sockaddr_in from;
  	int fromlen = sizeof(from);
  	int count, cc;
--- 185,191 ----
  	char *host;
  {
  	register struct ntpinfo *msg = (struct ntpinfo *) packet;
! 	register struct xclockinfo *n;
  	struct sockaddr_in from;
  	int fromlen = sizeof(from);
  	int count, cc;
***************
*** 238,244 ****
  			}
  		}
  		replies &= ~(1L << msg->seq);
! 		n = (struct clockinfo *)&msg[1];
  		for (count = msg->count; count > 0; count--) {
  			if(vflag)
  				print_verbose(n);
--- 241,247 ----
  			}
  		}
  		replies &= ~(1L << msg->seq);
! 		n = (struct xclockinfo *)&msg[1];
  		for (count = msg->count; count > 0; count--) {
  			if(vflag)
  				print_verbose(n);
***************
*** 300,306 ****
  }
  
  print_terse (n)
! 	struct clockinfo *n;
  {
  	int i;
  	double offset[PEER_SHIFT], delay[PEER_SHIFT], dsp,del,off;
--- 303,309 ----
  }
  
  print_terse (n)
! 	struct xclockinfo *n;
  {
  	int i;
  	double offset[PEER_SHIFT], delay[PEER_SHIFT], dsp,del,off;
***************
*** 346,352 ****
  }	
  
  print_verbose(n)
! 	struct clockinfo *n;
  {
  	int i;
  	struct in_addr clock_host;
--- 349,355 ----
  }	
  
  print_verbose(n)
! 	struct xclockinfo *n;
  {
  	int i;
  	struct in_addr clock_host;
*** /usr/src/new/ntp/patchlevel.h.old	Fri May 19 10:51:46 1989
--- /usr/src/new/ntp/patchlevel.h	Fri Jan 27 17:40:46 1995
***************
*** 1 ****
! #define PATCHLEVEL 13
--- 1 ----
! #define PATCHLEVEL 14
*** /VERSION.old	Sat Jan 21 22:23:48 1995
--- /VERSION	Mon Jan 30 20:45:58 1995
***************
*** 1,4 ****
! Current Patch Level: 223
  
  2.11 BSD
  ============
--- 1,4 ----
! Current Patch Level: 224
  
  2.11 BSD
  ============
