On Wed, Feb 15, 2006 at 01:04:49PM -0600, David Berg wrote:
> On 2/15/06, Marc Shapiro <mshapiro_42@yahoo.com> wrote:
> > Is there any way to determine the virtual terminal that an X session is
> > running on?
>
> $ man -k vt
> ...
> fgconsole (1) - print the number of the active VT.
> ...
>
> It seems to need super user privileges though. I can see why super
> user privileges should be necessary for chvt but not fgconsole. Does
> anyone know why or should it be reported as a "bug".
Hi,
it doesn't need root privileges here... this is basically all it's doing
(I hadn't found fgconsole, so I wrapped up something similar):
] #include <linux/vt.h>
] #include <sys/ioctl.h>
] #include <fcntl.h>
] #include <sys/types.h>
] #include <stdio.h>
] #include <unistd.h>
] #include <string.h>
] #include <errno.h>
]
] int main(int an, char **ac) {
] (void)an; (void)ac;
] struct vt_stat V; memset(&V, 0, sizeof(V));
] int o = open("/dev/tty", O_RDONLY|O_NOCTTY);
] if (o<0) { fprintf(stderr, "Can't open /dev/tty...\n"); return 1; }
] int r = ioctl(o, VT_GETSTATE, &V);
] if (r<0) { fprintf(stderr, "ioctl() failed... errno=%i\n", errno); return 1; }
] printf("Active terminal: %u\n", V.v_active);
] close(o);
] return 0;
] }
Apparently VT_GETSTATE doesn't work when you're under X (returns EINVAL)...
but there's an alternate solution: Marc, what about the "vtXX" commandline option
to the X server? See man XFree86 or Xorg...
HTH,
Jan
--
Jan C. Nordholz
<jckn At gmx net>
Attachment:
signature.asc
Description: Digital signature