9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: arisawa@ar.aichi-u.ac.jp arisawa@ar.aichi-u.ac.jp
Subject: [9fans] a curious process
Date: Sun, 16 Aug 1998 02:02:14 -0400	[thread overview]
Message-ID: <19980816060214._jpDcmY1MSHoTed9e2ue5QsozuhNkA6Royb7LPT74HM@z> (raw)

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 <u.h>
#include <libc.h>

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;
	}
}




             reply	other threads:[~1998-08-16  6:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-16  6:02 arisawa [this message]
1998-08-16 12:34 forsyth

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=19980816060214._jpDcmY1MSHoTed9e2ue5QsozuhNkA6Royb7LPT74HM@z \
    --to=arisawa@ar.aichi-u.ac.jp \
    /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).