Package: console-tools Version: 1:0.2.3dbs-65 Severity: wishlist The `chvt' utility takes a numeric argument and activates the specified virtual terminal.
Suppose I want to temporarily activate a specific vt for a special purpose, and then switch back to the previously active one when I've finished. In order to do this, I first need to find out what the _currently_ active vt is, then chvt to the new one, and finally chvt back to the original one. So I need a program which will tell me what the currently active vt is. A quick search with `apropos' was unable to find such a program, and console-tools in particular doesn't seem to contain one, which seems odd because it struck me as an obvious thing to want (it is to `read' as chvt is to `write') and because it's trivially implemented by an existing ioctl. Accordingly, I've written it, by hacking on a copy of chvt.c. I attach the resulting source file, `whichvt.c', which ought to be easy to slot into the existing console-tools source framework (in the vttools subdirectory, alongside chvt.c). I'm afraid I didn't get sufficiently to grips with the Debian packaging mechanism to be able to prepare a full update to the source package. I hope you'll consider incorporating this utility into a future version of the console-tools package. (Of course, feel free to pass it upstream if you think that's more sensible.) Cheers, Simon -- Simon Tatham "My heart bleeds. <[EMAIL PROTECTED]> (That's how it works.)" -- Gareth Taylor
/* * whichvt.c - sgt - 2007-12-08 - detect current virtual terminal */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/types.h> #include <sys/ioctl.h> #include <linux/vt.h> #include <getopt.h> #include <lct/local.h> #include <lct/utils.h> #include <lct/console.h> static void usage(char *progname) { printf(_("Usage: %s\n" "Find number of current virtual terminal\n"), progname); OPTIONS_ARE(); OPT("-h --help ", HELPDESC); OPT("-V --version ", VERSIONDESC); } void parse_args (int argc,char **argv) { char * progname = strip_path(argv[0]); const struct option long_opts[] = { {"help" , no_argument, NULL, 'h' }, {"version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0} }; int c, cons = -1; while ( (c = getopt_long (argc, argv, "Vht:", long_opts, NULL)) != EOF) { switch (c) { case 'h': usage(progname); exit(0); case 'V': version(progname); exit(0); case '?': default: usage(progname); exit(1); } } if (argc != optind) { fprintf(stderr,_("%s: Wrong number of args\n"), progname); exit(1); } } int main(int argc, char *argv[]) { int fd, num; struct vt_stat stat; setuplocale(); parse_args (argc, argv); if (-1 == (fd = get_console_fd(NULL))) exit (1); if (ioctl(fd, VT_GETSTATE, &stat)) { perror("chvt: VT_GETSTATE"); exit(1); } printf("%d\n", stat.v_active); exit(0); }