cttyhack/tty/initramfs problem (take a number)

Ersin Akinci ersin.akinci at gmail.com
Sun Dec 6 01:53:18 UTC 2009


Aha, thank you for clarifying.  I wasn't aware that virtual terminals
were different from pseudo-terminals.  That makes more sense.

I still haven't been able to solve my problem, however.  /dev/tty1
exists, and I went ahead and made /dev/tty0, as well.  All permissions
are correct.  I also tried your suggestion to do exec </dev/tty1
>/dev/tty1 2>/dev/tty1, but that didn't work, either.  Just for kicks,
I tried /bin/sh /dev/tty1, which leaves me promptless but allows me to
enter commands nevertheless (without job control, however).

"strace cttyhack sh" pulls up some interesting results.  I can't copy
and paste the entire thing, but I will write out the relevant parts:

/ # strace cttyhack sh
execve("/bin/cttyhack", [cttyhack", "sh"], [/* 7 vars *]) = 0
<snip>
ioctl(0, TIOCGSERIAL, 0xbfa39200)     = -1 EINVAL (Invalid argument)
ioctl(0, VT_GETSTATE, 0xbfa39200)     = 0
open("/dev/tty1", O_RDWR)     = 3
dup2(3, 0)     = 0
dup2(3, 1)     = 1
dup2(3, 2)     = 2
close(3)     = 0
ioctl(0, TIOCSCTTY)     = -1 EPERM (Operation not permitted)
<snip, trying and failing to execute standard sh locations>
execve("/bin/sh", ["sh"], [/* 7 vars */]) = 0
open("/dev/tty", O_RDWR)     = -1 ENXIO (No such device or address)
ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
fcntl(2, F_DUPFD, 10)     = 10
fcntl(10, F_SETFD, FD_CLOEXEC)     = 0
ioctl(10, TIOCGPGRP, [1464])     = -1 ENOTTY (Inappropriate ioctl for device)
<snip>

Strange.  /dev/tty definitely exists with the correct major/minor
number pair (5, 0), I made sure to create that beforehand with mknod.

Some more testing: I tried running /bin/sh /dev/tty2, and when I
switch to virtual terminal 2 it executes all my commands and outputs
to...um, whatever it's outputting to when I first boot my computer
(/dev/console?  /dev/tty0?)

Any other ideas?

Thanks,
Ersin

On 12/4/09, Denys Vlasenko <vda.linux at googlemail.com> wrote:
> On Sat, Dec 5, 2009 at 4:57 AM, Ersin Akinci <ersin.akinci at gmail.com> wrote:
>>> If you think you know better, why do you ask?
>>>
>>> http://www.catb.org/~esr/faqs/smart-questions.html
>>
>> Excuse me, I think you've misunderstood my question.  I will rephrase
>> it to make it clearer.
>>
>> I'm trying to start the shell over a virtual tty in a minimal
>> initramfs + busybox environment without any login or user account
>> tools (no getty, login, etc.)  When my init script runs "/bin/sh" at
>> the end, it works but without job control because apparently it's not
>> using a "normal" tty.  So, my goal is to get the shell to use a
>> "normal" tty rather than /dev/console or anything else.  Now, AFAIK
>> there are two steps involved, neither of which I understand very well
>> and both of which I need some advice on:
>>
>> 1) Generating the correct tty device nodes
>> 2) Making the shell use those device nodes
>>
>> You suggested that I create /dev/tty1, but as I understand it this is
>> using the "old", non-Unix98/devpts method,
>
> No, it is NOT the "old" method. It is the correct method.
> Where did you get this strange idea that all ttys
> should be ptys?
>
>> which in my first e-mail I
>> said I wasn't using.  When I mount devpts, however, /dev/pts is
>> completely empty.  I thought that maybe invoking getty magically
>> generates nodes in /dev/pts on demand, but you said that wasn't the
>> case.
>
> /dev/pty is for PSEUDO ttys, like those created by telnet, ssh, xterm etc.
> Forget about /dev/pty, is it irrelevant to your situation.
>
>> So my question is how do I generate the proper /dev/pts nodes, and
>> then how do I get my shell to use them?  Your solution is perfectly
>> fine, except that I'm not using the /dev/ttyXX naming scheme with my
>> kernel or libc libraries.  Moreover, if you had read my last e-mail
>> you would notice that I tried your suggestion and that I'm still
>> getting the job control error.
>
> You did not specify that you were still using cttyhack.
> IOW, you did not provide complete info, making it
> necessary to guess what do you actually do on your system.
>
>> #!/bin/sh
>>
>> export PATH="/usr/bin:/usr/sbin:/bin:/sbin"
>>
>> mount -t proc proc /proc
>> mount -t sysfs sysfs /sys
>> mount -t devpts none /dev/pts -o gid=4,mode=620
>>
>> echo 0 > /proc/sys/kernel/printk
>>
>> echo
>> echo "Welcome to 420CDT Linux!"
>> echo
>> exec cttyhack sh
>
> Does /dev/tty1 exist? If yes, can you strace  cttyhack sh?
> And also try:
>
> exec </dev/tty1 >/dev/tty1 2>/dev/tty1
> exec sh
>
> --
> vda
>


-- 

=========

Ersin Y. Akinci -- http://www.ersinakinci.com


More information about the busybox mailing list