Welcome, Guest. Please login or register.

Author Topic: Amiga UNIX Y2K problem...no problem?  (Read 2240 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline FailureTopic starter

  • Lifetime Member
  • Sr. Member
  • ****
  • Join Date: Jun 2004
  • Posts: 332
    • Show only replies by Failure
    • http://awhitlock.net/
Amiga UNIX Y2K problem...no problem?
« on: January 21, 2006, 12:35:21 AM »
You can\'t spell evil without "vi"
AMIX Wiki | AmixBP
 

Offline Floid

  • Hero Member
  • *****
  • Join Date: Feb 2003
  • Posts: 918
    • Show only replies by Floid
Re: Amiga UNIX Y2K problem...no problem?
« Reply #1 on: February 10, 2006, 06:57:41 PM »
year == 78 is > 70.

Perhaps the code works with a proper RTC.
 

Offline FailureTopic starter

  • Lifetime Member
  • Sr. Member
  • ****
  • Join Date: Jun 2004
  • Posts: 332
    • Show only replies by Failure
    • http://awhitlock.net/
Re: Amiga UNIX Y2K problem...no problem?
« Reply #2 on: February 11, 2006, 03:41:10 AM »
I dunno.  For kicks I tried changing the value to 80, but it's still broken in the same way.  I'm curious about it but I'm not sure what I can do to fix it.

Not calling it at all seems to work well.  I had the machine off for a couple weeks recently, and when I booted it, it just used the date from the last time it was up.  Much better than 1978!  :-)
You can\'t spell evil without "vi"
AMIX Wiki | AmixBP
 

Offline Dalamar

  • Full Member
  • ***
  • Join Date: Dec 2003
  • Posts: 190
    • Show only replies by Dalamar
Re: Amiga UNIX Y2K problem...no problem?
« Reply #3 on: February 11, 2006, 06:03:04 AM »
I had a friend look at the code a while back.  He couldn't get it to work and he is a programmer.  He figured it was the actual clock device that had bad code behind it, not setclk.  Unfortunatley we don't have that source I don't think.  

I just cheated and put ntpdate in my startup rc.inet.  It wont deal with clock drift, but at least it gets the time right at startup.   :-)

Nice to see you are still around Failure.  I still check the wiki from time to time.
-Dal
[color=993300]\\"Stop blowing holes in my ship!!\\"[/color]
--------------------------------------------------------------
...
- A500/4000/3000
 

Offline hagar

  • Jr. Member
  • **
  • Join Date: Jul 2002
  • Posts: 97
    • Show only replies by hagar
    • http://www.df.lth.se/~hagar
Re: Amiga UNIX Y2K problem...no problem?
« Reply #4 on: February 11, 2006, 08:04:43 AM »
This might be related to the UNIX epoch.

Time in a UNIX system is measured at a 1 Hz rate, time 0 is defined as 1970-01-01.

http://en.wikipedia.org/wiki/Unix_epoch


My guess is that a realtime-clock perpahs does not save the first to digits of the year (19, 20), but something like. Since the time pre 1970 is invalid in a UNIX system, one might assume that if the real time clock is pre "70", the year is 20xx.
Beware of the Ravenous Bugblatter Beast of Traal!

http://www.svenskascenarbetaremotkonfetti.se
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Amiga UNIX Y2K problem...no problem?
« Reply #5 on: February 11, 2006, 08:47:38 AM »
The bug was in sscanf() using %02d for the year. The year is 3 digits with years 2000++ so only first two first digits were parsed (year ended up 10 instead of 106). Also various buffers had to be extended to accommodate the extra char so no buffer overflow will occur.

Now assuming /usr/bin/date can handle 3 digit date (for example: 02111032106 that is: feb 11th 10:32 1900+106 = 2006), here is a fix:

Code: [Select]

