Xref: utzoo comp.unix.wizards:22437 comp.bugs.4bsd:1571 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!athena.mit.edu!mar From: mar@athena.mit.edu (Mark A. Rosenstein) Newsgroups: comp.unix.wizards,comp.bugs.4bsd Subject: Re: How to divorce a process from the controlling tty (was syslogd.c) Message-ID: <1990Jun12.175338.15490@athena.mit.edu> Date: 12 Jun 90 17:53:38 GMT References: <1990Jun8.070904.7466@athena.mit.edu> <36447@sequent.UUCP> <11388@pixar.UUCP> Sender: news@athena.mit.edu (News system) Reply-To: mar@athena.mit.edu (Mark A. Rosenstein) Organization: Massachusetts Institute of Technology Lines: 31 In article <11388@pixar.UUCP>, bp@pixar.UUCP (Bruce Perens) writes: |> Here's how I would divorce a process from a controlling tty. Feel |> free to criticize and correct this: [some code deleted] |> /* |> * Here's the fun part. See if there is still a controlling |> * tty by opening /dev/tty. If you don't have a controlling |> * tty, the open will fail! If it succeeds, do ioctl TIOCNOTTY |> * on that fd, and close it again. |> */ |> if ( (tty_fd = open("/dev/tty", 0)) >= 0 ) { |> ioctl(tty_fd, TIOCNOTTY, 0); |> close(tty_fd); |> } Some code like that caused a heisenbug (you know, one where observing it affects the outcome) here last year. We were restarting our nameserver regularly from a daemon. If the daemon were restarted by someone netting into the machine, then the daemon's controlling tty was a pseudo-tty. When the nameserver got to the code fragment above, if no one was currently logged in on that pseudo-tty, then it would hang. When we noticed it wasn't running and logged in to check on it, we would usually log in on the correct pseudo-tty to get it running again and not be able to tell that it had stopped. I fixed this by including the non-blocking I/O flag in the open(), but that requires a kernel mod from standard 4.3BSD for that to work. Does anyone know a better solution for this? -Mark Variables won't and constants aren't.