From b648c16370ca72e3b68678db41b29e62accb708c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 16 Jul 2013 21:37:27 -0700 Subject: [PATCH] A few more minor file errno-reporting bugs. * callproc.c (Fcall_process): * doc.c (Fsnarf_documentation): * fileio.c (Frename_file, Fadd_name_to_file, Fmake_symbolic_link): * process.c (set_socket_option): Don't let a constructor trash errno. * doc.c: Include . --- src/ChangeLog | 10 ++++++++++ src/callproc.c | 6 +++++- src/doc.c | 7 ++++++- src/fileio.c | 19 ++++++++++++++----- src/process.c | 7 ++++++- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 62529d8d778..23334449ef3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2013-07-17 Paul Eggert + + A few more minor file errno-reporting bugs. + * callproc.c (Fcall_process): + * doc.c (Fsnarf_documentation): + * fileio.c (Frename_file, Fadd_name_to_file, Fmake_symbolic_link): + * process.c (set_socket_option): + Don't let a constructor trash errno. + * doc.c: Include . + 2013-07-16 Juanma Barranquero * w32fns.c (unwind_create_tip_frame): Fix declaration. diff --git a/src/callproc.c b/src/callproc.c index 85ebf449e43..e0040ada609 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -405,7 +405,11 @@ 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", DECODE_FILE (infile)); + { + int open_errno = errno; + report_file_errno ("Opening process input file", DECODE_FILE (infile), + open_errno); + } if (STRINGP (output_file)) { diff --git a/src/doc.c b/src/doc.c index 92c7b2c6dc9..168af6da94a 100644 --- a/src/doc.c +++ b/src/doc.c @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see . */ #include +#include #include #include /* Must be after sys/types.h for USG. */ #include @@ -609,7 +610,11 @@ 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", build_string (name)); + { + int open_errno = errno; + report_file_errno ("Opening doc string file", build_string (name), + open_errno); + } Vdoc_file_name = filename; filled = 0; pos = 0; diff --git a/src/fileio.c b/src/fileio.c index b74b0ca91c2..06a0db2316f 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -204,7 +204,9 @@ report_file_errno (char const *string, Lisp_Object name, int errorno) } /* Signal a file-access failure that set errno. STRING describes the - failure, NAME the file involved. */ + failure, NAME the file involved. When invoking this function, take + care to not use arguments such as build_string ("foo") that involve + side effects that may set errno. */ void report_file_error (char const *string, Lisp_Object name) @@ -2371,7 +2373,8 @@ This is what happens in interactive use with M-x. */) INTEGERP (ok_if_already_exists), 0, 0); if (rename (SSDATA (encoded_file), SSDATA (encoded_newname)) < 0) { - if (errno == EXDEV) + int rename_errno = errno; + if (rename_errno == EXDEV) { ptrdiff_t count; symlink_target = Ffile_symlink_p (file); @@ -2397,7 +2400,7 @@ This is what happens in interactive use with M-x. */) unbind_to (count, Qnil); } else - report_file_error ("Renaming", list2 (file, newname)); + report_file_errno ("Renaming", list2 (file, newname), rename_errno); } UNGCPRO; return Qnil; @@ -2451,7 +2454,10 @@ This is what happens in interactive use with M-x. */) unlink (SSDATA (newname)); if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) < 0) - report_file_error ("Adding new name", list2 (file, newname)); + { + int link_errno = errno; + report_file_errno ("Adding new name", list2 (file, newname), link_errno); + } UNGCPRO; return Qnil; @@ -2510,6 +2516,7 @@ This happens for interactive use with M-x. */) if (symlink (SSDATA (encoded_filename), SSDATA (encoded_linkname)) < 0) { /* If we didn't complain already, silently delete existing file. */ + int symlink_errno; if (errno == EEXIST) { unlink (SSDATA (encoded_linkname)); @@ -2527,7 +2534,9 @@ This happens for interactive use with M-x. */) build_string ("Symbolic links are not supported")); } - report_file_error ("Making symbolic link", list2 (filename, linkname)); + symlink_errno = errno; + report_file_errno ("Making symbolic link", list2 (filename, linkname), + symlink_errno); } UNGCPRO; return Qnil; diff --git a/src/process.c b/src/process.c index 42a625b7e55..7c63964aee6 100644 --- a/src/process.c +++ b/src/process.c @@ -2321,7 +2321,12 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val) } if (ret < 0) - report_file_error ("Cannot set network option", list2 (opt, val)); + { + int setsockopt_errno = errno; + report_file_errno ("Cannot set network option", list2 (opt, val), + setsockopt_errno); + } + return (1 << sopt->optbit); } -- 2.39.2