linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* TIOCGDEV ioctl
@ 2000-12-16  0:55 Kurt Garloff
  2000-12-16  1:11 ` Linus Torvalds
  2000-12-16  1:18 ` James Simmons
  0 siblings, 2 replies; 12+ messages in thread
From: Kurt Garloff @ 2000-12-16  0:55 UTC (permalink / raw)
  To: Linus Torvalds, Alan Cox; +Cc: miquels, Linux kernel list

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

Hi Linus, Alan,

some applications do need to know where the console (/dev/console)
actually maps to. For processes with a controlling terminal, you may see 
it in /proc/$$/stat. However, daemons are supposed to run detached (they
don't want to get killed by ^C) and some processes like init or bootlogd 
do still need to be able to find out.

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!

Having a new ioctl, just returning the device no is a much cleaner solution,
IMHO. So, I created the TIOCGDEV, which Miquel suggests in his sysvinit
sources. It makes querying the actual console device as easy as 
int tty; ioctl (0, TIOCGDEV, &tty);

Patches against 2.2.18 and 2.4.0-testX are attached.
Please apply.
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, FRG                               SCSI, Security

[-- Attachment #2: TIOCGDEV-240t11.diff --]
[-- Type: text/plain, Size: 9069 bytes --]

diff -uNr linux-2.4.0_test10.SuSE/drivers/char/tty_io.c linux-2.4.0_test10.TIOCGDEV/drivers/char/tty_io.c
--- linux-2.4.0_test10.SuSE/drivers/char/tty_io.c	Mon Oct 16 21:58:51 2000
+++ linux-2.4.0_test10.TIOCGDEV/drivers/char/tty_io.c	Fri Dec 15 19:35:23 2000
@@ -1766,7 +1766,8 @@
 #endif
 		case TIOCTTYGSTRUCT:
 			return tiocttygstruct(tty, (struct tty_struct *) arg);
-
+		case TIOCGDEV:
+			return put_user (kdev_to_nr (real_tty->device, (unsigned int*) arg);
 		/*
 		 * Break handling
 		 */
diff -uNr linux-2.4.0_test10.SuSE/include/asm/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm/ioctls.h	Fri Jul 24 20:10:16 1998
+++ linux-2.4.0_test10.TIOCGDEV/include/asm/ioctls.h	Fri Dec 15 19:39:17 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.4.0_test10.SuSE/include/asm-alpha/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-alpha/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-alpha/ioctls.h	Fri Jan 28 01:40:09 2000
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-alpha/ioctls.h	Fri Dec 15 19:41:45 2000
@@ -91,6 +91,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
diff -uNr linux-2.4.0_test10.SuSE/include/asm-arm/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-arm/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-arm/ioctls.h	Fri Feb 13 01:25:04 1998
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-arm/ioctls.h	Fri Dec 15 19:42:39 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.4.0_test10.SuSE/include/asm-i386/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-i386/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-i386/ioctls.h	Fri Jul 24 20:10:16 1998
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-i386/ioctls.h	Fri Dec 15 19:39:17 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.4.0_test10.SuSE/include/asm-ia64/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-ia64/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-ia64/ioctls.h	Mon Feb  7 03:42:40 2000
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-ia64/ioctls.h	Fri Dec 15 19:41:31 2000
@@ -54,6 +54,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.4.0_test10.SuSE/include/asm-m68k/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-m68k/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-m68k/ioctls.h	Fri Feb 13 01:25:04 1998
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-m68k/ioctls.h	Fri Dec 15 19:40:58 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.4.0_test10.SuSE/include/asm-mips/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-mips/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-mips/ioctls.h	Sat May 13 17:31:25 2000
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-mips/ioctls.h	Fri Dec 15 19:42:54 2000
@@ -100,6 +100,7 @@
 #define TIOCGSID	0x7416  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5488
 #define TIOCSERGWILD	0x5489
diff -uNr linux-2.4.0_test10.SuSE/include/asm-mips64/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-mips64/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-mips64/ioctls.h	Sat May 13 17:31:25 2000
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-mips64/ioctls.h	Fri Dec 15 19:37:24 2000
@@ -100,6 +100,7 @@
 #define TIOCGSID	0x7416  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5488
 #define TIOCSERGWILD	0x5489
diff -uNr linux-2.4.0_test10.SuSE/include/asm-ppc/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-ppc/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-ppc/ioctls.h	Sun Nov 28 00:42:33 1999
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-ppc/ioctls.h	Fri Dec 15 19:42:28 2000
@@ -88,6 +88,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
diff -uNr linux-2.4.0_test10.SuSE/include/asm-s390/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-s390/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-s390/ioctls.h	Fri May 12 20:41:44 2000
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-s390/ioctls.h	Fri Dec 15 19:44:04 2000
@@ -57,6 +57,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.4.0_test10.SuSE/include/asm-sh/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-sh/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-sh/ioctls.h	Sat Nov  6 19:40:31 1999
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-sh/ioctls.h	Fri Dec 15 19:41:20 2000
@@ -80,6 +80,7 @@
 #define TIOCGSID	_IOR('T', 41, pid_t) /* 0x5429 */ /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	_IO('T', 83) /* 0x5453 */
 #define TIOCSERGWILD	_IOR('T', 84,  int) /* 0x5454 */
diff -uNr linux-2.4.0_test10.SuSE/include/asm-sparc/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-sparc/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-sparc/ioctls.h	Sun Oct  4 19:22:44 1998
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-sparc/ioctls.h	Fri Dec 15 19:39:50 2000
@@ -99,6 +99,7 @@
 #define TIOCSSERIAL	0x541F
 #define TCSBRKP		0x5425
 #define TIOCTTYGSTRUCT	0x5426
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
 #define TIOCSERSWILD	0x5455
diff -uNr linux-2.4.0_test10.SuSE/include/asm-sparc64/ioctls.h linux-2.4.0_test10.TIOCGDEV/include/asm-sparc64/ioctls.h
--- linux-2.4.0_test10.SuSE/include/asm-sparc64/ioctls.h	Wed Apr 15 02:44:24 1998
+++ linux-2.4.0_test10.TIOCGDEV/include/asm-sparc64/ioctls.h	Fri Dec 15 19:40:18 2000
@@ -100,6 +100,7 @@
 #define TIOCSSERIAL	0x541F
 #define TCSBRKP		0x5425
 #define TIOCTTYGSTRUCT	0x5426
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
 #define TIOCSERSWILD	0x5455

[-- Attachment #3: TIOCGDEV-2218.diff --]
[-- Type: text/plain, Size: 6094 bytes --]

diff -uNr linux-2.2.18.SuSE/drivers/char/tty_io.c linux-2.2.18.TIOCGDEV/drivers/char/tty_io.c
--- linux-2.2.18.SuSE/drivers/char/tty_io.c	Thu Dec 14 22:38:30 2000
+++ linux-2.2.18.TIOCGDEV/drivers/char/tty_io.c	Fri Dec 15 17:39:05 2000
@@ -1768,6 +1768,9 @@
 		case TIOCTTYGSTRUCT:
 			return tiocttygstruct(tty, (struct tty_struct *) arg);
 
+		case TIOCGDEV:
+			return put_user (kdev_t_to_nr (real_tty->device), (unsigned int *) arg);
+		
 		/*
 		 * Break handling
 		 */
diff -uNr linux-2.2.18.SuSE/include/asm-alpha/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-alpha/ioctls.h
--- linux-2.2.18.SuSE/include/asm-alpha/ioctls.h	Fri Feb 13 01:25:04 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-alpha/ioctls.h	Fri Dec 15 19:51:59 2000
@@ -88,6 +88,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
diff -uNr linux-2.2.18.SuSE/include/asm-arm/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-arm/ioctls.h
--- linux-2.2.18.SuSE/include/asm-arm/ioctls.h	Fri Feb 13 01:25:04 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-arm/ioctls.h	Fri Dec 15 19:53:09 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.2.18.SuSE/include/asm-i386/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-i386/ioctls.h
--- linux-2.2.18.SuSE/include/asm-i386/ioctls.h	Fri Jul 24 20:10:16 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-i386/ioctls.h	Fri Dec 15 19:50:35 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.2.18.SuSE/include/asm-m68k/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-m68k/ioctls.h
--- linux-2.2.18.SuSE/include/asm-m68k/ioctls.h	Fri Feb 13 01:25:04 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-m68k/ioctls.h	Fri Dec 15 19:51:48 2000
@@ -49,6 +49,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.2.18.SuSE/include/asm-mips/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-mips/ioctls.h
--- linux-2.2.18.SuSE/include/asm-mips/ioctls.h	Mon Aug  9 21:04:41 1999
+++ linux-2.2.18.TIOCGDEV/include/asm-mips/ioctls.h	Fri Dec 15 19:53:23 2000
@@ -100,6 +100,7 @@
 #define TIOCGSID	0x7416  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5488
 #define TIOCSERGWILD	0x5489
diff -uNr linux-2.2.18.SuSE/include/asm-ppc/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-ppc/ioctls.h
--- linux-2.2.18.SuSE/include/asm-ppc/ioctls.h	Fri Feb 13 01:25:04 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-ppc/ioctls.h	Fri Dec 15 19:52:49 2000
@@ -88,6 +88,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
diff -uNr linux-2.2.18.SuSE/include/asm-s390/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-s390/ioctls.h
--- linux-2.2.18.SuSE/include/asm-s390/ioctls.h	Tue Jan  4 19:12:24 2000
+++ linux-2.2.18.TIOCGDEV/include/asm-s390/ioctls.h	Fri Dec 15 19:53:34 2000
@@ -57,6 +57,7 @@
 #define TIOCGSID	0x5429  /* Return the session ID of FD */
 #define TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
diff -uNr linux-2.2.18.SuSE/include/asm-sparc/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-sparc/ioctls.h
--- linux-2.2.18.SuSE/include/asm-sparc/ioctls.h	Sun Oct  4 19:22:44 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-sparc/ioctls.h	Fri Dec 15 19:51:00 2000
@@ -99,6 +99,7 @@
 #define TIOCSSERIAL	0x541F
 #define TCSBRKP		0x5425
 #define TIOCTTYGSTRUCT	0x5426
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
 #define TIOCSERSWILD	0x5455
diff -uNr linux-2.2.18.SuSE/include/asm-sparc64/ioctls.h linux-2.2.18.TIOCGDEV/include/asm-sparc64/ioctls.h
--- linux-2.2.18.SuSE/include/asm-sparc64/ioctls.h	Wed Apr 15 02:44:24 1998
+++ linux-2.2.18.TIOCGDEV/include/asm-sparc64/ioctls.h	Fri Dec 15 19:53:43 2000
@@ -100,6 +100,7 @@
 #define TIOCSSERIAL	0x541F
 #define TCSBRKP		0x5425
 #define TIOCTTYGSTRUCT	0x5426
+#define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get real dev no below /dev/console */
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
 #define TIOCSERSWILD	0x5455

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  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-21 14:22   ` Dr. Werner Fink
  2000-12-16  1:18 ` James Simmons
  1 sibling, 2 replies; 12+ messages in thread
From: Linus Torvalds @ 2000-12-16  1:11 UTC (permalink / raw)
  To: Kurt Garloff; +Cc: Alan Cox, miquels, Linux kernel list



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)

		Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16  0:55 TIOCGDEV ioctl Kurt Garloff
  2000-12-16  1:11 ` Linus Torvalds
@ 2000-12-16  1:18 ` James Simmons
  2000-12-16 10:54   ` Miquel van Smoorenburg
  1 sibling, 1 reply; 12+ messages in thread
From: James Simmons @ 2000-12-16  1:18 UTC (permalink / raw)
  To: Kurt Garloff; +Cc: Linus Torvalds, Alan Cox, miquels, Linux kernel list


> Hi Linus, Alan,
> 
> some applications do need to know where the console (/dev/console)
> actually maps to. For processes with a controlling terminal, you may see 
> it in /proc/$$/stat. However, daemons are supposed to run detached (they
> don't want to get killed by ^C) and some processes like init or bootlogd 
> do still need to be able to find out.
> 
> 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!
> 
> Having a new ioctl, just returning the device no is a much cleaner solution,
> IMHO. So, I created the TIOCGDEV, which Miquel suggests in his sysvinit
> sources. It makes querying the actual console device as easy as 
> int tty; ioctl (0, TIOCGDEV, &tty);
> 
> Patches against 2.2.18 and 2.4.0-testX are attached.
> Please apply.

Based on fgconsole.c. I just threw it together in a few minutes.

/*
 * consolewhat.c - Prints which VC /dev/console is.
 */
#include <sys/ioctl.h>
#include <linux/vt.h>

int
main(){
    struct vt_stat vtstat;
    int fd;	

    fd = open("/dev/console", O_RDONLY);	

    if (fd < 0 && errno == EACCES)
	fd = open("/dev/console", O_WRONLY);
    if (fd < 0)
	return -1;

    if (ioctl(fd, VT_GETSTATE, &vtstat)) {
        perror("consolewhat: VT_GETSTATE");
	exit(1);
    }
    printf("%d\n", vtstat.v_active);
    return 0;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16  1:11 ` Linus Torvalds
@ 2000-12-16  1:54   ` Alexander Viro
  2000-12-16 10:46     ` Miquel van Smoorenburg
  2000-12-21 14:22   ` Dr. Werner Fink
  1 sibling, 1 reply; 12+ messages in thread
From: Alexander Viro @ 2000-12-16  1:54 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Kurt Garloff, Alan Cox, miquels, Linux kernel list



On Fri, 15 Dec 2000, Linus Torvalds wrote:

> 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)


There you go... (/proc/tty/console -> /dev/tty<current_VC>; may very well
be dangling, but then you have a current VC even if your /dev consists
of /dev/console and nothing else, so there's nothing to do about that;
doesn't handle TIOCCONS redirects, but IMO that should be a separate
object anyway).
							Cheers,
								Al

diff -urN rc12-pre8/fs/proc/proc_tty.c rc12-pre8-tty/fs/proc/proc_tty.c
--- rc12-pre8/fs/proc/proc_tty.c	Sat Apr 22 02:35:31 2000
+++ rc12-pre8-tty/fs/proc/proc_tty.c	Sat Dec 16 00:14:20 2000
@@ -166,6 +166,26 @@
 	driver->proc_entry = 0;
 }
 
+extern int fg_console;
+static int proc_cons_readlink(struct dentry *dentry, char *buffer, int buflen)
+{
+	char tmp[30];
+	sprintf(tmp, "/dev/tty%d", fg_console);
+	return vfs_readlink(dentry,buffer,buflen,tmp);
+}
+
+static int proc_cons_follow_link(struct dentry *dentry, struct nameidata *nd)
+{
+	char tmp[30];
+	sprintf(tmp, "/dev/tty%d", fg_console);
+	return vfs_follow_link(nd,tmp);
+}	
+
+static struct inode_operations proc_cons_operations = {
+	readlink:	proc_cons_readlink,
+	follow_link:	proc_cons_follow_link,
+};
+
 /*
  * Called by proc_root_init() to initialize the /proc/tty subtree
  */
@@ -175,6 +195,9 @@
 		return;
 	proc_tty_ldisc = proc_mkdir("tty/ldisc", 0);
 	proc_tty_driver = proc_mkdir("tty/driver", 0);
+
+	proc_tty_console = create_proc_entry("tty/console", S_IFLNK|0777, NULL);
+	proc_tty_console->proc_iops = &proc_console_ops;
 
 	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);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16  1:54   ` Alexander Viro
@ 2000-12-16 10:46     ` Miquel van Smoorenburg
  2000-12-16 11:15       ` Alexander Viro
  0 siblings, 1 reply; 12+ messages in thread
From: Miquel van Smoorenburg @ 2000-12-16 10:46 UTC (permalink / raw)
  To: Alexander Viro; +Cc: Linus Torvalds, Kurt Garloff, Alan Cox, Linux kernel list

According to Alexander Viro:
> On Fri, 15 Dec 2000, Linus Torvalds wrote:
> 
> > 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)
> 
> There you go... (/proc/tty/console -> /dev/tty<current_VC>; may very well

The current VT (fg_console) and /dev/console are 2 different things ...
/dev/console might be /dev/ttyS1. Besides to get at fg_console
we already have ioctl(/dev/tty0, TIOCLINUX, 12)

There is currently no way to find out with what device /dev/console
is associated.

Why is that needed? For example, I wrote a program 'bootlogd' that opens
/dev/console and a pty pair, uses TIOCCONS to redirect console
messages to the pty pair so they can be logged. However one would
like to write those messages to the _actual_ console as well, but
there is no way to find out what the real console is.

For this application a ioctl is better than a /proc symlink since
it would be started before /proc is even mounted.

Mike.
-- 
RAND USR 16514
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16  1:18 ` James Simmons
@ 2000-12-16 10:54   ` Miquel van Smoorenburg
  2000-12-18 17:07     ` James Simmons
  0 siblings, 1 reply; 12+ messages in thread
From: Miquel van Smoorenburg @ 2000-12-16 10:54 UTC (permalink / raw)
  To: linux-kernel

In article <Pine.LNX.4.21.0012151709591.1176-100000@euclid.oak.suse.com>,
James Simmons  <jsimmons@suse.com> wrote:
>Based on fgconsole.c. I just threw it together in a few minutes.
>/*
> * consolewhat.c - Prints which VC /dev/console is.
> */

You're confusing /dev/console and /dev/tty0. /dev/console might be
associated with /dev/ttyS0 or /dev/lp1

Mike.
-- 
RAND USR 16514
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16 10:46     ` Miquel van Smoorenburg
@ 2000-12-16 11:15       ` Alexander Viro
  2000-12-16 11:40         ` Miquel van Smoorenburg
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Viro @ 2000-12-16 11:15 UTC (permalink / raw)
  To: Miquel van Smoorenburg
  Cc: Linus Torvalds, Kurt Garloff, Alan Cox, Linux kernel list



On Sat, 16 Dec 2000, Miquel van Smoorenburg wrote:

> There is currently no way to find out with what device /dev/console
> is associated.
> 
> Why is that needed? For example, I wrote a program 'bootlogd' that opens
> /dev/console and a pty pair, uses TIOCCONS to redirect console
> messages to the pty pair so they can be logged. However one would
> like to write those messages to the _actual_ console as well, but
> there is no way to find out what the real console is.
> 
> For this application a ioctl is better than a /proc symlink since
> it would be started before /proc is even mounted.

So mount it... It's not like you didn't have enough privileges for that,
after all, and mount("proc", "/proc", "proc", 0, 0); doesn't look too
complex.

OK, I can see the point of finding out where the console is redirected
to. How about the following:

	/proc/sys/vc -> /dev/tty<n>
	/proc/sys/console -> where the hell did we redirect it or
			     vc if there's no redirect right now
Will that be OK with you?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16 11:15       ` Alexander Viro
@ 2000-12-16 11:40         ` Miquel van Smoorenburg
  2000-12-16 11:57           ` Alexander Viro
  0 siblings, 1 reply; 12+ messages in thread
From: Miquel van Smoorenburg @ 2000-12-16 11:40 UTC (permalink / raw)
  To: Alexander Viro; +Cc: Kurt Garloff, Linux kernel list

According to Alexander Viro:
> OK, I can see the point of finding out where the console is redirected
> to. How about the following:
> 
> 	/proc/sys/vc -> /dev/tty<n>
> 	/proc/sys/console -> where the hell did we redirect it or
> 			     vc if there's no redirect right now
> Will that be OK with you?

Well, I'd prefer the ioctl, but I can see the general direction the
kernel is heading to: get rid of numeric ioctls and sysctl()s and
put all that info under /proc.

However /proc/sys only contains directories now, it would look
kindof ugly to put 2 symlinks in there directly. Oh well.

Mike.
-- 
RAND USR 16514
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16 11:40         ` Miquel van Smoorenburg
@ 2000-12-16 11:57           ` Alexander Viro
  2000-12-19 11:34             ` Kurt Garloff
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Viro @ 2000-12-16 11:57 UTC (permalink / raw)
  To: Miquel van Smoorenburg; +Cc: Kurt Garloff, Linux kernel list



On Sat, 16 Dec 2000, Miquel van Smoorenburg wrote:

> According to Alexander Viro:
> > OK, I can see the point of finding out where the console is redirected
> > to. How about the following:
> > 
> > 	/proc/sys/vc -> /dev/tty<n>
> > 	/proc/sys/console -> where the hell did we redirect it or
> > 			     vc if there's no redirect right now
> > Will that be OK with you?
> 
> Well, I'd prefer the ioctl, but I can see the general direction the
> kernel is heading to: get rid of numeric ioctls and sysctl()s and
> put all that info under /proc.
> 
> However /proc/sys only contains directories now, it would look

Huh? Oh, sorry. /proc/tty, indeed - it was a braino. BTW, I think
that a mini-fs with a device node for each registered console +
symlink (say it, "default") pointing to the default one might make
sense too. Comments?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16 10:54   ` Miquel van Smoorenburg
@ 2000-12-18 17:07     ` James Simmons
  0 siblings, 0 replies; 12+ messages in thread
From: James Simmons @ 2000-12-18 17:07 UTC (permalink / raw)
  To: Miquel van Smoorenburg; +Cc: linux-kernel


> You're confusing /dev/console and /dev/tty0. /dev/console might be
> associated with /dev/ttyS0 or /dev/lp1

Oops. Forgot about serial consoles :-( 

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16 11:57           ` Alexander Viro
@ 2000-12-19 11:34             ` Kurt Garloff
  0 siblings, 0 replies; 12+ messages in thread
From: Kurt Garloff @ 2000-12-19 11:34 UTC (permalink / raw)
  To: Alexander Viro; +Cc: Miquel van Smoorenburg, Linux kernel list

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

On Sat, Dec 16, 2000 at 06:57:20AM -0500, Alexander Viro wrote:
> On Sat, 16 Dec 2000, Miquel van Smoorenburg wrote:
> > According to Alexander Viro:
> > > OK, I can see the point of finding out where the console is redirected
> > > to. How about the following:
> > > 
> > > 	/proc/sys/vc -> /dev/tty<n>
> > > 	/proc/sys/console -> where the hell did we redirect it or
> > > 			     vc if there's no redirect right now
> > > Will that be OK with you?
> > 
> > Well, I'd prefer the ioctl, but I can see the general direction the
> > kernel is heading to: get rid of numeric ioctls and sysctl()s and
> > put all that info under /proc.

Yes; it looks nicer not to grow the number of ioctls more and more,
but to make things more visible in /proc.

On the other hand, there are some advantages of the ioctl:
It's fast, easy and does not need /proc. That cab be of relevance
for embedded devices, e.g., where ram is short.

> Huh? Oh, sorry. /proc/tty, indeed - it was a braino. BTW, I think
> that a mini-fs with a device node for each registered console +
> symlink (say it, "default") pointing to the default one might make
> sense too. Comments?

Yes, looks like a good solution to me.
But that's far more complicated than the ioctl.

Looking at the sources and starting to write some code, it's not so obvious
to me how to get the right device no all the time and how to create the
correct symlink also in 2.2. Yes, it needs to work on both 2.2 and 2.4 
kernels.

So, I'd like to ask for inclusion of the original patch.
Or can we come up with the /proc/tty solution without adding too much code?

Regards,
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, FRG                               SCSI, Security

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: TIOCGDEV ioctl
  2000-12-16  1:11 ` Linus Torvalds
  2000-12-16  1:54   ` Alexander Viro
@ 2000-12-21 14:22   ` Dr. Werner Fink
  1 sibling, 0 replies; 12+ messages in thread
From: Dr. Werner Fink @ 2000-12-21 14:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Kurt Garloff, Alan Cox, miquels, Linux kernel list

[-- 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;
+}

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2000-12-21 14:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2000-12-16  1:18 ` James Simmons
2000-12-16 10:54   ` Miquel van Smoorenburg
2000-12-18 17:07     ` James Simmons

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).