From d887b6f842cfeb1c7368bb661ce37276327f6ec4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Wed, 26 May 1999 00:08:11 -0700
Subject: [PATCH] some speculative bugfixes

Rev: src/fd_control.c:1.23
Rev: src/signal_handler.c:1.134
---
 src/fd_control.c     | 41 ++++++++++++++++++++++++++---------------
 src/signal_handler.c | 27 ++++++++++++++++++---------
 2 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/src/fd_control.c b/src/fd_control.c
index eb44319ed0..8038c364c0 100644
--- a/src/fd_control.c
+++ b/src/fd_control.c
@@ -9,7 +9,7 @@
 #include "error.h"
 #include "fdlib.h"
 
-RCSID("$Id: fd_control.c,v 1.22 1998/11/22 11:02:46 hubbe Exp $");
+RCSID("$Id: fd_control.c,v 1.23 1999/05/26 07:08:10 hubbe Exp $");
 
 #else /* TESTING */
 #ifndef _LARGEFILE_SOURCE
@@ -63,26 +63,29 @@ RCSID("$Id: fd_control.c,v 1.22 1998/11/22 11:02:46 hubbe Exp $");
 
 int set_nonblocking(int fd,int which)
 {
+  int ret;
 #ifdef PIKE_DEBUG
   if(fd<0 || fd >MAX_OPEN_FILEDESCRIPTORS)
     fatal("Filedescriptor %d out of range [0,%d).\n",
 	  fd, MAX_OPEN_FILEDESCRIPTORS);
 #endif
 
+  do 
+  {
 #if defined(USE_IOCTL_FIONBIO) || defined(__NT__)
-  return fd_ioctl(fd, FIONBIO, &which);
+    ret=fd_ioctl(fd, FIONBIO, &which);
 #else
 
 #ifdef USE_FCNTL_O_NDELAY
-  return fcntl(fd, F_SETFL, which?O_NDELAY:0);
+    ret=fcntl(fd, F_SETFL, which?O_NDELAY:0);
 #else
 
 #ifdef USE_FCNTL_O_NONBLOCK
-  return fcntl(fd, F_SETFL, which?O_NONBLOCK:0);
+    ret=fcntl(fd, F_SETFL, which?O_NONBLOCK:0);
 #else
 
 #ifdef USE_FCNTL_FNDELAY
-  return fcntl(fd, F_SETFL, which?FNDELAY:0);
+    ret=fcntl(fd, F_SETFL, which?FNDELAY:0);
 #else
 
 #error Do not know how to set your filedescriptors nonblocking.
@@ -91,30 +94,37 @@ int set_nonblocking(int fd,int which)
 #endif
 #endif
 #endif
+  } while(ret <0 && errno==EINTR);
+  return ret;
 }
 
 int query_nonblocking(int fd)
 {
+  int ret;
 #ifdef PIKE_DEBUG
   if(fd<0 || fd > MAX_OPEN_FILEDESCRIPTORS)
     fatal("Filedescriptor out of range.\n");
 #endif
 
+  do 
+  {
 #ifdef USE_FCNTL_O_NDELAY
-  return fcntl(fd, F_GETFL, 0) & O_NDELAY;
+    ret=fcntl(fd, F_GETFL, 0) & O_NDELAY;
 #else
 
 #ifdef USE_FCNTL_O_NONBLOCK
-  return fcntl(fd, F_GETFL, 0) & O_NONBLOCK;
+    ret=return fcntl(fd, F_GETFL, 0) & O_NONBLOCK;
 #else
 
 #ifdef USE_FCNTL_FNDELAY
-  return fcntl(fd, F_GETFL, 0) & FNDELAY;
+    ret=fcntl(fd, F_GETFL, 0) & FNDELAY;
 #else
   return 0;
 #endif
 #endif
 #endif
+  } while(ret <0 && errno==EINTR);
+  return ret;
 }
 
 #ifndef FD_CLOEXEC
@@ -127,9 +137,9 @@ static int num_fds_to_close = 0;
 
 void do_close_on_exec(void)
 {
-  int i;
+  int i,ret;
   for(i=0; i < num_fds_to_close; i++) {
-    close(fds_to_close[i]);
+    while( close(fds_to_close[i]) <0 && errno==EINTR) ;
   }
   num_fds_to_close = 0;
 }
