diff options
Diffstat (limited to 'src/fnettrace/terminal.c')
-rw-r--r-- | src/fnettrace/terminal.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/fnettrace/terminal.c b/src/fnettrace/terminal.c new file mode 100644 index 000000000..0ca307bad --- /dev/null +++ b/src/fnettrace/terminal.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2023 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | #include "fnettrace.h" | ||
21 | #include <termios.h> | ||
22 | |||
23 | static struct termios tlocal; // startup terminal setting | ||
24 | static struct termios twait; // no wait on key press | ||
25 | static int tset = 0; | ||
26 | |||
27 | void terminal_restore(void) { | ||
28 | if (tset) | ||
29 | tcsetattr(0, TCSANOW, &tlocal); | ||
30 | } | ||
31 | |||
32 | void terminal_handler(int s) { | ||
33 | // Remove unused parameter warning | ||
34 | (void)s; | ||
35 | terminal_restore(); | ||
36 | _exit(0); | ||
37 | } | ||
38 | |||
39 | void terminal_set(void) { | ||
40 | if (tset == 0) { | ||
41 | tcgetattr(0, &twait); // get current terminal attributes; 0 is the file descriptor for stdin | ||
42 | memcpy(&tlocal, &twait, sizeof(tlocal)); | ||
43 | twait.c_lflag &= ~ICANON; // disable canonical mode | ||
44 | twait.c_lflag &= ~ECHO; // no echo | ||
45 | twait.c_cc[VMIN] = 1; // wait until at least one keystroke available | ||
46 | twait.c_cc[VTIME] = 0; // no timeout | ||
47 | tset = 1; | ||
48 | } | ||
49 | tcsetattr(0, TCSANOW, &twait); | ||
50 | } | ||
51 | |||
52 | |||