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