Kernel patch for tcgetsid() in glibc

Mark M._Kettenis (kettenis@phys.uva.nl)
Wed, 29 Oct 1997 15:24:13 +0100


Hi all,

I'm not sure if this is the right list to send this message to. If
not, please accept my apologies and tell me where to send it.

For implementing the tcgetsid() function from the Single Unix V2
specification in glibc we need some help from the kernel. The obvious
way to do this, is adding a new ioctl, TIOCGSID, to the tty driver.
The patch (against linux-2.1.60) included at the end of this message
implements this ioctl. Note that this patch is UNTESTED. Sorry for
that, but I do not have enough diskspace to compile the kernel at this
moment. In addition to this patch a

#define TIOCGSID xxxx

has to be added to the proper header files
(linux/include/asm-i386/ioctls.h, linux/include/asm-alpha/ioctls.h,
etc.).

Thanks,

Mark Kettenis

PS Since I'm not on the list. could you please CC me when replying to
this message?

--- linux/drivers/char/tty_io.c~ Tue Oct 21 17:57:28 1997
+++ linux/drivers/char/tty_io.c Wed Oct 29 15:04:27 1997
@@ -1479,6 +1479,19 @@
return 0;
}

+static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg)
+{
+ /*
+ * (tty == real_tty) is a cheap way of
+ * testing if the tty is NOT a master pty.
+ */
+ if (tty == real_tty && current->tty != real_tty)
+ return -ENOTTY;
+ if (real_tty->session <= 0)
+ return -ENOTTY;
+ return put_user(real_tty->session, arg);
+}
+
static int tiocttygstruct(struct tty_struct *tty, struct tty_struct *arg)
{
if (copy_to_user(arg, tty, sizeof(*arg)))
@@ -1546,6 +1559,8 @@
return tiocgpgrp(tty, real_tty, (pid_t *) arg);
case TIOCSPGRP:
return tiocspgrp(tty, real_tty, (pid_t *) arg);
+ case TIOCGSID:
+ return tiocgsid(tty, real_tty, (pid_t *) arg);
case TIOCGETD:
return put_user(tty->ldisc.num, (int *) arg);
case TIOCSETD: