aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorPaul Eggert2012-10-19 09:52:02 -0700
committerPaul Eggert2012-10-19 09:52:02 -0700
commite752e0b0a2622d8d0ba518bf81f6fa652d926e67 (patch)
tree3b7cfbf8aa3ecaa587cd6fbc2d17b64d055d2b07 /src/process.c
parent6ec83f926d5ff699901fb530162d7f1bdfa85808 (diff)
downloademacs-e752e0b0a2622d8d0ba518bf81f6fa652d926e67.tar.gz
emacs-e752e0b0a2622d8d0ba518bf81f6fa652d926e67.zip
Use faccessat, not access, when checking file permissions.
* .bzrignore: Add lib/fcntl.h. * configure.ac (euidaccess): Remove check; gnulib does this for us now. (gl_FCNTL_O_FLAGS): Define a dummy version. * lib/at-func.c, lib/euidaccess.c, lib/faccessat.c, lib/fcntl.in.h: * lib/getgroups.c, lib/group-member.c, lib/root-uid.h: * lib/xalloc-oversized.h, m4/euidaccess.m4, m4/faccessat.m4: * m4/fcntl_h.m4, m4/getgroups.m4, m4/group-member.m4: New files, from gnulib. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * admin/merge-gnulib (GNULIB_MODULES): Add faccessat. (GNULIB_TOOL_FLAGS): Avoid at-internal, fchdir, malloc-posix, openat-die, openat-h, save-cwd. Do not avoid fcntl-h. Omit gnulib's m4/fcntl-o.m4. * nt/inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols. (access): Remove. (faccessat): New macro. * src/Makefile.in (LIB_EACCESS): New macro. (LIBES): Use it. * src/callproc.c (init_callproc): * src/charset.c (init_charset): * src/fileio.c (check_existing, check_executable): * src/lread.c (openp, load_path_check): * src/process.c (allocate_pty): * src/xrdb.c (file_p): Use faccessat, not access or euidaccess. Use symbolic names instead of integers for the flags, as they're portable now. * src/charset.c, src/xrdb.c: Include <fcntl.h>, for the new flags used. * src/fileio.c (Ffile_readable_p): Use faccessat, not stat + open + close. (file_directory_p): New function, which uses 'stat' on most places but 'access' (for efficiency) if WINDOWSNT. * src/fileio.c (Ffile_directory_p, Fset_file_times): * src/xrdb.c (file_p): Use file_directory_p. * src/lisp.h (file_directory_p): New decl. * src/lread.c (openp): When opening a file, use fstat rather than stat, as that avoids a permissions race. When not opening a file, use file_directory_p rather than stat. * src/process.c, src/sysdep.c, src/term.c: All uses of '#ifdef O_NONBLOCK' changed to '#if O_NONBLOCK', to accommodate gnulib O_* tyle. * src/w32.c (sys_faccessat): Rename from sys_access and switch to faccessat's API. All uses changed. Fixes: debbugs:12632
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/process.c b/src/process.c
index 307e82819d6..572ab83de09 100644
--- a/src/process.c
+++ b/src/process.c
@@ -204,7 +204,7 @@ static EMACS_INT update_tick;
204#ifndef NON_BLOCKING_CONNECT 204#ifndef NON_BLOCKING_CONNECT
205#ifdef HAVE_SELECT 205#ifdef HAVE_SELECT
206#if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) 206#if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX)
207#if defined (O_NONBLOCK) || defined (O_NDELAY) 207#if O_NONBLOCK || O_NDELAY
208#if defined (EWOULDBLOCK) || defined (EINPROGRESS) 208#if defined (EWOULDBLOCK) || defined (EINPROGRESS)
209#define NON_BLOCKING_CONNECT 209#define NON_BLOCKING_CONNECT
210#endif /* EWOULDBLOCK || EINPROGRESS */ 210#endif /* EWOULDBLOCK || EINPROGRESS */
@@ -651,7 +651,7 @@ allocate_pty (void)
651 PTY_OPEN; 651 PTY_OPEN;
652#else /* no PTY_OPEN */ 652#else /* no PTY_OPEN */
653 { 653 {
654# ifdef O_NONBLOCK 654# if O_NONBLOCK
655 fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); 655 fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0);
656# else 656# else
657 fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0); 657 fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0);
@@ -668,7 +668,7 @@ allocate_pty (void)
668#else 668#else
669 sprintf (pty_name, "/dev/tty%c%x", c, i); 669 sprintf (pty_name, "/dev/tty%c%x", c, i);
670#endif /* no PTY_TTY_NAME_SPRINTF */ 670#endif /* no PTY_TTY_NAME_SPRINTF */
671 if (access (pty_name, 6) != 0) 671 if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0)
672 { 672 {
673 emacs_close (fd); 673 emacs_close (fd);
674# ifndef __sgi 674# ifndef __sgi
@@ -1621,7 +1621,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1621#if ! defined (USG) || defined (USG_SUBTTY_WORKS) 1621#if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1622 /* On most USG systems it does not work to open the pty's tty here, 1622 /* On most USG systems it does not work to open the pty's tty here,
1623 then close it and reopen it in the child. */ 1623 then close it and reopen it in the child. */
1624#ifdef O_NOCTTY 1624#if O_NOCTTY
1625 /* Don't let this terminal become our controlling terminal 1625 /* Don't let this terminal become our controlling terminal
1626 (in case we don't have one). */ 1626 (in case we don't have one). */
1627 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 1627 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
@@ -1675,11 +1675,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1675 } 1675 }
1676#endif 1676#endif
1677 1677
1678#ifdef O_NONBLOCK 1678#if O_NONBLOCK
1679 fcntl (inchannel, F_SETFL, O_NONBLOCK); 1679 fcntl (inchannel, F_SETFL, O_NONBLOCK);
1680 fcntl (outchannel, F_SETFL, O_NONBLOCK); 1680 fcntl (outchannel, F_SETFL, O_NONBLOCK);
1681#else 1681#else
1682#ifdef O_NDELAY 1682#if O_NDELAY
1683 fcntl (inchannel, F_SETFL, O_NDELAY); 1683 fcntl (inchannel, F_SETFL, O_NDELAY);
1684 fcntl (outchannel, F_SETFL, O_NDELAY); 1684 fcntl (outchannel, F_SETFL, O_NDELAY);
1685#endif 1685#endif
@@ -1967,7 +1967,7 @@ create_pty (Lisp_Object process)
1967#if ! defined (USG) || defined (USG_SUBTTY_WORKS) 1967#if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1968 /* On most USG systems it does not work to open the pty's tty here, 1968 /* On most USG systems it does not work to open the pty's tty here,
1969 then close it and reopen it in the child. */ 1969 then close it and reopen it in the child. */
1970#ifdef O_NOCTTY 1970#if O_NOCTTY
1971 /* Don't let this terminal become our controlling terminal 1971 /* Don't let this terminal become our controlling terminal
1972 (in case we don't have one). */ 1972 (in case we don't have one). */
1973 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 1973 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
@@ -1987,11 +1987,11 @@ create_pty (Lisp_Object process)
1987 } 1987 }
1988#endif /* HAVE_PTYS */ 1988#endif /* HAVE_PTYS */
1989 1989
1990#ifdef O_NONBLOCK 1990#if O_NONBLOCK
1991 fcntl (inchannel, F_SETFL, O_NONBLOCK); 1991 fcntl (inchannel, F_SETFL, O_NONBLOCK);
1992 fcntl (outchannel, F_SETFL, O_NONBLOCK); 1992 fcntl (outchannel, F_SETFL, O_NONBLOCK);
1993#else 1993#else
1994#ifdef O_NDELAY 1994#if O_NDELAY
1995 fcntl (inchannel, F_SETFL, O_NDELAY); 1995 fcntl (inchannel, F_SETFL, O_NDELAY);
1996 fcntl (outchannel, F_SETFL, O_NDELAY); 1996 fcntl (outchannel, F_SETFL, O_NDELAY);
1997#endif 1997#endif
@@ -2951,7 +2951,7 @@ usage: (make-network-process &rest ARGS) */)
2951 { 2951 {
2952 /* Don't support network sockets when non-blocking mode is 2952 /* Don't support network sockets when non-blocking mode is
2953 not available, since a blocked Emacs is not useful. */ 2953 not available, since a blocked Emacs is not useful. */
2954#if !defined (O_NONBLOCK) && !defined (O_NDELAY) 2954#if !O_NONBLOCK && !O_NDELAY
2955 error ("Network servers not supported"); 2955 error ("Network servers not supported");
2956#else 2956#else
2957 is_server = 1; 2957 is_server = 1;
@@ -3217,7 +3217,7 @@ usage: (make-network-process &rest ARGS) */)
3217#ifdef NON_BLOCKING_CONNECT 3217#ifdef NON_BLOCKING_CONNECT
3218 if (is_non_blocking_client) 3218 if (is_non_blocking_client)
3219 { 3219 {
3220#ifdef O_NONBLOCK 3220#if O_NONBLOCK
3221 ret = fcntl (s, F_SETFL, O_NONBLOCK); 3221 ret = fcntl (s, F_SETFL, O_NONBLOCK);
3222#else 3222#else
3223 ret = fcntl (s, F_SETFL, O_NDELAY); 3223 ret = fcntl (s, F_SETFL, O_NDELAY);
@@ -3434,10 +3434,10 @@ usage: (make-network-process &rest ARGS) */)
3434 3434
3435 chan_process[inch] = proc; 3435 chan_process[inch] = proc;
3436 3436
3437#ifdef O_NONBLOCK 3437#if O_NONBLOCK
3438 fcntl (inch, F_SETFL, O_NONBLOCK); 3438 fcntl (inch, F_SETFL, O_NONBLOCK);
3439#else 3439#else
3440#ifdef O_NDELAY 3440#if O_NDELAY
3441 fcntl (inch, F_SETFL, O_NDELAY); 3441 fcntl (inch, F_SETFL, O_NDELAY);
3442#endif 3442#endif
3443#endif 3443#endif
@@ -4169,10 +4169,10 @@ server_accept_connection (Lisp_Object server, int channel)
4169 4169
4170 chan_process[s] = proc; 4170 chan_process[s] = proc;
4171 4171
4172#ifdef O_NONBLOCK 4172#if O_NONBLOCK
4173 fcntl (s, F_SETFL, O_NONBLOCK); 4173 fcntl (s, F_SETFL, O_NONBLOCK);
4174#else 4174#else
4175#ifdef O_NDELAY 4175#if O_NDELAY
4176 fcntl (s, F_SETFL, O_NDELAY); 4176 fcntl (s, F_SETFL, O_NDELAY);
4177#endif 4177#endif
4178#endif 4178#endif
@@ -4873,11 +4873,11 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4873#endif 4873#endif
4874 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK, 4874 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK,
4875 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */ 4875 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */
4876#ifdef O_NONBLOCK 4876#if O_NONBLOCK
4877 else if (nread == -1 && errno == EAGAIN) 4877 else if (nread == -1 && errno == EAGAIN)
4878 ; 4878 ;
4879#else 4879#else
4880#ifdef O_NDELAY 4880#if O_NDELAY
4881 else if (nread == -1 && errno == EAGAIN) 4881 else if (nread == -1 && errno == EAGAIN)
4882 ; 4882 ;
4883 /* Note that we cannot distinguish between no input 4883 /* Note that we cannot distinguish between no input
@@ -7363,7 +7363,7 @@ init_process_emacs (void)
7363#ifdef HAVE_GETSOCKNAME 7363#ifdef HAVE_GETSOCKNAME
7364 ADD_SUBFEATURE (QCservice, Qt); 7364 ADD_SUBFEATURE (QCservice, Qt);
7365#endif 7365#endif
7366#if defined (O_NONBLOCK) || defined (O_NDELAY) 7366#if O_NONBLOCK || O_NDELAY
7367 ADD_SUBFEATURE (QCserver, Qt); 7367 ADD_SUBFEATURE (QCserver, Qt);
7368#endif 7368#endif
7369 7369