From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sun, 16 Aug 1998 02:02:14 -0400 From: arisawa@ar.aichi-u.ac.jp arisawa@ar.aichi-u.ac.jp Subject: [9fans] a curious process Topicbox-Message-UUID: 7c5b1588-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19980816060214._jpDcmY1MSHoTed9e2ue5QsozuhNkA6Royb7LPT74HM@z> Hello 9fans! I observed a curious process: The process of 'none' creates a file of 'arisawa'. Does plan9 admit such a process? The program is listed bellow. I have felt inconvenience to kill the processes of none because my system forbids login by none. So I wrote a program that is executed as none instead of me. Try something: [1] done ps [2] done 'echo kill > /proc/524/note' # where 524 is the process id to kill # you can observe that done can kill processes of none [3] done touch x # done cannot create files of none, but creates files of you! --------------- done.c --------------- /* done: do as none usage: done command example: done broke done 'echo kill > /proc/524/ctl' I felt inconvenient to kill processes of none, so I wrote. 1998/08/14 Kenji Arisawa (Kenar) E-mail: arisawa@ar.aichi-u.ac.jp */ #include #include void usage(void) { print("usage: done command\n"); exits("usage"); } void main(int argc, char **argv) { int f,i,n,r; char buf[256], *s; Waitmsg w; /* --------------------------------- * we combine argments to a single string. * "arg1 arg2 arg3 ... " */ *buf = 0; r = 256 - 2; s = buf; for(n = 1; n < argc; n++){ i = strlen(argv[n]); if(i > r) { /* error. so we exit */ fprint(2,"command line to long\n"); exits("argments"); } strcpy(s, argv[n]); s += i; strcpy(s, " "); s++; r -= i + 1; } s--; *s = 0; argv[0] = "rc"; argv[1] = "-c"; argv[2] = buf; argv[3] = 0; switch(rfork(RFNOTEG|RFPROC|RFFDG)) { case -1: fprint(2, "can't fork\n"); break; case 0: /* set user to none */ f = open("/dev/user", OWRITE); if(f < 0) exits("/dev/user"); write(f, "none", 4); close(f); exec("/bin/rc", argv); break; default: wait(&w); if(w.msg[0]) fprint(2,"%s\n", w.msg); break; } }