From frank@dynamical-systems.org  Fri Jan  6 00:41:46 2006
Return-Path: <frank@dynamical-systems.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id A2F7416A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  6 Jan 2006 00:41:46 +0000 (GMT)
	(envelope-from frank@dynamical-systems.org)
Received: from mout1.freenet.de (mout1.freenet.de [194.97.50.132])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C53D943D53
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  6 Jan 2006 00:41:43 +0000 (GMT)
	(envelope-from frank@dynamical-systems.org)
Received: from [194.97.55.242] (helo=mx9.freenet.de)
	by mout1.freenet.de with esmtpa (Exim 4.61)
	(envelope-from <frank@dynamical-systems.org>)
	id 1Euffq-0004mC-AM; Fri, 06 Jan 2006 01:41:42 +0100
Received: from p508e832e.dip0.t-ipconnect.de ([80.142.131.46] helo=pollux.senax.net)
	by mx9.freenet.de with esmtpsa (ID jr-relay@freenet.de) (TLSv1:AES256-SHA:256) (Exim 4.60 #3)
	id 1Euffp-00027m-Kf; Fri, 06 Jan 2006 01:41:42 +0100
Received: from pollux.senax.net (localhost.senax.net [127.0.0.1])
	by pollux.senax.net (8.13.5/8.13.5) with ESMTP id k060Oi6X002793;
	Fri, 6 Jan 2006 01:24:44 +0100 (CET)
	(envelope-from frank@dynamical-systems.org)
Received: (from root@localhost)
	by pollux.senax.net (8.13.5/8.13.5/Submit) id k060Ogbd002792;
	Fri, 6 Jan 2006 01:24:42 +0100 (CET)
	(envelope-from frank@dynamical-systems.org)
Message-Id: <200601060024.k060Ogbd002792@pollux.senax.net>
Date: Fri, 6 Jan 2006 01:24:42 +0100 (CET)
From: "Frank W. Josellis" <frank@dynamical-systems.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: josh@tcbug.org
Subject: astro/xephem - Proposal for fixing xephem's time conversion to cope with leap seconds 
X-Send-Pr-Version: 3.113
X-GNATS-Notify: josh@tcbug.org

>Number:         91368
>Category:       ports
>Synopsis:       astro/xephem - Proposal for fixing xephem's time conversion to cope with leap seconds
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 06 00:50:02 GMT 2006
>Closed-Date:    Fri Jan 06 21:39:21 GMT 2006
>Last-Modified:  Fri Jan 06 21:39:21 GMT 2006
>Originator:     Frank W. Josellis
>Release:        FreeBSD 5.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD pollux.senax.net 5.4-STABLE FreeBSD 5.4-STABLE #2: Tue Dec 20 16:37:59 CET 2005 root@pollux.senax.net:/usr/obj/usr/src/sys/POLLUX i386

>Description:
Xephem provides routines to convert between the astronomical MJD time scale
and civil date formats (UTC, local time). These conversions silently assume 
that 1 second equals 1/86400 of a day (so that, strictly speaking, MJD is
actually related to UT1 rather than UTC). Without having to think too much
about all this, everything looks fine as long as the system's zoneinfo files
were built conforming to POSIX, i.e., without support for UTC leap seconds.
If, however, the system was configured for true UTC, its idea of the current
time differs from what is displayed by xephem. Moreover, xephem's attempt to
derive the local time may fail to give the correct result and one obtains
odd TZ offset values. 

Please consider the patch below which enables consistent time conversions
even without requiring POSIX-style zoneinfo files.

NOTE 1: My patch adds the following files:
files/patch-time.c
files/patch-tools_lx200xed_Makefile
files/patch-tools_lx200xed_lx200xed.c

NOTE 2: In my patch, the idea of compiling with -D_BSD_SOURCE may look 
somewhat clumsy. The reason is that this strategy would also allow to
use the patch with glibc, so it's slightly more general than required
for a FreeBSD port.

>How-To-Repeat:
To see the effects described above, build the zoneinfo files with support
for leap seconds:

cd /usr/src/share/zoneinfo
make -DLEAPSECONDS clean all install ; make clean

and update /etc/localtime (repeat these steps without the -DLEAPSECONDS 
flag to regain POSIX-style zoneinfo files). Then run xephem and watch the 
time information in the control panel. 

>Fix:

--- xephem-3.7.1.patch begins here ---
diff -Nur xephem.BAK/Makefile xephem/Makefile
--- xephem.BAK/Makefile	Sat Dec 10 03:04:26 2005
+++ xephem/Makefile	Thu Jan  5 16:20:47 2006
@@ -54,10 +54,11 @@
 
 pre-install:
 	@${FIND} ${WRKSRC}/../.. -name Makefile.bak -type f | ${XARGS} ${RM} -f
+	@${FIND} ${WRKSRC}/tools -name "*.orig" -type f | ${XARGS} ${RM} -f
 
 do-install:
 	${INSTALL_PROGRAM} ${WRKSRC}/xephem ${PREFIX}/bin
-	${INSTALL_MAN} ${WRKSRC}/xephem.1 ${PREFIX}/man/man1 
+	${INSTALL_MAN} ${WRKSRC}/xephem.1 ${PREFIX}/man/man1
 	${INSTALL_DATA} ${WRKSRC}/XEphem.ad ${PREFIX}/lib/X11/app-defaults/XEphem
 	@${MKDIR} ${PREFIX}/lib/X11/xephem
 	${TAR} -C ${WRKSRC} -cf - auxil catalogs fifos fits gallery help lo tools \
diff -Nur xephem.BAK/files/patch-Makefile xephem/files/patch-Makefile
--- xephem.BAK/files/patch-Makefile	Sat Dec 10 03:04:26 2005
+++ xephem/files/patch-Makefile	Thu Jan  5 16:20:47 2006
@@ -1,5 +1,5 @@
---- Makefile.orig	Fri Nov 18 16:43:09 2005
-+++ Makefile	Mon Dec  5 12:58:21 2005
+--- Makefile.orig	Fri Nov 18 14:42:47 2005
++++ Makefile	Wed Jan  4 14:14:44 2006
 @@ -10,9 +10,9 @@
  # back here and compile and link all the *.c files into one executable, xephem.
  
@@ -13,15 +13,17 @@
  
  # MOTIFI is the directory containing the Xm directory of include files.
  # MOTIFL is the directory containing the libXm.a library.
-@@ -31,7 +31,7 @@
+@@ -31,8 +31,8 @@
  
  # for linux and Apple OS X
  CC = gcc
 -CLDFLAGS = -g
+-CFLAGS = $(LIBINC) $(CLDFLAGS) -O2 -Wall -I$(MOTIFI) -I/usr/X11R6/include
 +#CLDFLAGS = -g
- CFLAGS = $(LIBINC) $(CLDFLAGS) -O2 -Wall -I$(MOTIFI) -I/usr/X11R6/include
++CFLAGS = $(LIBINC) $(CLDFLAGS) -O2 -Wall -D_BSD_SOURCE -I$(MOTIFI) -I/usr/X11R6/include
  LDFLAGS = $(LIBLNK) $(CLDFLAGS) -L$(MOTIFL) -L/usr/X11R6/lib
  XLIBS = $(MOTIFL)/libXm.a -lXp -lXt -lXext -lSM -lICE -lXmu -lX11
+ LIBS = $(XLIBS) $(LIBLIB) -lm
 @@ -181,10 +181,7 @@
  libs:
  	cd ../../libastro; make
diff -Nur xephem.BAK/files/patch-time.c xephem/files/patch-time.c
--- xephem.BAK/files/patch-time.c	Thu Jan  1 01:00:00 1970
+++ xephem/files/patch-time.c	Thu Jan  5 16:20:47 2006
@@ -0,0 +1,52 @@
+--- time.c.orig	Sat Jul  9 04:11:48 2005
++++ time.c	Wed Jan  4 14:14:44 2006
+@@ -32,7 +32,8 @@
+ time_fromsys (np)
+ Now *np;
+ {
+-	time_t t;
++	time_t t, s;
++	struct tm *gm;
+ 
+ 	t = time(NULL);
+ 
+@@ -50,7 +51,22 @@
+ 	 */
+ 	mjd = (25567.5 + t/3600.0/24.0) + (tz/24.0);
+ #else
+-	mjd = 25567.5 + t/3600.0/24.0;
++	/* Get seconds since the EPOCH according to POSIX, i.e., without
++	 * UTC leap seconds. A consistent conversion MJD <-> UTC requires
++	 * here that a second be 1/86400 of a day, which, of course, is 
++	 * not identical to the SI second from the UTC time scale!
++	 */
++	gm = gmtime(&t);
++	s = gm->tm_sec 
++	  + gm->tm_min * 60 
++	  + gm->tm_hour * 3600 
++	  + gm->tm_yday * 86400 
++	  + (gm->tm_year - 70) * 31536000 
++	  + ((gm->tm_year - 69)/4) * 86400 
++	  - ((gm->tm_year - 1)/100) * 86400
++	  + ((gm->tm_year + 299)/400) * 86400;
++
++	mjd = 25567.5 + s/3600.0/24.0;
+ #endif
+ 
+ 	(void) tz_fromsys(np);
+@@ -93,10 +109,15 @@
+ 	    gmkt = (double) mktime (gtmp);
+ 
+ 	    ltmp = localtime (&t);
++
++#ifdef _BSD_SOURCE
++	    tz = -ltmp->tm_gmtoff / 3600.0;
++#else
+ 	    ltmp->tm_isdst = 0;	/* let mktime() figure out zone */
+ 	    lmkt = (double) mktime (ltmp);
+ 
+ 	    tz = (gmkt - lmkt) / 3600.0;
++#endif
+ 	    (void) strftime (tznm, sizeof(tznm)-1, "%Z", ltmp);
+ 	    return (0);
+ 	} else
diff -Nur xephem.BAK/files/patch-tools_lx200xed_Makefile xephem/files/patch-tools_lx200xed_Makefile
--- xephem.BAK/files/patch-tools_lx200xed_Makefile	Thu Jan  1 01:00:00 1970
+++ xephem/files/patch-tools_lx200xed_Makefile	Thu Jan  5 16:20:47 2006
@@ -0,0 +1,10 @@
+--- tools/lx200xed/Makefile.orig	Sun Mar 20 12:04:29 2005
++++ tools/lx200xed/Makefile	Wed Jan  4 14:49:30 2006
+@@ -1,6 +1,6 @@
+ LIBASTRO = ../../../../libastro
+ CLDFLAGS =
+-CFLAGS = -Wall -O2 $(CLDFLAGS) -I$(LIBASTRO)
++CFLAGS = -Wall -O2 -D_BSD_SOURCE $(CLDFLAGS) -I$(LIBASTRO)
+ LDFLAGS = $(CLDFLAGS) -L$(LIBASTRO)
+ CC = gcc
+ 
diff -Nur xephem.BAK/files/patch-tools_lx200xed_lx200xed.c xephem/files/patch-tools_lx200xed_lx200xed.c
--- xephem.BAK/files/patch-tools_lx200xed_lx200xed.c	Thu Jan  1 01:00:00 1970
+++ xephem/files/patch-tools_lx200xed_lx200xed.c	Thu Jan  5 16:20:47 2006
@@ -0,0 +1,56 @@
+--- tools/lx200xed/lx200xed.c.orig	Sun Mar 20 12:04:29 2005
++++ tools/lx200xed/lx200xed.c	Wed Jan  4 14:14:44 2006
+@@ -575,10 +575,12 @@
+ time_fromsys (Now *np)
+ {   
+ #if defined(__STDC__)
+-   time_t t;
++   time_t;
+ #else
+    long t;
+ #endif
++   time_t s;
++   struct tm *gm;
+ 
+    trace(6,"In time_fromsys...\n",NULL);
+    
+@@ -598,7 +600,22 @@
+     */
+    mjd = (25567.5 + t/3600.0/24.0) + (tz/24.0);
+ #else
+-   mjd = 25567.5 + t/3600.0/24.0;
++   /* Get seconds since the EPOCH according to POSIX, i.e., without
++    * UTC leap seconds. A consistent conversion MJD <-> UTC requires
++    * here that a second be 1/86400 of a day, which, of course, is 
++    * not identical to the SI second from the UTC time scale!
++    */
++   gm = gmtime(&t);
++   s = gm->tm_sec 
++     + gm->tm_min * 60 
++     + gm->tm_hour * 3600 
++     + gm->tm_yday * 86400 
++     + (gm->tm_year - 70) * 31536000 
++     + ((gm->tm_year - 69)/4) * 86400 
++     - ((gm->tm_year - 1)/100) * 86400
++     + ((gm->tm_year + 299)/400) * 86400;
++
++   mjd = 25567.5 + s/3600.0/24.0;
+ #endif
+    snprintf(szMsg,100,"TFS: %f\n",mjd);
+    trace(5,szMsg,NULL);
+@@ -637,10 +654,15 @@
+       gmkt = (double) mktime (gtmp);
+       
+       ltmp = localtime (&t);
++
++#ifdef _BSD_SOURCE
++      tz = -ltmp->tm_gmtoff / 3600.0;
++#else
+       ltmp->tm_isdst = 0;	/* let mktime() figure out zone */
+       lmkt = (double) mktime (ltmp);
+       
+       tz = (gmkt - lmkt) / 3600.0;
++#endif
+       (void) strftime (tznm, sizeof(tznm)-1, "%Z", ltmp);
+       return (0);
+    } else
--- xephem-3.7.1.patch ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Fri Jan 6 00:52:12 UTC 2006 
State-Changed-Why:  
Awaiting maintainers feedback 

http://www.freebsd.org/cgi/query-pr.cgi?pr=91368 

From: Josh Paetzel <josh@tcbug.org>
To: bug-followup@freebsd.org,
 frank@dynamical-systems.org,
 edwin@freebsd.org
Cc:  
Subject: ports/91368 xephem patch
Date: Fri, 6 Jan 2006 01:32:41 -0600

 I have passed this patch on to the xephem developers and they said 
 they will consider it.  In the meantime they do not want us to patch 
 the FreeBSD port.
 
 <quote>
 However, regardless of the validity of this patch, I ask that you not 
 include it in the freebsd ports version of
 XEphem. Our policies prohibit redistribution of modified versions of 
 XEphem other than non-functional changes required
 for proper operation on a given platform, which this is clearly 
 beyond. This policy avoids confusion amongst users
 regarding exactly what it is they are running when they run "XEphem", 
 and avoids proliferation of forked sources. Now
 and in the future, please always just use the current free version of 
 XEphem source code as posted on our web site
 when building for the freebsd port collection.
 </quote>
 
 -- 
 Thanks,
 
 Josh Paetzel

From: Edwin Groothuis <edwin@mavetju.org>
To: Josh Paetzel <josh@tcbug.org>
Cc: bug-followup@freebsd.org, frank@dynamical-systems.org
Subject: Re: ports/91368 xephem patch
Date: Fri, 6 Jan 2006 22:24:24 +1100

 On Fri, Jan 06, 2006 at 01:32:41AM -0600, Josh Paetzel wrote:
 > I have passed this patch on to the xephem developers and they said 
 > they will consider it.  In the meantime they do not want us to patch 
 > the FreeBSD port.
 
 If you want the patch in, we can add it to the port and set it to
 NO_PACKAGE which means that the compiled port doesn't show up in
 the distribution sites. That way we comply with their prerequisites
 while still are able to add these kind of things to the ports.
 
 Edwin
 
 -- 
 Edwin Groothuis      |            Personal website: http://www.mavetju.org
 edwin@mavetju.org    |          Weblog: http://weblog.barnet.com.au/edwin/

From: Josh Paetzel <josh@tcbug.org>
To: bug-followup@freebsd.org,
 frank@dynamical-systems.org,
 edwin@mavetju.org
Cc:  
Subject: ports/91368 xephem patch
Date: Fri, 6 Jan 2006 13:47:17 -0600

 <quote>However, regardless of the validity of this patch, I ask that 
 you not include it in the freebsd ports version of
 XEphem.</quote>
 
 That seems to be pretty clear to me.
 
 -- 
 Thanks,
 
 Josh Paetzel

From: "Frank W. Josellis" <frank@dynamical-systems.org>
To: bug-followup@freebsd.org
Cc: josh@tcbug.org, edwin@mavetju.org
Subject: Re: ports/91368 xephem patch
Date: Fri, 6 Jan 2006 22:26:45 +0100 (CET)

 Well, in view of the restrictive redistribution policy for xephem I do not 
 insist on the patch and I'd suggest to close this PR. Notifying the xephem 
 developers was a good idea anyway, and we'll see if they can make use of 
 it in future releases of the software.
 
 Thanks for your support,
 
 Frank Josellis
State-Changed-From-To: feedback->closed 
State-Changed-By: edwin 
State-Changed-When: Fri Jan 6 21:37:02 UTC 2006 
State-Changed-Why:  
Closed on request 

http://www.freebsd.org/cgi/query-pr.cgi?pr=91368 
>Unformatted:
