C or ioctl help needed.

Richard A Downing richard at langside.org.uk
Sun Oct 9 01:14:42 PDT 2005

Ken Moffat wrote:
> On Sat, 8 Oct 2005, Richard A Downing wrote:
>> I'm trying to debug fgetty.  It's a replacement for getty using dietlibc.
>> Now it's supposed to run if called like this:
>> fgetty /dev/tty3
>> But this fails for me.  The relevant code is:
>> if ((fd=open(tty, O_RDWR, 0))<0 || ioctl (fd, TIOCSCTTY, (void *1)==-1)
>>    error("could not open tty device\n",3);
>> and this always fails (despite any perms, mine are 666 of /dev/tty3).
>> The open is OK, it's the ioctl condition that's failing.  But I'm damned
>> if I know where to look for what this is doing.
>> Any ideas?  Google has revealed zilch.
>  Lots of hits for TIOCSCTTY !  It's trying to set the controlling tty.
> I've no idea how to find the code in the kernel (finding the define of
> the ioctl is easy enough, but I don't know how this is translated to a
> destination.
>  Maybe this url might provide some ideas.  Sounds as if you have to be
> root, AND the current process must not have a controlling tty (which
> will be interesting to debug, if true).
> http://seclists.org/linux-kernel/2000/Sep/2888.html
>  You might want to try ignoring the error (google found some ssh code
> for sparc which ignores the return value from TIOCSCTTY because HP
> returns EINVAL ! ).
> Ken

Thanks for that Ken.

Yes, Google gave me a lot of hits on it too, but I didn't understand a
them :-)

Taking your suggestion, I commented the ioctl out.  This produces a
working (?) fgetty.  However, I now have the problem that the bash that
results from logging in has job control off.  Starts:

-bash: job control disabled in this shell

I think this is because it's been started without the tty being the
controlling tty.

I also tried mingetty, from which fgetty is derived, and got the same
problem - no job control.  And gogetty, same thing.  Clearly there is
something here that I don't yet understand.

Interestingly, the bash that is started by a normal agetty/login has TTY
listed as tty3, whereas the bash started from fgetty/login has TTY
listes as ? in ps -Al.  This would seem to indicate that the tty has not
been set correctly.

So it's back to agetty for the moment.  Suggestions on how to proceed,
however, are welcome.  I'll be mailing the author too, of course.


More information about the lfs-chat mailing list