Skip to main content
Topic: Where is /dev/pts/0? (Read 5309 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Where is /dev/pts/0?

I noticed that when I open a graphical terminal window under openrc, the
outcome of the "tty" command is /dev/pts/1 (also on the Artix and Gentoo live
media, so it must have something to do with openrc). Under systemd the first
graphical terminal is /dev/pts/0.
When I set windowkeys="YES" in /etc/conf.d/keymaps, the first pseudo tty is
/dev/pts/0, the second is /dev/pts/2 (and I get "Error: fopen(/run/openrc/rc.log)
failed: No such file or directory" on boot). So what or who is using /dev/pts/{0,1}
in openrc? (I found nothing satisfactory on the www, but a lot about /dev/pts so
the answer should interest many people).

Re: Where is /dev/pts/0?

Reply #1
https://unix.stackexchange.com/questions/114468/which-process-is-occupying-a-certain-pseudo-terminal-pts-x
From that page:
As Superuser I did cd /proc and entered the following bash command:

for pid in [0-9]* ; do  \
    RES=`ls -l $pid/fd/* 2>/dev/null| grep pts/0`; \
    if [ -n "$RES" ]; then echo "Process $pid owns: $RES"; fi; \
done

Then I cross referenced the PID numbers found with the output of ps -ef which suggests that pts/0 is related to the agetty instances.
Could this be related to your other question? There might be something distinctive about the way OpenRC creates agettys because at one point I remember I tried to make a tty8 for testing which didn't work properly, but it is quite possible that I did something else wrong without noticing.
It looks like you are onto something interesting here  :)
(Also my how to guide was just a user contibuted best effort, so feel free to add improvements and alternatives if you find them.)

Re: Where is /dev/pts/0?

Reply #2
The commandline you give is slightly incorrect . I did:
Code: [Select]
# cd /proc
# for pid in /proc/[0-9]* ; do RES="`ls -l $pid/fd/* 2> /dev/null | grep pts/0`"; if [ -n "$RES" ]; then echo "Process $pid owns: $RES"; fi; done
Process /proc/1576 owns: lrwx------ 1 root root 64 Nov 28 19:46 /proc/1576/fd/1 -> /dev/pts/0 (deleted)
lrwx------ 1 root root 64 Nov 28 19:46 /proc/1576/fd/2 -> /dev/pts/0 (deleted)
Process /proc/1608 owns: lrwx------ 1 root root 64 Nov 28 19:46 /proc/1608/fd/1 -> /dev/pts/0 (deleted)
lrwx------ 1 root root 64 Nov 28 19:46 /proc/1608/fd/2 -> /dev/pts/0 (deleted)
Process /proc/1640 owns: lrwx------ 1 root root 64 Nov 28 19:46 /proc/1640/fd/1 -> /dev/pts/0 (deleted)
lrwx------ 1 root root 64 Nov 28 19:46 /proc/1640/fd/2 -> /dev/pts/0 (deleted)
Process /proc/1672 owns: lrwx------ 1 root root 64 Nov 28 19:46 /proc/1672/fd/1 -> /dev/pts/0 (deleted)
lrwx------ 1 root root 64 Nov 28 19:46 /proc/1672/fd/2 -> /dev/pts/0 (deleted)
Process /proc/1704 owns: lrwx------ 1 root root 64 Nov 28 19:46 /proc/1704/fd/1 -> /dev/pts/0 (deleted)
lrwx------ 1 root root 64 Nov 28 19:46 /proc/1704/fd/2 -> /dev/pts/0 (deleted)
Process /proc/1736 owns: lrwx------ 1 root root 64 Nov 28 19:46 /proc/1736/fd/1 -> /dev/pts/0 (deleted)
lrwx------ 1 root root 64 Nov 28 19:46 /proc/1736/fd/2 -> /dev/pts/0 (deleted)

cat /proc/1736/cmdline|tr '\0' ' '
supervise-daemon agetty.tty6 --start --pidfile /run/agetty.tty6.pid /sbin/agetty -- tty6 38400 linux
The other pids also belong to supervise-daemon.

 

Re: Where is /dev/pts/0?

Reply #3
Glad to see you have fully traced that out  :)
OpenRC uses the "openpty" function to set up a pairwise terminal in 3 places in the source code:
Line 371
https://github.com/OpenRC/openrc/blob/master/src/rc/openrc-run.c
Lines 162 and 165
https://github.com/OpenRC/openrc/blob/master/src/rc/rc-logger.c

I think rc-logger would only run if you enabled it to, and it doesn't by default. So (guessing a bit here) the first openpty () call above uses pts/0 and later calls are assigned the next available pty - ? (You can also open a pty using getpt () too, if you wanted to search any other source code.)
I also saw this open bug relating to your problem with the relogin issues:
https://github.com/OpenRC/openrc/issues/159