9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: arisawa <arisawa@ar.aichi-u.ac.jp>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] protection against resource exhaustion
Date: Mon, 26 Jan 2015 20:47:58 +0900	[thread overview]
Message-ID: <7A132462-4747-471A-A4BF-D9381E38A4EA@ar.aichi-u.ac.jp> (raw)
In-Reply-To: <44900c0d4896622fa8a9411b05efe730@brasstown.quanstro.net>

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”);
		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 <u.h>
#include <libc.h>
#define ERRLEN 256

static int
waitfor(int pid, char *msg)
{
	Waitmsg *w;
	while((w = wait()) != nil){
		if(w->pid == 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 = tokenize(cmd, args, 32);
	args[n] = nil;

	switch(pid = fork()) {/* assign = */
	case -1:
		sysfatal("fork: %r");
	case 0:
		close(0);
		exec(path, args);
		sysfatal("exec: %r");
	default:
		break;
	}
	status = 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 = 100;
	char buf[32];
	ARGBEGIN{
	case 'm':	m = atoi(ARGF());
		break;
	default: sysfatal("usage");
	}ARGEND

	if(argv[0])
		n = atoi(argv[0]);
	else
		n = 0;
	if(n == 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);
}




  reply	other threads:[~2015-01-26 11:47 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-25  6:16 arisawa
2015-01-25  6:59 ` mischief
2015-01-25 17:41   ` erik quanstrom
2015-01-26 11:47     ` arisawa [this message]
2015-01-26 12:46       ` cinap_lenrek
2015-01-26 14:13       ` erik quanstrom
2015-01-27  0:33         ` arisawa
2015-01-27  1:30           ` Lyndon Nerenberg
2015-01-27  4:13             ` erik quanstrom
2015-01-27  4:22           ` erik quanstrom
2015-01-27  7:03             ` arisawa
2015-01-27  7:10               ` Ori Bernstein
2015-01-27  7:15                 ` lucio
2015-01-27 14:05                 ` erik quanstrom
2015-01-27  7:12               ` lucio
2015-01-27 14:10               ` erik quanstrom
2015-01-28  0:10                 ` arisawa
2015-01-28  3:38                   ` erik quanstrom
2015-01-28  6:50                     ` arisawa
2015-01-28  7:22                       ` lucio
2015-01-28  7:48                       ` Quintile
2015-01-28 13:13                       ` cinap_lenrek
2015-01-28 14:03                         ` erik quanstrom
2015-01-28 14:09                           ` lucio
2015-01-28 14:14                             ` erik quanstrom
2015-01-28 14:53                               ` lucio
2015-01-28 17:02                                 ` Skip Tavakkolian
2015-01-28 14:16                       ` erik quanstrom
2015-01-28 17:28                       ` Charles Forsyth
2015-01-28 17:39                         ` cinap_lenrek
2015-01-28 18:51                           ` Charles Forsyth
2015-01-29  3:57                             ` arisawa
2015-01-29  6:34                               ` erik quanstrom
2015-01-29  6:42                         ` erik quanstrom
2015-01-29  8:11                           ` arisawa
2015-01-27 10:53             ` Charles Forsyth
2015-01-27 14:01               ` erik quanstrom
2015-01-25  9:04 ` arisawa
2015-01-25 11:06   ` Bence Fábián

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7A132462-4747-471A-A4BF-D9381E38A4EA@ar.aichi-u.ac.jp \
    --to=arisawa@ar.aichi-u.ac.jp \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).