Subject: xntpd TODO -- Apollo fixes
From: Jim Rees <[email-masked]>
To: [email-masked]
Cc: peter honeyman <[email-masked]>, [email-masked] (Bill Sommerfeld)
Date: Sat, 13 Jan 96 21:58:44 EST

I found this in your TODO list for xntp 3.4y:

  Apollo:
	- terminal affiliation
	Check whether thing are still correct in respect to breaking
	terminal affiliation - horrible stories are told in the code.
	File affected: xntpd/ntpd.c

My colleague Peter Honeyman was ribbing me for not immediately sending in a
fix.  I'm considered something of a dinosaur around here for keeping a
couple old Apollos running.

So, here are the fixes.  There were two calls to setpgrp() in main(), and
one of them was wrong (didn't have the ifdef for the different kinds of
setpgrp), so I took one out.  I put in some old Apollo calls (the proc2_$
stuff) that are no longer needed, but will make it work better on extremely
old versions of Domain/OS.

Also, I didn't at all understand this, in ntp_util.c:

  #if !defined(VMS) && !defined(apollo)
  record_loop_stats(offset, freq, poll)
  	l_fp *offset;
          s_fp freq;
          u_char poll;
  #else /* DECC compiler problem? NTPD.H doesn't match anyway! */
  record_loop_stats(l_fp *offset, s_fp freq, int poll)
  #endif

Since the prototype in the include file has an int for the third argument,
it seems to me the second declaration is correct.  So why the ifdef?

I've tested this with Domain/OS sr10.3.5, which is pretty recent, and C 6.7,
which is pretty old.  I think it will work for other versions too.

% diff -cb include/ntp_machine.h- include/ntp_machine.h
*** include/ntp_machine.h-	Tue Jul 18 12:29:20 1995
--- include/ntp_machine.h	Fri Jan 12 21:32:51 1996
***************
*** 676,681 ****
--- 676,689 ----
  #ifndef STR_SYSTEM
  #define STR_SYSTEM "UNIX/DOMAINOS"
  #endif
+ /* older versions of domain/os don't have class D */
+ #ifndef IN_CLASSD
+ #define IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
+ #define IN_CLASSD_NET		0xf0000000
+ #define IN_CLASSD_NSHIFT	28
+ #define IN_CLASSD_HOST		0xfffffff
+ #define IN_MULTICAST(i)		IN_CLASSD(i)
+ #endif
  #endif
  
  /* 
% diff -cb xntpd/ntp_io.c- xntpd/ntp_io.c
*** xntpd/ntp_io.c-	Thu Aug 10 13:08:21 1995
--- xntpd/ntp_io.c	Fri Jan 12 21:17:24 1996
***************
*** 11,17 ****
  #include <sys/param.h>
  #endif /* VMS */
  #include <sys/time.h>
! #ifndef __bsdi__
  #include <netinet/in.h>
  #endif
  #endif /* SYS_WINNT */
--- 11,17 ----
  #include <sys/param.h>
  #endif /* VMS */
  #include <sys/time.h>
! #if !defined(__bsdi__) && !defined(apollo)
  #include <netinet/in.h>
  #endif
  #endif /* SYS_WINNT */
% diff -cb xntpd/ntp_util.c- xntpd/ntp_util.c
*** xntpd/ntp_util.c-	Sun Jul  9 12:36:51 1995
--- xntpd/ntp_util.c	Fri Jan 12 21:22:31 1996
***************
*** 397,403 ****
   * time constant (log base 2)
   */
  void
! #if !defined(VMS)
  record_loop_stats(offset, freq, poll)
  	l_fp *offset;
          s_fp freq;
--- 397,403 ----
   * time constant (log base 2)
   */
  void
! #if !defined(VMS) && !defined(apollo)
  record_loop_stats(offset, freq, poll)
  	l_fp *offset;
          s_fp freq;
% diff -cb xntpd/ntpd.c- xntpd/ntpd.c
*** xntpd/ntpd.c-	Thu Aug 10 12:13:36 1995
--- xntpd/ntpd.c	Sat Jan 13 13:56:01 1996
***************
*** 34,39 ****
--- 34,43 ----
  #include <termios.h>
  #endif
  
+ #ifdef SYS_DOMAINOS
+ #include <apollo/base.h>
+ #endif /* SYS_DOMAINOS */
+ 
  #include "ntpd.h"
  #include "ntp_select.h"
  #include "ntp_io.h"
***************
*** 184,189 ****
--- 188,202 ----
  			(void) open("/", 0);
  			(void) dup2(0, 1);
  			(void) dup2(0, 2);
