aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2013-07-11 19:03:47 -0700
committerPaul Eggert2013-07-11 19:03:47 -0700
commitbacba3c26522ef297662bace31947d3e4f47c87a (patch)
tree7937ff9ad18bca16aff3ecf1f791632a8dec2ce3
parent1048af7c8ff6e8a84f802fbe655b95c261a6afc0 (diff)
downloademacs-bacba3c26522ef297662bace31947d3e4f47c87a.tar.gz
emacs-bacba3c26522ef297662bace31947d3e4f47c87a.zip
Fix races with threads and file descriptors.
* configure.ac (PTY_TTY_NAME_SPRINTF): Use emacs_close, not close. * src/callproc.c (Fcall_process_region): * src/dired.c (open_directory): * src/emacs.c (main, Fdaemon_initialized): * src/image.c (x_find_image_file): * src/inotify.c (Finotify_rm_watch): * src/lread.c (Flocate_file_internal): * src/process.c (Fnetwork_interface_list, Fnetwork_interface_info): * src/term.c (term_mouse_moveto, init_tty): * src/termcap.c (tgetent): * src/unexaix.c, src/unexcoff.c (report_error, report_error_1, adjust_lnnoptrs) * src/unexaix.c, src/unexcoff.c, src/unexcw.c, src/unexelf.c (unexec): * src/unexhp9k800.c, src/unexmacosx.c (unexec): * src/callproc.c (Fcall_process_region): Use emacs_close, not close. * src/sysdep.c (POSIX_CLOSE_RESTART, posix_close) [!POSIX_CLOSE_RESTART]: New macro and function, which emulates the POSIX_CLOSE_RESTART macro and posix_close function on current platforms (which all lack them). (emacs_close): Use it. This should fix the races on GNU/Linux and on AIX and on future platforms that support POSIX_CLOSE_RESTART, and it should avoid closing random victim file descriptors on other platforms.
-rw-r--r--ChangeLog5
-rw-r--r--configure.ac2
-rw-r--r--src/ChangeLog25
-rw-r--r--src/callproc.c2
-rw-r--r--src/dired.c2
-rw-r--r--src/emacs.c10
-rw-r--r--src/image.c2
-rw-r--r--src/inotify.c2
-rw-r--r--src/lread.c2
-rw-r--r--src/process.c6
-rw-r--r--src/sysdep.c62
-rw-r--r--src/term.c4
-rw-r--r--src/termcap.c4
-rw-r--r--src/unexaix.c12
-rw-r--r--src/unexcoff.c12
-rw-r--r--src/unexcw.c4
-rw-r--r--src/unexelf.c6
-rw-r--r--src/unexhp9k800.c4
-rw-r--r--src/unexmacosx.c4
19 files changed, 118 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index a96dbf214a8..e802ee2d15c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
12013-07-12 Paul Eggert <eggert@cs.ucla.edu>
2
3 Fix races with threads and file descriptors.
4 * configure.ac (PTY_TTY_NAME_SPRINTF): Use emacs_close, not close.
5
12013-07-10 Paul Eggert <eggert@cs.ucla.edu> 62013-07-10 Paul Eggert <eggert@cs.ucla.edu>
2 7
3 * Makefile.in (removenullpaths): Remove adjacent null paths (Bug#14835). 8 * Makefile.in (removenullpaths): Remove adjacent null paths (Bug#14835).
diff --git a/configure.ac b/configure.ac
index bb140a86b1b..6378ef19288 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3931,7 +3931,7 @@ case $opsys in
3931 AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)]) 3931 AC_DEFINE(PTY_ITERATION, [int i; for (i = 0; i < 1; i++)])
3932 dnl Note that grantpt and unlockpt may fork. We must block SIGCHLD 3932 dnl Note that grantpt and unlockpt may fork. We must block SIGCHLD
3933 dnl to prevent sigchld_handler from intercepting the child's death. 3933 dnl to prevent sigchld_handler from intercepting the child's death.
3934 AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (grantpt (fd) != -1 && unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { close (fd); return -1; } snprintf (pty_name, sizeof pty_name, "%s", ptyname); }]) 3934 AC_DEFINE(PTY_TTY_NAME_SPRINTF, [{ char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (grantpt (fd) != -1 && unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { emacs_close (fd); return -1; } snprintf (pty_name, sizeof pty_name, "%s", ptyname); }])
3935 dnl if HAVE_POSIX_OPENPT 3935 dnl if HAVE_POSIX_OPENPT
3936 if test "x$ac_cv_func_posix_openpt" = xyes; then 3936 if test "x$ac_cv_func_posix_openpt" = xyes; then
3937 AC_DEFINE(PTY_OPEN, [fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY)]) 3937 AC_DEFINE(PTY_OPEN, [fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY)])
diff --git a/src/ChangeLog b/src/ChangeLog
index 04d5a024672..20c8be63cd6 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,28 @@
12013-07-12 Paul Eggert <eggert@cs.ucla.edu>
2
3 Fix races with threads and file descriptors.
4 * callproc.c (Fcall_process_region):
5 * dired.c (open_directory):
6 * emacs.c (main, Fdaemon_initialized):
7 * image.c (x_find_image_file):
8 * inotify.c (Finotify_rm_watch):
9 * lread.c (Flocate_file_internal):
10 * process.c (Fnetwork_interface_list, Fnetwork_interface_info):
11 * term.c (term_mouse_moveto, init_tty):
12 * termcap.c (tgetent):
13 * unexaix.c, unexcoff.c (report_error, report_error_1, adjust_lnnoptrs)
14 * unexaix.c, unexcoff.c, unexcw.c, unexelf.c (unexec):
15 * unexhp9k800.c, unexmacosx.c (unexec):
16 * callproc.c (Fcall_process_region):
17 Use emacs_close, not close.
18 * sysdep.c (POSIX_CLOSE_RESTART, posix_close) [!POSIX_CLOSE_RESTART]:
19 New macro and function, which emulates the POSIX_CLOSE_RESTART macro
20 and posix_close function on current platforms (which all lack them).
21 (emacs_close): Use it. This should fix the races on GNU/Linux and
22 on AIX and on future platforms that support POSIX_CLOSE_RESTART,
23 and it should avoid closing random victim file descriptors on
24 other platforms.
25
12013-07-11 Paul Eggert <eggert@cs.ucla.edu> 262013-07-11 Paul Eggert <eggert@cs.ucla.edu>
2 27
3 * inotify.c (uninitialized): Remove. All uses replaced by -1. 28 * inotify.c (uninitialized): Remove. All uses replaced by -1.
diff --git a/src/callproc.c b/src/callproc.c
index fc274f3d9c0..ac9477bff10 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1052,7 +1052,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1052 report_file_error ("Failed to open temporary file", 1052 report_file_error ("Failed to open temporary file",
1053 Fcons (build_string (tempfile), Qnil)); 1053 Fcons (build_string (tempfile), Qnil));
1054 else 1054 else
1055 close (fd); 1055 emacs_close (fd);
1056 } 1056 }
1057#else 1057#else
1058 errno = 0; 1058 errno = 0;
diff --git a/src/dired.c b/src/dired.c
index 7bbfee7e5b0..b3348b0aff0 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -95,7 +95,7 @@ open_directory (char const *name, int *fdp)
95 d = fdopendir (fd); 95 d = fdopendir (fd);
96 opendir_errno = errno; 96 opendir_errno = errno;
97 if (! d) 97 if (! d)
98 close (fd); 98 emacs_close (fd);
99 } 99 }
100#endif 100#endif
101 101
diff --git a/src/emacs.c b/src/emacs.c
index 5babf3af029..2d55cfad3d8 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1010,7 +1010,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1010 char buf[1]; 1010 char buf[1];
1011 1011
1012 /* Close unused writing end of the pipe. */ 1012 /* Close unused writing end of the pipe. */
1013 close (daemon_pipe[1]); 1013 emacs_close (daemon_pipe[1]);
1014 1014
1015 /* Just wait for the child to close its end of the pipe. */ 1015 /* Just wait for the child to close its end of the pipe. */
1016 do 1016 do
@@ -1030,7 +1030,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1030 exit (1); 1030 exit (1);
1031 } 1031 }
1032 1032
1033 close (daemon_pipe[0]); 1033 emacs_close (daemon_pipe[0]);
1034 exit (0); 1034 exit (0);
1035 } 1035 }
1036 if (f < 0) 1036 if (f < 0)
@@ -1080,7 +1080,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1080 if (dname_arg) 1080 if (dname_arg)
1081 daemon_name = xstrdup (dname_arg); 1081 daemon_name = xstrdup (dname_arg);
1082 /* Close unused reading end of the pipe. */ 1082 /* Close unused reading end of the pipe. */
1083 close (daemon_pipe[0]); 1083 emacs_close (daemon_pipe[0]);
1084 1084
1085 setsid (); 1085 setsid ();
1086#else /* DOS_NT */ 1086#else /* DOS_NT */
@@ -2254,7 +2254,7 @@ from the parent process and its tty file descriptors. */)
2254 err |= dup2 (nfd, 0) < 0; 2254 err |= dup2 (nfd, 0) < 0;
2255 err |= dup2 (nfd, 1) < 0; 2255 err |= dup2 (nfd, 1) < 0;
2256 err |= dup2 (nfd, 2) < 0; 2256 err |= dup2 (nfd, 2) < 0;
2257 err |= close (nfd) != 0; 2257 err |= emacs_close (nfd) != 0;
2258 2258
2259 /* Closing the pipe will notify the parent that it can exit. 2259 /* Closing the pipe will notify the parent that it can exit.
2260 FIXME: In case some other process inherited the pipe, closing it here 2260 FIXME: In case some other process inherited the pipe, closing it here
@@ -2264,7 +2264,7 @@ from the parent process and its tty file descriptors. */)
2264 call-process to make sure the pipe is never inherited by 2264 call-process to make sure the pipe is never inherited by
2265 subprocesses. */ 2265 subprocesses. */
2266 err |= write (daemon_pipe[1], "\n", 1) < 0; 2266 err |= write (daemon_pipe[1], "\n", 1) < 0;
2267 err |= close (daemon_pipe[1]) != 0; 2267 err |= emacs_close (daemon_pipe[1]) != 0;
2268 /* Set it to an invalid value so we know we've already run this function. */ 2268 /* Set it to an invalid value so we know we've already run this function. */
2269 daemon_pipe[1] = -1; 2269 daemon_pipe[1] = -1;
2270 2270
diff --git a/src/image.c b/src/image.c
index b3a52688ebd..0938a11da7b 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2260,7 +2260,7 @@ x_find_image_file (Lisp_Object file)
2260 else 2260 else
2261 { 2261 {
2262 file_found = ENCODE_FILE (file_found); 2262 file_found = ENCODE_FILE (file_found);
2263 close (fd); 2263 emacs_close (fd);
2264 } 2264 }
2265 2265
2266 return file_found; 2266 return file_found;
diff --git a/src/inotify.c b/src/inotify.c
index 0bbcd443332..f4f850bf180 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -387,7 +387,7 @@ See inotify_rm_watch(2) for more information.
387 /* Cleanup if no more files are watched. */ 387 /* Cleanup if no more files are watched. */
388 if (NILP (watch_list)) 388 if (NILP (watch_list))
389 { 389 {
390 close (inotifyfd); 390 emacs_close (inotifyfd);
391 delete_read_fd (inotifyfd); 391 delete_read_fd (inotifyfd);
392 inotifyfd = -1; 392 inotifyfd = -1;
393 } 393 }
diff --git a/src/lread.c b/src/lread.c
index ae945d113dd..5729cca9560 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1413,7 +1413,7 @@ directories, make sure the PREDICATE function returns `dir-ok' for them. */)
1413 Lisp_Object file; 1413 Lisp_Object file;
1414 int fd = openp (path, filename, suffixes, &file, predicate); 1414 int fd = openp (path, filename, suffixes, &file, predicate);
1415 if (NILP (predicate) && fd > 0) 1415 if (NILP (predicate) && fd > 0)
1416 close (fd); 1416 emacs_close (fd);
1417 return file; 1417 return file;
1418} 1418}
1419 1419
diff --git a/src/process.c b/src/process.c
index 36ca1cf6784..bdab1f8cb8a 100644
--- a/src/process.c
+++ b/src/process.c
@@ -3555,14 +3555,14 @@ format; see the description of ADDRESS in `make-network-process'. */)
3555 ifconf.ifc_len = buf_size; 3555 ifconf.ifc_len = buf_size;
3556 if (ioctl (s, SIOCGIFCONF, &ifconf)) 3556 if (ioctl (s, SIOCGIFCONF, &ifconf))
3557 { 3557 {
3558 close (s); 3558 emacs_close (s);
3559 xfree (buf); 3559 xfree (buf);
3560 return Qnil; 3560 return Qnil;
3561 } 3561 }
3562 } 3562 }
3563 while (ifconf.ifc_len == buf_size); 3563 while (ifconf.ifc_len == buf_size);
3564 3564
3565 close (s); 3565 emacs_close (s);
3566 3566
3567 res = Qnil; 3567 res = Qnil;
3568 ifreq = ifconf.ifc_req; 3568 ifreq = ifconf.ifc_req;
@@ -3819,7 +3819,7 @@ FLAGS is the current flags of the interface. */)
3819#endif 3819#endif
3820 res = Fcons (elt, res); 3820 res = Fcons (elt, res);
3821 3821
3822 close (s); 3822 emacs_close (s);
3823 3823
3824 return any ? res : Qnil; 3824 return any ? res : Qnil;
3825} 3825}
diff --git a/src/sysdep.c b/src/sysdep.c
index 653cf22b078..a1f217b39a6 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2201,23 +2201,59 @@ emacs_fopen (char const *file, char const *mode)
2201 return fd < 0 ? 0 : fdopen (fd, mode); 2201 return fd < 0 ? 0 : fdopen (fd, mode);
2202} 2202}
2203 2203
2204int 2204/* Approximate posix_close and POSIX_CLOSE_RESTART well enough for Emacs.
2205emacs_close (int fd) 2205 For the background behind this mess, please see Austin Group defect 529
2206 <http://austingroupbugs.net/view.php?id=529>. */
2207
2208#ifndef POSIX_CLOSE_RESTART
2209# define POSIX_CLOSE_RESTART 1
2210static int
2211posix_close (int fd, int flag)
2206{ 2212{
2207 bool did_retry = 0; 2213 /* Only the POSIX_CLOSE_RESTART case is emulated. */
2208 int rtnval; 2214 eassert (flag == POSIX_CLOSE_RESTART);
2209 2215
2210 while ((rtnval = close (fd)) == -1 2216 /* Things are tricky if close (fd) returns -1 with errno == EINTR
2211 && (errno == EINTR)) 2217 on a system that does not define POSIX_CLOSE_RESTART.
2212 did_retry = 1;
2213 2218
2214 /* If close is interrupted SunOS 4.1 may or may not have closed the 2219 In this case, in some systems (e.g., GNU/Linux, AIX) FD is
2215 file descriptor. If it did the second close will fail with 2220 closed, and retrying the close could inadvertently close a file
2216 errno = EBADF. That means we have succeeded. */ 2221 descriptor allocated by some other thread. In other systems
2217 if (rtnval == -1 && did_retry && errno == EBADF) 2222 (e.g., HP/UX) FD is not closed. And in still other systems
2218 return 0; 2223 (e.g., OS X, Solaris), maybe FD is closed, maybe not, and in a
2224 multithreaded program there can be no way to tell.
2225
2226 So, in this case, pretend that the close succeeded. This works
2227 well on systems like GNU/Linux that close FD. Although it may
2228 leak a file descriptor on other systems, the leak is unlikely and
2229 it's better to leak than to close a random victim. */
2230 return close (fd) == 0 || errno == EINTR ? 0 : -1;
2231}
2232#endif
2219 2233
2220 return rtnval; 2234/* Close FD, retrying if interrupted. If successful, return 0;
2235 otherwise, return -1 and set errno to a non-EINTR value. Consider
2236 an EINPROGRESS error to be successful, as that's merely a signal
2237 arriving. FD is always closed when this function returns, even
2238 when it returns -1.
2239
2240 Do not call this function if FD might already be closed, as that
2241 might close an innocent victim opened by some other thread. */
2242
2243int
2244emacs_close (int fd)
2245{
2246 while (1)
2247 {
2248 int r = posix_close (fd, POSIX_CLOSE_RESTART);
2249 if (r == 0)
2250 return r;
2251 if (!POSIX_CLOSE_RESTART || errno != EINTR)
2252 {
2253 eassert (errno != EBADF);
2254 return errno == EINPROGRESS ? 0 : r;
2255 }
2256 }
2221} 2257}
2222 2258
2223/* Maximum number of bytes to read or write in a single system call. 2259/* Maximum number of bytes to read or write in a single system call.
diff --git a/src/term.c b/src/term.c
index 00a3f6837ee..b6878a0abd1 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2478,7 +2478,7 @@ term_mouse_moveto (int x, int y)
2478 name = (const char *) ttyname (0); 2478 name = (const char *) ttyname (0);
2479 fd = emacs_open (name, O_WRONLY, 0); 2479 fd = emacs_open (name, O_WRONLY, 0);
2480 SOME_FUNCTION (x, y, fd); 2480 SOME_FUNCTION (x, y, fd);
2481 close (fd); 2481 emacs_close (fd);
2482 last_mouse_x = x; 2482 last_mouse_x = x;
2483 last_mouse_y = y; */ 2483 last_mouse_y = y; */
2484} 2484}
@@ -3012,7 +3012,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
3012 name); 3012 name);
3013 if (!isatty (fd)) 3013 if (!isatty (fd))
3014 { 3014 {
3015 close (fd); 3015 emacs_close (fd);
3016 maybe_fatal (must_succeed, terminal, 3016 maybe_fatal (must_succeed, terminal,
3017 "Not a tty device: %s", 3017 "Not a tty device: %s",
3018 "Not a tty device: %s", 3018 "Not a tty device: %s",
diff --git a/src/termcap.c b/src/termcap.c
index 5f731077463..be05828eea6 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -455,7 +455,7 @@ tgetent (char *bp, const char *name)
455 /* Scan the file, reading it via buf, till find start of main entry. */ 455 /* Scan the file, reading it via buf, till find start of main entry. */
456 if (scan_file (term, fd, &buf) == 0) 456 if (scan_file (term, fd, &buf) == 0)
457 { 457 {
458 close (fd); 458 emacs_close (fd);
459 xfree (buf.beg); 459 xfree (buf.beg);
460 if (malloc_size) 460 if (malloc_size)
461 xfree (bp); 461 xfree (bp);
@@ -493,7 +493,7 @@ tgetent (char *bp, const char *name)
493 term = tgetst1 (tc_search_point, (char **) 0); 493 term = tgetst1 (tc_search_point, (char **) 0);
494 } 494 }
495 495
496 close (fd); 496 emacs_close (fd);
497 xfree (buf.beg); 497 xfree (buf.beg);
498 498
499 if (malloc_size) 499 if (malloc_size)
diff --git a/src/unexaix.c b/src/unexaix.c
index 204f6cf4ad3..45b3ca667b0 100644
--- a/src/unexaix.c
+++ b/src/unexaix.c
@@ -97,7 +97,7 @@ report_error (const char *file, int fd)
97 if (fd) 97 if (fd)
98 { 98 {
99 int failed_errno = errno; 99 int failed_errno = errno;
100 close (fd); 100 emacs_close (fd);
101 errno = failed_errno; 101 errno = failed_errno;
102 } 102 }
103 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); 103 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
@@ -111,7 +111,7 @@ static _Noreturn void ATTRIBUTE_FORMAT_PRINTF (2, 3)
111report_error_1 (int fd, const char *msg, ...) 111report_error_1 (int fd, const char *msg, ...)
112{ 112{
113 va_list ap; 113 va_list ap;
114 close (fd); 114 emacs_close (fd);
115 va_start (ap, msg); 115 va_start (ap, msg);
116 verror (msg, ap); 116 verror (msg, ap);
117 va_end (ap); 117 va_end (ap);
@@ -148,13 +148,13 @@ unexec (const char *new_name, const char *a_name)
148 || adjust_lnnoptrs (new, a_out, new_name) < 0 148 || adjust_lnnoptrs (new, a_out, new_name) < 0
149 || unrelocate_symbols (new, a_out, a_name, new_name) < 0) 149 || unrelocate_symbols (new, a_out, a_name, new_name) < 0)
150 { 150 {
151 close (new); 151 emacs_close (new);
152 return; 152 return;
153 } 153 }
154 154
155 close (new); 155 emacs_close (new);
156 if (a_out >= 0) 156 if (a_out >= 0)
157 close (a_out); 157 emacs_close (a_out);
158 mark_x (new_name); 158 mark_x (new_name);
159} 159}
160 160
@@ -534,7 +534,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
534 } 534 }
535 } 535 }
536 } 536 }
537 close (new); 537 emacs_close (new);
538 538
539 return 0; 539 return 0;
540} 540}
diff --git a/src/unexcoff.c b/src/unexcoff.c
index e79821251ba..6b2a3336c8a 100644
--- a/src/unexcoff.c
+++ b/src/unexcoff.c
@@ -128,7 +128,7 @@ static void
128report_error (const char *file, int fd) 128report_error (const char *file, int fd)
129{ 129{
130 if (fd) 130 if (fd)
131 close (fd); 131 emacs_close (fd);
132 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); 132 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
133} 133}
134 134
@@ -139,7 +139,7 @@ report_error (const char *file, int fd)
139static void 139static void
140report_error_1 (int fd, const char *msg, int a1, int a2) 140report_error_1 (int fd, const char *msg, int a1, int a2)
141{ 141{
142 close (fd); 142 emacs_close (fd);
143 error (msg, a1, a2); 143 error (msg, a1, a2);
144} 144}
145 145
@@ -511,7 +511,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
511 } 511 }
512 } 512 }
513#ifndef MSDOS 513#ifndef MSDOS
514 close (new); 514 emacs_close (new);
515#endif 515#endif
516 return 0; 516 return 0;
517} 517}
@@ -541,13 +541,13 @@ unexec (const char *new_name, const char *a_name)
541 || adjust_lnnoptrs (new, a_out, new_name) < 0 541 || adjust_lnnoptrs (new, a_out, new_name) < 0
542 ) 542 )
543 { 543 {
544 close (new); 544 emacs_close (new);
545 return; 545 return;
546 } 546 }
547 547
548 close (new); 548 emacs_close (new);
549 if (a_out >= 0) 549 if (a_out >= 0)
550 close (a_out); 550 emacs_close (a_out);
551 mark_x (new_name); 551 mark_x (new_name);
552} 552}
553 553
diff --git a/src/unexcw.c b/src/unexcw.c
index 0312a7328fb..12435a85051 100644
--- a/src/unexcw.c
+++ b/src/unexcw.c
@@ -316,13 +316,13 @@ unexec (const char *outfile, const char *infile)
316 ret2 = write (fd_out, buffer, ret); 316 ret2 = write (fd_out, buffer, ret);
317 assert (ret2 == ret); 317 assert (ret2 == ret);
318 } 318 }
319 ret = close (fd_in); 319 ret = emacs_close (fd_in);
320 assert (ret == 0); 320 assert (ret == 0);
321 321
322 bss_sbrk_did_unexec = 1; 322 bss_sbrk_did_unexec = 1;
323 fixup_executable (fd_out); 323 fixup_executable (fd_out);
324 bss_sbrk_did_unexec = 0; 324 bss_sbrk_did_unexec = 0;
325 325
326 ret = close (fd_out); 326 ret = emacs_close (fd_out);
327 assert (ret == 0); 327 assert (ret == 0);
328} 328}
diff --git a/src/unexelf.c b/src/unexelf.c
index 28847157e40..e2412393286 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -1312,13 +1312,13 @@ temacs:
1312 /* Close the files and make the new file executable. */ 1312 /* Close the files and make the new file executable. */
1313 1313
1314#if MAP_ANON == 0 1314#if MAP_ANON == 0
1315 close (mmap_fd); 1315 emacs_close (mmap_fd);
1316#endif 1316#endif
1317 1317
1318 if (close (old_file) != 0) 1318 if (emacs_close (old_file) != 0)
1319 fatal ("Can't close (%s): %s", old_name, strerror (errno)); 1319 fatal ("Can't close (%s): %s", old_name, strerror (errno));
1320 1320
1321 if (close (new_file) != 0) 1321 if (emacs_close (new_file) != 0)
1322 fatal ("Can't close (%s): %s", new_name, strerror (errno)); 1322 fatal ("Can't close (%s): %s", new_name, strerror (errno));
1323 1323
1324 if (stat (new_name, &stat_buf) != 0) 1324 if (stat (new_name, &stat_buf) != 0)
diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c
index 0f6eb87ee01..bee2517307a 100644
--- a/src/unexhp9k800.c
+++ b/src/unexhp9k800.c
@@ -306,6 +306,6 @@ unexec (const char *new_name, /* name of the new a.out file to be created *
306 write_header (new, &hdr, &auxhdr); 306 write_header (new, &hdr, &auxhdr);
307 307
308 /* Close the binary file */ 308 /* Close the binary file */
309 close (old); 309 emacs_close (old);
310 close (new); 310 emacs_close (new);
311} 311}
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 2bc6de177eb..87848b012ba 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -1332,7 +1332,7 @@ unexec (const char *outfile, const char *infile)
1332 outfd = emacs_open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755); 1332 outfd = emacs_open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755);
1333 if (outfd < 0) 1333 if (outfd < 0)
1334 { 1334 {
1335 close (infd); 1335 emacs_close (infd);
1336 unexec_error ("cannot open output file `%s'", outfile); 1336 unexec_error ("cannot open output file `%s'", outfile);
1337 } 1337 }
1338 1338
@@ -1346,7 +1346,7 @@ unexec (const char *outfile, const char *infile)
1346 1346
1347 dump_it (); 1347 dump_it ();
1348 1348
1349 close (outfd); 1349 emacs_close (outfd);
1350} 1350}
1351 1351
1352 1352