[comp.unix.questions] unopenable tty

expc55@castle.ed.ac.uk (Andrew Myles) (09/20/90)

Try (assuming file descriptor 1 is still your tty and not a pipe, else
open the tty yourself for any operation e.g. read or write)..

#include <sys/ioctl.h>		/* or whatever your machine needs */

int main()
{
ioctl(1,TIOCEXCL);		/* no more opens - when I use this I find
				   that mail demons cannot tell me of new
				   mail, sysops cannot wall etc... :-) */

/* insert your code here. Any other processes attempting to do
   things like open(this tty,O_RDONLY); will fail now even if
   this tty is crwxrwxrwx... */

ioctl(1,TIOCNXCL);		/* Free device on fildes 1. You didn't
				   do close(1) did you ?  If so, now
				   you can't re-open it either - so do
				   NOT do it to other peoples tty unless
				   they know how to free it.*/
return (0);
}

 Hope this works for you. Andrew.

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (09/21/90)

In article <6429@castle.ed.ac.uk> expc55@castle.ed.ac.uk (Andrew Myles) writes:
>ioctl(1,TIOCEXCL);		/* no more opens - when I use this I find
>				   that mail demons cannot tell me of new
>				   mail, sysops cannot wall etc... :-) */
>

This is not the case! "biff", "talk" and "wall" seem to work fine for me
even with the tty - exclusive on mode. The reason talk works is because the
talk daemon is a root process, and "wall" is a setuid root (or root run)
program. As to "mail", it is another thing which works. Root can have his
way regardless of what you do.

I ran a program like this for quite a while (still do) to stop direct writes
on my tty with cat and friends, but still allow talk messages.
subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet
kartik@silvertone.Princeton.EDU (NeXT mail)       -|	
subbarao@pucc.Princeton.EDU		          - Bitnet