TIOCSCTTY

Florian La Roche (florian@jurix.jura.uni-sb.de)
Mon, 26 Jun 1995 15:35:56 +0200 (MET DST)


I just came across a BSD source file, that was changed for the linux
C library. I don't have any standard where I could look what needs
to be implemented. (Is there a standard??)
But it seems to be not a good idea, that normal BSD source has to be
modified to work, if no other document has clear words about this.

The problem is with ioctl TIOCSCTTY (set controlling tty) in
drivers/char/tty_io.c. Here is the relevant source:
The question is: Why do we check for "(arg == 1)" in the code below?

/*
* This tty is already the controlling
* tty for another session group!
*/
if ((arg == 1) && suser()) {
/*
* Steal it away
*/
struct task_struct *p;

for_each_task(p)
if (p->tty == tty)
p->tty = NULL;
} else
return -EPERM;

Here is the source code for the Linux C library:
(The version with NULL as parameter to ioctl() is original BSD
and this was changed to "1" for Linux...

+#include <unistd.h>
#include <sys/param.h>
#include <sys/ioctl.h>
-#include <unistd.h>

-int login_tty(fd)
+login_tty(fd)
int fd;
{
(void) setsid();
- if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
+ if (ioctl(fd, TIOCSCTTY, (char *)1) == -1)
return (-1);
(void) dup2(fd, 0);
(void) dup2(fd, 1);
(void) dup2(fd, 2);
if (fd > 2)
close(fd);
return (0);
}

I appreciate any feedback,
Thanks a lot,

Florian