git ssb

8+

cel / sbotc



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.cchanged
sbotc.cView
@@ -103,8 +103,15 @@
103103 0xac, 0x1b, 0x08, 0x42, 0x0c, 0xea, 0xac, 0x23,
104104 0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb
105105 };
106106
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 +
107114 static void usage() {
108115 fputs("usage: sbotc [-j] [-T] [-l] [-r]\n"
109116 " [ -n | [-c <cap>] [-k <key>] [-K <keypair_seed>] ]\n"
110117 " [ [-s <host>] [-p <port>] [ -4 | -6 ] | [-u <socket_path>] ]\n"
@@ -1135,17 +1142,18 @@
11351142 }
11361143
11371144 muxrpc_call(&bs, method, argument, type, typestr, 1);
11381145
1139- struct termios orig_tc;
11401146 if (raw) {
11411147 struct termios raw_tc;
11421148 rc = tcgetattr(STDIN_FILENO, &orig_tc);
11431149 if (rc < 0) warn("tcgetattr");
11441150 raw_tc = orig_tc;
11451151 raw_tc.c_lflag &= ~(ICANON | ECHO);
11461152 rc = tcsetattr(STDIN_FILENO, TCSANOW, &raw_tc);
11471153 if (rc < 0) warn("tcgetattr");
1154 + rc = atexit(reset_termios);
1155 + if (rc < 0) warn("atexit");
11481156 }
11491157
11501158 switch (type) {
11511159 case muxrpc_type_async:
@@ -1165,13 +1173,8 @@
11651173 rc = muxrpc_duplex(&bs, STDIN_FILENO, STDOUT_FILENO, ptype, 1, no_newline, raw);
11661174 break;
11671175 }
11681176
1169- if (raw) {
1170- rc = tcsetattr(STDIN_FILENO, TCSANOW, &orig_tc);
1171- if (rc < 0) warn("tcsetattr");
1172- }
1173-
11741177 ps_goodbye(&bs);
11751178 bs_end(&bs);
11761179 close(s);
11771180 return rc;

Built with git-ssb-web