From 22a0db99a682f2e9f189978dde51ba5da9d1ec2c Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Wed, 19 Mar 2008 16:27:07 +0000 Subject: 20080319-1635 --- CHANGES | 4 ++++ appl/cmd/ip/sntp.b | 51 ++++++++++++++++++++++++--------------------------- appl/lib/names.b | 2 ++ dis/ip/sntp.dis | Bin 4530 -> 4372 bytes dis/lib/names.dis | Bin 1309 -> 1322 bytes include/version.h | 2 +- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CHANGES b/CHANGES index 29afc57c..3bc1c90a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +20080319 + ip/sntp neither read nor set the time correctly +20080311 + in appl/lib/names.b define "" as valid prefix for anything 20080304 auth/secstore uses dial module 20080210 diff --git a/appl/cmd/ip/sntp.b b/appl/cmd/ip/sntp.b index 067d857d..96df92c1 100644 --- a/appl/cmd/ip/sntp.b +++ b/appl/cmd/ip/sntp.b @@ -13,6 +13,9 @@ include "ip.m"; ip: IP; IPaddr: import ip; +include "dial.m"; + dial: Dial; + include "timers.m"; timers: Timers; Timer: import timers; @@ -60,7 +63,7 @@ ClientMode: con 3; ServerMode: con 4; Epoch: con big 86400*big (365*70 + 17); # seconds between 1 Jan 1900 and 1 Jan 1970 -Microsec: con big 100000; +Microsec: con big 1000000; server := "$ntp"; stderr: ref Sys->FD; @@ -70,6 +73,7 @@ init(nil: ref Draw->Context, args: list of string) sys = load Sys Sys->PATH; ip = load IP IP->PATH; timers = load Timers Timers->PATH; + dial = load Dial Dial->PATH; ip->init(); arg := load Arg Arg->PATH; @@ -95,8 +99,8 @@ init(nil: ref Draw->Context, args: list of string) stderr = sys->fildes(2); timers->init(100); - (ok, conn) := sys->dial(netmkaddr(server, "udp", "ntp"), nil); - if(ok < 0){ + conn := dial->dial(dial->netmkaddr(server, "udp", "ntp"), nil); + if(conn == nil){ sys->fprint(stderr, "sntp: can't dial %s: %r\n", server); raise "fail:dial"; } @@ -141,7 +145,7 @@ init(nil: ref Draw->Context, args: list of string) sys->print("%bd\n", now); if(doset){ settime("#r/rtc", now); - settime("/dev/time", now * Microsec); + settime("/dev/time", now*Microsec); } quit(nil); <-t.timeout => @@ -187,17 +191,25 @@ quit(s: string) time(): int { - fd := sys->open("#r/rtctime", Sys->OREAD); - if(fd == nil){ - fd = sys->open("/dev/time", Sys->OREAD); - if(fd == nil) - return 0; - } + n := rdn("#r/rtc"); + if(n > big 300) # ie, possibly set + return int n; + n = rdn("/dev/time"); + if(n <= big 0) + return 0; + return int(n/big Microsec); +} + +rdn(f: string): big +{ + fd := sys->open(f, Sys->OREAD); + if(fd == nil) + return big -1; b := array[128] of byte; n := sys->read(fd, b, len b); if(n <= 0) - return 0; - return int (big string b[0:n] / big 1000000); + return big 0; + return big string b[0:n]; } settime(f: string, t: big) @@ -296,18 +308,3 @@ SNTP.new(vn, mode: int): ref SNTP s.xmttime = big 0; return s; } - -netmkaddr(addr, net, svc: string): string -{ - if(net == nil) - net = "net"; - (n, nil) := sys->tokenize(addr, "!"); - if(n <= 1){ - if(svc== nil) - return sys->sprint("%s!%s", net, addr); - return sys->sprint("%s!%s!%s", net, addr, svc); - } - if(svc == nil || n > 2) - return addr; - return sys->sprint("%s!%s", addr, svc); -} diff --git a/appl/lib/names.b b/appl/lib/names.b index 8a0db807..d3a2082e 100644 --- a/appl/lib/names.b +++ b/appl/lib/names.b @@ -119,6 +119,8 @@ rooted(root: string, name: string): string isprefix(a: string, b: string): int { la := len a; + if(la == 0) + return 0; # "" isnt' a pathname while(la > 1 && a[la-1] == '/') a = a[0:--la]; lb := len b; diff --git a/dis/ip/sntp.dis b/dis/ip/sntp.dis index b25dafa1..9f040cf9 100644 Binary files a/dis/ip/sntp.dis and b/dis/ip/sntp.dis differ diff --git a/dis/lib/names.dis b/dis/lib/names.dis index 0feb7b25..934fefc8 100644 Binary files a/dis/lib/names.dis and b/dis/lib/names.dis differ diff --git a/include/version.h b/include/version.h index b50fad67..b394c298 100644 --- a/include/version.h +++ b/include/version.h @@ -1 +1 @@ -#define VERSION "Fourth Edition (20080304)" +#define VERSION "Fourth Edition (20080319)" -- cgit v1.2.3