]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 46261] Add more EINTRLOOP wrappers.
authorPaul Smith <psmith@gnu.org>
Sat, 5 Mar 2016 20:21:59 +0000 (15:21 -0500)
committerPaul Smith <psmith@gnu.org>
Tue, 8 Mar 2016 05:31:47 +0000 (00:31 -0500)
This cannot be a perfect solution because there are always other
possible places EINTR can happen, including external libraries
such as gettext, Guile etc.

arscan.c
configure.ac
job.c
main.c
output.c
remake.c

index 568c3b87f5669696a034d78755f3af2c427737c4..d35686ddf8ca522e474e5bedfcb4896ddd7782f7 100644 (file)
--- a/arscan.c
+++ b/arscan.c
@@ -420,7 +420,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
 #ifdef SARMAG
   {
     char buf[SARMAG];
-    register int nread = read (desc, buf, SARMAG);
+    int nread;
+    EINTRLOOP (nread, read (desc, buf, SARMAG));
     if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG))
       {
         (void) close (desc);
@@ -430,8 +431,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
 #else
 #ifdef AIAMAG
   {
-    register int nread = read (desc, &fl_header, FL_HSZ);
-
+    int nread;
+    EINTRLOOP (nread, read (desc, &fl_header, FL_HSZ));
     if (nread != FL_HSZ)
       {
         (void) close (desc);
@@ -442,17 +443,20 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
        re-read the header into the "big" structure. */
     if (!memcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG))
       {
+        off_t o;
+
         big_archive = 1;
 
         /* seek back to beginning of archive */
-        if (lseek (desc, 0, 0) < 0)
+        EINTRLOOP (o, lseek (desc, 0, 0));
+        if (o < 0)
           {
             (void) close (desc);
             return -2;
           }
 
         /* re-read the header into the "big" structure */
-        nread = read (desc, &fl_header_big, FL_HSZ_BIG);
+        EINTRLOOP (nread, read (desc, &fl_header_big, FL_HSZ_BIG));
         if (nread != FL_HSZ_BIG)
           {
             (void) close (desc);
@@ -475,7 +479,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
 #else
     unsigned short int buf;
 #endif
-    register int nread = read (desc, &buf, sizeof (buf));
+    int nread;
+    EINTRLOOP (nread, read (desc, &buf, sizeof (buf)));
     if (nread != sizeof (buf) || buf != ARMAG)
       {
         (void) close (desc);
@@ -544,8 +549,10 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
         long int eltsize;
         int eltmode;
         long int fnval;
+        off_t o;
 
-        if (lseek (desc, member_offset, 0) < 0)
+        EINTRLOOP (o, lseek (desc, member_offset, 0));
+        if (o < 0)
           {
             (void) close (desc);
             return -2;
@@ -557,8 +564,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
 #ifdef AIAMAGBIG
         if (big_archive)
           {
-            nread = read (desc, &member_header_big,
-                          AR_MEMHDR_SZ(member_header_big) );
+            EINTRLOOP (nread, read (desc, &member_header_big,
+                                    AR_MEMHDR_SZ(member_header_big)));
 
             if (nread != AR_MEMHDR_SZ(member_header_big))
               {
@@ -567,7 +574,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
               }
 
             sscanf (member_header_big.ar_namlen, "%4d", &name_len);
-            nread = read (desc, name, name_len);
+            EINTRLOOP (nread, read (desc, name, name_len));
 
             if (nread != name_len)
               {
@@ -589,8 +596,8 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
         else
 #endif
           {
-            nread = read (desc, &member_header,
-                          AR_MEMHDR_SZ(member_header) );
+            EINTRLOOP (nread, read (desc, &member_header,
+                                    AR_MEMHDR_SZ(member_header)));
 
             if (nread != AR_MEMHDR_SZ(member_header))
               {
@@ -599,7 +606,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
               }
 
             sscanf (member_header.ar_namlen, "%4d", &name_len);
-            nread = read (desc, name, name_len);
+            EINTRLOOP (nread, read (desc, name, name_len));
 
             if (nread != name_len)
               {
@@ -627,7 +634,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
                        eltmode, arg);
 
 #else   /* Not AIAMAG.  */
-        nread = read (desc, &member_header, AR_HDR_SIZE);
+        EINTRLOOP (nread, read (desc, &member_header, AR_HDR_SIZE));
         if (nread == 0)
           /* No data left means end of file; that is OK.  */
           break;
@@ -696,7 +703,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
               int namesize = atoi (name + 3);
 
               name = alloca (namesize + 1);
-              nread = read (desc, name, namesize);
+              EINTRLOOP (nread, read (desc, name, namesize));
               if (nread != namesize)
                 {
                   close (desc);
@@ -767,7 +774,7 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
             char *limit;
 
             namemap = alloca (eltsize);
-            nread = read (desc, namemap, eltsize);
+            EINTRLOOP (nread, read (desc, namemap, eltsize));
             if (nread != eltsize)
               {
                 (void) close (desc);
@@ -885,7 +892,8 @@ ar_member_touch (const char *arname, const char *memname)
   long int pos = ar_scan (arname, ar_member_pos, memname);
   int fd;
   struct ar_hdr ar_hdr;
-  int i;
+  off_t o;
+  int r;
   unsigned int ui;
   struct stat statbuf;
 
@@ -894,28 +902,32 @@ ar_member_touch (const char *arname, const char *memname)
   if (!pos)
     return 1;
 
-  fd = open (arname, O_RDWR, 0666);
+  EINTRLOOP (fd, open (arname, O_RDWR, 0666));
   if (fd < 0)
     return -3;
   /* Read in this member's header */
-  if (lseek (fd, pos, 0) < 0)
+  EINTRLOOP (o, lseek (fd, pos, 0));
+  if (o < 0)
     goto lose;
-  if (AR_HDR_SIZE != read (fd, &ar_hdr, AR_HDR_SIZE))
+  EINTRLOOP (r, read (fd, &ar_hdr, AR_HDR_SIZE));
+  if (r != AR_HDR_SIZE)
     goto lose;
   /* Write back the header, thus touching the archive file.  */
-  if (lseek (fd, pos, 0) < 0)
+  EINTRLOOP (o, lseek (fd, pos, 0));
+  if (o < 0)
     goto lose;
-  if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE))
+  EINTRLOOP (r, write (fd, &ar_hdr, AR_HDR_SIZE));
+  if (r != AR_HDR_SIZE)
     goto lose;
   /* The file's mtime is the time we we want.  */
-  EINTRLOOP (i, fstat (fd, &statbuf));
-  if (i < 0)
+  EINTRLOOP (r, fstat (fd, &statbuf));
+  if (r < 0)
     goto lose;
 #if defined(ARFMAG) || defined(ARFZMAG) || defined(AIAMAG) || defined(WINDOWS32)
   /* Advance member's time to that time */
   for (ui = 0; ui < sizeof ar_hdr.ar_date; ui++)
     ar_hdr.ar_date[ui] = ' ';
-  sprintf (TOCHAR (ar_hdr.ar_date), "%ld", (long int) statbuf.st_mtime);
+  sprintf (TOCHAR (ar_hdr.ar_date), "%lu", (long unsigned) statbuf.st_mtime);
 #ifdef AIAMAG
   ar_hdr.ar_date[strlen (ar_hdr.ar_date)] = ' ';
 #endif
@@ -923,17 +935,19 @@ ar_member_touch (const char *arname, const char *memname)
   ar_hdr.ar_date = statbuf.st_mtime;
 #endif
   /* Write back this member's header */
-  if (lseek (fd, pos, 0) < 0)
+  EINTRLOOP (o, lseek (fd, pos, 0));
+  if (o < 0)
     goto lose;
-  if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE))
+  EINTRLOOP (r, write (fd, &ar_hdr, AR_HDR_SIZE));
+  if (r != AR_HDR_SIZE)
     goto lose;
   close (fd);
   return 0;
 
  lose:
-  i = errno;
+  r = errno;
   close (fd);
-  errno = i;
+  errno = r;
   return -3;
 }
 #endif
index 35d4c8cb5d6898971e947e62aea2a6ada0314e1a..7062246a6c9c4c493e90dfdd2b2f49e611dcfdf9 100644 (file)
@@ -75,15 +75,10 @@ AC_C_CONST
 AC_TYPE_SIGNAL
 AC_TYPE_UID_T
 AC_TYPE_PID_T
-
-# Find some definition for uintmax_t
-
-AC_CHECK_TYPE([uintmax_t],[],
-[ uintmax_t="unsigned long"
-  AC_CHECK_TYPE([unsigned long long],[uintmax_t="unsigned long long"])
-  AC_DEFINE_UNQUOTED([uintmax_t], [$uintmax_t],
-    [Define uintmax_t if not defined in <stdint.h> or <inttypes.h>.])
-])
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+AC_TYPE_UINTMAX_T
 
 # Find out whether our struct stat returns nanosecond resolution timestamps.
 
diff --git a/job.c b/job.c
index 45a433f113f492c633c1e65bd79ab1aa5730c6cb..7717b2698536164fe7a73eae8895f97fa76c82b8 100644 (file)
--- a/job.c
+++ b/job.c
@@ -685,7 +685,7 @@ reap_children (int block, int err)
                 pid = WAIT_NOHANG (&status);
               else
 #endif
-                EINTRLOOP(pid, wait (&status));
+                EINTRLOOP (pid, wait (&status));
 #endif /* !VMS */
             }
           else
@@ -1999,7 +1999,7 @@ new_job (struct file *file)
         if (job_rfd < 0)
           {
             DB (DB_JOBS, ("Duplicate the job FD\n"));
-            job_rfd = dup (job_fds[0]);
+            EINTRLOOP (job_rfd, dup (job_fds[0]));
           }
 #endif
 
@@ -2036,7 +2036,7 @@ new_job (struct file *file)
 #else
         /* Set interruptible system calls, and read() for a job token.  */
         set_child_handler_action_flags (1, waiting_jobs != NULL);
-        got_token = read (job_rfd, &token, 1);
+        EINTRLOOP (got_token, read (job_rfd, &token, 1));
         saved_errno = errno;
         set_child_handler_action_flags (0, waiting_jobs != NULL);
 #endif
@@ -2352,17 +2352,19 @@ void
 child_execute_job (int stdin_fd, int stdout_fd, int stderr_fd,
                    char **argv, char **envp)
 {
+  int r;
+
   /* For any redirected FD, dup2() it to the standard FD then close it.  */
   if (stdin_fd != FD_STDIN)
     {
-      dup2 (stdin_fd, FD_STDIN);
+      EINTRLOOP (r, dup2 (stdin_fd, FD_STDIN));
       close (stdin_fd);
     }
 
   if (stdout_fd != FD_STDOUT)
-    dup2 (stdout_fd, FD_STDOUT);
+    EINTRLOOP (r, dup2 (stdout_fd, FD_STDOUT));
   if (stderr_fd != FD_STDERR)
-    dup2 (stderr_fd, FD_STDERR);
+    EINTRLOOP (r, dup2 (stderr_fd, FD_STDERR));
 
   if (stdout_fd != FD_STDOUT)
     close (stdout_fd);
@@ -3690,7 +3692,7 @@ dup2 (int old, int new)
   int fd;
 
   (void) close (new);
-  fd = dup (old);
+  EINTRLOOP (fd, dup (old));
   if (fd != new)
     {
       (void) close (fd);
diff --git a/main.c b/main.c
index 31b29d648242673b51a96896dde8e643bad84542..df5540a8c7dc922c3fa50be4800adba9a2ee8063 100644 (file)
--- a/main.c
+++ b/main.c
@@ -3488,8 +3488,14 @@ clean_jobserver (int status)
       /* Close the write side, so the read() won't hang.  */
       close (job_fds[1]);
 
-      while (read (job_fds[0], &token, 1) == 1)
-        ++tcnt;
+      while (1)
+        {
+          int r;
+          EINTRLOOP (r, read (job_fds[0], &token, 1));
+          if (r != 1)
+            break;
+          ++tcnt;
+        }
 #endif
 
       if (tcnt != master_job_slots)
index f81c9a8f3cfa18a9e18e8ef1812b1e39d84cc304..4b7bd5da45437a859a3a07af3d3503da09968a09 100644 (file)
--- a/output.c
+++ b/output.c
@@ -441,7 +441,7 @@ output_tmpfile (char **name, const char *template)
 
 # ifdef HAVE_FDOPEN
   /* Can't use mkstemp(), but guard against a race condition.  */
-  fd = open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600);
+  EINTRLOOP (fd, open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600));
   if (fd == -1)
     return 0;
   return fdopen (fd, "w");
index 5a7f167e3e279cc75612ba55815d51321d210318..e7a7d495a4965d55618f5d15e41b2b6e0e1b968d 100644 (file)
--- a/remake.c
+++ b/remake.c
@@ -1158,8 +1158,9 @@ touch_file (struct file *file)
   else
 #endif
     {
-      int fd = open (file->name, O_RDWR | O_CREAT, 0666);
+      int fd;
 
+      EINTRLOOP (fd, open (file->name, O_RDWR | O_CREAT, 0666));
       if (fd < 0)
         TOUCH_ERROR ("touch: open: ");
       else
@@ -1172,18 +1173,24 @@ touch_file (struct file *file)
           if (e < 0)
             TOUCH_ERROR ("touch: fstat: ");
           /* Rewrite character 0 same as it already is.  */
-          if (read (fd, &buf, 1) < 0)
+          EINTRLOOP (e, read (fd, &buf, 1));
+          if (e < 0)
             TOUCH_ERROR ("touch: read: ");
-          if (lseek (fd, 0L, 0) < 0L)
-            TOUCH_ERROR ("touch: lseek: ");
-          if (write (fd, &buf, 1) < 0)
+          {
+            off_t o;
+            EINTRLOOP (o, lseek (fd, 0L, 0));
+            if (o < 0L)
+              TOUCH_ERROR ("touch: lseek: ");
+          }
+          EINTRLOOP (e, write (fd, &buf, 1));
+          if (e < 0)
             TOUCH_ERROR ("touch: write: ");
-          /* If file length was 0, we just
-             changed it, so change it back.  */
+
+          /* If file length was 0, we just changed it, so change it back.  */
           if (statbuf.st_size == 0)
             {
               (void) close (fd);
-              fd = open (file->name, O_RDWR | O_TRUNC, 0666);
+              EINTRLOOP (fd, open (file->name, O_RDWR | O_TRUNC, 0666));
               if (fd < 0)
                 TOUCH_ERROR ("touch: open: ");
             }