-su: /dev/tty: No such device or address
The manpage for su states that the executed command will have no controlling terminal. Any writes to /dev/tty will return the ENXIO error:
$ errno ENXIO
ENXIO 6 No such device or address
sudo does allocate a controlling terminal:
sudo -u someone /bin/bash -c "echo hello > /dev/tty"
There's no need for you to make a symbolic link to /dev/tty (/dev/stdout and /dev/stderr is enough) or use sudo if you use the USER directive in the Dockerfile or supervisor.
Related videos on Youtube
manifestor
Updated on June 04, 2022Comments
-
manifestor almost 2 years
could please someone explain to me why this happens?
# su - someone -s /bin/bash -c "ls -la /dev/tty" crw-rw-rw- 1 nobody nogroup 5, 0 Dec 7 20:53 /dev/tty # BUT: # su - someone -s /bin/bash -c "echo hello > /dev/tty" -su: /dev/tty: No such device or address
I'm trieng to build a docker Container which has two services inside. Those services a startet by a Shell-Script:
CMD ["./starter.sh"]
Withing the
Dockerfile
I have redirected the Logs to/dev/stderr
or/dev/tty
# None of the following works: RUN ln -sf /dev/tty /var/log/thelog.log RUN ln -sf /dev/stdout /var/log/thelog.log RUN ln -sf /dev/stderr /var/log/thelog.log
The problem is that I'm trying to run one of the services as not root (
su - someone -c "service"
), which give's the following error:unable to open log file [/var/log/thelog.log]: [6] No such device or address
How could I solve this problem? I want the logs to be linked to
/dev/*
AND want to run the User as non-root. Also I tried to add the User to the grouptty
, which did not work out.Thanks.
-
tripleee over 6 yearsReplacing devices with symlinks seems like a very brittle and dangerous thing to do. The kernel manipulates the tty, it's not a static file descriptor, that's why you get the error in the first place.
-
tripleee over 6 yearsWrap the service in something which captures its output to a sensible place. Most sane services don't really print anything to the console anyway.
-
manifestor over 6 yearsHi, thanks, but doing so is a common practice with docker. Redirecting to
/dev/*
makes you see the logs withdocker logs mycontainer
. So the crux of this matter is thesu -
and starting the process as another (!=root) user.
-
-
manifestor over 6 yearsHi thanks. Yes, true I could use supervisor and I know about
USER
. But how do you start 2 services with a Shell-Script where one must run as non root and one as root without using supervisor? If I useUSER non_root
I could not start the root-service as I have only oneRUN
command. -
Ricardo Branco over 6 yearsEither use supervisor or run each service in a different container.
-
manifestor over 6 yearsJust wanted to complement, that even with
supervisord
it is not possible to use/dev/tty
as a non-root User.