0

I'm currently learning about the TTY system, and I want to create a demo application which opens /dev/pts/ptmx which will create a new terminal, and then have a process create a new session which will open this new terminal and be controlled by it.

But something is very weird. In order to open /dev/pts/ptmx you must be root. Now, when you open /dev/pts/ptmx, you get a file descriptor which you should pass to grantpts, which will "change the owner and mode of the slave ... device corresponding to the master pseudo-terminal corresponding to fd. The user ID of the slave the real UID of the calling process". But the calling process must be run by root in order to open /dev/pts/ptmx, and only there you have the file descriptor... what gives?

YoavKlein
  • 312
  • 2
  • 10
  • According to `man ptmx`, you should be opening `/dev/ptmx`, not `/dev/pts/ptmx` (and `/dev/ptmx` is by default mode `0666`). – larsks May 03 '22 at 02:51
  • See https://unix.stackexchange.com/questions/492823/where-does-dev-pts-ptmx-come-from for some interesting commenary on why there are two `ptmx` device nodes (pointing at the same device). – larsks May 03 '22 at 02:53

0 Answers0