linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. Werner Fink" <werner@suse.de>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Kurt Garloff <garloff@suse.de>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	miquels@cistron.nl,
	Linux kernel list <linux-kernel@vger.kernel.org>
Subject: Re: TIOCGDEV ioctl
Date: Thu, 21 Dec 2000 15:22:49 +0100	[thread overview]
Message-ID: <20001221152249.A12011@boole.suse.de> (raw)
In-Reply-To: <20001216015537.G21372@garloff.suse.de> <Pine.LNX.4.10.10012151710040.1325-100000@penguin.transmeta.com>
In-Reply-To: <Pine.LNX.4.10.10012151710040.1325-100000@penguin.transmeta.com>; from torvalds@transmeta.com on Fri, Dec 15, 2000 at 05:11:07PM -0800

[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]

On Fri, Dec 15, 2000 at 05:11:07PM -0800, Linus Torvalds wrote:
> 
> 
> On Sat, 16 Dec 2000, Kurt Garloff wrote:
> > 
> > The kernel provides this information -- sort of:
> > It contains the TIOCTTYGSTRUCT syscall which returns a struct. Of course,
> > it changes between different kernel archs and revisions, so using it is
> > an ugly hack. Grab for TIOCTTYGSTRUCT_HACK in the bootlogd.c file of the
> > sysvinit sources. Shudder!
> 
> Please instead do the same thing /dev/tty does, namely a sane interface
> that shows it as a symlink in /proc (or even in /dev)

Not a symlink but this is what is needed: if fd 0 of the current task is a
tty then give the hash of the tty.  I'm using fd 0 because current->tty may
not be set for spawned tasks of init.

I've attached two patches, one for 2.4 and one for 2.2.  They're rather
simple, therefore one may use this for setting a link.


        Werner

BTW: I'm missing a real replacement for my sys_revoke() patch done at the
end of October.  Al Viro has wipe it out but never shows an alternative way
of implementing such a beast.

[-- Attachment #2: linux-2.4-real-tty.patch --]
[-- Type: text/plain, Size: 1739 bytes --]

--- fs/proc/proc_tty.c
+++ fs/proc/proc_tty.c	Thu Dec 21 15:16:08 2000
@@ -9,6 +9,7 @@
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
+#include <linux/file.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
 #include <linux/tty.h>
@@ -22,6 +23,8 @@
 				 int count, int *eof, void *data);
 static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
 				int count, int *eof, void *data);
+static int real_tty_read_proc(char *page, char **start, off_t off,
+				int count, int *eof, void *data);
 
 /*
  * The /proc/tty directory inodes...
@@ -128,7 +131,32 @@
 }
 
 /*
- * Thsi function is called by register_tty_driver() to handle
+ * This is the handler for /proc/tty/tty
+ */
+static int real_tty_read_proc(char *page, char **start, off_t off,
+				int count, int *eof, void *data)
+{
+	struct	file * zero = fcheck(0); /* of current task */
+	struct	tty_struct * tty = NULL;
+	unsigned int dev = 0;
+	int	len = 0;
+	off_t	begin = 0;
+
+	if (zero)
+		tty = (struct tty_struct *)zero->private_data;
+	if (tty && tty->magic == TTY_MAGIC)
+		dev = kdev_t_to_nr(tty->device);
+
+	len += sprintf(page+len, "%u\n", dev);
+
+	if (off >= len+begin)
+		return 0;
+	*start = page + (off-begin);
+	return ((count < begin+len-off) ? count : begin+len-off);
+}
+
+/*
+ * This function is called by register_tty_driver() to handle
  * registering the driver's /proc handler into /proc/tty/driver/<foo>
  */
 void proc_tty_register_driver(struct tty_driver *driver)
@@ -178,4 +206,5 @@
 
 	create_proc_read_entry("tty/ldiscs", 0, 0, tty_ldiscs_read_proc,NULL);
 	create_proc_read_entry("tty/drivers", 0, 0, tty_drivers_read_proc,NULL);
+	create_proc_read_entry("tty/tty", 0, 0, real_tty_read_proc,NULL);
 }

[-- Attachment #3: linux-2.2-real-tty.patch --]
[-- Type: text/plain, Size: 1695 bytes --]

--- fs/proc/proc_tty.c
+++ fs/proc/proc_tty.c	Thu Dec 21 15:14:12 2000
@@ -9,6 +9,7 @@
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
+#include <linux/file.h>
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
 #include <linux/tty.h>
@@ -22,6 +23,8 @@
 				 int count, int *eof, void *data);
 static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
 				int count, int *eof, void *data);
+static int real_tty_read_proc(char *page, char **start, off_t off,
+				 int count, int *eof, void *data);
 
 /*
  * The /proc/tty directory inodes...
@@ -128,7 +131,32 @@
 }
 
 /*
- * Thsi function is called by register_tty_driver() to handle
+ * This is the handler for /proc/tty/tty
+ */
+static int real_tty_read_proc(char *page, char **start, off_t off,
+				 int count, int *eof, void *data)
+{
+	struct	file * zero = fcheck_task(current, 0);
+	struct	tty_struct * tty = NULL;
+	unsigned int dev = 0;
+	int	len = 0;
+	off_t	begin = 0;
+
+	if (zero)
+		tty = (struct tty_struct *)zero->private_data;
+	if (tty && tty->magic == TTY_MAGIC)
+		dev = kdev_t_to_nr(tty->device);
+
+	len += sprintf(page+len, "%u\n", dev);
+
+	if (off >= len+begin)
+		return 0;
+	*start = page + (off-begin);
+	return ((count < begin+len-off) ? count : begin+len-off);
+}
+
+/*
+ * This function is called by register_tty_driver() to handle
  * registering the driver's /proc handler into /proc/tty/driver/<foo>
  */
 void proc_tty_register_driver(struct tty_driver *driver)
@@ -185,5 +213,7 @@
 
 	ent = create_proc_entry("tty/drivers", 0, 0);
 	ent->read_proc = tty_drivers_read_proc;
-}
 
+	ent = create_proc_entry("tty/tty", 0, 0);
+	ent->read_proc = real_tty_read_proc;
+}

  parent reply	other threads:[~2000-12-21 14:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-16  0:55 TIOCGDEV ioctl Kurt Garloff
2000-12-16  1:11 ` Linus Torvalds
2000-12-16  1:54   ` Alexander Viro
2000-12-16 10:46     ` Miquel van Smoorenburg
2000-12-16 11:15       ` Alexander Viro
2000-12-16 11:40         ` Miquel van Smoorenburg
2000-12-16 11:57           ` Alexander Viro
2000-12-19 11:34             ` Kurt Garloff
2000-12-21 14:22   ` Dr. Werner Fink [this message]
2000-12-16  1:18 ` James Simmons
2000-12-16 10:54   ` Miquel van Smoorenburg
2000-12-18 17:07     ` James Simmons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20001221152249.A12011@boole.suse.de \
    --to=werner@suse.de \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=garloff@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miquels@cistron.nl \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).