#include <signal.h>;

int tty;
char *argp[] = { "-sh",0};
char *envp[] = { 0 };

_main()
{
    int pid;
    char ubuf[120];

    signal(SIGINT,SIG_IGN);
   
    do
       tty = open("/dev/tty",2);
    while (tty < 0);

    dup(tty);
    dup(tty);

    read(0, ubuf, sizeof(ubuf));  /* Flush the tty after the "boot:" thing */

    while(1)
    {
        write(1,"Welcome to UNIX\n",16);

	pid = fork();
	if (pid == -1)
	{
	    perror("init: cant fork");
	    continue;
  	}

        if (pid)
	{
	    while (wait(0) != pid && wait(0) != -1) {}
	}
        else
        {
	    write(1,"user: ",6);
	    read(0, ubuf, sizeof(ubuf));
	    setuid(atoi(ubuf));
	    signal(SIGINT,SIG_DFL);
 	    execve("/bin/sh",argp,envp);
	    execve("/sh",argp,envp);
	    perror("fork: cant exec sh");
	    _exit(1);
        }

    }
}

