Daylight Savings Time fix: binary patcher program for the UNIX PC

Lenny Tropiano lenny at icus.islp.ny.us
Fri Mar 31 12:09:23 AEST 1989


It should be self explanatory, if not read the "README" file ...

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile README dstconvert.c
# Wrapped by lenny at icus on Thu Mar 30 21:06:51 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(541 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile to compile dstconvert.c  (Daylight Savings file format convert)
X# By Lenny Tropiano
X# (c)1989 ICUS Software Systems UUCP:  ...icus!lenny -or- lenny at icus.islp.ny.us
X#
XCFLAGS=-v -O
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
XDEST=/usr/lbin/
X#
Xdstconvert:  dstconvert.o
X	@echo "Loading ..."
X	$(LD) $(LDFLAGS) -o dstconvert dstconvert.o $(LIBS) 
X#
Xinstall: dstconvert /usr/lbin
X	cp dstconvert ${DEST}
X	chown root ${DEST}/dstconvert
X	chgrp bin  ${DEST}/dstconvert
X	chmod 4755 ${DEST}/dstconvert
X#
Xclean:
X	rm -f dstconvert *.o core
END_OF_Makefile
if test 541 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(3390 characters\)
sed "s/^X//" >README <<'END_OF_README'
X-------------------------------------------------------
XDaylight Savings Time file convert program (dstconvert)
X-------------------------------------------------------
X
XBeing it's that time of the year again (how time flys!), this Sunday, April 2nd,
Xmost of the United States will change their clocks one hour ahead to compensate
Xfor daylight savings time.  It used to be the last Sunday, but now it's
Xthe first Sunday of April.   Being the UNIX pc is lagging behind with operating
Xsystem versions, the ctime(3C) function still thinks the clock should be changed
Xon the last Sunday.  This program will binary patch any executable that has
X*not* been compiled with shared libraries.   You should run dstconvert on:
X	/lib/shlib (the shared library)
X	ctime.o (extracted from /lib/libc.a)
X	/etc/ph (if you're running 3.51 fixdisks, since ph isn't compiled with
X		 shared libraries)
X	/etc/smgr
X	...and any other binary that might use ctime(3C) and isn't compiled
X	   with shared libraries.
X
XYou then should reboot, for the /lib/shlib to take effect.  Note that dstconvert
Xisn't destructive on the original file, you should run it like so:
X
X$ dstconvert /lib/shlib /tmp/shlib
X...
XIt is up to you to save the original, if you care to (this is suggested!)
X$ cp /lib/shlib /lib/shlib.old
X$ cp /tmp/shlib /lib/shlib
X$ rm /tmp/shlib
X
XThis is how we found out about the binary patch (a year ago, almost to the day).
X
X|From: jts at scbhq.UUCP (ulim=5000J.Sandidge)
X|Newsgroups: unix-pc.general,comp.sys.att
X|Subject: Re: What to do for Daylight Savings time? It's early this year!
X|Message-ID: <582 at scbhq.UUCP>
X|Date: 3 Apr 88 17:42:01 GMT
X|References: <329 at icus.UUCP> <65 at kenobi.UUCP> <66 at kenobi.UUCP>
X|Reply-To: jts at scbhq.UUCP (J.Sandidge)
X|Distribution: usa
X|Organization: South Central Bell
X|Lines: 53
X|
X|
X|For those who want to change the day that Daylight Savings time begins
X|in the UNIX-PC and have the means to do so, the following information
X|is provided:
X|
X|1.	Be advised you are on your on!  Any errors in patching object
X|	code may result in a reload of UNIX from floppy disk.
X|
X|2.	You must have a way to patch object files, (sdb, adb or other).
X|
X|3.	Extract ctime.o from /lib/libc.a.
X|
X|4.	Find the address of this sequence of hex bytes:
X|
X|	0x76 0x77 0x28 0x3c 0x00 0x00 0x01 0x2f
X|
X|	0x76 0x77		moveq.l &77,%d3
X|	0x28 0x3c 0x0000012f	mov.l	&12f,%d4
X|
X|	0x77 or 119 decimal is the earliest day of the year of the last
X|	Sunday in April and 0x012f or 303 decimal is the earliest day
X|	of the last Sunday in October.
X|
X|5.	Change the 0x77 to 0x60.
X|
X|	0x60 or 96 decimal is the earliest day of the year of the first
X|	Sunday in April.
X|
X|6.	Replace the patched ctime.o in the libc.a archive.
X|
X|7.	Patch /lib/shlib using steps 4 and 5 above.
X|
X|8.	After a reboot, all programs that use the shared libraries
X|	will have the DST fix.
X|
X|9.	However, there are several program which used libc.a and
X|	have to be patched using steps 4 and 5.
X|
X|	The time on the top of the UNIX-PC screen will not reflect
X|	the correct time until /etc/smgr is patched and the
X|	system is again rebooted.
X|
X|10.	By using the 'file' command on other object files that reference
X|	the time of day, one can tell if they were compiled using the
X|	shared library.
X|
X|
X|I have made these patches and have not experenced any problems
X|from them YET.
X|
X|Jere Sandidge
X|Birmingham, AL
X|{ihnp4 | gatech!sbmsg1}!scbhq!jts
X|
END_OF_README
if test 3390 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f dstconvert.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"dstconvert.c\"
else
echo shar: Extracting \"dstconvert.c\" \(4891 characters\)
sed "s/^X//" >dstconvert.c <<'END_OF_dstconvert.c'
X/************************************************************************\
X**                                                                      **
X** Program name:    dstconvert.c (Convert UNIX PC binaries to new DST)  **
X** Programmer:      Lenny Tropiano                                      **
X** E-Mail address:  ...!icus!lenny -or- lenny at icus.islp.ny.us           **
X** Organization:    ICUS Software Systems     (c)1989                   **
X** Date:            March 30, 1989                                      **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Program use:  This is to change the code in the ctime(3C) routine    **
X**               so that for the comparision to check to see if the     **
X**               daylight savings time is the LAST Sunday of April      **
X**               to be changed to the FIRST Sunday of April.  This is   **
X**               as of 1988, when this was officially moved.            **
X**                                                                      **
X**               Program should be run on mc68k binaries that HAVEN'T   **
X**               been compiled with the shared libaries, that are known **
X**               to have a call time ctime(3C), as well as the shared   **
X**               library, /lib/shlib.                                   **
X**                                                                      **
X**************************************************************************
X** Thanks to Gil for his infinite wisdom in debugging algorithms, and   **
X** making this harder :-) than it should have been...                   **
X**************************************************************************
X** Permission is granted to distribute this program by any means as     **
X** long as credit is given for my work.     I would also like to see    **
X** any modifications or enhancements to this program.                   **
X\************************************************************************/
X
X#include <stdio.h>
X
Xchar	buffer[BUFSIZ];		/* big buffer */
Xchar	*progname;		/* program name */
X
X#undef TRUE
X#define TRUE		1
X#define	MAGICNUM	0522	/* magic number of a mc68k binary for UNIX pc */
X#define	SHAREDLIB	04	/* magic number of a shared library binary */
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X	char	*infile, 
X		*outfile;
X	FILE	*infp,
X		*outfp,
X		*fopen();
X	int	convert_dst(), changed_flag;
X
X	progname = argv[0];
X
X	if (argc != 3) {
X		fprintf(stderr, "Usage: %s Old_Binary New_Binary\n",
X			progname);
X		exit(1);
X	}
X
X	infile = argv[1];	/* filename to convert */
X	outfile = argv[2];	/* filename to save converted file to */
X
X	if ((infp = fopen(infile,"r")) == NULL) {
X		fprintf(stderr,"%s: cannot open %s for read\n",
X			progname, infile);
X		perror(progname);
X		exit(1);
X	}
X
X	check_magic_number(infp);
X
X	if ((outfp = fopen(outfile,"w")) == NULL) {
X		fprintf(stderr,"%s: cannot open %s for write\n",
X			progname, outfile);
X		perror(progname);
X		exit(1);
X	}
X
X	changed_flag = convert_dst(infp, outfp);
X	if (changed_flag == 1) {
X		printf("%s: converted to new daylight savings file format.\n",
X			progname);
X	} else if (changed_flag == -1) {
X		fprintf(stderr,"%s: file already converted to new daylight savings file format.\n",
X			progname);
X		fclose(outfp);
X		unlink(outfile);
X		exit(1);
X	} else {
X		fprintf(stderr,"%s: binary pattern not found to convert.\n",
X			progname);
X		fclose(outfp);
X		unlink(outfile);
X		exit(1);
X	}
X
X	fclose(infp);
X	fclose(outfp);
X
X	exit(0);
X
X}
X
Xcheck_magic_number(fp)
XFILE *fp;
X{
X	short	magic;				/* magic number on file */
X
X	/* read the first two bytes, which contains the magic number */
X
X	fread(&magic, sizeof(magic),1,fp);
X	if (magic != MAGICNUM) {
X		fprintf(stderr,"%s: not a binary file\n", progname);
X		exit(1);
X	}
X
X	/*
X	 * read the next two bytes, which contains if the binary is compiled
X	 * with shared libaries or not. 
X	 */
X
X	fread(&magic, sizeof(magic),1,fp);
X	if (magic == SHAREDLIB) {
X		fprintf(stderr,"%s: binary is compiled with shared libraries\n",
X			progname);
X		exit(1);
X	}
X
X	rewind(fp);
X
X}
X
Xint convert_dst(infp, outfp)
XFILE *infp, *outfp;
X{
X	int fgetc(), ch1, ch2, ch3, changed_flag;
X	long offset;
X	
X	changed_flag = 0;
X	ch1 = fgetc(infp);
X	ch2 = fgetc(infp);
X	ch3 = fgetc(infp);
X	while (TRUE) {
X		if (ch1 == EOF || ch2 == EOF || ch3 == EOF) {
X			if (ch1 != EOF) 
X				fputc(ch1, outfp);
X			if (ch2 != EOF) 
X				fputc(ch2, outfp);
X			if (ch3 != EOF) 
X				fputc(ch3, outfp);
X			return changed_flag;
X		} else {
X			if (ch1 == 0x76 && ch2 == 0x77 && ch3 == 0x28) {
X				ch2 = 0x60;
X				changed_flag = 1;
X			} else if (ch1 == 0x76 && ch2 == 0x60 && ch3 == 0x28)
X				changed_flag = -1;
X			fputc(ch1, outfp);
X			ch1 = ch2;
X			ch2 = ch3;
X			ch3 = fgetc(infp);
X		}
X	}
X}
END_OF_dstconvert.c
if test 4891 -ne `wc -c <dstconvert.c`; then
    echo shar: \"dstconvert.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
Lenny Tropiano             ICUS Software Systems         [w] +1 (516) 582-5525
lenny at icus.islp.ny.us      Telex; 154232428 ICUS         [h] +1 (516) 968-8576
{talcott,decuac,boulder,hombre,pacbell,sbcs}!icus!lenny  attmail!icus!lenny
        ICUS Software Systems -- PO Box 1; Islip Terrace, NY  11752



More information about the Unix-pc.sources mailing list