Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!rochester!udel!mmdf From: waltje@minixug.hobby.nl (Fred van Kempen) Newsgroups: comp.os.minix Subject: Re: write() statements in init Message-ID: <23132@nigel.udel.EDU> Date: 29 Jun 90 04:12:49 GMT Sender: mmdf@udel.EDU Lines: 71 From article <1990Jun26.170818.4257@mozart.amd.com>, by tim@proton.amd.com (Tim Olson): > In article <11355@bsu-cs.bsu.edu> jtn3@bsu-cs.bsu.edu (Jim Nelson) writes: > | Is it permissable to use write statements in init.c? I know that main() > | in init.c uses them, but only inside an if statement (or while loop. I'm > | not looking at the source right now.) so it's never actually executed. > | When I add them so they WILL be executed, the computer locks up (power off > | reboot. aargh) > | > | I'm using write statements to print debugging information to the screen > | (or I would be if they didn't cause my system to hang :-} > > Init is started with no files associated with stdin, stdout, or stderr > (FD 0, 1, and 2). To print debug output, you must first open up a > file (such as /dev/tty0) for each of these descriptors: > > open("/dev/tty0", 0); /* open descriptor 0 (stdin) for read */ > open("/dev/tty0", 1); /* open descriptor 1 (stdout) for write */ > open("/dev/tty0", 1); /* open descriptor 2 (stderr) for write */ > > -- Tim Olson > Advanced Micro Devices > (tim@amd.com) Yeah, but then INIT will gain the Process Group Leadership for the opened terminal device, tty0 (console) in this case. Since this status can only be undone by exiting, INIT will ALWAYS be the process group leader after the first open(). This means, that you cannot hit DEL on your console anymore, since that causes a signal to be sent to the procgrp leader of the line on which the DEL was typed, which is usually the login process associated with a terminal device... This bug has been around since version 1.3B of MINIX-PC... If you really want to have INIT say something, you can do either: 1. print(s) char *s; { int pid, tty; int status; if ((pid = fork()) == 0) { tty = open("/dev/tty0", O_WRONLY); if (tty < 0) exit(-1); write(tty, s, strlen(s)); close(tty); exit(0); } else if (pid > 0) { while (wait(&status) != pid) ; } } This routine forks a process, has it print something, and exit, which releases the control terminal. 2. Use Gordon Irlam's VC driver, since that uses tty0 for the default console. This is never associated with a login process, so INIT may use it if it pleases to. Fred. +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | MINIX User Group Holland UUCP: waltje@minixug.hobby.nl | | c/o Fred van Kempen, or: hp4nl!minixug!waltje | | Hoefbladhof 27 | | 2215 DV VOORHOUT | | The Netherlands "A good programmer knows his Sources" | +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+