aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Stephani2021-01-10 22:28:31 +0100
committerPhilipp Stephani2021-01-10 22:31:22 +0100
commit94344d130c2c2db90bcc47e12870d1d58f020ecf (patch)
tree58eac6671be87a7c662cc1ee0f591a8e0aee7586 /src
parentc7c154bb5756e0ae71d342c5d8aabf725877f186 (diff)
downloademacs-94344d130c2c2db90bcc47e12870d1d58f020ecf.tar.gz
emacs-94344d130c2c2db90bcc47e12870d1d58f020ecf.zip
Add functions to open a file without quitting.
In some situations, e.g. when the Lisp machinery isn't available, we can't quit. Don't check the quit flags in such situations, in case they contain garbage. * src/sysdep.c (emacs_open_noquit, emacs_openat_noquit): New variants of 'emacs_open' and 'emacs_openat' that don't check the quit flags. * src/emacs.c (main, Fdaemon_initialized): * src/pdumper.c (pdumper_load): * src/w32term.c (w32_initialize): * src/buffer.c (mmap_init): * src/callproc.c (emacs_spawn): Use them where we can't quit.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c2
-rw-r--r--src/callproc.c2
-rw-r--r--src/emacs.c4
-rw-r--r--src/lisp.h1
-rw-r--r--src/pdumper.c2
-rw-r--r--src/sysdep.c22
-rw-r--r--src/w32term.c3
7 files changed, 30 insertions, 6 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 71ad5edd527..80c799e719b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -4785,7 +4785,7 @@ mmap_init (void)
4785 if (mmap_fd <= 0) 4785 if (mmap_fd <= 0)
4786 { 4786 {
4787 /* No anonymous mmap -- we need the file descriptor. */ 4787 /* No anonymous mmap -- we need the file descriptor. */
4788 mmap_fd = emacs_open ("/dev/zero", O_RDONLY, 0); 4788 mmap_fd = emacs_open_noquit ("/dev/zero", O_RDONLY, 0);
4789 if (mmap_fd == -1) 4789 if (mmap_fd == -1)
4790 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); 4790 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno));
4791 } 4791 }
diff --git a/src/callproc.c b/src/callproc.c
index 1da315bef18..cb72b070b7b 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1336,7 +1336,7 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err,
1336 would work? */ 1336 would work? */
1337 if (std_in >= 0) 1337 if (std_in >= 0)
1338 emacs_close (std_in); 1338 emacs_close (std_in);
1339 std_out = std_in = emacs_open (pty, O_RDWR, 0); 1339 std_out = std_in = emacs_open_noquit (pty, O_RDWR, 0);
1340 1340
1341 if (std_in < 0) 1341 if (std_in < 0)
1342 { 1342 {
diff --git a/src/emacs.c b/src/emacs.c
index 69d10821fae..77114271b27 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1275,7 +1275,7 @@ main (int argc, char **argv)
1275 { 1275 {
1276 emacs_close (STDIN_FILENO); 1276 emacs_close (STDIN_FILENO);
1277 emacs_close (STDOUT_FILENO); 1277 emacs_close (STDOUT_FILENO);
1278 int result = emacs_open (term, O_RDWR, 0); 1278 int result = emacs_open_noquit (term, O_RDWR, 0);
1279 if (result != STDIN_FILENO 1279 if (result != STDIN_FILENO
1280 || (fcntl (STDIN_FILENO, F_DUPFD_CLOEXEC, STDOUT_FILENO) 1280 || (fcntl (STDIN_FILENO, F_DUPFD_CLOEXEC, STDOUT_FILENO)
1281 != STDOUT_FILENO)) 1281 != STDOUT_FILENO))
@@ -2847,7 +2847,7 @@ from the parent process and its tty file descriptors. */)
2847 int nfd; 2847 int nfd;
2848 2848
2849 /* Get rid of stdin, stdout and stderr. */ 2849 /* Get rid of stdin, stdout and stderr. */
2850 nfd = emacs_open ("/dev/null", O_RDWR, 0); 2850 nfd = emacs_open_noquit ("/dev/null", O_RDWR, 0);
2851 err |= nfd < 0; 2851 err |= nfd < 0;
2852 err |= dup2 (nfd, STDIN_FILENO) < 0; 2852 err |= dup2 (nfd, STDIN_FILENO) < 0;
2853 err |= dup2 (nfd, STDOUT_FILENO) < 0; 2853 err |= dup2 (nfd, STDOUT_FILENO) < 0;
diff --git a/src/lisp.h b/src/lisp.h
index 86be25852a6..9d8dbbd629f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4577,6 +4577,7 @@ extern AVOID emacs_abort (void) NO_INLINE;
4577extern int emacs_fstatat (int, char const *, void *, int); 4577extern int emacs_fstatat (int, char const *, void *, int);
4578extern int emacs_openat (int, char const *, int, int); 4578extern int emacs_openat (int, char const *, int, int);
4579extern int emacs_open (const char *, int, int); 4579extern int emacs_open (const char *, int, int);
4580extern int emacs_open_noquit (const char *, int, int);
4580extern int emacs_pipe (int[2]); 4581extern int emacs_pipe (int[2]);
4581extern int emacs_close (int); 4582extern int emacs_close (int);
4582extern ptrdiff_t emacs_read (int, void *, ptrdiff_t); 4583extern ptrdiff_t emacs_read (int, void *, ptrdiff_t);
diff --git a/src/pdumper.c b/src/pdumper.c
index 116cc28dbba..c1388ebbb37 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -5273,7 +5273,7 @@ pdumper_load (const char *dump_filename)
5273 eassert (!dump_loaded_p ()); 5273 eassert (!dump_loaded_p ());
5274 5274
5275 int err; 5275 int err;
5276 int dump_fd = emacs_open (dump_filename, O_RDONLY, 0); 5276 int dump_fd = emacs_open_noquit (dump_filename, O_RDONLY, 0);
5277 if (dump_fd < 0) 5277 if (dump_fd < 0)
5278 { 5278 {
5279 err = (errno == ENOENT || errno == ENOTDIR 5279 err = (errno == ENOENT || errno == ENOTDIR
diff --git a/src/sysdep.c b/src/sysdep.c
index a49f1775ebd..941b4e2fa24 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2320,6 +2320,28 @@ emacs_open (char const *file, int oflags, int mode)
2320 return emacs_openat (AT_FDCWD, file, oflags, mode); 2320 return emacs_openat (AT_FDCWD, file, oflags, mode);
2321} 2321}
2322 2322
2323/* Same as above, but doesn't allow the user to quit. */
2324
2325static int
2326emacs_openat_noquit (int dirfd, const char *file, int oflags,
2327 int mode)
2328{
2329 int fd;
2330 if (! (oflags & O_TEXT))
2331 oflags |= O_BINARY;
2332 oflags |= O_CLOEXEC;
2333 do
2334 fd = openat (dirfd, file, oflags, mode);
2335 while (fd < 0 && errno == EINTR);
2336 return fd;
2337}
2338
2339int
2340emacs_open_noquit (char const *file, int oflags, int mode)
2341{
2342 return emacs_openat_noquit (AT_FDCWD, file, oflags, mode);
2343}
2344
2323/* Open FILE as a stream for Emacs use, with mode MODE. 2345/* Open FILE as a stream for Emacs use, with mode MODE.
2324 Act like emacs_open with respect to threads, signals, and quits. */ 2346 Act like emacs_open with respect to threads, signals, and quits. */
2325 2347
diff --git a/src/w32term.c b/src/w32term.c
index e5a8a823b48..109aa58d732 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -7507,7 +7507,8 @@ w32_initialize (void)
7507 } 7507 }
7508 7508
7509#ifdef CYGWIN 7509#ifdef CYGWIN
7510 if ((w32_message_fd = emacs_open ("/dev/windows", O_RDWR, 0)) == -1) 7510 if ((w32_message_fd = emacs_open_noquit ("/dev/windows", O_RDWR, 0))
7511 == -1)
7511 fatal ("opening /dev/windows: %s", strerror (errno)); 7512 fatal ("opening /dev/windows: %s", strerror (errno));
7512#endif /* CYGWIN */ 7513#endif /* CYGWIN */
7513 7514