Fix GCC -static-libstdc++.
[nethome.git] / src / orphanripper.c
index 1189df6..b289477 100644 (file)
@@ -41,6 +41,7 @@
 #include <assert.h>
 #include <pty.h>
 #include <poll.h>
+#include <sys/stat.h>
 
 #define LENGTH(x) (sizeof (x) / sizeof (*(x)))
 
@@ -87,6 +88,8 @@ static int read_out (int amaster)
   /* Weird but at least after POLLHUP we get EIO instead of just EOF.  */
   if (buf_got == -1 && errno == EIO)
     return 0;
+  if (buf_got == -1 && errno == EAGAIN)
+    return 0;
   if (buf_got < 0)
     {
       perror ("read (amaster)");
@@ -276,12 +279,16 @@ static int spawn (char **argv, int timeout)
 
   assert (signal_chld_hit != 0);
 
+  /* Do not unset O_NONBLOCK as a stale child (the whole purpose of this
+     program) having open its output pty would block us in read_out.  */
+#if 0
   i = fcntl (amaster, F_SETFL, O_RDONLY /* !O_NONBLOCK */);
   if (i != 0)
     {
       perror ("fcntl (amaster, F_SETFL, O_RDONLY /* !O_NONBLOCK */)");
       exit (EXIT_FAILURE);
     }
+#endif
 
   while (read_out (amaster));