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
13 13
14#define MaxStr 12814#define MaxStr 128
15 15
16static void fatal(int, char*, ...);
17static void usage(void);16static void usage(void);
18static void writestr(int, char*, char*, int);17static void writestr(int, char*, char*, int);
19static int readstr(int, char*, int);18static int readstr(int, char*, int);
@@ -37,10 +36,10 @@ static int p9authtls(int); · 17 unmodified lines
37char *authserver;36char *authserver;
38char *secstore;37char *secstore;
39 38
40void39static void
41exits(char *s)40ending(void)
42{41{
43 exit(1);42 panic("ending");
44}43}
45 44
46void45void
@@ -98,7 +97,7 @@ startaan(char *host, int fd) · 51 unmodified lines
98 int n;97 int n;
99 98
100 if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0)99 if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0)
101 fatal(1, "sending aan script");100 sysfatal("sending aan script: %r");
102 n = read(fd, buf, sizeof(buf)-1);101 n = read(fd, buf, sizeof(buf)-1);
103 close(fd);102 close(fd);
104 103
@@ -139,17 +138,17 @@ rcpu(char *host) · 34 unmodified lines
139 if(aanfilter){138 if(aanfilter){
140 fd = startaan(host, fd);139 fd = startaan(host, fd);
141 if(fd < 0)140 if(fd < 0)
142 fatal(1, "startaan");141 sysfatal("startaan: %r");
143 fd = p9authtls(fd);142 fd = p9authtls(fd);
144 }143 }
145 memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */144 memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */
146 145
147 if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0)146 if(fprint(fd, "%7ld\n%s", strlen(script), script) < 0)
148 fatal(1, "sending script");147 sysfatal("sending script: %r");
149 148
150 /* Begin serving the namespace */149 /* Begin serving the namespace */
151 exportfs(fd);150 exportfs(fd);
152 fatal(1, "starting exportfs");151 sysfatal("starting exportfs: %r");
153}152}
154 153
155void154void
@@ -169,9 +168,9 @@ ncpu(char *host) · 13 unmodified lines
169 }168 }
170 writestr(fd, buf, "negotiating authentication method", 0);169 writestr(fd, buf, "negotiating authentication method", 0);
171 if(readstr(fd, buf, sizeof buf) < 0)170 if(readstr(fd, buf, sizeof buf) < 0)
172 fatal(1, "can't negotiate authentication method: %r");171 sysfatal("can't negotiate authentication method: %r");
173 if(*buf)172 if(*buf)
174 fatal(1, "%s", buf);173 sysfatal("%s", buf);
175 174
176 /* authenticate and encrypt the channel */175 /* authenticate and encrypt the channel */
177 fd = p9authssl(fd);176 fd = p9authssl(fd);
@@ -187,14 +186,14 @@ ncpu(char *host) · 9 unmodified lines
187 * of /mnt/term186 * of /mnt/term
188 */187 */
189 if(readstr(fd, buf, sizeof(buf)) < 0)188 if(readstr(fd, buf, sizeof(buf)) < 0)
190 fatal(1, "waiting for FS: %r");189 sysfatal("waiting for FS: %r");
191 if(strncmp("FS", buf, 2) != 0) {190 if(strncmp("FS", buf, 2) != 0) {
192 print("remote cpu: %s", buf);191 print("remote cpu: %s", buf);
193 exits(buf);192 exits(buf);
194 }193 }
195 194
196 if(readstr(fd, buf, sizeof(buf)) < 0)195 if(readstr(fd, buf, sizeof(buf)) < 0)
197 fatal(1, "waiting for remote export: %r");196 sysfatal("waiting for remote export: %r");
198 if(strcmp(buf, "/") != 0){197 if(strcmp(buf, "/") != 0){
199 print("remote cpu: %s", buf);198 print("remote cpu: %s", buf);
200 exits(buf);199 exits(buf);
@@ -203,7 +202,7 @@ ncpu(char *host) · 2 unmodified lines
203 202
204 /* Begin serving the gnot namespace */203 /* Begin serving the gnot namespace */
205 exportfs(fd);204 exportfs(fd);
206 fatal(1, "starting exportfs");205 sysfatal("starting exportfs: %r");
207}206}
208 207
209void208void
@@ -267,19 +266,23 @@ cpumain(int argc, char **argv) · 57 unmodified lines
267 panic("bind #i: %r");266 panic("bind #i: %r");
268 if(bind("#m", "/dev", MBEFORE) < 0)267 if(bind("#m", "/dev", MBEFORE) < 0)
269 panic("bind #m: %r");268 panic("bind #m: %r");
269 atexit(ending);
270 }270 }
271 271
272 if(bind("/root", "/", MAFTER) < 0)272 if(bind("/root", "/", MAFTER) < 0)
273 panic("bind /root: %r");273 panic("bind /root: %r");
274 274
275 if(host == nil)275 if(host == nil)
276 host = readcons("cpu", "cpu", 0);276 if((host = readcons("cpu", "cpu", 0)) == nil)
277 277 sysfatal("user terminated input");
278 if(user == nil)
279 user = readcons("user", "glenda", 0);
280 278
281 if(authserver == nil)279 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");
283 286
284 if(mountfactotum() < 0){287 if(mountfactotum() < 0){
285 if(secstore == nil)288 if(secstore == nil)
@@ -299,27 +302,7 @@ cpumain(int argc, char **argv) · 13 unmodified lines
299 302
300 ncpu(host);303 ncpu(host);
301 304
302 fatal(1, "can't dial %s: %r", host);305 sysfatal("can't dial %s: %r", host);
303}
304
305void
306fatal(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);
323}306}
324 307
325void308void
@@ -330,7 +313,7 @@ writestr(int fd, char *str, char *thing, int ignore) · 4 unmodified lines
330 l = strlen(str);313 l = strlen(str);
331 n = write(fd, str, l+1);314 n = write(fd, str, l+1);
332 if(!ignore && n < 0)315 if(!ignore && n < 0)
333 fatal(1, "writing network: %s", thing);316 sysfatal("writing network: %s: %r", thing);
334}317}
335 318
336int319int
@@ -372,13 +355,13 @@ p9authssl(int fd) · 35 unmodified lines
372 ai = p9any(fd);355 ai = p9any(fd);
373 memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */356 memset(secstorebuf, 0, sizeof(secstorebuf)); /* forget secstore secrets */
374 if(ai == nil)357 if(ai == nil)
375 fatal(1, "can't authenticate");358 sysfatal("can't authenticate: %r");
376 359
377 if(ealgs == nil)360 if(ealgs == nil)
378 return fd;361 return fd;
379 362
380 if(ai->nsecret < 8){363 if(ai->nsecret < 8){
381 fatal(1, "p9authssl: secret too small");364 sysfatal("p9authssl: secret too small");
382 return -1;365 return -1;
383 }366 }
384 memmove(key+4, ai->secret, 8);367 memmove(key+4, ai->secret, 8);
@@ -386,11 +369,11 @@ p9authssl(int fd) · 1 unmodified line
386 /* exchange random numbers */369 /* exchange random numbers */
387 genrandom(key, 4);370 genrandom(key, 4);
388 if(write(fd, key, 4) != 4){371 if(write(fd, key, 4) != 4){
389 fatal(1, "p9authssl: write random: %r");372 sysfatal("p9authssl: write random: %r");
390 return -1;373 return -1;
391 }374 }
392 if(readn(fd, key+12, 4) != 4){375 if(readn(fd, key+12, 4) != 4){
393 fatal(1, "p9authssl: read random: %r");376 sysfatal("p9authssl: read random: %r");
394 return -1;377 return -1;
395 }378 }
396 379
@@ -402,7 +385,7 @@ p9authssl(int fd) · 5 unmodified lines
402 /* set up encryption */385 /* set up encryption */
403 fd = pushssl(fd, ealgs, fromclientsecret, fromserversecret, nil);386 fd = pushssl(fd, ealgs, fromclientsecret, fromserversecret, nil);
404 if(fd < 0)387 if(fd < 0)
405 fatal(1, "p9authssl: pushssl: %r");388 sysfatal("p9authssl: pushssl: %r");
406 389
407 return fd;390 return fd;
408}391}
@@ -418,7 +401,7 @@ p9authtls(int fd) · 9 unmodified lines
418 401
419 ai = p9any(fd);402 ai = p9any(fd);
420 if(ai == nil)403 if(ai == nil)
421 fatal(1, "can't authenticate");404 sysfatal("can't authenticate: %r");
422 405
423 conn = mallocz(sizeof(TLSconn), 1);406 conn = mallocz(sizeof(TLSconn), 1);
424 conn->pskID = "p9secret";407 conn->pskID = "p9secret";
@@ -427,7 +410,7 @@ p9authtls(int fd) · 2 unmodified lines
427 410
428 fd = tlsClient(fd, conn);411 fd = tlsClient(fd, conn);
429 if(fd < 0)412 if(fd < 0)
430 fatal(1, "tlsClient");413 sysfatal("tlsClient: %r");
431 414
432 auth_freeAI(ai);415 auth_freeAI(ai);
433 free(conn->sessionID);416 free(conn->sessionID);
@@ -627,7 +610,7 @@ p9any(int fd) · 193 unmodified lines
627 werrstr("");610 werrstr("");
628 611
629 if(readstr(fd, buf, sizeof buf) < 0)612 if(readstr(fd, buf, sizeof buf) < 0)
630 fatal(1, "cannot read p9any negotiation");613 sysfatal("cannot read p9any negotiation: %r");
631 bbuf = buf;614 bbuf = buf;
632 v2 = 0;615 v2 = 0;
633 if(strncmp(buf, "v.2 ", 4) == 0){616 if(strncmp(buf, "v.2 ", 4) == 0){
@@ -640,7 +623,7 @@ p9any(int fd) · 6 unmodified lines
640 if((p = strchr(bbuf, ' ')))623 if((p = strchr(bbuf, ' ')))
641 *p++ = 0;624 *p++ = 0;
642 if((dom = strchr(bbuf, '@')) == nil)625 if((dom = strchr(bbuf, '@')) == nil)
643 fatal(1, "bad p9any domain");626 sysfatal("bad p9any domain");
644 *dom++ = 0;627 *dom++ = 0;
645 if(strcmp(bbuf, "p9sk1") == 0 || strcmp(bbuf, "dp9ik") == 0){628 if(strcmp(bbuf, "p9sk1") == 0 || strcmp(bbuf, "dp9ik") == 0){
646 proto = bbuf;629 proto = bbuf;
@@ -652,32 +635,32 @@ p9any(int fd) · 5 unmodified lines
652 bbuf = p;635 bbuf = p;
653 }636 }
654 if(proto == nil)637 if(proto == nil)
655 fatal(1, "server did not offer p9sk1 or dp9ik");638 sysfatal("server did not offer p9sk1 or dp9ik");
656 proto = estrdup(proto);639 proto = estrdup(proto);
657 sprint(buf2, "%s %s", proto, dom);640 sprint(buf2, "%s %s", proto, dom);
658 if(write(fd, buf2, strlen(buf2)+1) != strlen(buf2)+1)641 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");
660 if(v2){643 if(v2){
661 if(readstr(fd, buf, sizeof buf) < 0)644 if(readstr(fd, buf, sizeof buf) < 0)
662 fatal(1, "cannot read OK in p9any");645 sysfatal("cannot read OK in p9any: %r");
663 if(memcmp(buf, "OK\0", 3) != 0)646 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);
665 }648 }
666 genrandom(crand, 2*NONCELEN);649 genrandom(crand, 2*NONCELEN);
667 genrandom(cchal, CHALLEN);650 genrandom(cchal, CHALLEN);
668 if(write(fd, cchal, CHALLEN) != CHALLEN)651 if(write(fd, cchal, CHALLEN) != CHALLEN)
669 fatal(1, "cannot write p9sk1 challenge");652 sysfatal("cannot write p9sk1 challenge: %r");
670 653
671 n = TICKREQLEN;654 n = TICKREQLEN;
672 if(dp9ik)655 if(dp9ik)
673 n += PAKYLEN;656 n += PAKYLEN;
674 657
675 if(readn(fd, trbuf, n) != n || convM2TR(trbuf, TICKREQLEN, &tr) <= 0)658 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");
677 660
678 if(!findkey(&authkey, user, tr.authdom, proto)){661 if(!findkey(&authkey, user, tr.authdom, proto)){
679again: if(!getkey(&authkey, user, tr.authdom, proto))662again: if(!getkey(&authkey, user, tr.authdom, proto))
680 fatal(1, "no password");663 sysfatal("no password");
681 }664 }
682 665
683 strecpy(tr.hostid, tr.hostid+sizeof tr.hostid, user);666 strecpy(tr.hostid, tr.hostid+sizeof tr.hostid, user);
@@ -690,7 +673,7 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 6 unmodified lines
690 n = gettickets(&authkey, &tr, nil, tbuf, sizeof(tbuf));673 n = gettickets(&authkey, &tr, nil, tbuf, sizeof(tbuf));
691 }674 }
692 if(n <= 0)675 if(n <= 0)
693 fatal(1, "cannot get auth tickets in p9sk1");676 sysfatal("cannot get auth tickets in p9sk1: %r");
694 677
695 m = convM2T(tbuf, n, &t, &authkey);678 m = convM2T(tbuf, n, &t, &authkey);
696 if(m <= 0 || t.num != AuthTc){679 if(m <= 0 || t.num != AuthTc){
@@ -701,7 +684,7 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 4 unmodified lines
701 memmove(tbuf, tbuf+m, n);684 memmove(tbuf, tbuf+m, n);
702 685
703 if(dp9ik && write(fd, y, PAKYLEN) != PAKYLEN)686 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");
705 688
706 auth.num = AuthAc;689 auth.num = AuthAc;
707 memmove(auth.rand, crand, NONCELEN);690 memmove(auth.rand, crand, NONCELEN);
@@ -710,11 +693,11 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 2 unmodified lines
710 n += m;693 n += m;
711 694
712 if(write(fd, tbuf, n) != n)695 if(write(fd, tbuf, n) != n)
713 fatal(1, "cannot send ticket and authenticator back");696 sysfatal("cannot send ticket and authenticator back: %r");
714 697
715 if((n=readn(fd, tbuf, m)) != m || memcmp(tbuf, "cpu:", 4) == 0){698 if((n=readn(fd, tbuf, m)) != m || memcmp(tbuf, "cpu:", 4) == 0){
716 if(n <= 4)699 if(n <= 4)
717 fatal(1, "cannot read authenticator");700 sysfatal("cannot read authenticator");
718 701
719 /*702 /*
720 * didn't send back authenticator:703 * didn't send back authenticator:
@@ -725,15 +708,14 @@ again: if(!getkey(&authkey, user, tr.authdom, proto)) · 4 unmodified lines
725 if(i > 0)708 if(i > 0)
726 n += i;709 n += i;
727 buf[n] = 0;710 buf[n] = 0;
728 werrstr("");711 sysfatal("server says: %s", buf);
729 fatal(0, "server says: %s", buf);
730 }712 }
731 713
732 if(convM2A(tbuf, n, &auth, &t) <= 0714 if(convM2A(tbuf, n, &auth, &t) <= 0
733 || auth.num != AuthAs || tsmemcmp(auth.chal, cchal, CHALLEN) != 0){715 || auth.num != AuthAs || tsmemcmp(auth.chal, cchal, CHALLEN) != 0){
734 print("?you and auth server agree about password.\n");716 print("?you and auth server agree about password.\n");
735 print("?server is confused.\n");717 print("?server is confused.\n");
736 fatal(0, "server lies got %llux want %llux", *(vlong*)auth.chal, *(vlong*)cchal);718 sysfatal("server lies");
737 }719 }
738 memmove(crand+NONCELEN, auth.rand, NONCELEN);720 memmove(crand+NONCELEN, auth.rand, NONCELEN);
739 721
include/user.h+1−0
@@ -93,4 +93,5 @@ extern vlong nsec(void); · 92 unmodified lines
93extern void lock(Lock*);93extern void lock(Lock*);
94extern void unlock(Lock*);94extern void unlock(Lock*);
95extern int iprint(char*, ...);95extern int iprint(char*, ...);
96extern int atexit(void (*)(void));
96extern void exits(char*);97extern void exits(char*);
kern/Makefile+0−1
@@ -33,7 +33,6 @@ OFILES=\ · 32 unmodified lines
33 smalloc.$O\33 smalloc.$O\
34 stub.$O\34 stub.$O\
35 sysfile.$O\35 sysfile.$O\
36 sysproc.$O\
37 qio.$O\36 qio.$O\
38 qlock.$O\37 qlock.$O\
39 term.$O\38 term.$O\
kern/devcons.c+5−93
@@ -11,7 +11,6 @@ · 10 unmodified lines
11#undef write11#undef write
12#undef read12#undef read
13 13
14void (*consdebug)(void) = 0;
15void (*screenputs)(char*, int) = 0;14void (*screenputs)(char*, int) = 0;
16 15
17Queue* kbdq; /* unprocessed console input */16Queue* kbdq; /* unprocessed console input */
@@ -38,7 +37,6 @@ static struct · 20 unmodified lines
38 char line[1024]; /* current input line */37 char line[1024]; /* current input line */
39 38
40 int count;39 int count;
41 int ctlpoff;
42 40
43 /* a place to save up characters at interrupt time before dumping them in the queue */41 /* a place to save up characters at interrupt time before dumping them in the queue */
44 Lock lockputc;42 Lock lockputc;
@@ -53,7 +51,6 @@ static struct · 8 unmodified lines
53 0,51 0,
54 { 0 },52 { 0 },
55 0,53 0,
56 0,
57 { 0 },54 { 0 },
58 { 0 },55 { 0 },
59 kbd.istage,56 kbd.istage,
@@ -102,11 +99,6 @@ printinit(void) · 42 unmodified lines
102 setterm(0);99 setterm(0);
103}100}
104 101
105void
106prflush(void)
107{
108}
109
110/*102/*
111 * Print a string on the console. Convert \n to \r\n for serial103 * Print a string on the console. Convert \n to \r\n for serial
112 * line consoles. Locking of the queues is left up to the screen104 * line consoles. Locking of the queues is left up to the screen
@@ -166,25 +158,19 @@ panic(char *fmt, ...) · 53 unmodified lines
166 158
167 kprintoq = nil; /* don't try to write to /dev/kprint */159 kprintoq = nil; /* don't try to write to /dev/kprint */
168 160
169 if(panicking)161 if(panicking++)
170 for(;;);162 for(;;) osyield();
171 panicking = 1;
172
173 splhi();163 splhi();
174 strcpy(buf, "panic: ");164 strcpy(buf, "panic: ");
175 va_start(arg, fmt);165 va_start(arg, fmt);
176 n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf;166 n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf;
177 va_end(arg);167 va_end(arg);
178 buf[n] = '\n';168 buf[n] = '\n';
179 if(screenputs != 0)
180 write(2, buf, n+1);
181 if(consdebug)
182 (*consdebug)();
183 spllo();169 spllo();
184 prflush();
185 putstrn(buf, n+1);170 putstrn(buf, n+1);
186 dumpstack();171 while(screenputs != 0)
187 172 osyield();
173 setterm(0);
188 exit(1);174 exit(1);
189}175}
190 176
@@ -248,76 +234,6 @@ echoscreen(char *buf, int n) · 57 unmodified lines
248static void234static void
249echo(char *buf, int n)235echo(char *buf, int n)
250{236{
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
321 qproduce(kbdq, buf, n);237 qproduce(kbdq, buf, n);
322 if(kbd.raw)238 if(kbd.raw)
323 return;239 return;
@@ -789,10 +705,6 @@ conswrite(Chan *c, void *va, long n, vlong off) · 465 unmodified lines
789 if(screenputs == 0)705 if(screenputs == 0)
790 setterm(0);706 setterm(0);
791 qunlock(&kbd.lk);707 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;
796 }708 }
797 if((a = strchr(a, ' ')))709 if((a = strchr(a, ' ')))
798 a++;710 a++;
kern/fns.h+0−1
@@ -215,7 +215,6 @@ void pio(Segment *, ulong, ulong, Page **); · 214 unmodified lines
215void portclock(Ureg*);215void portclock(Ureg*);
216int postnote(Proc*, int, char*, int);216int postnote(Proc*, int, char*, int);
217int pprint(char*, ...);217int pprint(char*, ...);
218void prflush(void);
219ulong procalarm(ulong);218ulong procalarm(ulong);
220int proccounter(char *name);219int proccounter(char *name);
221void procctl(Proc*);220void 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
7long
8sysexits(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
3LIB=libc.a3LIB=libc.a
4 4
5OFILES=\5OFILES=\
6 atexit.$O\
6 charstod.$O\7 charstod.$O\
7 cleanname.$O\8 cleanname.$O\
8 convD2M.$O\9 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
6typedef struct Onex Onex;
7struct Onex{
8 void (*f)(void);
9 int pid;
10};
11
12static Lock onexlock;
13Onex onex[NEXIT];
14
15int
16atexit(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
32void
33exits(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
11 fprint(2, "%s: %s\n", argv0, buf);11 fprint(2, "%s: %s\n", argv0, buf);
12 else12 else
13 fprint(2, "%s\n", buf);13 fprint(2, "%s\n", buf);
14#undef write14 exits("sysfatal");
15write(2, buf, strlen(buf));
16write(2, "\n", 1);
17 panic("sysfatal");
18}15}
19 16
20void (*_sysfatal)(char *fmt, va_list arg) = _sysfatalimpl;17void (*_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