Probems opening /dev/tty when running from gmenu2x

David Kuehling dvdkhlng at gmx.de
Mon Dec 27 04:30:14 EST 2010


>>>>> "Xiangfu" == Xiangfu Liu <xiangfu at sharism.cc> writes:

> On 12/26/2010 01:43 AM, David Kuehling wrote:
>>>>>>> "David" == David Kuehling <dvdkhlng at gmx.de> writes:
>> 
>>>>>>> "Xiangfu" == Xiangfu Liu <xiangfu at sharism.cc> writes:
>> 
>>>> when we run 'ash' 'bash' in gmenu2x it's always give me : /bin/ash
>>>> : can't access tty; job control is turned off when start 'ash'
>>>> 'bash'
>>>> (http://en.qi-hardware.com/wiki/OpenWrt_Software_Image#Image_2010-12-14
>>>> see the * KNOWN ISSUES)
>> 
>>> Ok, after lots of trial and error, I now have a fix that works.  It
>>> is *ugly*, need to clean it up a bit, but anyways:
>> [..]
>> 
>> Turns out there is a much more concise fix for the problem:
>> 
>> --8<-- int pid = setsid(); tcsetpgrp(1, pid); ioctl(1, TIOCSCTTY,
>> (char *)1); --8<--

> Hi David

> just test your code. it works fine. but the tcsetpgrp(1, pid); it
> always return "-1".  seems we don't need it.

Ok, nice you found that out.  

> form the manual:
> http://pubs.opengroup.org/onlinepubs/009695399/functions/setsid.html
> when we run 'setsid', pid have no controlling terminal, so 'tcsetpgrp'
> will fail.

Hmm.  I had a long look through documuentation Linux' rules about when
and how processes get (and lose) their controlling terminal.  And even
now it doesn't really make sense to me :) This is what I looked at:

http://www.win.tue.nl/~aeb/linux/lk/lk-10.html

> one question about ioctl(1, TIOCSCTTY, (char *)1); the first "1" means
> /dev/tty1, right??  what is the meaning of "(char *)1"?

It means stdout (the file descriptor, not the stream).  As Alan pointed
out, we could (and should) replace this with constant STDOUT_FILENO as
defined in unistd.h

cheers,

David
-- 
GnuPG public key: http://user.cs.tu-berlin.de/~dvdkhlng/dk.gpg
Fingerprint: B17A DC95 D293 657B 4205  D016 7DEF 5323 C174 7D40
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.en.qi-hardware.com/pipermail/discussion/attachments/20101227/38602e24/attachment.pgp>


More information about the discussion mailing list


interactive