sync with nix boot Reference: /n/atom/patch/applied/9bootsync Date: Thu Apr 17 22:30:56 CES 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/boot/aux.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/aux.c Thu Apr 17 22:30:56 2014 @@ -2,57 +2,6 @@ #include #include <../boot/boot.h> -/* -int -plumb(char *dir, char *dest, int *efd, char *here) -{ - char buf[128]; - char name[128]; - int n; - - sprint(name, "%s/clone", dir); - efd[0] = open(name, ORDWR); - if(efd[0] < 0) - return -1; - n = read(efd[0], buf, sizeof(buf)-1); - if(n < 0){ - close(efd[0]); - return -1; - } - buf[n] = 0; - sprint(name, "%s/%s/data", dir, buf); - if(here){ - sprint(buf, "announce %s", here); - if(sendmsg(efd[0], buf) < 0){ - close(efd[0]); - return -1; - } - } - sprint(buf, "connect %s", dest); - if(sendmsg(efd[0], buf) < 0){ - close(efd[0]); - return -1; - } - efd[1] = open(name, ORDWR); - if(efd[1] < 0){ - close(efd[0]); - return -1; - } - return efd[1]; -} - */ - -int -sendmsg(int fd, char *msg) -{ - int n; - - n = strlen(msg); - if(write(fd, msg, n) != n) - return -1; - return 0; -} - void warning(char *s) { @@ -160,20 +109,22 @@ if(len >= sizeof buf) len = sizeof(buf)-1; - if(cpuflag){ + if(cpuflag && *def != 0){ notify(catchint); alarm(15*1000); } print("%s[%s]: ", prompt, *def ? def : "no default"); memset(buf, 0, sizeof buf); n = read(0, buf, len); - if(cpuflag){ + if(cpuflag && *def != 0){ alarm(0); notify(0); } - if(n < 0) + if(n < 0){ + print("\n"); return 1; + } if(n > 1){ buf[n-1] = 0; strcpy(def, buf); --- /sys/src/9/boot/boot.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/boot.c Thu Apr 17 22:30:56 2014 @@ -15,7 +15,6 @@ char *bargv[Nbarg]; int bargc; -static void swapproc(void); static Method *rootserver(char*); static void usbinit(void); static void kbmap(void); @@ -107,6 +106,7 @@ /* * connect to the root file system */ + print("connect..."); fd = (*mp->connect)(); if(fd < 0) fatal("can't connect to file server"); @@ -166,7 +166,6 @@ settime(islocal, afd, rsp); if(afd > 0) close(afd); -//// swapproc(); cmd = getenv("init"); if(cmd == nil){ @@ -268,19 +267,26 @@ return mp; } +/* debugging: remove */ static void -swapproc(void) +dumpusbdrives(void) { - int fd; + char *s; + int fd, i, n; + Dir *d, *dbuf; - fd = open("#c/swap", OWRITE); - if(fd < 0){ - warning("opening #c/swap"); - return; + fd = open("/dev", OREAD); + while((n = dirread(fd, &dbuf)) > 0){ + for(i = 0; i < n; i++){ + d = dbuf+i; + s = d->name; + if(s[0] == 's' && s[1] == 'd' && (s[2] == 'u' || s[2] == 'U')) + print("usbdrive %s\n", s); + } + free(dbuf); } - if(write(fd, "start", 5) <= 0) - warning("starting swap kproc"); close(fd); + sleep(20*1000); } static void @@ -302,24 +308,34 @@ fprint(2, "usbbootdrive: open #S/sdctl: %r\n"); return; } - if(fprint(fd, "config switch on spec u type loop/%s\n", usbdrv) == -1) + if(fprint(fd, "config switch on spec u type loop/%s\n", usbdrv) == -1){ fprint(2, "usbbootdrive: loopback: %r\n"); + dumpusbdrives(); + } close(fd); } static void usbinit(void) { - char *s; + char *s, *t; static char usbd[] = "/boot/usbd"; if(access("#u/usb/ctl", 0) >= 0 && bind("#u", "/dev", MAFTER) >= 0 && access(usbd, AEXIST) >= 0){ - run(usbd, "-m", "/dev", nil); + run(0, usbd, "-m", "/dev", nil); /* may fail if no hubs */ s = getenv("drive0"); + t = getenv("bootargs"); + if(t == nil) + t = getenv("nobootprompt"); if(s != nil && strstr(s, " usb=") != nil) usbbootdrive(); + else if(t != nil && strstr(t, "#S/sdu") != nil){ + print("warning: usb boot with drive0 %s but boot %s\n", s, t); + usbbootdrive(); + } free(s); + free(t); } } @@ -335,7 +351,7 @@ return; if(bind("#κ", "/dev", MAFTER) < 0){ warning("can't bind #κ"); - return; +// return; } in = open(f, OREAD); --- /sys/src/9/boot/boot.h Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/boot.h Thu Apr 17 22:30:56 2014 @@ -21,9 +21,7 @@ extern int fflag; extern int kflag; extern Method method[]; -extern void (*pword)(int, Method*); extern char sys[]; -extern uchar hostkey[]; extern uchar statbuf[Statsz]; extern int bargc; extern char *bargv[Nbarg]; @@ -36,11 +34,8 @@ extern void getpasswd(char*, int); extern void key(int, Method*); extern int outin(char*, char*, int); -extern int plumb(char*, char*, int*, char*); extern int readfile(char*, char*, int); -extern long readn(int, void*, long); -extern void run(char *file, ...); -extern int sendmsg(int, char*); +extern void run(int, char*, ...); extern void setenv(char*, char*); extern void settime(int, int, char*); extern void srvcreate(char*, int); --- /sys/src/9/boot/bootauth.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/bootauth.c Thu Apr 17 22:30:56 2014 @@ -10,8 +10,7 @@ void authentication(int cpuflag) { - char *s; - char *argv[16], **av; + char *s, *argv[16], **av; int ac; if(access("/boot/factotum", AEXEC) < 0){ --- /sys/src/9/boot/bootip.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/bootip.c Thu Apr 17 22:30:56 2014 @@ -17,8 +17,7 @@ { Waitmsg *w; int argc, pid; - char **arg, **argv, buf[32], *p; - char buf1[32]; + char **arg, **argv, buf[32], buf1[32], *p; fmtinstall('I', eipfmt); fmtinstall('M', eipfmt); @@ -30,6 +29,7 @@ memmove(arg, bargv, bargc * sizeof(char*)); arg[bargc] = 0; + print("ipconfig..."); argc = bargc; argv = arg; strcpy(mpoint, "/net"); @@ -62,7 +62,7 @@ /* let ipconfig configure the ip interface */ switch(pid = fork()){ case -1: - fatal("configuring ip: %r"); + fatal("fork configuring ip: %r"); case 0: exec("/boot/ipconfig", arg); fatal("execing /ipconfig"); --- /sys/src/9/boot/getpasswd.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/getpasswd.c Thu Apr 17 22:30:56 2014 @@ -12,7 +12,7 @@ if(fd < 0) fatal("can't open consctl; please reboot"); write(fd, "rawon", 5); - Prompt: +Prompt: print("password: "); n = 0; for(;;){ --- /sys/src/9/boot/local.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/local.c Thu Apr 17 22:30:56 2014 @@ -118,7 +118,7 @@ } void -run(char *file, ...) +run(int must, char *file, ...) { int i, pid; @@ -131,7 +131,7 @@ default: while ((i = waitpid()) != pid && i != -1) ; - if(i == -1) + if(must && i == -1) fatal(smprint("wait failed running %s", file)); } } @@ -212,7 +212,7 @@ f[2] = "tcp!127.1!8000"; } configloopback(); - run("/boot/venti", "-c", f[0], "-a", f[1], "-h", f[2], nil); + run(1, "/boot/venti", "-c", f[0], "-a", f[1], "-h", f[2], nil); /* * If the announce address is tcp!*!foo, then set * $venti to tcp!127.1!foo instead, which is actually dialable. @@ -233,7 +233,7 @@ /* start fossil */ print("fossil(%s)...", partition); - run("/boot/fossil", "-f", partition, "-c", "srv -A fboot", "-c", "srv -p fscons", nil); + run(1, "/boot/fossil", "-f", partition, "-c", "srv -A fboot", "-c", "srv -p fscons", nil); fd = open("#s/fboot", ORDWR); if(fd < 0){ print("open #s/fboot: %r\n"); --- /sys/src/9/boot/settime.c Thu Apr 17 22:30:56 2014 +++ /sys/src/9/boot/settime.c Thu Apr 17 22:30:56 2014 @@ -4,7 +4,7 @@ #include #include "../boot/boot.h" -static long lusertime(char*); +static long lusertime(char*, int); char *timeserver = "#s/boot"; @@ -12,7 +12,7 @@ settime(int islocal, int afd, char *rp) { int n, f; - Dir dir[2]; + Dir *dir; char timebuf[64]; static int timeset; @@ -33,7 +33,7 @@ }else do{ strcpy(timebuf, "yymmddhhmm[ss]"); outin("\ndate/time ", timebuf, sizeof(timebuf)); - }while((timeset=lusertime(timebuf)) <= 0); + }while((timeset=lusertime(timebuf, sizeof timebuf)) <= 0); } if(timeset == 0){ /* @@ -48,10 +48,10 @@ return; } close(f); - if(stat("/tmp", statbuf, sizeof statbuf) < 0) + if((dir = dirstat("/tmp")) == nil) fatal("stat"); - convM2D(statbuf, sizeof statbuf, &dir[0], (char*)&dir[1]); - sprint(timebuf, "%ld", dir[0].atime); + snprint(timebuf, sizeof timebuf, "%ld", dir->atime); + free(dir); unmount(0, "/tmp"); } @@ -105,7 +105,7 @@ * compute seconds since Jan 1 1970 */ static long -lusertime(char *argbuf) +lusertime(char *argbuf, int bufsz) { char *buf; ulong secs; @@ -145,6 +145,6 @@ if(*buf) secs += g2(&buf); - sprint(argbuf, "%ld", secs); + snprint(argbuf, bufsz, "%ld", secs); return secs; }