Would chmod 000 /dev/stdin disable terminal forever

chmoddevicesterminal

I'm working through questions from Unix The Textbook (chapter 8, #16, page 207):

Give chmod command lines that perform the same tasks that the mesg
n
and mesg y commands do. (Hint: Every hardware device, including
your terminal, has an associated file in the /dev directory.)

I believe the answer is:

mesg n = chmod 770 /dev/stdout

mesg y = chmod 777 /dev/stdout

But I was wondering what happens if you use chmod 000 /dev/stdin?

Do you get locked out of entering commands in the terminal?

Best Answer

No, /dev/stdin and /dev/stdout are the wrong device. These are not terminal devices, they're aliases for standard input and standard output respectively. Standard input and standard output are, by definition, file descriptors that applications expect to be open and have a conventional meaning (file descriptor 0 and 1 respectively, there's also 2 which is standard error). Devices such as /dev/stdin and /dev/stdout are useful when an application requires a file name, but the user of the application wants it to access a particular file descriptor rather than opening some file. Depending on the unix variant, they might not even be device files; for example, on Linux, they're symbolic links to /proc/self/fd/0 and friends, and these are in turn “magic” symbolic links to whatever file the process has already open on that file descriptor.

Changing the permissions of /dev/stdin and /dev/stdout would only change what happens when these file names are used explicitly. It doesn't affect anything related to the terminal, and it doesn't affect normal use of standard input and standard output, since the permissions only matter when opening a particular filename.

What mesg does is to change the permissions of the process's controlling terminal. For an application that's running in a terminal, the terminal is open on standard input, standard ouput and standard error (file descriptors 0, 1 and 2). You can use the command tty to see what the terminal device is. mesg n is equivalent to chmod g-w "$(tty)" and mesg y is equivalent to chmod g+w "$(tty)".

Related Question