Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <sys/vt.h>
- int main(int argc, char **argv)
- {
- int fd;
- unsigned char vtnum;
- bool vtlock;
- if (argc < 3) {
- fprintf(stderr, "Usage: vt_set_lock <vtnum> <lock>\n"
- " (use numeric int/bool values)\n");
- exit(EXIT_FAILURE);
- }
- fd = open("/dev/tty0", O_RDWR);
- if (fd < 0) {
- perror("/dev/tty");
- exit(EXIT_FAILURE);
- }
- vtnum = *argv[1]-'0';
- vtlock = !!(*argv[2]-'0');
- /* switch */
- if (ioctl(fd, VT_UNLOCKSWITCH, 1) < 0) {
- perror("VT_UNLOCKSWITCH");
- exit(EXIT_FAILURE);
- }
- if (ioctl(fd, VT_ACTIVATE, vtnum) < 0) {
- perror("VT_ACTIVATE");
- exit(EXIT_FAILURE);
- }
- /* lock */
- if (vtlock) {
- if (ioctl(fd, VT_LOCKSWITCH, 1) < 0) {
- perror("VT_LOCKSWITCH");
- exit(EXIT_FAILURE);
- }
- } else {
- if (ioctl(fd, VT_UNLOCKSWITCH, 1) < 0) {
- perror("VT_UNLOCKSWITCH");
- exit(EXIT_FAILURE);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement