]> rtime.felk.cvut.cz Git - sojka/sterm.git/commitdiff
Handle hang-up event on stdin
authorMichal Sojka <michal.sojka@cvut.cz>
Thu, 12 Sep 2019 19:01:07 +0000 (21:01 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 12 Sep 2019 19:01:07 +0000 (21:01 +0200)
When sterm is run with pipe as stdin rather than terminal, as is the
case, for example, with the following command:

     ssh somewhere sterm /dev/ttyS0

closing the pipe (e.g. killing ssh) does not send SIGHUP signal, but
POLLHUP event is reported by poll(). When this happened, sterm ended
up in an infinite loop, consuming 100% CPU. Now, we handle this event
and exit.

sterm.c

diff --git a/sterm.c b/sterm.c
index e5bf7df51423dfb12428ccd935ad842eb0e31011..040c22f29c9a5ec163c4b944862087f5069068ca 100644 (file)
--- a/sterm.c
+++ b/sterm.c
@@ -1,7 +1,7 @@
 /*
  * Simple serial terminal
  *
- * Copyright 2014, 2015, 2016, 2017 Michal Sojka <sojkam1@fel.cvut.cz>
+ * Copyright 2014, 2015, 2016, 2017, 2019 Michal Sojka <sojkam1@fel.cvut.cz>
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -373,6 +373,10 @@ int main(int argc, char *argv[])
                                exit(1);
                        }
                }
+               if (fds[0].revents & POLLHUP) {
+                       VERBOSE("HUP on stdin\r\n");
+                       break;
+               }
                if (fds[1].revents & POLLIN) {
                        r1 = CHECK(read(fd, buf, sizeof(buf)));
                        if (r1 == 0) {