Commit 1938337af35bcd8ecf8ed91c36eba77d6bc88c7d
Reset terminal atexit
Reset it when exiting from warn/err, not just when exiting cleanly.cel committed on 12/17/2018, 5:22:13 AM
Parent: 077a9ec3311d0f31d272f71bb0a99dfd5d8102a1
Files changed
sbotc.c | changed |
sbotc.c | ||
---|---|---|
@@ -103,8 +103,15 @@ | ||
103 | 103 … | 0xac, 0x1b, 0x08, 0x42, 0x0c, 0xea, 0xac, 0x23, |
104 | 104 … | 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb |
105 | 105 … | }; |
106 | 106 … | |
107 … | +struct termios orig_tc; | |
108 … | + | |
109 … | +static void reset_termios() { | |
110 … | + int rc = tcsetattr(STDIN_FILENO, TCSANOW, &orig_tc); | |
111 … | + if (rc < 0) warn("tcsetattr"); | |
112 … | +} | |
113 … | + | |
107 | 114 … | static void usage() { |
108 | 115 … | fputs("usage: sbotc [-j] [-T] [-l] [-r]\n" |
109 | 116 … | " [ -n | [-c <cap>] [-k <key>] [-K <keypair_seed>] ]\n" |
110 | 117 … | " [ [-s <host>] [-p <port>] [ -4 | -6 ] | [-u <socket_path>] ]\n" |
@@ -1135,17 +1142,18 @@ | ||
1135 | 1142 … | } |
1136 | 1143 … | |
1137 | 1144 … | muxrpc_call(&bs, method, argument, type, typestr, 1); |
1138 | 1145 … | |
1139 | - struct termios orig_tc; | |
1140 | 1146 … | if (raw) { |
1141 | 1147 … | struct termios raw_tc; |
1142 | 1148 … | rc = tcgetattr(STDIN_FILENO, &orig_tc); |
1143 | 1149 … | if (rc < 0) warn("tcgetattr"); |
1144 | 1150 … | raw_tc = orig_tc; |
1145 | 1151 … | raw_tc.c_lflag &= ~(ICANON | ECHO); |
1146 | 1152 … | rc = tcsetattr(STDIN_FILENO, TCSANOW, &raw_tc); |
1147 | 1153 … | if (rc < 0) warn("tcgetattr"); |
1154 … | + rc = atexit(reset_termios); | |
1155 … | + if (rc < 0) warn("atexit"); | |
1148 | 1156 … | } |
1149 | 1157 … | |
1150 | 1158 … | switch (type) { |
1151 | 1159 … | case muxrpc_type_async: |
@@ -1165,13 +1173,8 @@ | ||
1165 | 1173 … | rc = muxrpc_duplex(&bs, STDIN_FILENO, STDOUT_FILENO, ptype, 1, no_newline, raw); |
1166 | 1174 … | break; |
1167 | 1175 … | } |
1168 | 1176 … | |
1169 | - if (raw) { | |
1170 | - rc = tcsetattr(STDIN_FILENO, TCSANOW, &orig_tc); | |
1171 | - if (rc < 0) warn("tcsetattr"); | |
1172 | - } | |
1173 | - | |
1174 | 1177 … | ps_goodbye(&bs); |
1175 | 1178 … | bs_end(&bs); |
1176 | 1179 … | close(s); |
1177 | 1180 … | return rc; |
Built with git-ssb-web