emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113434: * fileio.c (report_file_errno): Fix errno r


From: Paul Eggert
Subject: [Emacs-diffs] trunk r113434: * fileio.c (report_file_errno): Fix errno reporting bug.
Date: Tue, 16 Jul 2013 16:39:47 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113434
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2013-07-16 09:39:42 -0700
message:
  * fileio.c (report_file_errno): Fix errno reporting bug.
  
  If the file name is neither null nor a pair, package it up as a
  singleton list.  All callers changed, both to this function and to
  report_file_error.  This fixes a bug where the memory allocator
  invoked by list1 set errno so that the immediately following
  report_file_error reported the wrong errno value.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/callproc.c                 callproc.c-20091113204419-o5vbwnq5f7feedwu-248
  src/dired.c                    dired.c-20091113204419-o5vbwnq5f7feedwu-171
  src/dispnew.c                  dispnew.c-20091113204419-o5vbwnq5f7feedwu-258
  src/doc.c                      doc.c-20091113204419-o5vbwnq5f7feedwu-250
  src/fileio.c                   fileio.c-20091113204419-o5vbwnq5f7feedwu-210
  src/gfilenotify.c              gfilenotify.c-20130528100009-4z0x3dhiuzxnn8hq-1
  src/keyboard.c                 keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
  src/print.c                    print.c-20091113204419-o5vbwnq5f7feedwu-262
  src/process.c                  process.c-20091113204419-o5vbwnq5f7feedwu-462
  src/unexaix.c                  unexaix.c-20091113204419-o5vbwnq5f7feedwu-147
  src/unexcoff.c                 unexec.c-20091113204419-o5vbwnq5f7feedwu-184
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-07-16 14:52:22 +0000
+++ b/src/ChangeLog     2013-07-16 16:39:42 +0000
@@ -1,5 +1,12 @@
 2013-07-16  Paul Eggert  <address@hidden>
 
+       * fileio.c (report_file_errno): Fix errno reporting bug.
+       If the file name is neither null nor a pair, package it up as a
+       singleton list.  All callers changed, both to this function and to
+       report_file_error.  This fixes a bug where the memory allocator
+       invoked by list1 set errno so that the immediately following
+       report_file_error reported the wrong errno value.
+
        Fix minor problems found by --enable-gcc-warnings.
        * frame.c (Fhandle_focus_in, Fhandle_focus_out): Return a value.
        * keyboard.c (kbd_buffer_get_event): Remove unused local.

=== modified file 'src/callproc.c'
--- a/src/callproc.c    2013-07-16 07:05:41 +0000
+++ b/src/callproc.c    2013-07-16 16:39:42 +0000
@@ -392,7 +392,7 @@
 
     if (NILP (Ffile_accessible_directory_p (current_dir)))
       report_file_error ("Setting current directory",
-                        list1 (BVAR (current_buffer, directory)));
+                        BVAR (current_buffer, directory));
 
     if (STRING_MULTIBYTE (infile))
       infile = ENCODE_FILE (infile);
@@ -409,8 +409,7 @@
 
   filefd = emacs_open (SSDATA (infile), O_RDONLY, 0);
   if (filefd < 0)
-    report_file_error ("Opening process input file",
-                      list1 (DECODE_FILE (infile)));
+    report_file_error ("Opening process input file", DECODE_FILE (infile));
 
   if (STRINGP (output_file))
     {
@@ -422,7 +421,7 @@
          int open_errno = errno;
          output_file = DECODE_FILE (output_file);
          report_file_errno ("Opening process output file",
-                            list1 (output_file), open_errno);
+                            output_file, open_errno);
        }
       if (STRINGP (error_file) || NILP (error_file))
        output_to_buffer = 0;
@@ -440,8 +439,7 @@
       {
        int openp_errno = errno;
        emacs_close (filefd);
-       report_file_errno ("Searching for program",
-                          list1 (args[0]), openp_errno);
+       report_file_errno ("Searching for program", args[0], openp_errno);
       }
   }
 
