From: Paul Eggert Date: Tue, 16 Jul 2013 16:39:42 +0000 (-0700) Subject: * fileio.c (report_file_errno): Fix errno reporting bug. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1779 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a9757f6a03cce5ff2931b1125a9a2249573c8e1c;p=emacs.git * 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index 3f597ec63b1..0c96e4b901b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2013-07-16 Paul Eggert + * 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. diff --git a/src/callproc.c b/src/callproc.c index facaac60f2a..f53750372d5 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -392,7 +392,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * { 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * 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 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * 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 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args) #endif if (fd < 0) report_file_error ("Failed to open temporary file using pattern", - list1 (pattern)); + pattern); emacs_close (fd); } diff --git a/src/dired.c b/src/dired.c index ecce47ab415..42baa915348 100644 --- a/src/dired.c +++ b/src/dired.c @@ -185,7 +185,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, 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 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, 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)); diff --git a/src/dispnew.c b/src/dispnew.c index 89496304baf..ef75ed6d176 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -5619,7 +5619,7 @@ FILE = nil means just close any termscript file currently open. */) 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; } diff --git a/src/doc.c b/src/doc.c index 04af74102ef..92c7b2c6dc9 100644 --- a/src/doc.c +++ b/src/doc.c @@ -609,7 +609,7 @@ the same file name is found in the `doc-directory'. */) 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; diff --git a/src/fileio.c b/src/fileio.c index b87455d151e..ae9c15a0164 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -160,11 +160,16 @@ static bool e_write (int, Lisp_Object, ptrdiff_t, ptrdiff_t, /* 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 @@ report_file_errno (char const *string, Lisp_Object data, int errorno) } } +/* 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 @@ make_temp_name (Lisp_Object prefix, bool base64_p) 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 @@ entries (depending on how Emacs was built). */) { 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 @@ entries (depending on how Emacs was built). */) 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 @@ entries (depending on how Emacs was built). */) 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 @@ entries (depending on how Emacs was built). */) { 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 @@ entries (depending on how Emacs was built). */) /* 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 @@ entries (depending on how Emacs was built). */) 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 @@ entries (depending on how Emacs was built). */) 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 @@ entries (depending on how Emacs was built). */) 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 @@ entries (depending on how Emacs was built). */) 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 @@ entries (depending on how Emacs was built). */) } 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 @@ DEFUN ("make-directory-internal", Fmake_directory_internal, #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 @@ DEFUN ("delete-directory-internal", Fdelete_directory_internal, 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 @@ With a prefix argument, TRASH is nil. */) 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 @@ If there is no error, returns nil. */) 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 @@ or if Emacs was not compiled with SELinux support. */) != 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 @@ support. */) 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 @@ support. */) 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 @@ symbolic notation, like the `chmod' command from GNU Coreutils. */) 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 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of 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 @@ by calling `format-decode', which see. */) { 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 @@ by calling `format-decode', which see. */) 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 @@ by calling `format-decode', which see. */) 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 @@ by calling `format-decode', which see. */) /* 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 @@ by calling `format-decode', which see. */) 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 @@ by calling `format-decode', which see. */) /* 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 @@ by calling `format-decode', which see. */) 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 @@ by calling `format-decode', which see. */) 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 @@ by calling `format-decode', which see. */) && 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 @@ This calls `write-region-annotate-functions' at the start, and 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 @@ This calls `write-region-annotate-functions' at the start, and 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); } } diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 47b645bc075..8f13c72df81 100644 --- a/src/gfilenotify.c +++ b/src/gfilenotify.c @@ -173,7 +173,7 @@ will be reported only in case of the 'moved' event. */) 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); diff --git a/src/keyboard.c b/src/keyboard.c index e852fb65cdd..e67da06ec23 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -10128,7 +10128,7 @@ The file will be closed when Emacs exits. */) 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; } diff --git a/src/print.c b/src/print.c index 464fd459320..55659414b05 100644 --- a/src/print.c +++ b/src/print.c @@ -770,8 +770,7 @@ append to existing target file. */) { 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; diff --git a/src/process.c b/src/process.c index 125a9389341..b51e3bab033 100644 --- a/src/process.c +++ b/src/process.c @@ -1397,7 +1397,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) 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 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) 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 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, 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 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, } 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; diff --git a/src/unexaix.c b/src/unexaix.c index f97de45449e..fc1acc9ab4f 100644 --- a/src/unexaix.c +++ b/src/unexaix.c @@ -97,7 +97,7 @@ report_error (const char *file, int fd) 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) diff --git a/src/unexcoff.c b/src/unexcoff.c index 0b45d729710..5ac8ea8c9b0 100644 --- a/src/unexcoff.c +++ b/src/unexcoff.c @@ -130,7 +130,7 @@ report_error (const char *file, int fd) 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