10

I have a minimal Linux system.

init is /bin/bash, only bare minimum of libraries in /lib/, /dev/ is populated statically, no daemons running (no udev, ..)

When bash starts, I get following error:

bash: cannot set terminal process group (-1) inappropriate ioctl for device
bash: no job control in this shell

When I start bash with strace, I get following output:

rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
open("/dev/tty", O_RDWR|O_NONBLOCK)     = -1 ENXIO (No such device or address)
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0

....

readlink("/proc/self/fd/0", "/dev/console"..., 4095) = 12
stat("/dev/console", {st_mode=S_IFCHR|0600, st_rdev=makedev(5, 1), ...}) = 0
open("/dev/console", O_RDWR|O_NONBLOCK) = 3

It looks, as if bash cannot open /dev/tty. But /dev/tty exists in /dev/ and has correct permissions:

ll /dev/tty*
crw-rw-rwT 1 root root 5, 0  2014-Sep-29  23:39:47  dev/tty
crw------T 1 root root 4, 0  2015-Dec-23  20:10:18  dev/tty0
crw------T 1 root root 4, 1  2015-Dec-23  20:10:18  dev/tty1

Why cannot bash open /dev/tty? And what does the ENXIO error mean ?

Martin Vegter
  • 69
  • 66
  • 195
  • 326

1 Answers1

5

init is /bin/bash

As I said at https://unix.stackexchange.com/a/197472/5132, init=/bin/sh doesn't get "API" fileystems mounted, crashes in an ungainly fashion with no cache flush when one types exit (https://unix.stackexchange.com/a/195978/5132), and in general leaves it to the (super)user to manually do the actions that make the system minimally usable.

One of those actions (if you want to use a job control shell, as you apparently do) is acquiring a controlling terminal. /dev/tty isn't an actual terminal device. It's a device that redirects to whatever the opening process' controlling terminal is. If it does not have one, as process #1 does not to begin with (and usually all of the time when a real system manager program is being run as process #1), then opening the device fails.

Your system is too minimal. You need to run a program that sets up a controlling terminal, initializes a proper session, and probably does some of the bare minima of system management such as shutting down properly and cleanly, that then runs your job control shell.

Further reading

JdeBP
  • 66,967
  • 12
  • 159
  • 343