@@ -506,7 +504,7 @@
          int open_errno = errno;
          emacs_close (filefd);
          report_file_errno ("Opening process output file",
-                            list1 (build_string (tempfile)), open_errno);
+                            build_string (tempfile), open_errno);
        }
     }
   else
@@ -563,8 +561,7 @@
          error_file = build_string (NULL_DEVICE);
        else if (STRINGP (error_file))
          error_file = DECODE_FILE (error_file);
-       report_file_errno ("Cannot redirect stderr",
-                          list1 (error_file), open_errno);
+       report_file_errno ("Cannot redirect stderr", error_file, open_errno);
       }
 
 #ifdef MSDOS /* MW, July 1993 */
@@ -596,7 +593,7 @@
            unlink (tempfile);
            emacs_close (filefd);
            report_file_errno ("Cannot re-open temporary file",
-                              list1 (build_string (tempfile)), open_errno);
+                              build_string (tempfile), open_errno);
          }
       }
     else
@@ -1027,7 +1024,7 @@
 #endif
       if (fd < 0)
        report_file_error ("Failed to open temporary file using pattern",
-                          list1 (pattern));
+                          pattern);
       emacs_close (fd);
     }
 

=== modified file 'src/dired.c'
--- a/src/dired.c       2013-07-16 06:39:49 +0000
+++ b/src/dired.c       2013-07-16 16:39:42 +0000
@@ -185,7 +185,7 @@
 
   d = open_directory (SSDATA (dirfilename), &fd);
   if (d == NULL)
-    report_file_error ("Opening directory", list1 (directory));
+    report_file_error ("Opening directory", directory);
 
   /* Unfortunately, we can now invoke expand-file-name and
      file-attributes on filenames, both of which can throw, so we must
@@ -488,7 +488,7 @@
 
   d = open_directory (SSDATA (encoded_dir), &fd);
   if (!d)
-    report_file_error ("Opening directory", list1 (dirname));
+    report_file_error ("Opening directory", dirname);
 
   record_unwind_protect (directory_files_internal_unwind,
                         make_save_pointer (d));

=== modified file 'src/dispnew.c'
--- a/src/dispnew.c     2013-07-16 06:39:49 +0000
+++ b/src/dispnew.c     2013-07-16 16:39:42 +0000
@@ -5619,7 +5619,7 @@
       file = Fexpand_file_name (file, Qnil);
       tty->termscript = emacs_fopen (SSDATA (file), "w");
       if (tty->termscript == 0)
-       report_file_error ("Opening termscript", list1 (file));
+       report_file_error ("Opening termscript", file);
     }
   return Qnil;
 }

=== modified file 'src/doc.c'
--- a/src/doc.c 2013-07-16 06:39:49 +0000
+++ b/src/doc.c 2013-07-16 16:39:42 +0000
@@ -609,7 +609,7 @@
 
   fd = emacs_open (name, O_RDONLY, 0);
   if (fd < 0)
-    report_file_error ("Opening doc string file", list1 (build_string (name)));
+    report_file_error ("Opening doc string file", build_string (name));
   Vdoc_file_name = filename;
   filled = 0;
   pos = 0;

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2013-07-16 06:39:49 +0000
+++ b/src/fileio.c      2013-07-16 16:39:42 +0000
@@ -160,11 +160,16 @@
 
 
 /* Signal a file-access failure.  STRING describes the failure,
-   DATA the file that was involved, and ERRORNO the errno value.  */
+   NAME the file involved, and ERRORNO the errno value.
+
+   If NAME is neither null nor a pair, package it up as a singleton
+   list before reporting it; this saves report_file_errno's caller the
+   trouble of preserving errno before calling list1.  */
 
 void
-report_file_errno (char const *string, Lisp_Object data, int errorno)
+report_file_errno (char const *string, Lisp_Object name, int errorno)
 {
+  Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name);
   Lisp_Object errstring;
   char *str;
 