--- setclk.c-orig Sat Feb 11 02:48:57 2006
+++ setclk.c Sat Feb 11 10:41:14 2006
@@ -51,7 +51,7 @@
 
     if (!strcmp(*argv, "getclk"))
     {
- char buffer[11];
+ char buffer[12];
 
  retval = read_clock(buffer);
 
@@ -80,7 +80,7 @@
     if (argc == 1)
     {
  time_t thetime = read_from_clock_device();
- char buffer[BUFSIZ*2], tmpbuf[sizeof("MMDDhhmmYY")];
+ char buffer[BUFSIZ*2], tmpbuf[sizeof("MMDDhhmmYYY")];
 
  /*
  ** Set the system time to what the hardware thinks is correct.
@@ -138,7 +138,7 @@
 
     if (set_clock)
     {
- char buffer[11];
+ char buffer[12];
  struct tm *tm;
  time_t thetime;
 
@@ -175,7 +175,7 @@
 
     if (display_clock)
     {
- char buffer[11];
+ char buffer[12];
 
  retval = read_clock(buffer);
 
@@ -299,7 +299,7 @@
  return FALSE;
     }
 
-    if (sscanf(buffer, "%02d%02d%02d%02d%02d", &month, &days, &hours, &mins,
+    if (sscanf(buffer, "%02d%02d%02d%02d%03d", &month, &days, &hours, &mins,
         &year) != 5)
     {
  (void) fprintf(stderr, "%s: Bad date format \"%s\"\n", progname,


However, if date can't grock it (which might well be the case), /usr/bin/date itself has to be fixed aswell (or if it handles < 70 year by adding 100, the parsed date has to be adjusted with 'if (year > 99) year -= 100;').

If you find the patch above useful please feel free to use it as you wish. I hereby place it in public domain.
 

Offline FailureTopic starter

  • Lifetime Member
  • Sr. Member
  • ****
  • Join Date: Jun 2004
  • Posts: 332
    • Show only replies by Failure
    • http://awhitlock.net/
Re: Amiga UNIX Y2K problem...no problem?
« Reply #6 on: February 12, 2006, 07:45:04 PM »
@Piru:

Thanks a lot for taking a look at it! Looks like date can't handle it.  I enabled the DEBUG define in the code for extra output:
[color=0000ff]
Code: [Select]
root@motoko:~# date
Sun Feb 12 14:23:23 EST 2006
root@motoko:~# setclk
localtime (from system): 0215060979
time (to hardware): buffer=`0215060979', thetime=`0215060979'
Thu Feb 15 06:09:00 GMT 1979
root@motoko:~# ntpdate timex.peachnet.edu
Looking for host timex.peachnet.edu and service ntp
host found : ns2.usg.edu
12 Feb 14:23:43 ntpdate[195]: step time server 131.144.4.9 offset 851865265.938420 sec
root@motoko:~# date
Sun Feb 12 14:23:54 EST 2006
root@motoko:~# setclk -p
0215060979
root@motoko:~# setclk -s
localtime (from system): 02121924106
time (to hardware): buffer=`02121924106', thetime=`02121924106'
root@motoko:~# date
Sun Feb 12 14:24:12 EST 2006
root@motoko:~# setclk
date: bad conversion
[/color]
One interesting thing to note is the date calls setclk when it is used to set the time.  It apparently does this properly!
[color=0000ff]
Code: [Select]

root@motoko:~# date
Fri Feb 12 14:29:56 EST 1999
root@motoko:~# date 021214312006
localtime (from system): 02121931106
time (to hardware): buffer=`02121931106', thetime=`02121931106'
Sun Feb 12 14:31:00 EST 2006
[/color]
This suggests that if setclk.c was modified to use a 4 digit year it would work properly.  Source code for date isn't on the system.  Running setclk after setting the time this way results in "date: bad conversion".

@Dal:

I still play around with AMIX, but I've been so busy lately the site has been a bit neglected.  I'm finding 8 hours of work followed by study and homework a bit draining.  I want to finish my degree though...

One thing I want to get done is the history section of the site.  At one point I had at least a list of names of people who had worked on AMIX, and I thought I had found the website of one of them...in the shuffle though I seem to have lost most if not all of that.  I'll have to hit Google Groups again at some point.
You can\'t spell evil without "vi"
AMIX Wiki | AmixBP
 

Offline a_petri

  • Newbie
  • *
  • Join Date: Sep 2007
  • Posts: 1
    • Show only replies by a_petri
Re: Amiga UNIX Y2K problem...no problem?
« Reply #7 on: September 27, 2007, 10:15:43 PM »
Dear Failure and Piru,

I have stumbled to this topic accidentally, as I had the same problem: after a long, arduous, but finally successful fight, I could install AMIX 2.1 to my Amiga 2000, and it worked, but it reset the date on every reboot.

I investigated the problem, and I found some interesting facts:

- The setclk command is able to handle the "three-digit" year format (e.g. 107 for 2007), but not the normal four-digit year format. It seems to be an internal limitation of the RTC device driver in the kernel (or the RTC chip itself).

- The date command is able to handle the four-digit year format, but not the three-digit format.

- The two commands call each other in a tricky way: setclk without arguments call date with an argument decoded from reading the RTC, and date with a single date argument calls setclk with the -s argument.

Therefore I tried to modify the argument passed to the date command in setclk.c to the four-digit year format.

My patch is the following (against Piru's version published here):

*** setclk.c.piru    Feb 11 10:41:14 2006
--- setclk.c      Thu Sep 27 02:56:26 2007
**************
*** 81,87 ****
--- 81,87 ----
      if (argc == 1)
      {
        time_t thetime = read_from_clock_device();
-       char buffer[BUFSIZ*2], tmpbuf[sizeof("MMDDhhmmYYY")];
+       char buffer[BUFSIZ*2], tmpbuf[sizeof("MMDDhhmmYYYY")];
 
        /*
        ** Set the system time to what the hardware thinks is correct.
***************
*** 96,101 ****
--- 96,109 ----
        }
 
        convert_time(thetime, tmpbuf);
+       if (tmpbuf[8] == '1')
+       {
+           tmpbuf[12] = tmpbuf[11];
+           tmpbuf[11] = tmpbuf[10];
+           tmpbuf[10] = tmpbuf[9];
+           tmpbuf[9] = '0';
+           tmpbuf[8] = '2';
+       }
        sprintf(buffer, "%s /usr/bin/date %s", bexleyTZ, tmpbuf);
        system(buffer);


With this patch, the compiled setclk binary seems to work correctly with both pre-Y2K and post-Y2K dates.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Amiga UNIX Y2K problem...no problem?
« Reply #8 on: September 27, 2007, 10:47:38 PM »
Cool :-)
 

Offline FailureTopic starter

  • Lifetime Member
  • Sr. Member
  • ****
  • Join Date: Jun 2004
  • Posts: 332
    • Show only replies by Failure
    • http://awhitlock.net/
Re: Amiga UNIX Y2K problem...no problem?
« Reply #9 on: April 05, 2008, 07:15:23 PM »
I had tried this patch a while ago, works great!  I'm having trouble putting the binary on the wiki, still having MySQL problems I have to correct whenever I try something new...but in the meantime the file can be fetched from the Amix box direct:

http://failsure.net:8085/root/sbin/setclk

Thanks for the efforts to fix this, really cool to boot and have the right time without use of NTP!
You can\'t spell evil without "vi"
AMIX Wiki | AmixBP