careadlinkat: Clarify specification.
[gnulib.git] / tests / test-passfd.c
index ca46266..d657ad9 100644 (file)
 #include "passfd.h"
 
 #include <fcntl.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 
 #include "macros.h"
 
@@ -39,6 +41,12 @@ main ()
   int fd;
   struct stat st;
 
+#if HAVE_DECL_ALARM
+  /* Avoid hanging on failure.  */
+  signal (SIGALRM, SIG_DFL);
+  alarm (5);
+#endif
+
   fdnull = open ("/dev/null", O_RDWR);
   if (fdnull < 0)
     {
@@ -86,8 +94,7 @@ main ()
         }
       ASSERT (ret == pid);
 
-      ret = WIFEXITED (status);
-      if (ret == 0)
+      if (!WIFEXITED (status))
         {
           fprintf (stderr, "Child does not normally exit\n");
           return 65;
@@ -100,8 +107,8 @@ main ()
         }
 
       /* try to stat new fd */
-      ret == fstat (fd, &st);
-      if (0 != ret)
+      ret = fstat (fd, &st);
+      if (ret < 0)
         {
           perror ("fstat");
           return 80;