@@ -198,10 +203,13 @@
       }
 }
 
+/* Signal a file-access failure that set errno.  STRING describes the
+   failure, NAME the file involved.  */
+
 void
-report_file_error (char const *string, Lisp_Object data)
+report_file_error (char const *string, Lisp_Object name)
 {
-  report_file_errno (string, data, errno);
+  report_file_errno (string, name, errno);
 }
 
 Lisp_Object
@@ -749,7 +757,7 @@
               dog-slow, but also useless since eventually nil would
               have to be returned anyway.  */
            report_file_error ("Cannot create temporary name for prefix",
-                              list1 (prefix));
+                              prefix);
          /* not reached */
        }
     }
@@ -2019,7 +2027,7 @@
     {
       acl = acl_get_file (SDATA (encoded_file), ACL_TYPE_ACCESS);
       if (acl == NULL && acl_errno_valid (errno))
-       report_file_error ("Getting ACL", list1 (file));
+       report_file_error ("Getting ACL", file);
     }
   if (!CopyFile (SDATA (encoded_file),
                 SDATA (encoded_newname),
@@ -2058,7 +2066,7 @@
       bool fail =
        acl_set_file (SDATA (encoded_newname), ACL_TYPE_ACCESS, acl) != 0;
       if (fail && acl_errno_valid (errno))
-       report_file_error ("Setting ACL", list1 (newname));
+       report_file_error ("Setting ACL", newname);
 
       acl_free (acl);
     }
@@ -2068,12 +2076,12 @@
   immediate_quit = 0;
 
   if (ifd < 0)
-    report_file_error ("Opening input file", list1 (file));
+    report_file_error ("Opening input file", file);
 
   record_unwind_protect (close_file_unwind, make_number (ifd));
 
   if (fstat (ifd, &st) != 0)
-    report_file_error ("Input file status", list1 (file));
+    report_file_error ("Input file status", file);
 
   if (!NILP (preserve_extended_attributes))
     {
@@ -2082,7 +2090,7 @@
        {
          conlength = fgetfilecon (ifd, &con);
          if (conlength == -1)
-           report_file_error ("Doing fgetfilecon", list1 (file));
+           report_file_error ("Doing fgetfilecon", file);
        }
 #endif
     }
@@ -2094,7 +2102,7 @@
 
   /* We can copy only regular files.  */
   if (!S_ISREG (st.st_mode))
-    report_file_errno ("Non-regular file", list1 (file),
+    report_file_errno ("Non-regular file", file,
                       S_ISDIR (st.st_mode) ? EISDIR : EINVAL);
 
   {
@@ -2109,7 +2117,7 @@
                      new_mask);
   }
   if (ofd < 0)
-    report_file_error ("Opening output file", list1 (newname));
+    report_file_error ("Opening output file", newname);
 
   record_unwind_protect (close_file_unwind, make_number (ofd));
 
@@ -2117,7 +2125,7 @@
   QUIT;
   while ((n = emacs_read (ifd, buf, sizeof buf)) > 0)
     if (emacs_write_sig (ofd, buf, n) != n)
-      report_file_error ("I/O error", list1 (newname));
+      report_file_error ("I/O error", newname);
   immediate_quit = 0;
 
 #ifndef MSDOS
@@ -2145,8 +2153,8 @@
                         st.st_mode & mode_mask)
            : fchmod (ofd, st.st_mode & mode_mask))
       {
-      case -2: report_file_error ("Copying permissions from", list1 (file));
-      case -1: report_file_error ("Copying permissions to", list1 (newname));
+      case -2: report_file_error ("Copying permissions from", file);
+      case -1: report_file_error ("Copying permissions to", newname);
       }
   }
 #endif /* not MSDOS */
