aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace/terminal.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-07-16 11:32:00 -0400
committerLibravatar netblue30 <netblue30@protonmail.com>2023-07-16 11:32:00 -0400
commitf3e428e6fab326c993e17eeae1c223dcb5f8dc2b (patch)
treea750e0b86041ae5df4ab2acb817af23648c2a568 /src/fnettrace/terminal.c
parentMerge branch 'master' of ssh://github.com/netblue30/firejail (diff)
downloadfirejail-f3e428e6fab326c993e17eeae1c223dcb5f8dc2b.tar.gz
firejail-f3e428e6fab326c993e17eeae1c223dcb5f8dc2b.tar.zst
firejail-f3e428e6fab326c993e17eeae1c223dcb5f8dc2b.zip
feature: stats support for --nettrace
Diffstat (limited to 'src/fnettrace/terminal.c')
-rw-r--r--src/fnettrace/terminal.c52
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
23static struct termios tlocal; // startup terminal setting
24static struct termios twait; // no wait on key press
25static int tset = 0;
26
27void terminal_restore(void) {
28 if (tset)
29 tcsetattr(0, TCSANOW, &tlocal);
30}
31
32void terminal_handler(int s) {
33 // Remove unused parameter warning
34 (void)s;
35 terminal_restore();
36 _exit(0);
37}
38
39void 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