1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/*
* open.c open a vt to run a new command (or shell).
*
* Copyright (c) 1994 by Jon Tombs <jon@gtex02.us.es>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include "open.h"
const char *SWITCHTOversion = "switchto: 1.0 (c) Jon Tombs 1994";
int
main(int argc, char *argv[])
{
int fd;
int vtno = -1;
if (argc < 2)
usage(1);
vtno = (int) atol(argv[1]);
if (vtno < 0 || vtno > 63)
usage(2);
if ((fd = open("/dev/console",O_WRONLY,0)) < 0) {
perror("switchto: Can't open /dev/console\n");
return(3);
}
if (ioctl(fd, VT_ACTIVATE, vtno) < 0) {
fprintf(stderr, "switcho: Failed to select VT %d (%s)\n", vtno,
strerror(errno));
return(3);
}
/* wait to be really sure we have switched */
(void) ioctl(fd, VT_WAITACTIVE, vtno);
return 0;
}
void usage(int stat)
{
fprintf(stderr,
"Usage: switchto vt_num\n");
exit (stat);
}
|