@@ -2158,7 +2166,7 @@
       bool fail = fsetfilecon (ofd, con) != 0;
       /* See http://debbugs.gnu.org/11245 for ENOTSUP.  */
       if (fail && errno != ENOTSUP)
-       report_file_error ("Doing fsetfilecon", list1 (newname));
+       report_file_error ("Doing fsetfilecon", newname);
 
       freecon (con);
     }
@@ -2174,7 +2182,7 @@
     }
 
   if (emacs_close (ofd) < 0)
-    report_file_error ("I/O error", list1 (newname));
+    report_file_error ("I/O error", newname);
 
   emacs_close (ifd);
 
@@ -2220,7 +2228,7 @@
 #else
   if (mkdir (dir, 0777 & ~auto_saving_dir_umask) != 0)
 #endif
-    report_file_error ("Creating directory", list1 (directory));
+    report_file_error ("Creating directory", directory);
 
   return Qnil;
 }
@@ -2239,7 +2247,7 @@
   dir = SSDATA (encoded_dir);
 
   if (rmdir (dir) != 0)
-    report_file_error ("Removing directory", list1 (directory));
+    report_file_error ("Removing directory", directory);
 
   return Qnil;
 }
@@ -2282,7 +2290,7 @@
   encoded_file = ENCODE_FILE (filename);
 
   if (unlink (SSDATA (encoded_file)) < 0)
-    report_file_error ("Removing old name", list1 (filename));
+    report_file_error ("Removing old name", filename);
   return Qnil;
 }
 
@@ -2719,7 +2727,7 @@
   encoded_filename = ENCODE_FILE (absname);
 
   if (faccessat (AT_FDCWD, SSDATA (encoded_filename), R_OK, AT_EACCESS) != 0)
-    report_file_error (SSDATA (string), list1 (filename));
+    report_file_error (SSDATA (string), filename);
 
   return Qnil;
 }
@@ -3054,14 +3062,14 @@
                  != 0);
           /* See http://debbugs.gnu.org/11245 for ENOTSUP.  */
          if (fail && errno != ENOTSUP)
-           report_file_error ("Doing lsetfilecon", list1 (absname));
+           report_file_error ("Doing lsetfilecon", absname);
 
          context_free (parsed_con);
          freecon (con);
          return fail ? Qnil : Qt;
        }
       else
-       report_file_error ("Doing lgetfilecon", list1 (absname));
+       report_file_error ("Doing lgetfilecon", absname);
     }
 #endif
 
@@ -3151,7 +3159,7 @@
       acl = acl_from_text (SSDATA (acl_string));
       if (acl == NULL)
        {
-         report_file_error ("Converting ACL", list1 (absname));
+         report_file_error ("Converting ACL", absname);
          return Qnil;
        }
 
@@ -3161,7 +3169,7 @@
                            acl)
              != 0);
       if (fail && acl_errno_valid (errno))
-       report_file_error ("Setting ACL", list1 (absname));
+       report_file_error ("Setting ACL", absname);
 
       acl_free (acl);
       return fail ? Qnil : Qt;
@@ -3221,7 +3229,7 @@
   encoded_absname = ENCODE_FILE (absname);
 
   if (chmod (SSDATA (encoded_absname), XINT (mode) & 07777) < 0)
-    report_file_error ("Doing chmod", list1 (absname));
+    report_file_error ("Doing chmod", absname);
 
   return Qnil;
 }
@@ -3287,7 +3295,7 @@
         if (file_directory_p (SSDATA (encoded_absname)))
           return Qnil;
 #endif
-        report_file_error ("Setting file times", list1 (absname));
+        report_file_error ("Setting file times", absname);
       }
   }
 
