-
Notifications
You must be signed in to change notification settings - Fork 41
/
vt.c
47 lines (40 loc) · 795 Bytes
/
vt.c
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
/*
* vt.c
*
* vt switch handling
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
/*
* signal handler: leave the virtual terminal
*/
void sigusr1(int s) {
(void) s;
ioctl(STDIN_FILENO, VT_RELDISP, 1);
}
/*
* signal handler: enter the virtual terminal
*/
void sigusr2(int s) {
(void) s;
ioctl(STDIN_FILENO, VT_RELDISP, VT_ACKACQ);
}
/*
* setup the virtual terminal for enter and leave
*/
void vt_setup() {
struct vt_mode vtmode;
signal(SIGUSR1, sigusr1);
signal(SIGUSR2, sigusr2);
siginterrupt(SIGUSR2, 1);
ioctl(STDIN_FILENO, VT_GETMODE, &vtmode);
vtmode.mode = VT_PROCESS;
vtmode.relsig = SIGUSR1;
vtmode.acqsig = SIGUSR2;
ioctl(STDIN_FILENO, VT_SETMODE, &vtmode);
}