lkml.org 
[lkml]   [2000]   [Dec]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: TIOCGDEV ioctl

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

\
 
 \ /
  Last update: 2005-03-22 12:52    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site