Path: utzoo!mnetor!uunet!husc6!mit-eddie!minya!jc From: jc@minya.UUCP (John Chambers) Newsgroups: comp.unix.wizards Subject: /dev/tty doesn't exist? Message-ID: <445@minya.UUCP> Date: 2 Jan 88 13:50:01 GMT Organization: home Lines: 45 Well, here I am with something else I've screwed up, and can't make sense of from the Unix manuals! (:-) What's going wrong now is that I have a program, let's call it X, which starts up a sub-process, and execs /bin/sh in it. It then hangs around waiting for the shell to die. All very normal, you say? Well, then, explain why, to this shell and anything it starts, /dev/tty doesn't seem to exist. The first hint was from a script that did something like: | echo "This is an error message." >/dev/tty so that it could write to the control terminal regardless of how output had been redirected. Instead of the error message, what appeared on the control terminal was: | /dev/tty: cannot create This seems a bit bizarre; a bit of looking turns up the fact that: | crw-rw-rw- 1 root sys 2, 0 Jan 1 20:42 /dev/tty I.e., /dev/tty does indeed exist, and is world-writable. After a bit of testing, I wrote a little test C program that says: | if ((fn = open("/dev/tty", 2)) < 0) | fprintf(stderr,"Can't open(\"/dev/tty\",2) errno=%d.\n",errno); Guess what it says? OK, I'll tell you: | Can't open("/dev/tty",2) errno=6. Replacing the '2' with '1' or '0' gets the same results. Anyone have an idea what my program X might be doing to screw up /dev/tty? Some hints: This is a rather generic Unix Sys/V.2, so the problem should be similar to most ATT Unices. The most unusual thing about how X is run is that it isn't being started by a login shell; it is started as a daemon by init, and in some cases, decides to grab a terminal (whose name is on its command line, and which doesn't have getty on it) and run a program there. This is a useful thing to do if, for instance, you are playing around with process-control applications. Perhaps the question could be rephrased: What is the official, approved way for a daemon process like this to attach a terminal? If the answer is RTFM, can you say where? The 1/4-page /dev/tty entry isn't much help. [In fact, the Unix manuals aren't very helpful in general if you want to write a free-running background program. I've tried to help various users who wanted to do this, and it's frustrating never quite knowing what I'm talking about :-] -- John Chambers <{adelie,ima,maynard,mit-eddie}!minya!{jc,root}> (617/484-6393)