TIOCGDEV ioctl
Subsystems (2)
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.
Signature · 3 lines
Kurt Garloff <[email protected]> Eindhoven, NL GPG key: See mail header, key servers Linux kernel development SuSE GmbH, Nuernberg, FRG SCSI, Security
drivers/char/tty_io.c +2 -1
@@ -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 */
include/asm/ioctls.h +1 -0
@@ -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
include/asm-alpha/ioctls.h +1 -0
@@ -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
include/asm-arm/ioctls.h +1 -0
@@ -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
include/asm-i386/ioctls.h +1 -0
@@ -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
include/asm-ia64/ioctls.h +1 -0
@@ -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
include/asm-m68k/ioctls.h +1 -0
@@ -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
include/asm-mips/ioctls.h +1 -0
@@ -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
include/asm-mips64/ioctls.h +1 -0
@@ -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
include/asm-ppc/ioctls.h +1 -0
@@ -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
include/asm-s390/ioctls.h +1 -0
@@ -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
include/asm-sh/ioctls.h +1 -0
@@ -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 */
include/asm-sparc/ioctls.h +1 -0
@@ -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
include/asm-sparc64/ioctls.h +1 -0
@@ -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
drivers/char/tty_io.c +3 -0
@@ -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 */
include/asm-alpha/ioctls.h +1 -0
@@ -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
include/asm-arm/ioctls.h +1 -0
@@ -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
include/asm-i386/ioctls.h +1 -0
@@ -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
include/asm-m68k/ioctls.h +1 -0
@@ -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
include/asm-mips/ioctls.h +1 -0
@@ -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
include/asm-ppc/ioctls.h +1 -0
@@ -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
include/asm-s390/ioctls.h +1 -0
@@ -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
include/asm-sparc/ioctls.h +1 -0
@@ -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
include/asm-sparc64/ioctls.h +1 -0
@@ -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
Quoted 6 lines · Kurt Garloff
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 forTIOCTTYGSTRUCT_HACKin thebootlogd.cfile 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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Quoted 2 lines · Linus Torvalds
Please instead do the same thing
/dev/ttydoes, 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
fs/proc/proc_tty.c +23 -0
@@ -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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/
According to Alexander Viro:
Quoted 6 lines · Linus Torvalds
Quoted 3 lines
Please instead do the same thing
/dev/ttydoes, 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.
Signature · 5 lines
RAND USR 16514 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] Please read the FAQ at http://www.tux.org/lkml/
Quoted 11 lines · Miquel van Smoorenburg
There is currently no way to find out with what device
/dev/consoleis associated.Why is that needed? For example, I wrote a program 'bootlogd' that opens
/dev/consoleand 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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/
According to Alexander Viro:
Quoted 7 lines
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 nowWill 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.
Signature · 5 lines
RAND USR 16514 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] Please read the FAQ at http://www.tux.org/lkml/
Quoted 9 lines · Miquel van Smoorenburg
According to Alexander Viro:
Quoted 7 lines
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 nowWill that be OK with you?
Quoted 5 lines
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/sysonly 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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Quoted 5 lines · Alexander Viro
Quoted 4 lines · Miquel van Smoorenburg
According to Alexander Viro:
Quoted 3 lines
OK, I can see the point of finding out where the console is redirected to. How about the following:
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
/proc/sys/vc -> /dev/tty<n> /proc/sys/console -> where the hell did we redirect it or vc if there's no redirect right nowWill 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.
Quoted 4 lines
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,
Signature · 3 lines
Kurt Garloff <[email protected]> Eindhoven, NL GPG key: See mail header, key servers Linux kernel development SuSE GmbH, Nuernberg, FRG SCSI, Security
Quoted 15 lines
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 forTIOCTTYGSTRUCT_HACKin thebootlogd.cfile of the sysvinit sources. Shudder!
Quoted 7 lines
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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/
In article <[email protected]>,
Quoted 4 lines · James Simmons
Based on
fgconsole.c. I just threw it together in a few minutes. /*
*consolewhat.c- Prints which VC/dev/consoleis.
*/
You're confusing /dev/console and /dev/tty0. /dev/console might be associated with /dev/ttyS0 or /dev/lp1
Mike.
Signature · 5 lines
RAND USR 16514 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] Please read the FAQ at http://www.tux.org/lkml/
Quoted 3 lines
You're confusing
/dev/consoleand/dev/tty0./dev/consolemight be associated with/dev/ttyS0or/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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Quoted 4 lines · Linus Torvalds
Quoted 1 line · Kurt Garloff
Quoted 8 lines
Quoted 5 lines
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 forTIOCTTYGSTRUCT_HACKin thebootlogd.cfile of the sysvinit sources. Shudder!Please instead do the same thing
/dev/ttydoes, 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.
proc/proc_tty.c +30 -1
@@ -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 ); }
proc/proc_tty.c +32 -2
@@ -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; +}