@@ -3553,7 +3561,7 @@
     {
       save_errno = errno;
       if (NILP (visit))
-       report_file_error ("Opening input file", list1 (orig_filename));
+       report_file_error ("Opening input file", orig_filename);
       mtime = time_error_value (save_errno);
       st.st_size = -1;
       if (!NILP (Vcoding_system_for_read))
@@ -3568,7 +3576,7 @@
   record_unwind_protect (close_file_unwind, make_number (fd));
 
   if (fstat (fd, &st) != 0)
-    report_file_error ("Input file status", list1 (orig_filename));
+    report_file_error ("Input file status", orig_filename);
   mtime = get_stat_mtime (&st);
 
   /* This code will need to be changed in order to work on named
@@ -3682,7 +3690,7 @@
                      int ntail;
                      if (lseek (fd, - (1024 * 3), SEEK_END) < 0)
                        report_file_error ("Setting file position",
-                                          list1 (orig_filename));
+                                          orig_filename);
                      ntail = emacs_read (fd, read_buf + nread, 1024 * 3);
                      nread = ntail < 0 ? ntail : nread + ntail;
                    }
@@ -3726,8 +3734,7 @@
 
                  /* Rewind the file for the actual read done later.  */
                  if (lseek (fd, 0, SEEK_SET) < 0)
-                   report_file_error ("Setting file position",
-                                      list1 (orig_filename));
+                   report_file_error ("Setting file position", orig_filename);
                }
            }
 
@@ -3793,8 +3800,7 @@
       if (beg_offset != 0)
        {
          if (lseek (fd, beg_offset, SEEK_SET) < 0)
-           report_file_error ("Setting file position",
-                              list1 (orig_filename));
+           report_file_error ("Setting file position", orig_filename);
        }
 
       immediate_quit = 1;
@@ -3866,8 +3872,7 @@
          /* How much can we scan in the next step?  */
          trial = min (curpos, sizeof read_buf);
          if (lseek (fd, curpos - trial, SEEK_SET) < 0)
-           report_file_error ("Setting file position",
-                              list1 (orig_filename));
+           report_file_error ("Setting file position", orig_filename);
 
          total_read = nread = 0;
          while (total_read < trial)
@@ -3987,8 +3992,7 @@
         CONVERSION_BUFFER.  */
 
       if (lseek (fd, beg_offset, SEEK_SET) < 0)
-       report_file_error ("Setting file position",
-                          list1 (orig_filename));
+       report_file_error ("Setting file position", orig_filename);
 
       inserted = 0;            /* Bytes put into CONVERSION_BUFFER so far.  */
       unprocessed = 0;         /* Bytes not processed in previous loop.  */
@@ -4168,8 +4172,7 @@
   if (beg_offset != 0 || !NILP (replace))
     {
       if (lseek (fd, beg_offset, SEEK_SET) < 0)
-       report_file_error ("Setting file position",
-                          list1 (orig_filename));
+       report_file_error ("Setting file position", orig_filename);
     }
 
   /* In the following loop, HOW_MUCH contains the total bytes read so
@@ -4574,8 +4577,7 @@
       && EMACS_NSECS (current_buffer->modtime) == NONEXISTENT_MODTIME_NSECS)
     {
       /* If visiting nonexistent file, return nil.  */
-      report_file_errno ("Opening input file", list1 (orig_filename),
-                        save_errno);
+      report_file_errno ("Opening input file", orig_filename, save_errno);
     }
 
   if (read_quit)
@@ -4901,8 +4903,7 @@
       if (!auto_saving) unlock_file (lockname);
 #endif /* CLASH_DETECTION */
       UNGCPRO;
-      report_file_errno ("Opening output file", list1 (filename),
-                        open_errno);
+      report_file_errno ("Opening output file", filename, open_errno);
     }
 
   record_unwind_protect (close_file_unwind, make_number (desc));
@@ -4917,8 +4918,7 @@
          if (!auto_saving) unlock_file (lockname);
 #endif /* CLASH_DETECTION */
          UNGCPRO;
-         report_file_errno ("Lseek error", list1 (filename),
-                            lseek_errno);
+         report_file_errno ("Lseek error", filename, lseek_errno);
        }
     }
 

