Reset terminal atexit

Reset it when exiting from warn/err, not just when exiting cleanly.
main
cel 6 years ago
parent 077a9ec331
commit 1938337af3

@ -104,6 +104,13 @@ static const unsigned char ssb_cap[] = {
0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
};
struct termios orig_tc;
static void reset_termios() {
int rc = tcsetattr(STDIN_FILENO, TCSANOW, &orig_tc);
if (rc < 0) warn("tcsetattr");
}
static void usage() {
fputs("usage: sbotc [-j] [-T] [-l] [-r]\n"
" [ -n | [-c <cap>] [-k <key>] [-K <keypair_seed>] ]\n"
@ -1136,7 +1143,6 @@ do_tcp_connect:
muxrpc_call(&bs, method, argument, type, typestr, 1);
struct termios orig_tc;
if (raw) {
struct termios raw_tc;
rc = tcgetattr(STDIN_FILENO, &orig_tc);
@ -1145,6 +1151,8 @@ do_tcp_connect:
raw_tc.c_lflag &= ~(ICANON | ECHO);
rc = tcsetattr(STDIN_FILENO, TCSANOW, &raw_tc);
if (rc < 0) warn("tcgetattr");
rc = atexit(reset_termios);
if (rc < 0) warn("atexit");
}
switch (type) {
@ -1166,11 +1174,6 @@ do_tcp_connect:
break;
}
if (raw) {
rc = tcsetattr(STDIN_FILENO, TCSANOW, &orig_tc);
if (rc < 0) warn("tcsetattr");
}
ps_goodbye(&bs);
bs_end(&bs);
close(s);

Loading…
Cancel
Save