@@ -138,11 +148,12 @@ void do_close_on_exec(void)
 int set_close_on_exec(int fd, int which)
 {
 #ifndef HAVE_BROKEN_F_SETFD
-  if (which) {
-    return fcntl(fd, F_SETFD, FD_CLOEXEC);
-  } else {
-    return fcntl(fd, F_SETFD, 0);
-  }
+  int ret;
+  do 
+  {
+    ret=fcntl(fd, F_SETFD, which ? FD_CLOEXEC : 0);
+  } while (ret <0 && errno==EINTR );
+  return ret;
 #else /* HAVE_BROKEN_F_SETFD */
   int i;
   if (which) {
diff --git a/src/signal_handler.c b/src/signal_handler.c
index db689c8377..57cc5ba398 100644
--- a/src/signal_handler.c
+++ b/src/signal_handler.c
@@ -25,7 +25,7 @@
 #include "main.h"
 #include <signal.h>
 
-RCSID("$Id: signal_handler.c,v 1.133 1999/05/23 22:50:58 grubba Exp $");
+RCSID("$Id: signal_handler.c,v 1.134 1999/05/26 07:08:11 hubbe Exp $");
 
 #ifdef HAVE_PASSWD_H
 # include <passwd.h>
@@ -1282,6 +1282,7 @@ extern int pike_make_pipe(int *);
 #define PROCE_INITGROUPS	6
 #define PROCE_SETUID		7
 #define PROCE_EXEC		8
+#define PROCE_CLOEXEC		9
 
 #define PROCERROR(err, id)	do { int _l, _i; \
     buf[0] = err; buf[1] = errno; buf[2] = id; \
@@ -1291,7 +1292,7 @@ extern int pike_make_pipe(int *);
         ; \
       if (_l < 0) break; \
     } \
-    close(control_pipe[1]); \
+    while(close(control_pipe[1]) < 0 && errno==EINTR); \
     exit(99); \
   } while(0)
 
@@ -2200,8 +2201,8 @@ void f_create_process(INT32 args)
        * fork() failed
        */
 
-      close(control_pipe[0]);
-      close(control_pipe[1]);
+      while(close(control_pipe[0]) < 0 && errno==EINTR);
+      while(close(control_pipe[1]) < 0 && errno==EINTR);
 
       free_perishables(&storage);
 
@@ -2215,7 +2216,7 @@ void f_create_process(INT32 args)
        */
 
       /* Close our child's end of the pipe. */
-      close(control_pipe[1]);
+      while(close(control_pipe[1]) < 0 && errno==EINTR);
 
       free_perishables(&storage);
 
@@ -2247,7 +2248,7 @@ void f_create_process(INT32 args)
       if(e!=1) {
 	/* Paranoia in case close() sets errno. */
 	olderrno = errno;
-	close(control_pipe[0]);
+	while(close(control_pipe[0]) < 0 && errno==EINTR);
 	error("Child process died prematurely. (e=%d errno=%d)\n",
 	      e ,olderrno);
       }
@@ -2257,7 +2258,9 @@ void f_create_process(INT32 args)
 	;
       /* Paranoia in case close() sets errno. */
       olderrno = errno;
-      close(control_pipe[0]);
+
+      while(close(control_pipe[0]) < 0 && errno==EINTR);
+
       if (!e) {
 	/* OK! */
 	pop_n_elems(args);
@@ -2298,6 +2301,10 @@ void f_create_process(INT32 args)
 	  error("Process.create_process(): exec() failed. errno:%d\n"
 		"File not found?\n", buf[1]);
 	  break;
+	case PROCE_CLOEXEC:
+	  error("Process.create_process(): set_close_on_exec() failed. errno:%d\n",
+		buf[1]);
+	  break;
 	case 0:
 	  /* read() probably failed. */
 	default:
@@ -2320,9 +2327,11 @@ void f_create_process(INT32 args)
       extern void do_set_close_on_exec(void);
 
       /* Close our parent's end of the pipe. */
-      close(control_pipe[0]);
+      while(close(control_pipe[0]) < 0 && errno==EINTR);
+
       /* Ensure that the pipe will be closed when the child starts. */
-      set_close_on_exec(control_pipe[1], 1);
+      if(set_close_on_exec(control_pipe[1], 1) < 0)
+          PROCERROR(PROCE_CLOEXEC, 0);
 
       SET_ONERROR(oe, exit_on_error, "Error in create_process() child.");
 
-- 
GitLab