From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) From: arisawa In-Reply-To: <44900c0d4896622fa8a9411b05efe730@brasstown.quanstro.net> Date: Mon, 26 Jan 2015 20:47:58 +0900 Content-Transfer-Encoding: quoted-printable Message-Id: <7A132462-4747-471A-A4BF-D9381E38A4EA@ar.aichi-u.ac.jp> References: <0F748B67-FB11-464C-84FA-66B4E0B29918@9.offblast.org> <44900c0d4896622fa8a9411b05efe730@brasstown.quanstro.net> To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Subject: Re: [9fans] protection against resource exhaustion Topicbox-Message-UUID: 3b7a3588-ead9-11e9-9d60-3106f5b1d025 Hello, I have been playing the following program. I tried on official plan9, 9front, and 9atom. none of them showed messages that come from: sysfatal("fork: %r=E2=80=9D); sysfatal("exec: %r"); I suspect that fork() does not return -1 even if it failed in creating new process. Be ware this program may cause system panic. #include #include #define ERRLEN 256 static int waitfor(int pid, char *msg) { Waitmsg *w; while((w =3D wait()) !=3D nil){ if(w->pid =3D=3D pid){ strncpy(msg, w->msg, ERRMAX); free(w); return 0; } free(w); } return -1; } int run(char *path, char *cmd) { int pid; int status; int n; char *args[32]; char msg[ERRLEN]; n =3D tokenize(cmd, args, 32); args[n] =3D nil; switch(pid =3D fork()) {/* assign =3D */ case -1: sysfatal("fork: %r"); case 0: close(0); exec(path, args); sysfatal("exec: %r"); default: break; } status =3D waitfor(pid, msg); if(status < 0){ werrstr("waitfor: %r"); return -1; } return 0; } void main(int argc, char *argv[]) { char *e; int n; int m =3D 100; char buf[32]; ARGBEGIN{ case 'm': m =3D atoi(ARGF()); break; default: sysfatal("usage"); }ARGEND if(argv[0]) n =3D atoi(argv[0]); else n =3D 0; if(n =3D=3D m) sysfatal("stop"); print("%d\n",n); snprint(buf,sizeof(buf),"8.out -m %d %d",m,n + 1); run("./8.out", buf); exits(nil); }