=== modified file 'src/gfilenotify.c'
--- a/src/gfilenotify.c 2013-07-16 04:39:23 +0000
+++ b/src/gfilenotify.c 2013-07-16 16:39:42 +0000
@@ -173,7 +173,7 @@
   CHECK_STRING (file);
   file = Fdirectory_file_name (Fexpand_file_name (file, Qnil));
   if (NILP (Ffile_exists_p (file)))
-    report_file_error ("File does not exist", list1 (file));
+    report_file_error ("File does not exist", file);
 
   CHECK_LIST (flags);
 

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2013-07-16 14:52:22 +0000
+++ b/src/keyboard.c    2013-07-16 16:39:42 +0000
@@ -10128,7 +10128,7 @@
       file = Fexpand_file_name (file, Qnil);
       dribble = emacs_fopen (SSDATA (file), "w");
       if (dribble == 0)
-       report_file_error ("Opening dribble", list1 (file));
+       report_file_error ("Opening dribble", file);
     }
   return Qnil;
 }

=== modified file 'src/print.c'
--- a/src/print.c       2013-07-16 06:39:49 +0000
+++ b/src/print.c       2013-07-16 16:39:42 +0000
@@ -770,8 +770,7 @@
        {
          stderr = initial_stderr_stream;
          initial_stderr_stream = NULL;
-         report_file_error ("Cannot open debugging output stream",
-                            list1 (file));
+         report_file_error ("Cannot open debugging output stream", file);
        }
     }
   return Qnil;

=== modified file 'src/process.c'
--- a/src/process.c     2013-07-16 07:05:41 +0000
+++ b/src/process.c     2013-07-16 16:39:42 +0000
@@ -1397,7 +1397,7 @@
     current_dir = expand_and_dir_to_file (current_dir, Qnil);
     if (NILP (Ffile_accessible_directory_p (current_dir)))
       report_file_error ("Setting current directory",
-                        list1 (BVAR (current_buffer, directory)));
+                        BVAR (current_buffer, directory));
 
     UNGCPRO;
   }
@@ -1519,7 +1519,7 @@
          openp (Vexec_path, program, Vexec_suffixes, &tem, make_number (X_OK));
          UNGCPRO;
          if (NILP (tem))
-           report_file_error ("Searching for program", list1 (program));
+           report_file_error ("Searching for program", program);
          tem = Fexpand_file_name (tem, Qnil);
        }
       else
@@ -5466,7 +5466,7 @@
              if (rv >= 0)
                written = rv;
              else if (errno == EMSGSIZE)
-               report_file_error ("sending datagram", list1 (proc));
+               report_file_error ("sending datagram", proc);
            }
          else
 #endif
@@ -5543,7 +5543,7 @@
                }
              else
                /* This is a real error.  */
-               report_file_error ("writing to process", list1 (proc));
+               report_file_error ("writing to process", proc);
            }
          cur_buf += written;
          cur_len -= written;

=== modified file 'src/unexaix.c'
--- a/src/unexaix.c     2013-07-16 06:39:49 +0000
+++ b/src/unexaix.c     2013-07-16 16:39:42 +0000
@@ -97,7 +97,7 @@
   int err = errno;
   if (fd)
     emacs_close (fd);
-  report_file_errno ("Cannot unexec", list1 (build_string (file)), err);
+  report_file_errno ("Cannot unexec", build_string (file), err);
 }
 
 #define ERROR0(msg) report_error_1 (new, msg)

=== modified file 'src/unexcoff.c'
--- a/src/unexcoff.c    2013-07-16 06:39:49 +0000
+++ b/src/unexcoff.c    2013-07-16 16:39:42 +0000
@@ -130,7 +130,7 @@
   int err = errno;
   if (fd)
     emacs_close (fd);
-  report_file_errno ("Cannot unexec", list1 (build_string (file)), err);
+  report_file_errno ("Cannot unexec", build_string (file), err);
 }
 
 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]