History

reduce error verbosity, hang when panicing in graphics mode

cinap_lenrek committed 10 years ago

Commit 6ffcc161 parent 50746b19 files · +99 −194Browse files

Unified · Split

9 files
  1. cpu.c +45 −63
  2. include/user.h +1 −0
  3. kern/Makefile +0 −1
  4. kern/devcons.c +5 −93
  5. kern/fns.h +0 −1
  6. kern/sysproc.c +0 −32
  7. libc/Makefile +1 −0
  8. libc/atexit.c +46 −0
  9. libc/sysfatal.c +1 −4
cpu.c+45−63
@@ -13,7 +13,6 @@ · 12 unmodified lines
1313
1414 #define MaxStr 128
1515
16−static void fatal(int, char*, ...);
1716 static void usage(void);
1817 static void writestr(int, char*, char*, int);
1918 static int readstr(int, char*, int);
@@ -37,10 +36,10 @@ static int p9authtls(int); · 17 unmodified lines
3736 char *authserver;
3837 char *secstore;
3938
40−void
41−exits(char *s)
39+static void
40+ending(void)
4241 {
43− exit(1);
42+ panic("ending");
4443 }
4544
4645 void
@@ -98,7 +97,7 @@ startaan(char *host, int fd) · 51 unmodified lines
9897 int n;
9998
10099 if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0)
101− fatal(1, "sending aan script");
100+ sysfatal("sending aan script: %r");
102101 n = read(fd, buf, sizeof(buf)-1);
103102 close(fd);
104103
@@ -139,17 +138,17 @@ rcpu(char *host) · 34 unmodified lines
139138 if(aanfilter){
140139 fd = startaan(host, fd);
141140 if(fd < 0)
142− fatal(1, "startaan");
141+ sysfatal("startaan: %r");
143142 fd = p9authtls(fd);
144143 }
145144 memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */
146145
147146 if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0)
148− fatal(1, "sending script");
147+ sysfatal("sending script: %r");
149148
150149 /* Begin serving the namespace */
151150 exportfs(fd);
152− fatal(1, "starting exportfs");
151+ sysfatal("starting exportfs: %r");
153152 }
154153
155154 void
@@ -169,9 +168,9 @@ ncpu(char *host) · 13 unmodified lines
169168 }
170169 writestr(fd, buf, "negotiating authentication method", 0);
171170 if(readstr(fd, buf, sizeof buf) < 0)
172− fatal(1, "can't negotiate authentication method: %r");
171+ sysfatal("can't negotiate authentication method: %r");
173172 if(*buf)
174− fatal(1, "%s", buf);
173+ sysfatal("%s", buf);
175174
176175 /* authenticate and encrypt the channel */
177176 fd = p9authssl(fd);
@@ -187,14 +186,14 @@ ncpu(char *host) · 9 unmodified lines
187186 * of /mnt/term
188187 */
189188 if(readstr(fd, buf, sizeof(buf)) < 0)
190− fatal(1, "waiting for FS: %r");
189+ sysfatal("waiting for FS: %r");
191190 if(strncmp("FS", buf, 2) != 0) {
192191 print("remote cpu: %s", buf);
193192 exits(buf);
194193 }
195194
196195 if(readstr(fd, buf, sizeof(buf)) < 0)
197− fatal(1, "waiting for remote export: %r");
196+ sysfatal("waiting for remote export: %r");
198197 if(strcmp(buf, "/") != 0){
199198 print("remote cpu: %s", buf);
200199 exits(buf);
@@ -203,7 +202,7 @@ ncpu(char *host) · 2 unmodified lines
203202
204203 /* Begin serving the gnot namespace */
205204 exportfs(fd);
206− fatal(1, "starting exportfs");
205+ sysfatal("starting exportfs: %r");
207206 }
208207
209208 void
@@ -267,19 +266,23 @@ cpumain(int argc, char **argv) · 57 unmodified lines
267266 panic("bind #i: %r");
268267 if(bind("#m", "/dev", MBEFORE) < 0)
269268 panic("bind #m: %r");
269+ atexit(ending);
270270 }
271271
272272 if(bind("/root", "/", MAFTER) < 0)
273273 panic("bind /root: %r");
274274
275275 if(host == nil)
276− host = readcons("cpu", "cpu", 0);
277−
278− if(user == nil)
279− user = readcons("user", "glenda", 0);
276+ if((host = readcons("cpu", "cpu", 0)) == nil)
277+ sysfatal("user terminated input");
280278
281279 if(authserver == nil)
282− authserver = readcons("auth", host, 0);
280+ if((authserver = readcons("auth", host, 0)) == nil)
281+ sysfatal("user terminated input");
282+
283+ if(user == nil)
284+ if((user = readcons("user", "glenda", 0)) == nil)
285+ sysfatal("user terminated input");
283286
284287 if(mountfactotum() < 0){
285288 if(secstore == nil)
@@ -299,27 +302,7 @@ cpumain(int argc, char **argv) · 13 unmodified lines
299302
300303 ncpu(host);
301304
302− fatal(1, "can't dial %s: %r", host);
303−}
304−
305−void
306−fatal(int syserr, char *fmt, ...)
307−{
308− Fmt f;
309− char *str;
310− va_list arg;
311−
312− fmtstrinit(&f);
313− fmtprint(&f, "cpu: ");
314− va_start(arg, fmt);
315− fmtvprint(&f, fmt, arg);
316− va_end(arg);
317− if(syserr)
318− fmtprint(&f, ": %r");
319− fmtprint(&f, "\n");
320− str = fmtstrflush(&f);
321− write(2, str, strlen(str));
322− exits(str);
305+ sysfatal("can't dial %s: %r", host);
323306 }
324307
325308 void
@@ -330,7 +313,7 @@ writestr(int fd, char *str, char *thing, int ignore) · 4 unmodified lines
330313 l = strlen(str);
331314 n = write(fd, str, l+1);
332315 if(!ignore && n < 0)
333− fatal(1, "writing network: %s", thing);
316+ sysfatal("writing network: %s: %r", thing);
334317 }
335318
336319 int
@@ -372,13 +355,13 @@ p9authssl(int fd) · 35 unmodified lines
372355 ai = p9any(fd);
373356 memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */
374357 if(ai == nil)
375− fatal(1, "can't authenticate");
358+ sysfatal("can't authenticate: %r");
376359
377360 if(ealgs == nil)
378361 return fd;
379362
380363 if(ai->nsecret < 8){
381− fatal(1, "p9authssl: secret too small");
364+ sysfatal("p9authssl: secret too small");
382365 return -1;
383366 }
384367 memmove(key+4, ai->secret, 8);
@@ -386,11 +369,11 @@ p9authssl(int fd) · 1 unmodified line
386369 /* exchange random numbers */
387370 genrandom(key, 4);
388371 if(write(fd, key, 4) != 4){
389− fatal(1, "p9authssl: write random: %r");
372+ sysfatal("p9authssl: write random: %r");
390373 return -1;
391374 }
392375 if(readn(fd, key+12, 4) != 4){
393− fatal(1, "p9authssl: read random: %r");
376+ sysfatal("p9authssl: read random: %r");
394377 return -1;
395378 }
396379
@@ -402,7 +385,7 @@ p9authssl(int fd) · 5 unmodified lines
402385 /* set up encryption */
403386 fd = pushssl(fd, ealgs, fromclientsecret, fromserversecret, nil);
404387 if(fd < 0)
405− fatal(1, "p9authssl: pushssl: %r");
388+ sysfatal("p9authssl: pushssl: %r");
406389
407390 return fd;
408391 }
@@ -418,7 +401,7 @@ p9authtls(int fd) · 9 unmodified lines
418401
419402 ai = p9any(fd);
420403 if(ai == nil)
421− fatal(1, "can't authenticate");
404+ sysfatal("can't authenticate: %r");
422405
423406 conn = mallocz(sizeof(TLSconn), 1);
424407 conn->pskID = "p9secret";
@@ -427,7 +410,7 @@ p9authtls(int fd) · 2 unmodified lines
427410
428411 fd = tlsClient(fd, conn);
429412 if(fd < 0)
430− fatal(1, "tlsClient");
413+ sysfatal("tlsClient: %r");
431414
432415 auth_freeAI(ai);
433416 free(conn->sessionID);
@@ -627,7 +610,7 @@ p9any(int fd) · 193 unmodified lines
627610 werrstr("");
628611
629612 if(readstr(fd, buf, sizeof buf) < 0)
630− fatal(1, "cannot read p9any negotiation");
613+ sysfatal("cannot read p9any negotiation: %r");
631614 bbuf = buf;
632615 v2 = 0;
633616 if(strncmp(buf, "v.2 ", 4) == 0){
@@ -640,7 +623,7 @@ p9any(int fd) · 6 unmodified lines
640623 if((p = strchr(bbuf, ' ')))
641624 *p++ = 0;
642625 if((dom = strchr(bbuf, '@')) == nil)
643− fatal(1, "bad p9any domain");
626+ sysfatal("bad p9any domain");
644627 *dom++ = 0;
645628 if(strcmp(bbuf, "p9sk1") == 0 || strcmp(bbuf, "dp9ik") == 0){
646629 proto = bbuf;
@@ -652,32 +635,32 @@ p9any(int fd) · 5 unmodified lines
652635 bbuf = p;
653636 }
654637 if(proto == nil)
655− fatal(1, "server did not offer p9sk1 or dp9ik");
638+ sysfatal("server did not offer p9sk1 or dp9ik");
656639 proto = estrdup(proto);
657640 sprint(buf2, "%s %s", proto, dom);
658641 if(write(fd, buf2, strlen(buf2)+1) != strlen(buf2)+1)
659− fatal(1, "cannot write user/domain choice in p9any");
642+ sysfatal("cannot write user/domain choice in p9any");
660643 if(v2){
661644 if(readstr(fd, buf, sizeof buf) < 0)
662− fatal(1, "cannot read OK in p9any");
645+ sysfatal("cannot read OK in p9any: %r");
663646 if(memcmp(buf, "OK\0", 3) != 0)
664− fatal(1, "did not get OK in p9any: got %s", buf);
647+ sysfatal("did not get OK in p9any: got %s", buf);
665648 }
666649 genrandom(crand, 2*NONCELEN);
667650 genrandom(cchal, CHALLEN);
668651 if(write(fd, cchal, CHALLEN) != CHALLEN)
669− fatal(1, "cannot write p9sk1 challenge");
652+ sysfatal("cannot write p9sk1 challenge: %r");
670653
671654 n = TICKREQLEN;
672655 if(dp9ik)
673656 n += PAKYLEN;
674657
675658 if(readn(fd, trbuf, n) != n || convM2TR(trbuf, TICKREQLEN, &tr) <= 0)
676− fatal(1, "cannot read ticket request in p9sk1");
659+ sysfatal("cannot read ticket request in p9sk1: %r");
677660
678661 if(!findkey(&authkey, user, tr.authdom, proto)){
679662 again: if(!getkey(&authkey, user, tr.authdom, proto))
680− fatal(1, "no password");
663+ sysfatal("no password");
681664 }
682665
683666 strecpy(tr.hostid, tr.hostid+sizeof tr.hostid, user);
@@ -690,7 +673,7 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 6 unmodified lines
690673 n = gettickets(&authkey, &tr, nil, tbuf, sizeof(tbuf));
691674 }
692675 if(n <= 0)
693− fatal(1, "cannot get auth tickets in p9sk1");
676+ sysfatal("cannot get auth tickets in p9sk1: %r");
694677
695678 m = convM2T(tbuf, n, &t, &authkey);
696679 if(m <= 0 || t.num != AuthTc){
@@ -701,7 +684,7 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 4 unmodified lines
701684 memmove(tbuf, tbuf+m, n);
702685
703686 if(dp9ik && write(fd, y, PAKYLEN) != PAKYLEN)
704− fatal(1, "cannot send authpak public key back");
687+ sysfatal("cannot send authpak public key back: %r");
705688
706689 auth.num = AuthAc;
707690 memmove(auth.rand, crand, NONCELEN);
@@ -710,11 +693,11 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 2 unmodified lines
710693 n += m;
711694
712695 if(write(fd, tbuf, n) != n)
713− fatal(1, "cannot send ticket and authenticator back");
696+ sysfatal("cannot send ticket and authenticator back: %r");
714697
715698 if((n=readn(fd, tbuf, m)) != m || memcmp(tbuf, "cpu:", 4) == 0){
716699 if(n <= 4)
717− fatal(1, "cannot read authenticator");
700+ sysfatal("cannot read authenticator");
718701
719702 /*
720703 * didn't send back authenticator:
@@ -725,15 +708,14 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 4 unmodified lines
725708 if(i > 0)
726709 n += i;
727710 buf[n] = 0;
728− werrstr("");
729− fatal(0, "server says: %s", buf);
711+ sysfatal("server says: %s", buf);
730712 }
731713
732714 if(convM2A(tbuf, n, &auth, &t) <= 0
733715 || auth.num != AuthAs || tsmemcmp(auth.chal, cchal, CHALLEN) != 0){
734716 print("?you and auth server agree about password.\n");
735717 print("?server is confused.\n");
736− fatal(0, "server lies got %llux want %llux", *(vlong*)auth.chal, *(vlong*)cchal);
718+ sysfatal("server lies");
737719 }
738720 memmove(crand+NONCELEN, auth.rand, NONCELEN);
739721
include/user.h+1−0
@@ -93,4 +93,5 @@ extern vlong nsec(void); · 92 unmodified lines
9393 extern void lock(Lock*);
9494 extern void unlock(Lock*);
9595 extern int iprint(char*, ...);
96+extern int atexit(void (*)(void));
9697 extern void exits(char*);
kern/Makefile+0−1
@@ -33,7 +33,6 @@ OFILES=\ · 32 unmodified lines
3333 smalloc.$O\
3434 stub.$O\
3535 sysfile.$O\
36− sysproc.$O\
3736 qio.$O\
3837 qlock.$O\
3938 term.$O\
kern/devcons.c+5−93
@@ -11,7 +11,6 @@ · 10 unmodified lines
1111 #undef write
1212 #undef read
1313
14−void (*consdebug)(void) = 0;
1514 void (*screenputs)(char*, int) = 0;
1615
1716 Queue* kbdq; /* unprocessed console input */
@@ -38,7 +37,6 @@ static struct · 20 unmodified lines
3837 char line[1024]; /* current input line */
3938
4039 int count;
41− int ctlpoff;
4240
4341 /* a place to save up characters at interrupt time before dumping them in the queue */
4442 Lock lockputc;
@@ -53,7 +51,6 @@ static struct · 8 unmodified lines
5351 0,
5452 { 0 },
5553 0,
56− 0,
5754 { 0 },
5855 { 0 },
5956 kbd.istage,
@@ -102,11 +99,6 @@ printinit(void) · 42 unmodified lines
10299 setterm(0);
103100 }
104101
105−void
106−prflush(void)
107−{
108−}
109−
110102 /*
111103 * Print a string on the console. Convert \n to \r\n for serial
112104 * line consoles. Locking of the queues is left up to the screen
@@ -166,25 +158,19 @@ panic(char *fmt, ...) · 53 unmodified lines
166158
167159 kprintoq = nil; /* don't try to write to /dev/kprint */
168160
169− if(panicking)
170− for(;;);
171− panicking = 1;
172−
161+ if(panicking++)
162+ for(;;) osyield();
173163 splhi();
174164 strcpy(buf, "panic: ");
175165 va_start(arg, fmt);
176166 n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf;
177167 va_end(arg);
178168 buf[n] = '\n';
179− if(screenputs != 0)
180− write(2, buf, n+1);
181− if(consdebug)
182− (*consdebug)();
183169 spllo();
184− prflush();
185170 putstrn(buf, n+1);
186− dumpstack();
187−
171+ while(screenputs != 0)
172+ osyield();
173+ setterm(0);
188174 exit(1);
189175 }
190176
@@ -248,76 +234,6 @@ echoscreen(char *buf, int n) · 57 unmodified lines
248234 static void
249235 echo(char *buf, int n)
250236 {
251− static int ctrlt;
252− int x;
253− char *e, *p;
254−
255− e = buf+n;
256− for(p = buf; p < e; p++){
257− switch(*p){
258− case 0x10: /* ^P */
259− if(cpuserver && !kbd.ctlpoff){
260− active.exiting = 1;
261− return;
262− }
263− break;
264− case 0x14: /* ^T */
265− ctrlt++;
266− if(ctrlt > 2)
267− ctrlt = 2;
268− continue;
269− }
270−
271− if(ctrlt != 2)
272− continue;
273−
274− /* ^T escapes */
275− ctrlt = 0;
276− switch(*p){
277− case 'S':
278− x = splhi();
279− dumpstack();
280− procdump();
281− splx(x);
282− return;
283− case 's':
284− dumpstack();
285− return;
286− case 'x':
287− xsummary();
288− ixsummary();
289− mallocsummary();
290− pagersummary();
291− return;
292− case 'd':
293− if(consdebug == 0)
294− consdebug = rdb;
295− else
296− consdebug = 0;
297− print("consdebug now 0x%p\n", consdebug);
298− return;
299− case 'D':
300− if(consdebug == 0)
301− consdebug = rdb;
302− consdebug();
303− return;
304− case 'p':
305− x = spllo();
306− procdump();
307− splx(x);
308− return;
309− case 'q':
310− scheddump();
311− return;
312− case 'k':
313− killbig();
314− return;
315− case 'r':
316− exit(0);
317− return;
318− }
319− }
320−
321237 qproduce(kbdq, buf, n);
322238 if(kbd.raw)
323239 return;
@@ -789,10 +705,6 @@ conswrite(Chan *c, void *va, long n, vlong off) · 465 unmodified lines
789705 if(screenputs == 0)
790706 setterm(0);
791707 qunlock(&kbd.lk);
792− } else if(strncmp(a, "ctlpon", 6) == 0){
793− kbd.ctlpoff = 0;
794− } else if(strncmp(a, "ctlpoff", 7) == 0){
795− kbd.ctlpoff = 1;
796708 }
797709 if((a = strchr(a, ' ')))
798710 a++;
kern/fns.h+0−1
@@ -215,7 +215,6 @@ void pio(Segment *, ulong, ulong, Page **); · 214 unmodified lines
215215 void portclock(Ureg*);
216216 int postnote(Proc*, int, char*, int);
217217 int pprint(char*, ...);
218−void prflush(void);
219218 ulong procalarm(ulong);
220219 int proccounter(char *name);
221220 void procctl(Proc*);
kern/sysproc.c+0−32
@@ -1,32 +0,0 @@
1−#include "u.h"
2−#include "lib.h"
3−#include "dat.h"
4−#include "fns.h"
5−#include "error.h"
6−
7−long
8−sysexits(ulong *arg)
9−{
10− char *status;
11− char *inval = "invalid exit string";
12− char buf[ERRMAX];
13−
14− status = (char*)arg[0];
15− if(status){
16− if(waserror())
17− status = inval;
18− else{
19− validaddr((ulong)status, 1, 0);
20− if(vmemchr(status, 0, ERRMAX) == 0){
21− memmove(buf, status, ERRMAX);
22− buf[ERRMAX-1] = 0;
23− status = buf;
24− }
25− }
26− poperror();
27−
28− }
29− pexit(status, 1);
30− return 0; /* not reached */
31−}
32−
libc/Makefile+1−0
@@ -3,6 +3,7 @@ include ../Make.config · 2 unmodified lines
33 LIB=libc.a
44
55 OFILES=\
6+ atexit.$O\
67 charstod.$O\
78 cleanname.$O\
89 convD2M.$O\
libc/atexit.c+46−0
@@ -0,0 +1,46 @@
1+#include <u.h>
2+#include <libc.h>
3+
4+#define NEXIT 33
5+
6+typedef struct Onex Onex;
7+struct Onex{
8+ void (*f)(void);
9+ int pid;
10+};
11+
12+static Lock onexlock;
13+Onex onex[NEXIT];
14+
15+int
16+atexit(void (*f)(void))
17+{
18+ int i;
19+
20+ lock(&onexlock);
21+ for(i=0; i<NEXIT; i++)
22+ if(onex[i].f == 0) {
23+ onex[i].pid = getpid();
24+ onex[i].f = f;
25+ unlock(&onexlock);
26+ return 1;
27+ }
28+ unlock(&onexlock);
29+ return 0;
30+}
31+
32+void
33+exits(char *s)
34+{
35+ int i, pid;
36+ void (*f)(void);
37+
38+ pid = getpid();
39+ for(i = NEXIT-1; i >= 0; i--)
40+ if((f = onex[i].f) && pid == onex[i].pid) {
41+ onex[i].f = 0;
42+ (*f)();
43+ }
44+ exit(s && *s);
45+}
46+
libc/sysfatal.c+1−4
@@ -11,10 +11,7 @@ _sysfatalimpl(char *fmt, va_list arg) · 10 unmodified lines
1111 fprint(2, "%s: %s\n", argv0, buf);
1212 else
1313 fprint(2, "%s\n", buf);
14−#undef write
15−write(2, buf, strlen(buf));
16−write(2, "\n", 1);
17− panic("sysfatal");
14+ exits("sysfatal");
1815 }
1916
2017 void (*_sysfatal)(char *fmt, va_list arg) = _sysfatalimpl;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t