+ #ifdef SYS_DOMAINOS
+ 			{
+ 				uid_$t puid;
+ 				status_$t st;
+ 
+ 				proc2_$who_am_i(&puid);
+ 				proc2_$make_server(&puid, &st);
+ 			}
+ #endif /* SYS_DOMAINOS */
  #if defined(NTP_POSIX_SOURCE) || defined(HAVE_SETSID)
  #ifndef SYS_ULTRIX
  			(void) setsid();
***************
*** 191,207 ****
  			(void) setpgid(0, 0);
  #endif
  #else /* NTP_POSIX_SOURCE || HAVE_SETSID */
- #ifdef HAVE_ATT_SETPGRP
- 			(void) setpgrp();
- #else /* HAVE_ATT_SETPGRP */
- 			(void) setpgrp(0, getpid());
- #endif /* HAVE_ATT_SETPGRP */
- #ifdef SYS_DOMAINOS
- /*
-  * This breaks... the program fails to listen to any packets coming
-  * in on the UDP socket.  So how do you break terminal affiliation?
-  */
- #else /* SYS_DOMAINOS */
  			{
  				int fid;
  
--- 204,209 ----
***************
*** 211,219 ****
  						(char *) 0);
  					(void) close(fid);
  				}
  				(void) setpgrp(0, getpid());
  			}
- #endif /* SYS_DOMAINOS */
  #endif /* NTP_POSIX_SOURCE || HAVE_SETSID */
  		}
  #endif /* BSD19906 */
--- 213,224 ----
  						(char *) 0);
  					(void) close(fid);
  				}
+ #ifdef HAVE_ATT_SETPGRP
+ 				(void) setpgrp();
+ #else /* HAVE_ATT_SETPGRP */
  				(void) setpgrp(0, getpid());
+ #endif /* HAVE_ATT_SETPGRP */
  			}
  #endif /* NTP_POSIX_SOURCE || HAVE_SETSID */
  		}
  #endif /* BSD19906 */
% diff -cb xntpdc/ntpdc_ops.c- xntpdc/ntpdc_ops.c
*** xntpdc/ntpdc_ops.c-	Mon May  1 22:30:08 1995
--- xntpdc/ntpdc_ops.c	Fri Jan 12 21:43:31 1996
***************
*** 7,13 ****
  #ifndef SYS_WINNT
  #include <sys/time.h>
  #include <netdb.h>
! #ifndef __bsdi__
  #include <netinet/in.h>
  #endif
  #endif /* SYS_WINNT */
--- 7,13 ----
  #ifndef SYS_WINNT
  #include <sys/time.h>
  #include <netdb.h>
! #if !defined(__bsdi__) && !defined(apollo)
  #include <netinet/in.h>
  #endif
  #endif /* SYS_WINNT */
--
From: [email-masked] (Bill Sommerfeld)
Newsgroups: comp.sys.apollo
Subject: xntp patches for apollo SR10.2
Message-ID: <[email-masked]>
Date: 29 Mar 90 01:51:00 GMT
Organization: HP Apollo Systems Division, Chelmsford, MA.

NTP is the Network Time Protocol, a time synchronization protocol in
use on the Internet; xntp is an implementation of NTP for UNIX
systems.  This message includes patches to xntp to allow it to run on
Apollo systems running Domain/OS SR10.2 and later.

Note that xntp and xntpd are *not* supported by myself or by
HP/Apollo; use it at your own risk; however, if you do have any
problems with this software, I'm interested in hearing about them;
send a *complete* report including as much information as possible
about the problem via email at [email-masked]

The base sources to which these patches can be applied was obtained by
anonymous FTP from gw.ccie.utoronto.ca, in pub/ntp/xntp.tar.Z.  Those
interested in the details of the protocol will probably want to pick
up the Internet Request for Comments 1119 (RFC1119); these are
available from a number of places on the Internet, including by
anonymous FTP from NIC.DDN.MIL in the RFC: directory.

You may want to join an Internet mailing list about NTP; send mail to
[email-masked] to join.  Announcements of new versions of
ntp software and much other discussion happens on that list.

Those configuring clocks on the Internet should fetch pub/ntp/ntpinfo
and pub/ntp/clock.txt from louie.udel.edu for some advice.

I'm not aware of any non-Internet sites which have xntp available for
anonymous UUCP, so you're probably SOL if you're not connected to the
Internet (please don't ask me to post sources; they're over 1MB
uncompressed).

What works:

