Probems opening /dev/tty when running from gmenu2x

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

>>>>> "Xiangfu" == Xiangfu Liu <xiangfu at> writes:

> On 12/26/2010 01:43 AM, David Kuehling wrote:
>>>>>>> "David" == David Kuehling <dvdkhlng at> writes:
>>>>>>> "Xiangfu" == Xiangfu Liu <xiangfu at> 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'
>>>> (
>>>> 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:
> 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:

> 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


GnuPG public key:
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: <>

More information about the discussion mailing list