summaryrefslogtreecommitdiffstats
path: root/main/sipp/fix-stdin.patch
blob: c420d5dcebdf2638193ffdb1a838d620763c1465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--- ./sipp.cpp.orig	2013-09-23 15:05:15.164194852 +0000
+++ ./sipp.cpp	2013-09-23 15:07:12.685491835 +0000
@@ -1989,8 +1989,15 @@
   }
 }
 
+static int stdin_mode;
+void reset_stdin_socket() {
+  fcntl(fileno(stdin), F_SETFL, stdin_mode);
+}
+
 void setup_stdin_socket() {
-  fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL) | O_NONBLOCK);
+  stdin_mode = fcntl(fileno(stdin), F_GETFL);
+  atexit(reset_stdin_socket);
+  fcntl(fileno(stdin), F_SETFL, stdin_mode | O_NONBLOCK);
   stdin_socket = sipp_allocate_socket(0, T_UDP, fileno(stdin), 0);
   if (!stdin_socket) {
     ERROR_NO("Could not setup keyboard (stdin) socket!\n");