Support for both unicast and broadcast NTP has been tested with these
patches; it has been built on both 680x0 and PRISM systems.  Support
for reference clocks has not been tested, although it might work;
people with a spare radio clock are encouraged to try it out.

Known bugs:

XNTPD uses asynchronous I/O (aka SIGIO).  There is a bug in the "short
circuit" support for asynchronous UDP at SR10.2 and before; in order
to run ntpq, xntpdc, and other programs that may talk to the daemon on
the same host as the daemon, you need to either: a) turn on the lo0
("loopback") interface in /etc/rc.local and communicate with
"localhost" b) run these programs as root.

To build on an SR10.2 system, you need to do the following in the
BSD4.3 environment:

 - fetch and unpack the source tar file.
 - read the documentation and man pages in doc/*
 - apply the enclosed patches, either by hand or with "patch".
 - edit Config to include the appropriate definitions; 
    you *must* include -DNOKMEM in DEFS; you might need to use
    -DNO_SIGNED_CHAR_DECL as well depending on which version of the
    C compiler you have.
 - apply the config file to the makefiles by running "make makefiles"
 - build the system by using "make".

See the README file in the sources for additional information.

*** xntpd/ntp_io.c/1	Sun Nov  5 19:24:42 1989
--- xntpd/ntp_io.c	Fri Mar 23 15:43:38 1990
***************
*** 339,346 ****
--- 339,348 ----
  			continue;
  		if (inter_list[i].flags & INT_BCASTOPEN)
  			continue;
+ #ifndef apollo
  		inter_list[i].bfd = open_socket(&inter_list[i].bcast, 0);
  		inter_list[i].flags |= INT_BCASTOPEN;
+ #endif
  	}
  }
  
***************
*** 744,753 ****
  				n--;
  				/*
  				 * Get a buffer and read the frame.  If we
! 				 * haven't got a buffer, or this is received
! 				 * on the wild card socket, just dump the packet.
  				 */
! 				if (i == 0 || free_recvbufs == 0) {
  					char buf[RX_BUFF_SIZE];
  
  					(void) read(fd, buf, sizeof buf);
--- 746,763 ----
  				n--;
  				/*
  				 * Get a buffer and read the frame.  If we
! 				 * haven't got a buffer,
! #ifndef apollo
! 				 * or this is received
! 				 * on the wild card socket,
! #endif
! 				 * just dump the packet.
  				 */
! 				if (
! #ifndef apollo
! 				    i == 0 ||
! #endif
! 				    free_recvbufs == 0) {
  					char buf[RX_BUFF_SIZE];
  
  					(void) read(fd, buf, sizeof buf);
*** xntpd/ntp_unixclock.c/1	Wed Oct 25 22:53:05 1989
--- xntpd/ntp_unixclock.c	Fri Mar 23 00:55:06 1990
***************
*** 4,10 ****
--- 4,12 ----
   */
  
  #include <stdio.h>
+ #ifndef NOKMEM
  #include <nlist.h>
+ #endif
  #include <sys/types.h>
  #include <sys/time.h>
  #include <sys/file.h>
***************
*** 365,371 ****

  
! #ifndef NOKMEM
  /*
   * clock_parms - return the local clock tickadj and tick parameters
   *
--- 367,405 ----

  
! #ifdef NOKMEM
! /*
!  * clock_parms - return the local clock tickadj and tick parameters.
!  *
!  * Note that this version requires the correct constants to be set at
!  * compile time.
!  */
! void
! clock_parms(tickadj, tick)
! 	u_long *tickadj;
!         u_long *tick;
! {
! #ifndef HZ
! #define HZ	60
! #endif
! 
! #ifndef TICKADJ
! #define TICKADJ 668		/* correct for apollo SR10.2 ... */
! #endif
! 
! 	*tickadj = TICKADJ;
! 	*tick = 1000000L / HZ;
! #ifdef	DEBUG
! 	if (debug) {
! 		printf("NOTE: Using preset values for tick and tickadj !!\n");
! 		printf("kernel vars: tickadj = %d, tick = %d\n",
! 		       *tickadj, *tick);
! 	}
! #endif
! }
! 
!     
! #else
  /*
   * clock_parms - return the local clock tickadj and tick parameters
   *
*** xntpd/ntpd.c/1	Sat Sep 23 17:22:45 1989
--- xntpd/ntpd.c	Fri Mar 23 00:38:51 1990
***************
*** 119,124 ****
--- 119,125 ----
  				(void) ioctl(s, (u_long) TIOCNOTTY, (char *) 0);
  				(void) close(s);
  			}
+ 			(void) setpgrp(0, getpid());
  		}
  #ifdef	DEBUG
  	}