From afb8aa2482db730a8ebdabe314c320c01dda383c Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 18 Oct 2012 20:21:55 +0200 Subject: [PATCH 01/18] Fix wording of error message in staticpro. --- src/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alloc.c b/src/alloc.c index 08dc26784cc..257e4fdd5e3 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5030,7 +5030,7 @@ staticpro (Lisp_Object *varaddress) { staticvec[staticidx++] = varaddress; if (staticidx >= NSTATICS) - fatal ("NSTATICS too small. Try increasing and recompiling Emacs."); + fatal ("NSTATICS too small; try increasing and recompiling Emacs."); } From 1a9327d5cd660040a282ab595509c16fe90f63a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dj=C3=A4rv?= Date: Thu, 18 Oct 2012 20:54:37 +0200 Subject: [PATCH 02/18] * nsterm.m (ns_select): Check writefds before call to FD_ISSET. Fixes: debbugs:12668 --- src/ChangeLog | 5 +++++ src/nsterm.m | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6fece1e72c5..f1e3a99dbc6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2012-10-18 Jan Djärv + + * nsterm.m (ns_select): Check writefds before call to + FD_ISSET (Bug#12668). + 2012-10-18 Daniel Colascione * alloc.c (NSTATICS): Increase from 0x650 to 0x1000 diff --git a/src/nsterm.m b/src/nsterm.m index dfc84db50f7..a4eaad47ac1 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -3443,10 +3443,10 @@ overwriting cursor (usually when cursor on a tab) */ /* NSTRACE (ns_select); */ - for (k = 0; readfds && k < nfds+1; k++) + for (k = 0; k < nfds+1; k++) { - if (FD_ISSET(k, readfds)) ++nr; - if (FD_ISSET(k, writefds)) ++nr; + if (readfds && FD_ISSET(k, readfds)) ++nr; + if (writefds && FD_ISSET(k, writefds)) ++nr; } if (NSApp == nil From 8c27235eadcdde07da4d037aa523fd9af065f865 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Fri, 19 Oct 2012 03:46:18 +0800 Subject: [PATCH 03/18] Fix how gdb-mi calls display-buffer to avoid switching frames. * lisp/progmodes/gdb-mi.el (gdb-display-buffer-other-frame-action): Convert to defcustom. (gdb-get-source-file): Don't bind pop-up-windows. * lisp/progmodes/gud.el (gud-display-line): Don't specially re-use other frames for the gdb-mi case. Fixes: debbugs:12648 --- lisp/ChangeLog | 9 ++++++ lisp/progmodes/gdb-mi.el | 19 +++++++----- lisp/progmodes/gud.el | 65 +++++++++++++++++++--------------------- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 51e6b67b86c..46336af6e71 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-10-18 Chong Yidong + + * progmodes/gdb-mi.el (gdb-display-buffer-other-frame-action): + Convert to defcustom. + (gdb-get-source-file): Don't bind pop-up-windows. + + * progmodes/gud.el (gud-display-line): Don't specially re-use + other frames for the gdb-mi case (Bug#12648). + 2012-10-18 Stefan Monnier * emacs-lisp/advice.el: Clean up commentary a bit. diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 59c419abfc3..805ffa36e4e 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -1516,9 +1516,9 @@ this trigger is subscribed to `gdb-buf-publisher' and called with (comint-exec io-buffer "gdb-inferior" nil nil nil) (gdb-inferior-io--init-proc (get-buffer-process io-buffer)))))) -(defvar gdb-display-buffer-other-frame-action - `((display-buffer-reuse-window display-buffer-pop-up-frame) - (reusable-frames . 0) +(defcustom gdb-display-buffer-other-frame-action + '((display-buffer-reuse-window display-buffer-pop-up-frame) + (reusable-frames . visible) (inhibit-same-window . t) (pop-up-frame-parameters (height . 14) (width . 80) @@ -1526,8 +1526,11 @@ this trigger is subscribed to `gdb-buf-publisher' and called with (tool-bar-lines . nil) (menu-bar-lines . nil) (minibuffer . nil))) - "A `display-buffer' action for displaying GDB utility frames.") -(put 'gdb-display-buffer-other-frame-action 'risky-local-variable t) + "`display-buffer' action for displaying GDB utility frames." + :group 'gdb + :type display-buffer--action-custom-type + :risky t + :version "24.3") (defun gdb-frame-io-buffer () "Display IO of debugged program in another frame." @@ -4175,9 +4178,9 @@ buffers, if required." (if gdb-many-windows (gdb-setup-windows) (gdb-get-buffer-create 'gdb-breakpoints-buffer) - (if (and gdb-show-main gdb-main-file) - (let ((pop-up-windows t)) - (display-buffer (gud-find-file gdb-main-file))))) + (and gdb-show-main + gdb-main-file + (display-buffer (gud-find-file gdb-main-file)))) (gdb-force-mode-line-update (propertize "ready" 'face font-lock-variable-name-face))) diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 2e3858b2cc5..719471278a8 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -2700,42 +2700,39 @@ Obeying it means displaying in another window the specified file and line." (gud-find-file true-file))) (window (and buffer (or (get-buffer-window buffer) - (if (eq gud-minor-mode 'gdbmi) - (display-buffer buffer nil 'visible)) (display-buffer buffer)))) (pos)) - (if buffer - (progn - (with-current-buffer buffer - (unless (or (verify-visited-file-modtime buffer) gud-keep-buffer) - (if (yes-or-no-p - (format "File %s changed on disk. Reread from disk? " - (buffer-name))) - (revert-buffer t t) - (setq gud-keep-buffer t))) - (save-restriction - (widen) - (goto-char (point-min)) - (forward-line (1- line)) - (setq pos (point)) - (or gud-overlay-arrow-position - (setq gud-overlay-arrow-position (make-marker))) - (set-marker gud-overlay-arrow-position (point) (current-buffer)) - ;; If they turned on hl-line, move the hl-line highlight to - ;; the arrow's line. - (when (featurep 'hl-line) - (cond - (global-hl-line-mode - (global-hl-line-highlight)) - ((and hl-line-mode hl-line-sticky-flag) - (hl-line-highlight))))) - (cond ((or (< pos (point-min)) (> pos (point-max))) - (widen) - (goto-char pos)))) - (when window - (set-window-point window gud-overlay-arrow-position) - (if (eq gud-minor-mode 'gdbmi) - (setq gdb-source-window window))))))) + (when buffer + (with-current-buffer buffer + (unless (or (verify-visited-file-modtime buffer) gud-keep-buffer) + (if (yes-or-no-p + (format "File %s changed on disk. Reread from disk? " + (buffer-name))) + (revert-buffer t t) + (setq gud-keep-buffer t))) + (save-restriction + (widen) + (goto-char (point-min)) + (forward-line (1- line)) + (setq pos (point)) + (or gud-overlay-arrow-position + (setq gud-overlay-arrow-position (make-marker))) + (set-marker gud-overlay-arrow-position (point) (current-buffer)) + ;; If they turned on hl-line, move the hl-line highlight to + ;; the arrow's line. + (when (featurep 'hl-line) + (cond + (global-hl-line-mode + (global-hl-line-highlight)) + ((and hl-line-mode hl-line-sticky-flag) + (hl-line-highlight))))) + (cond ((or (< pos (point-min)) (> pos (point-max))) + (widen) + (goto-char pos)))) + (when window + (set-window-point window gud-overlay-arrow-position) + (if (eq gud-minor-mode 'gdbmi) + (setq gdb-source-window window)))))) ;; The gud-call function must do the right thing whether its invoking ;; keystroke is from the GUD buffer itself (via major-mode binding) From f60d391f5f8b3fbaa8ebe253afcf47b5ed9144f1 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 18 Oct 2012 20:54:35 -0400 Subject: [PATCH 04/18] * src/fns.c (Fnreverse): Include the problem element when signalling an error. Fixes: debbugs:12677 --- src/ChangeLog | 5 +++++ src/fns.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f1e3a99dbc6..4a4887579a7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2012-10-19 Stefan Monnier + + * fns.c (Fnreverse): Include the problem element when signalling an + error (bug#12677). + 2012-10-18 Jan Djärv * nsterm.m (ns_select): Check writefds before call to diff --git a/src/fns.c b/src/fns.c index c999b5b08b9..b1ba5ce9509 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1689,7 +1689,7 @@ changing the value of a sequence `foo'. */) DEFUN ("nreverse", Fnreverse, Snreverse, 1, 1, 0, doc: /* Reverse LIST by modifying cdr pointers. -Return the reversed list. */) +Return the reversed list. Expects a properly nil-terminated list. */) (Lisp_Object list) { register Lisp_Object prev, tail, next; @@ -1700,7 +1700,7 @@ Return the reversed list. */) while (!NILP (tail)) { QUIT; - CHECK_LIST_CONS (tail, list); + CHECK_LIST_CONS (tail, tail); next = XCDR (tail); Fsetcdr (tail, prev); prev = tail; From d282492862879e50bcbb8d10510da4a7a7f6eb4c Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 19 Oct 2012 08:43:12 +0200 Subject: [PATCH 05/18] Decrease NSTATICS to 0x800. --- src/ChangeLog | 4 ++++ src/alloc.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4a4887579a7..cf7302914ab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2012-10-19 Eli Zaretskii + + * alloc.c (NSTATICS): Decrease to 0x800. + 2012-10-19 Stefan Monnier * fns.c (Fnreverse): Include the problem element when signalling an diff --git a/src/alloc.c b/src/alloc.c index 257e4fdd5e3..5bb528c64ab 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -376,7 +376,7 @@ struct gcpro *gcprolist; /* Addresses of staticpro'd variables. Initialize it to a nonzero value; otherwise some compilers put it into BSS. */ -#define NSTATICS 0x1000 +#define NSTATICS 0x800 static Lisp_Object *staticvec[NSTATICS] = {&Vpurify_flag}; /* Index of next unused slot in staticvec. */ From fb0104dabe260892805790f36df7d5968ee1f53d Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Fri, 19 Oct 2012 11:28:50 +0200 Subject: [PATCH 06/18] In debug record height of debugger window also when debugger will be back (Bug#8789). * emacs-lisp/debug.el (debug): Record height of debugger window also when debugger will be back (Bug#8789). --- lisp/ChangeLog | 5 +++++ lisp/emacs-lisp/debug.el | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 46336af6e71..f9d9ad4b03d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-10-19 Martin Rudalics + + * emacs-lisp/debug.el (debug): Record height of debugger window + also when debugger will be back (Bug#8789). + 2012-10-18 Chong Yidong * progmodes/gdb-mi.el (gdb-display-buffer-other-frame-action): diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index c30ccf3315e..c04e68c0cfa 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el @@ -267,15 +267,17 @@ first will be printed into the backtrace buffer." ;; Make sure we unbind buffer-read-only in the right buffer. (save-excursion (recursive-edit)))) + (when (and (window-live-p debugger-window) + (eq (window-buffer debugger-window) debugger-buffer)) + ;; Record height of debugger window. + (setq debugger-previous-window-height + (window-total-size debugger-window))) (if debugger-will-be-back ;; Restore previous window configuration (Bug#12623). (set-window-configuration window-configuration) (when (and (window-live-p debugger-window) (eq (window-buffer debugger-window) debugger-buffer)) (progn - ;; Record height of debugger window. - (setq debugger-previous-window-height - (window-total-size debugger-window)) ;; Unshow debugger-buffer. (quit-restore-window debugger-window debugger-bury-or-kill) ;; Restore current buffer (Bug#12502). From c052c554b44b809e672370e498dd3957494126d8 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 19 Oct 2012 12:05:09 +0200 Subject: [PATCH 07/18] Increase the value of BASE_PURESIZE to avoid pure space overflow. src/puresize.h (BASE_PURESIZE): Bump the base value to 1700000. See http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00593.html for the reasons. --- src/ChangeLog | 4 ++++ src/puresize.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index cf7302914ab..cef1edff87d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2012-10-19 Eli Zaretskii + * puresize.h (BASE_PURESIZE): Bump the base value to 1700000. See + http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00593.html + for the reasons. + * alloc.c (NSTATICS): Decrease to 0x800. 2012-10-19 Stefan Monnier diff --git a/src/puresize.h b/src/puresize.h index 2f024345d61..26395a5729d 100644 --- a/src/puresize.h +++ b/src/puresize.h @@ -40,7 +40,7 @@ along with GNU Emacs. If not, see . */ #endif #ifndef BASE_PURESIZE -#define BASE_PURESIZE (1620000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA) +#define BASE_PURESIZE (1700000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA) #endif /* Increase BASE_PURESIZE by a ratio depending on the machine's word size. */ From a0d7415fb62cf17e1465ee19cffb3ae6e20390b3 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 19 Oct 2012 21:59:42 +0900 Subject: [PATCH 08/18] font.c (Ffont_at): Fix previous change. --- src/ChangeLog | 4 ++++ src/coding.c | 2 +- src/font.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cef1edff87d..a7f12bc37ad 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2012-10-19 Kenichi Handa + + * font.c (Ffont_at): Fix previous change. + 2012-10-19 Eli Zaretskii * puresize.h (BASE_PURESIZE): Bump the base value to 1700000. See diff --git a/src/coding.c b/src/coding.c index 412d7245223..7628a9fbf2e 100644 --- a/src/coding.c +++ b/src/coding.c @@ -415,7 +415,7 @@ enum iso_code_class_type ISO_shift_out, /* ISO_CODE_SO (0x0E) */ ISO_shift_in, /* ISO_CODE_SI (0x0F) */ ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ - ISO_escape, /* ISO_CODE_SO (0x1B) */ + ISO_escape, /* ISO_CODE_ESC (0x1B) */ ISO_control_1, /* Control codes in the range 0x80..0x9F, except for the following 3 codes. */ diff --git a/src/font.c b/src/font.c index 629e8bb977a..7cb4149ac4e 100644 --- a/src/font.c +++ b/src/font.c @@ -4775,7 +4775,7 @@ the current buffer. It defaults to the currently selected window. */) { CHECK_NUMBER (position); CHECK_STRING (string); - if (! (0 < XINT (position) && XINT (position) < SCHARS (string))) + if (! (0 <= XINT (position) && XINT (position) < SCHARS (string))) args_out_of_range (string, position); pos = XINT (position); } From 6ec83f926d5ff699901fb530162d7f1bdfa85808 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 19 Oct 2012 22:02:52 +0900 Subject: [PATCH 09/18] src/ChangeLog: Fix changers name. --- src/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index a7f12bc37ad..5a1b4a5d8ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,4 @@ -2012-10-19 Kenichi Handa +2012-10-19 Kazuhiro Ito (tiny change) * font.c (Ffont_at): Fix previous change. From e752e0b0a2622d8d0ba518bf81f6fa652d926e67 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 Oct 2012 09:52:02 -0700 Subject: [PATCH 10/18] 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 , 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 --- ChangeLog | 13 ++++++ admin/ChangeLog | 8 ++++ admin/merge-gnulib | 13 +++--- configure.ac | 4 +- lib/gnulib.mk | 97 ++++++++++++++++++++++++++++++++++++++++- m4/gnulib-comp.m4 | 105 +++++++++++++++++++++++++++++++++++++++++++++ nt/ChangeLog | 7 +++ nt/inc/ms-w32.h | 7 ++- src/ChangeLog | 29 +++++++++++++ src/Makefile.in | 3 +- src/callproc.c | 4 +- src/charset.c | 3 +- src/conf_post.h | 4 ++ src/fileio.c | 97 +++++++++++------------------------------ src/lisp.h | 1 + src/lread.c | 56 ++++++++++++------------ src/process.c | 36 ++++++++-------- src/sysdep.c | 6 +-- src/term.c | 4 +- src/w32.c | 18 +++++--- src/xrdb.c | 8 ++-- 21 files changed, 377 insertions(+), 146 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81eddade0a0..c7fcd319af2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-10-19 Paul Eggert + + Use faccessat, not access, when checking file permissions (Bug#12632). + * .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. + 2012-10-18 Stefan Monnier * Makefile.in ($(MAKEFILE_NAME)): Depend on src/lisp.mk as well. diff --git a/admin/ChangeLog b/admin/ChangeLog index e21293d618d..6d08bf7c37e 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog @@ -1,3 +1,11 @@ +2012-10-19 Paul Eggert + + Use faccessat, not access, when checking file permissions (Bug#12632). + * 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. + 2012-10-12 Kenichi Handa * charsets/Makefile (JISC6226.map): Add missing mappings. diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 7fc0b5f4844..3c4d8e8058d 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -28,7 +28,7 @@ GNULIB_URL=git://git.savannah.gnu.org/gnulib.git GNULIB_MODULES=' alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 - dtoastr dtotimespec dup2 environ execinfo + dtoastr dtotimespec dup2 environ execinfo faccessat filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink @@ -39,9 +39,12 @@ GNULIB_MODULES=' ' GNULIB_TOOL_FLAGS=' - --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat - --avoid=msvc-inval --avoid=msvc-nothrow - --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types + --avoid=at-internal + --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat + --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow + --avoid=openat-die --avoid=openat-h + --avoid=raise + --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --conditional-dependencies --import --no-changelog --no-vc-files --makefile-name=gnulib.mk @@ -85,7 +88,7 @@ test -x "$gnulib_srcdir"/gnulib-tool || { } "$gnulib_srcdir"/gnulib-tool --dir="$src" $GNULIB_TOOL_FLAGS $GNULIB_MODULES && -rm -- "$src"m4/gnulib-cache.m4 "$src"m4/warn-on-use.m4 && +rm -- "$src"m4/fcntl-o.m4 "$src"m4/gnulib-cache.m4 "$src"m4/warn-on-use.m4 && cp -- "$gnulib_srcdir"/build-aux/texinfo.tex "$src"doc/misc && cp -- "$gnulib_srcdir"/build-aux/move-if-change "$src"build-aux && autoreconf -i -I m4 -- ${src:+"$src"} diff --git a/configure.ac b/configure.ac index 5520dd6a903..6b4c757ced5 100644 --- a/configure.ac +++ b/configure.ac @@ -572,6 +572,8 @@ else test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS" fi +# Avoid gnulib's tests for O_NOATIME and O_NOFOLLOW, as we don't use them. +AC_DEFUN([gl_FCNTL_O_FLAGS]) # Avoid gnulib's threadlib module, as we do threads our own way. AC_DEFUN([gl_THREADLIB]) @@ -2872,7 +2874,7 @@ AC_SUBST(BLESSMAIL_TARGET) AC_CHECK_FUNCS(gethostname \ closedir getrusage get_current_dir_name \ lrand48 setsid \ -fpathconf select euidaccess getpagesize setlocale \ +fpathconf select getpagesize setlocale \ utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \ __fpending strsignal setitimer \ sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ diff --git a/lib/gnulib.mk b/lib/gnulib.mk index 23749331a83..d2562a4dae1 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk @@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings MOSTLYCLEANFILES += core *.stackdump @@ -150,6 +150,17 @@ EXTRA_libgnu_a_SOURCES += dup2.c ## end gnulib module dup2 +## begin gnulib module euidaccess + +if gl_GNULIB_ENABLED_euidaccess + +endif +EXTRA_DIST += euidaccess.c + +EXTRA_libgnu_a_SOURCES += euidaccess.c + +## end gnulib module euidaccess + ## begin gnulib module execinfo BUILT_SOURCES += $(EXECINFO_H) @@ -175,6 +186,50 @@ EXTRA_libgnu_a_SOURCES += execinfo.c ## end gnulib module execinfo +## begin gnulib module faccessat + + +EXTRA_DIST += at-func.c faccessat.c + +EXTRA_libgnu_a_SOURCES += at-func.c faccessat.c + +## end gnulib module faccessat + +## begin gnulib module fcntl-h + +BUILT_SOURCES += fcntl.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \ + -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \ + -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \ + -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \ + -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \ + -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \ + -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \ + -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \ + -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \ + -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/fcntl.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += fcntl.h fcntl.h-t + +EXTRA_DIST += fcntl.in.h + +## end gnulib module fcntl-h + ## begin gnulib module filemode libgnu_a_SOURCES += filemode.c @@ -183,6 +238,17 @@ EXTRA_DIST += filemode.h ## end gnulib module filemode +## begin gnulib module getgroups + +if gl_GNULIB_ENABLED_getgroups + +endif +EXTRA_DIST += getgroups.c + +EXTRA_libgnu_a_SOURCES += getgroups.c + +## end gnulib module getgroups + ## begin gnulib module getloadavg @@ -242,6 +308,17 @@ EXTRA_libgnu_a_SOURCES += gettimeofday.c ## end gnulib module gettimeofday +## begin gnulib module group-member + +if gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 + +endif +EXTRA_DIST += group-member.c + +EXTRA_libgnu_a_SOURCES += group-member.c + +## end gnulib module group-member + ## begin gnulib module ignore-value @@ -354,6 +431,15 @@ EXTRA_libgnu_a_SOURCES += readlink.c ## end gnulib module readlink +## begin gnulib module root-uid + +if gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c + +endif +EXTRA_DIST += root-uid.h + +## end gnulib module root-uid + ## begin gnulib module signal-h BUILT_SOURCES += signal.h @@ -1312,6 +1398,15 @@ EXTRA_DIST += verify.h ## end gnulib module verify +## begin gnulib module xalloc-oversized + +if gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec + +endif +EXTRA_DIST += xalloc-oversized.h + +## end gnulib module xalloc-oversized + mostlyclean-local: mostlyclean-generic @for dir in '' $(MOSTLYCLEANDIRS); do \ diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index de2355d87c3..9b2dcee1cfa 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -53,17 +53,22 @@ AC_DEFUN([gl_EARLY], # Code from module dtotimespec: # Code from module dup2: # Code from module environ: + # Code from module euidaccess: # Code from module execinfo: # Code from module extensions: AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) # Code from module extern-inline: + # Code from module faccessat: + # Code from module fcntl-h: # Code from module filemode: + # Code from module getgroups: # Code from module getloadavg: # Code from module getopt-gnu: # Code from module getopt-posix: # Code from module gettext-h: # Code from module gettime: # Code from module gettimeofday: + # Code from module group-member: # Code from module ignore-value: # Code from module include_next: # Code from module intprops: @@ -79,6 +84,7 @@ AC_DEFUN([gl_EARLY], # Code from module pselect: # Code from module pthread_sigmask: # Code from module readlink: + # Code from module root-uid: # Code from module signal-h: # Code from module snippet/_Noreturn: # Code from module snippet/arg-nonnull: @@ -120,6 +126,7 @@ AC_DEFUN([gl_EARLY], # Code from module utimens: # Code from module verify: # Code from module warnings: + # Code from module xalloc-oversized: ]) # This macro should be invoked from ./configure.ac, in the section @@ -156,6 +163,14 @@ AC_DEFUN([gl_INIT], gl_UNISTD_MODULE_INDICATOR([environ]) gl_EXECINFO_H AC_REQUIRE([gl_EXTERN_INLINE]) + gl_FUNC_FACCESSAT + if test $HAVE_FACCESSAT = 0; then + AC_LIBOBJ([faccessat]) + gl_PREREQ_FACCESSAT + fi + gl_MODULE_INDICATOR([faccessat]) + gl_UNISTD_MODULE_INDICATOR([faccessat]) + gl_FCNTL_H gl_FILEMODE gl_GETLOADAVG if test $HAVE_GETLOADAVG = 0; then @@ -269,18 +284,53 @@ AC_DEFUN([gl_INIT], gl_UNISTD_H gl_UTIMENS gl_gnulib_enabled_dosname=false + gl_gnulib_enabled_euidaccess=false + gl_gnulib_enabled_getgroups=false gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=false + gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false gl_gnulib_enabled_pathmax=false + gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false gl_gnulib_enabled_stat=false gl_gnulib_enabled_strtoll=false gl_gnulib_enabled_strtoull=false gl_gnulib_enabled_verify=false + gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false func_gl_gnulib_m4code_dosname () { if ! $gl_gnulib_enabled_dosname; then gl_gnulib_enabled_dosname=true fi } + func_gl_gnulib_m4code_euidaccess () + { + if ! $gl_gnulib_enabled_euidaccess; then + gl_FUNC_EUIDACCESS + if test $HAVE_EUIDACCESS = 0; then + AC_LIBOBJ([euidaccess]) + gl_PREREQ_EUIDACCESS + fi + gl_UNISTD_MODULE_INDICATOR([euidaccess]) + gl_gnulib_enabled_euidaccess=true + if test $HAVE_EUIDACCESS = 0; then + func_gl_gnulib_m4code_a9786850e999ae65a836a6041e8e5ed1 + fi + func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c + if test $HAVE_EUIDACCESS = 0; then + func_gl_gnulib_m4code_stat + fi + fi + } + func_gl_gnulib_m4code_getgroups () + { + if ! $gl_gnulib_enabled_getgroups; then + gl_FUNC_GETGROUPS + if test $HAVE_GETGROUPS = 0 || test $REPLACE_GETGROUPS = 1; then + AC_LIBOBJ([getgroups]) + fi + gl_UNISTD_MODULE_INDICATOR([getgroups]) + gl_gnulib_enabled_getgroups=true + fi + } func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 () { if ! $gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36; then @@ -289,6 +339,24 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=true fi } + func_gl_gnulib_m4code_a9786850e999ae65a836a6041e8e5ed1 () + { + if ! $gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1; then + gl_FUNC_GROUP_MEMBER + if test $HAVE_GROUP_MEMBER = 0; then + AC_LIBOBJ([group-member]) + gl_PREREQ_GROUP_MEMBER + fi + gl_UNISTD_MODULE_INDICATOR([group-member]) + gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=true + if test $HAVE_GROUP_MEMBER = 0; then + func_gl_gnulib_m4code_getgroups + fi + if test $HAVE_GROUP_MEMBER = 0; then + func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec + fi + fi + } func_gl_gnulib_m4code_pathmax () { if ! $gl_gnulib_enabled_pathmax; then @@ -296,6 +364,12 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_pathmax=true fi } + func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c () + { + if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then + gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=true + fi + } func_gl_gnulib_m4code_stat () { if ! $gl_gnulib_enabled_stat; then @@ -347,6 +421,18 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_verify=true fi } + func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec () + { + if ! $gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec; then + gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=true + fi + } + if test $HAVE_FACCESSAT = 0; then + func_gl_gnulib_m4code_dosname + fi + if test $HAVE_FACCESSAT = 0; then + func_gl_gnulib_m4code_euidaccess + fi if test $REPLACE_GETOPT = 1; then func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 fi @@ -373,12 +459,17 @@ AC_DEFUN([gl_INIT], fi m4_pattern_allow([^gl_GNULIB_ENABLED_]) AM_CONDITIONAL([gl_GNULIB_ENABLED_dosname], [$gl_gnulib_enabled_dosname]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_euidaccess], [$gl_gnulib_enabled_euidaccess]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_getgroups], [$gl_gnulib_enabled_getgroups]) AM_CONDITIONAL([gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36], [$gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1]) AM_CONDITIONAL([gl_GNULIB_ENABLED_pathmax], [$gl_gnulib_enabled_pathmax]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c]) AM_CONDITIONAL([gl_GNULIB_ENABLED_stat], [$gl_gnulib_enabled_stat]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoull], [$gl_gnulib_enabled_strtoull]) AM_CONDITIONAL([gl_GNULIB_ENABLED_verify], [$gl_gnulib_enabled_verify]) + AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec]) # End of code from modules m4_ifval(gl_LIBSOURCES_LIST, [ m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || @@ -527,6 +618,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/alloca.in.h lib/allocator.c lib/allocator.h + lib/at-func.c lib/c-ctype.c lib/c-ctype.h lib/c-strcase.h @@ -538,12 +630,16 @@ AC_DEFUN([gl_FILE_LIST], [ lib/dtoastr.c lib/dtotimespec.c lib/dup2.c + lib/euidaccess.c lib/execinfo.c lib/execinfo.in.h + lib/faccessat.c + lib/fcntl.in.h lib/filemode.c lib/filemode.h lib/ftoastr.c lib/ftoastr.h + lib/getgroups.c lib/getloadavg.c lib/getopt.c lib/getopt.in.h @@ -552,6 +648,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/gettext.h lib/gettime.c lib/gettimeofday.c + lib/group-member.c lib/ignore-value.h lib/intprops.h lib/inttypes.in.h @@ -564,6 +661,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/pselect.c lib/pthread_sigmask.c lib/readlink.c + lib/root-uid.h lib/sha1.c lib/sha1.h lib/sha256.c @@ -605,21 +703,28 @@ AC_DEFUN([gl_FILE_LIST], [ lib/utimens.c lib/utimens.h lib/verify.h + lib/xalloc-oversized.h m4/00gnulib.m4 m4/alloca.m4 m4/c-strtod.m4 m4/clock_time.m4 m4/dup2.m4 m4/environ.m4 + m4/euidaccess.m4 m4/execinfo.m4 m4/extensions.m4 m4/extern-inline.m4 + m4/faccessat.m4 + m4/fcntl-o.m4 + m4/fcntl_h.m4 m4/filemode.m4 + m4/getgroups.m4 m4/getloadavg.m4 m4/getopt.m4 m4/gettime.m4 m4/gettimeofday.m4 m4/gnulib-common.m4 + m4/group-member.m4 m4/include_next.m4 m4/inttypes.m4 m4/largefile.m4 diff --git a/nt/ChangeLog b/nt/ChangeLog index 94d2ce18551..f64cafe2e16 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog @@ -1,3 +1,10 @@ +2012-10-19 Paul Eggert + + Use faccessat, not access, when checking file permissions (Bug#12632). + * inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols. + (access): Remove. + (faccessat): New macro. + 2012-10-17 Eli Zaretskii * inc/pwd.h (getuid, geteuid): Add prototypes. diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h index dd2ae781cb8..0f6b51d3915 100644 --- a/nt/inc/ms-w32.h +++ b/nt/inc/ms-w32.h @@ -124,6 +124,10 @@ extern char *getenv (); #define MAXPATHLEN _MAX_PATH #endif +/* Use values compatible with gnulib, as there's no reason to differ. */ +#define AT_FDCWD (-3041965) +#define AT_EACCESS 4 + #ifdef HAVE_NTGUI #define HAVE_WINDOW_SYSTEM 1 #define HAVE_MENUS 1 @@ -145,8 +149,6 @@ extern char *getenv (); #endif /* Calls that are emulated or shadowed. */ -#undef access -#define access sys_access #undef chdir #define chdir sys_chdir #undef chmod @@ -161,6 +163,7 @@ extern char *getenv (); #define dup sys_dup #undef dup2 #define dup2 sys_dup2 +#define faccessat sys_faccessat #define fopen sys_fopen #define link sys_link #define localtime sys_localtime diff --git a/src/ChangeLog b/src/ChangeLog index 5a1b4a5d8ee..ee18650e992 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,32 @@ +2012-10-19 Paul Eggert + + Use faccessat, not access, when checking file permissions (Bug#12632). + * Makefile.in (LIB_EACCESS): New macro. + (LIBES): Use it. + * callproc.c (init_callproc): + * charset.c (init_charset): + * fileio.c (check_existing, check_executable): + * lread.c (openp, load_path_check): + * process.c (allocate_pty): + * xrdb.c (file_p): + Use faccessat, not access or euidaccess. Use symbolic names + instead of integers for the flags, as they're portable now. + * charset.c, xrdb.c: Include , for the new flags used. + * 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. + * fileio.c (Ffile_directory_p, Fset_file_times): + * xrdb.c (file_p): Use file_directory_p. + * lisp.h (file_directory_p): New decl. + * 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. + * process.c, sysdep.c, term.c: All uses of '#ifdef O_NONBLOCK' + changed to '#if O_NONBLOCK', to accommodate gnulib O_* style. + * w32.c (sys_faccessat): Rename from sys_access and switch to + faccessat's API. All uses changed. + 2012-10-19 Kazuhiro Ito (tiny change) * font.c (Ffont_at): Fix previous change. diff --git a/src/Makefile.in b/src/Makefile.in index c24e421bbbc..d034ad04796 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -150,6 +150,7 @@ M17N_FLT_CFLAGS = @M17N_FLT_CFLAGS@ M17N_FLT_LIBS = @M17N_FLT_LIBS@ LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ +LIB_EACCESS=@LIB_EACCESS@ LIB_TIMER_TIME=@LIB_TIMER_TIME@ DBUS_CFLAGS = @DBUS_CFLAGS@ @@ -392,7 +393,7 @@ otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \ LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \ $(LIBX_OTHER) $(LIBSOUND) \ $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ - $(LIB_TIMER_TIME) $(DBUS_LIBS) \ + $(LIB_EACCESS) $(LIB_TIMER_TIME) $(DBUS_LIBS) \ $(LIB_EXECINFO) \ $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ diff --git a/src/callproc.c b/src/callproc.c index b33882e54c2..5a9b32f08c3 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1597,13 +1597,13 @@ init_callproc (void) #endif { tempdir = Fdirectory_file_name (Vexec_directory); - if (access (SSDATA (tempdir), 0) < 0) + if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0) dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n", Vexec_directory); } tempdir = Fdirectory_file_name (Vdata_directory); - if (access (SSDATA (tempdir), 0) < 0) + if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0) dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n", Vdata_directory); diff --git a/src/charset.c b/src/charset.c index 6b999824dab..fe068e1d3bc 100644 --- a/src/charset.c +++ b/src/charset.c @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */ #define CHARSET_INLINE EXTERN_INLINE +#include #include #include #include @@ -2293,7 +2294,7 @@ init_charset (void) { Lisp_Object tempdir; tempdir = Fexpand_file_name (build_string ("charsets"), Vdata_directory); - if (access (SSDATA (tempdir), 0) < 0) + if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0) { /* This used to be non-fatal (dir_warning), but it should not happen, and if it does sooner or later it will cause some diff --git a/src/conf_post.h b/src/conf_post.h index aa008107ba6..eade536e6e1 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -169,6 +169,10 @@ extern void _DebPrint (const char *fmt, ...); #endif #endif +/* Tell gnulib to omit support for openat-related functions having a + first argument other than AT_FDCWD. */ +#define GNULIB_SUPPORT_ONLY_AT_FDCWD + #include #include diff --git a/src/fileio.c b/src/fileio.c index d47d7dd9e0b..3accb58a3eb 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2425,15 +2425,7 @@ On Unix, this is a name starting with a `/' or a `~'. */) bool check_existing (const char *filename) { -#ifdef DOS_NT - /* The full emulation of Posix 'stat' is too expensive on - DOS/Windows, when all we want to know is whether the file exists. - So we use 'access' instead, which is much more lightweight. */ - return (access (filename, F_OK) >= 0); -#else - struct stat st; - return (stat (filename, &st) >= 0); -#endif + return faccessat (AT_FDCWD, filename, F_OK, AT_EACCESS) == 0; } /* Return true if file FILENAME exists and can be executed. */ @@ -2441,21 +2433,7 @@ check_existing (const char *filename) static bool check_executable (char *filename) { -#ifdef DOS_NT - struct stat st; - if (stat (filename, &st) < 0) - return 0; - return ((st.st_mode & S_IEXEC) != 0); -#else /* not DOS_NT */ -#ifdef HAVE_EUIDACCESS - return (euidaccess (filename, 1) >= 0); -#else - /* Access isn't quite right because it uses the real uid - and we really want to test with the effective uid. - But Unix doesn't give us a right way to do it. */ - return (access (filename, 1) >= 0); -#endif -#endif /* not DOS_NT */ + return faccessat (AT_FDCWD, filename, X_OK, AT_EACCESS) == 0; } /* Return true if file FILENAME exists and can be written. */ @@ -2464,15 +2442,16 @@ static bool check_writable (const char *filename) { #ifdef MSDOS + /* FIXME: an faccessat implementation should be added to the + DOS/Windows ports and this #ifdef branch should be removed. */ struct stat st; if (stat (filename, &st) < 0) return 0; return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); #else /* not MSDOS */ -#ifdef HAVE_EUIDACCESS - bool res = (euidaccess (filename, 2) >= 0); + bool res = faccessat (AT_FDCWD, filename, W_OK, AT_EACCESS) == 0; #ifdef CYGWIN - /* euidaccess may have returned failure because Cygwin couldn't + /* faccessat may have returned failure because Cygwin couldn't determine the file's UID or GID; if so, we return success. */ if (!res) { @@ -2483,14 +2462,6 @@ check_writable (const char *filename) } #endif /* CYGWIN */ return res; -#else /* not HAVE_EUIDACCESS */ - /* Access isn't quite right because it uses the real uid - and we really want to test with the effective uid. - But Unix doesn't give us a right way to do it. - Opening with O_WRONLY could work for an ordinary file, - but would lose for directories. */ - return (access (filename, 2) >= 0); -#endif /* not HAVE_EUIDACCESS */ #endif /* not MSDOS */ } @@ -2547,9 +2518,6 @@ See also `file-exists-p' and `file-attributes'. */) { Lisp_Object absname; Lisp_Object handler; - int desc; - int flags; - struct stat statbuf; CHECK_STRING (filename); absname = Fexpand_file_name (filename, Qnil); @@ -2561,31 +2529,8 @@ See also `file-exists-p' and `file-attributes'. */) return call2 (handler, Qfile_readable_p, absname); absname = ENCODE_FILE (absname); - -#if defined (DOS_NT) || defined (macintosh) - /* Under MS-DOS, Windows, and Macintosh, open does not work for - directories. */ - if (access (SDATA (absname), 0) == 0) - return Qt; - return Qnil; -#else /* not DOS_NT and not macintosh */ - flags = O_RDONLY; -#ifdef O_NONBLOCK - /* Opening a fifo without O_NONBLOCK can wait. - We don't want to wait. But we don't want to mess wth O_NONBLOCK - except in the case of a fifo, on a system which handles it. */ - desc = stat (SSDATA (absname), &statbuf); - if (desc < 0) - return Qnil; - if (S_ISFIFO (statbuf.st_mode)) - flags |= O_NONBLOCK; -#endif - desc = emacs_open (SSDATA (absname), flags, 0); - if (desc < 0) - return Qnil; - emacs_close (desc); - return Qt; -#endif /* not DOS_NT and not macintosh */ + return (faccessat (AT_FDCWD, SSDATA (absname), R_OK, AT_EACCESS) == 0 + ? Qt : Qnil); } /* Having this before file-symlink-p mysteriously caused it to be forgotten @@ -2622,7 +2567,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, /* The read-only attribute of the parent directory doesn't affect whether a file or directory can be created within it. Some day we should check ACLs though, which do affect this. */ - return (access (SDATA (dir), D_OK) < 0) ? Qnil : Qt; + return file_directory_p (SDATA (dir)) ? Qt : Qnil; #else return (check_writable (!NILP (dir) ? SSDATA (dir) : "") ? Qt : Qnil); @@ -2703,8 +2648,7 @@ Symbolic links to directories count as directories. See `file-symlink-p' to distinguish symlinks. */) (Lisp_Object filename) { - register Lisp_Object absname; - struct stat st; + Lisp_Object absname; Lisp_Object handler; absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory)); @@ -2717,9 +2661,20 @@ See `file-symlink-p' to distinguish symlinks. */) absname = ENCODE_FILE (absname); - if (stat (SSDATA (absname), &st) < 0) - return Qnil; - return S_ISDIR (st.st_mode) ? Qt : Qnil; + return file_directory_p (SSDATA (absname)) ? Qt : Qnil; +} + +/* Return true if FILE is a directory or a symlink to a directory. */ +bool +file_directory_p (char const *file) +{ +#ifdef WINDOWSNT + /* This is cheaper than 'stat'. */ + return faccessat (AT_FDCWD, file, D_OK, AT_EACCESS) == 0; +#else + struct stat st; + return stat (file, &st) == 0 && S_ISDIR (st.st_mode); +#endif } DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, @@ -3044,10 +2999,8 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of if (set_file_times (-1, SSDATA (encoded_absname), t, t)) { #ifdef MSDOS - struct stat st; - /* Setting times on a directory always fails. */ - if (stat (SSDATA (encoded_absname), &st) == 0 && S_ISDIR (st.st_mode)) + if (file_directory_p (SSDATA (encoded_absname))) return Qnil; #endif report_file_error ("Setting file times", Fcons (absname, Qnil)); diff --git a/src/lisp.h b/src/lisp.h index 01f6ca5e57c..897757cf462 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3178,6 +3178,7 @@ extern Lisp_Object close_file_unwind (Lisp_Object); extern Lisp_Object restore_point_unwind (Lisp_Object); extern _Noreturn void report_file_error (const char *, Lisp_Object); extern void internal_delete_file (Lisp_Object); +extern bool file_directory_p (const char *); extern void syms_of_fileio (void); extern Lisp_Object make_temp_name (Lisp_Object, bool); extern Lisp_Object Qdelete_file; diff --git a/src/lread.c b/src/lread.c index 6d4c0d990af..dedce50de2a 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1404,7 +1404,7 @@ Returns the file's name in absolute form, or nil if not found. If SUFFIXES is non-nil, it should be a list of suffixes to append to file name when searching. If non-nil, PREDICATE is used instead of `file-readable-p'. -PREDICATE can also be an integer to pass to the access(2) function, +PREDICATE can also be an integer to pass to the faccessat(2) function, in which case file-name-handlers are ignored. This function will normally skip directories, so if you want it to find directories, make sure the PREDICATE function returns `dir-ok' for them. */) @@ -1442,7 +1442,6 @@ static Lisp_Object Qdir_ok; int openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate) { - int fd; ptrdiff_t fn_size = 100; char buf[100]; char *fn = buf; @@ -1497,7 +1496,6 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto { ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail)); Lisp_Object handler; - bool exists; /* Concatenate path element/specified name with the suffix. If the directory starts with /:, remove that. */ @@ -1521,6 +1519,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto handler = Ffind_file_name_handler (string, Qfile_exists_p); if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) { + bool exists; if (NILP (predicate)) exists = !NILP (Ffile_readable_p (string)); else @@ -1542,37 +1541,40 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto } else { -#ifndef WINDOWSNT - struct stat st; -#endif + int fd; const char *pfn; encoded_fn = ENCODE_FILE (string); pfn = SSDATA (encoded_fn); -#ifdef WINDOWSNT - exists = access (pfn, F_OK) == 0 && access (pfn, D_OK) < 0; -#else - exists = (stat (pfn, &st) == 0 && ! S_ISDIR (st.st_mode)); -#endif - if (exists) - { - /* Check that we can access or open it. */ - if (NATNUMP (predicate)) - fd = (((XFASTINT (predicate) & ~INT_MAX) == 0 - && access (pfn, XFASTINT (predicate)) == 0) - ? 1 : -1); - else - fd = emacs_open (pfn, O_RDONLY, 0); - if (fd >= 0) + /* Check that we can access or open it. */ + if (NATNUMP (predicate)) + fd = (((XFASTINT (predicate) & ~INT_MAX) == 0 + && (faccessat (AT_FDCWD, pfn, XFASTINT (predicate), + AT_EACCESS) + == 0) + && ! file_directory_p (pfn)) + ? 1 : -1); + else + { + struct stat st; + fd = emacs_open (pfn, O_RDONLY, 0); + if (0 <= fd + && (fstat (fd, &st) != 0 || S_ISDIR (st.st_mode))) { - /* We succeeded; return this descriptor and filename. */ - if (storeptr) - *storeptr = string; - UNGCPRO; - return fd; + emacs_close (fd); + fd = -1; } } + + if (fd >= 0) + { + /* We succeeded; return this descriptor and filename. */ + if (storeptr) + *storeptr = string; + UNGCPRO; + return fd; + } } } if (absolute) @@ -4088,7 +4090,7 @@ load_path_check (void) if (STRINGP (dirfile)) { dirfile = Fdirectory_file_name (dirfile); - if (access (SSDATA (dirfile), 0) < 0) + if (faccessat (AT_FDCWD, SSDATA (dirfile), F_OK, AT_EACCESS) != 0) dir_warning ("Warning: Lisp directory `%s' does not exist.\n", XCAR (path_tail)); } 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; #ifndef NON_BLOCKING_CONNECT #ifdef HAVE_SELECT #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) -#if defined (O_NONBLOCK) || defined (O_NDELAY) +#if O_NONBLOCK || O_NDELAY #if defined (EWOULDBLOCK) || defined (EINPROGRESS) #define NON_BLOCKING_CONNECT #endif /* EWOULDBLOCK || EINPROGRESS */ @@ -651,7 +651,7 @@ allocate_pty (void) PTY_OPEN; #else /* no PTY_OPEN */ { -# ifdef O_NONBLOCK +# if O_NONBLOCK fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); # else fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0); @@ -668,7 +668,7 @@ allocate_pty (void) #else sprintf (pty_name, "/dev/tty%c%x", c, i); #endif /* no PTY_TTY_NAME_SPRINTF */ - if (access (pty_name, 6) != 0) + if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0) { emacs_close (fd); # ifndef __sgi @@ -1621,7 +1621,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) #if ! defined (USG) || defined (USG_SUBTTY_WORKS) /* On most USG systems it does not work to open the pty's tty here, then close it and reopen it in the child. */ -#ifdef O_NOCTTY +#if O_NOCTTY /* Don't let this terminal become our controlling terminal (in case we don't have one). */ 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) } #endif -#ifdef O_NONBLOCK +#if O_NONBLOCK fcntl (inchannel, F_SETFL, O_NONBLOCK); fcntl (outchannel, F_SETFL, O_NONBLOCK); #else -#ifdef O_NDELAY +#if O_NDELAY fcntl (inchannel, F_SETFL, O_NDELAY); fcntl (outchannel, F_SETFL, O_NDELAY); #endif @@ -1967,7 +1967,7 @@ create_pty (Lisp_Object process) #if ! defined (USG) || defined (USG_SUBTTY_WORKS) /* On most USG systems it does not work to open the pty's tty here, then close it and reopen it in the child. */ -#ifdef O_NOCTTY +#if O_NOCTTY /* Don't let this terminal become our controlling terminal (in case we don't have one). */ int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); @@ -1987,11 +1987,11 @@ create_pty (Lisp_Object process) } #endif /* HAVE_PTYS */ -#ifdef O_NONBLOCK +#if O_NONBLOCK fcntl (inchannel, F_SETFL, O_NONBLOCK); fcntl (outchannel, F_SETFL, O_NONBLOCK); #else -#ifdef O_NDELAY +#if O_NDELAY fcntl (inchannel, F_SETFL, O_NDELAY); fcntl (outchannel, F_SETFL, O_NDELAY); #endif @@ -2951,7 +2951,7 @@ usage: (make-network-process &rest ARGS) */) { /* Don't support network sockets when non-blocking mode is not available, since a blocked Emacs is not useful. */ -#if !defined (O_NONBLOCK) && !defined (O_NDELAY) +#if !O_NONBLOCK && !O_NDELAY error ("Network servers not supported"); #else is_server = 1; @@ -3217,7 +3217,7 @@ usage: (make-network-process &rest ARGS) */) #ifdef NON_BLOCKING_CONNECT if (is_non_blocking_client) { -#ifdef O_NONBLOCK +#if O_NONBLOCK ret = fcntl (s, F_SETFL, O_NONBLOCK); #else ret = fcntl (s, F_SETFL, O_NDELAY); @@ -3434,10 +3434,10 @@ usage: (make-network-process &rest ARGS) */) chan_process[inch] = proc; -#ifdef O_NONBLOCK +#if O_NONBLOCK fcntl (inch, F_SETFL, O_NONBLOCK); #else -#ifdef O_NDELAY +#if O_NDELAY fcntl (inch, F_SETFL, O_NDELAY); #endif #endif @@ -4169,10 +4169,10 @@ server_accept_connection (Lisp_Object server, int channel) chan_process[s] = proc; -#ifdef O_NONBLOCK +#if O_NONBLOCK fcntl (s, F_SETFL, O_NONBLOCK); #else -#ifdef O_NDELAY +#if O_NDELAY fcntl (s, F_SETFL, O_NDELAY); #endif #endif @@ -4873,11 +4873,11 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, #endif /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK, and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */ -#ifdef O_NONBLOCK +#if O_NONBLOCK else if (nread == -1 && errno == EAGAIN) ; #else -#ifdef O_NDELAY +#if O_NDELAY else if (nread == -1 && errno == EAGAIN) ; /* Note that we cannot distinguish between no input @@ -7363,7 +7363,7 @@ init_process_emacs (void) #ifdef HAVE_GETSOCKNAME ADD_SUBFEATURE (QCservice, Qt); #endif -#if defined (O_NONBLOCK) || defined (O_NDELAY) +#if O_NONBLOCK || O_NDELAY ADD_SUBFEATURE (QCserver, Qt); #endif diff --git a/src/sysdep.c b/src/sysdep.c index 35beeaa7202..8a31957d182 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1216,7 +1216,7 @@ reset_sys_modes (struct tty_display_info *tty_out) old_fcntl_owner[fileno (tty_out->input)]); } #endif /* F_SETOWN */ -#ifdef O_NDELAY +#if O_NDELAY fcntl (fileno (tty_out->input), F_SETFL, fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY); #endif @@ -2312,12 +2312,12 @@ serial_open (char *port) fd = emacs_open ((char*) port, O_RDWR -#ifdef O_NONBLOCK +#if O_NONBLOCK | O_NONBLOCK #else | O_NDELAY #endif -#ifdef O_NOCTTY +#if O_NOCTTY | O_NOCTTY #endif , 0); diff --git a/src/term.c b/src/term.c index f7c87b7608d..87ce5447b76 100644 --- a/src/term.c +++ b/src/term.c @@ -3023,7 +3023,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) int fd; FILE *file; -#ifdef O_IGNORE_CTTY +#if O_IGNORE_CTTY if (!ctty) /* Open the terminal device. Don't recognize it as our controlling terminal, and don't make it the controlling tty @@ -3054,7 +3054,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) name); } -#ifndef O_IGNORE_CTTY +#if !O_IGNORE_CTTY if (!ctty) dissociate_if_controlling_tty (fd); #endif diff --git a/src/w32.c b/src/w32.c index 5ac1bc3eb7c..341f4d3fef3 100644 --- a/src/w32.c +++ b/src/w32.c @@ -1597,7 +1597,7 @@ init_environment (char ** argv) see if it succeeds. But I think that's too much to ask. */ /* MSVCRT's _access crashes with D_OK. */ - if (tmp && sys_access (tmp, D_OK) == 0) + if (tmp && sys_faccessat (AT_FDCWD, tmp, D_OK, AT_EACCESS) == 0) { char * var = alloca (strlen (tmp) + 8); sprintf (var, "TMPDIR=%s", tmp); @@ -2714,10 +2714,16 @@ logon_network_drive (const char *path) long file names. */ int -sys_access (const char * path, int mode) +sys_faccessat (int dirfd, const char * path, int mode, int flags) { DWORD attributes; + if (dirfd != AT_FDCWD) + { + errno = EINVAL; + return -1; + } + /* MSVCRT implementation of 'access' doesn't recognize D_OK, and its newer versions blow up when passed D_OK. */ path = map_w32_filename (path, NULL); @@ -2960,7 +2966,7 @@ sys_mktemp (char * template) { int save_errno = errno; p[0] = first_char[i]; - if (sys_access (template, 0) < 0) + if (sys_faccessat (AT_FDCWD, template, F_OK, AT_EACCESS) < 0) { errno = save_errno; return template; @@ -4011,7 +4017,7 @@ symlink (char const *filename, char const *linkname) { /* Non-absolute FILENAME is understood as being relative to LINKNAME's directory. We need to prepend that directory to - FILENAME to get correct results from sys_access below, since + FILENAME to get correct results from sys_faccessat below, since otherwise it will interpret FILENAME relative to the directory where the Emacs process runs. Note that make-symbolic-link always makes sure LINKNAME is a fully @@ -4025,10 +4031,10 @@ symlink (char const *filename, char const *linkname) strncpy (tem, linkfn, p - linkfn); tem[p - linkfn] = '\0'; strcat (tem, filename); - dir_access = sys_access (tem, D_OK); + dir_access = sys_faccessat (AT_FDCWD, tem, D_OK, AT_EACCESS); } else - dir_access = sys_access (filename, D_OK); + dir_access = sys_faccessat (AT_FDCWD, filename, D_OK, AT_EACCESS); /* Since Windows distinguishes between symlinks to directories and to files, we provide a kludgy feature: if FILENAME doesn't diff --git a/src/xrdb.c b/src/xrdb.c index 9d056a607e4..982a6e46a13 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see . */ #include +#include #include #include #include @@ -261,11 +262,8 @@ gethomedir (void) static int file_p (const char *filename) { - struct stat status; - - return (access (filename, 4) == 0 /* exists and is readable */ - && stat (filename, &status) == 0 /* get the status */ - && (S_ISDIR (status.st_mode)) == 0); /* not a directory */ + return (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) == 0 + && ! file_directory_p (filename)); } From 2c43889e841d1c4e19d876ec2c7d078b940d10d0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 Oct 2012 10:14:00 -0700 Subject: [PATCH 11/18] New files from gnulib. Fixes: debbugs:12632 --- lib/at-func.c | 146 +++++++++++++++++ lib/euidaccess.c | 221 ++++++++++++++++++++++++++ lib/faccessat.c | 45 ++++++ lib/fcntl.in.h | 347 +++++++++++++++++++++++++++++++++++++++++ lib/getgroups.c | 116 ++++++++++++++ lib/group-member.c | 119 ++++++++++++++ lib/root-uid.h | 30 ++++ lib/xalloc-oversized.h | 38 +++++ m4/euidaccess.m4 | 52 ++++++ m4/faccessat.m4 | 28 ++++ m4/fcntl_h.m4 | 50 ++++++ m4/getgroups.m4 | 107 +++++++++++++ m4/group-member.m4 | 29 ++++ 13 files changed, 1328 insertions(+) create mode 100644 lib/at-func.c create mode 100644 lib/euidaccess.c create mode 100644 lib/faccessat.c create mode 100644 lib/fcntl.in.h create mode 100644 lib/getgroups.c create mode 100644 lib/group-member.c create mode 100644 lib/root-uid.h create mode 100644 lib/xalloc-oversized.h create mode 100644 m4/euidaccess.m4 create mode 100644 m4/faccessat.m4 create mode 100644 m4/fcntl_h.m4 create mode 100644 m4/getgroups.m4 create mode 100644 m4/group-member.m4 diff --git a/lib/at-func.c b/lib/at-func.c new file mode 100644 index 00000000000..481eea475a1 --- /dev/null +++ b/lib/at-func.c @@ -0,0 +1,146 @@ +/* Define at-style functions like fstatat, unlinkat, fchownat, etc. + Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* written by Jim Meyering */ + +#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ + +#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD +# include +# ifndef ENOTSUP +# define ENOTSUP EINVAL +# endif +#else +# include "openat.h" +# include "openat-priv.h" +# include "save-cwd.h" +#endif + +#ifdef AT_FUNC_USE_F1_COND +# define CALL_FUNC(F) \ + (flag == AT_FUNC_USE_F1_COND \ + ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \ + : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS)) +# define VALIDATE_FLAG(F) \ + if (flag & ~AT_FUNC_USE_F1_COND) \ + { \ + errno = EINVAL; \ + return FUNC_FAIL; \ + } +#else +# define CALL_FUNC(F) (AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS)) +# define VALIDATE_FLAG(F) /* empty */ +#endif + +#ifdef AT_FUNC_RESULT +# define FUNC_RESULT AT_FUNC_RESULT +#else +# define FUNC_RESULT int +#endif + +#ifdef AT_FUNC_FAIL +# define FUNC_FAIL AT_FUNC_FAIL +#else +# define FUNC_FAIL -1 +#endif + +/* Call AT_FUNC_F1 to operate on FILE, which is in the directory + open on descriptor FD. If AT_FUNC_USE_F1_COND is defined to a value, + AT_FUNC_POST_FILE_PARAM_DECLS must include a parameter named flag; + call AT_FUNC_F2 if FLAG is 0 or fail if FLAG contains more bits than + AT_FUNC_USE_F1_COND. Return int and fail with -1 unless AT_FUNC_RESULT + or AT_FUNC_FAIL are defined. If possible, do it without changing the + working directory. Otherwise, resort to using save_cwd/fchdir, + then AT_FUNC_F?/restore_cwd. If either the save_cwd or the restore_cwd + fails, then give a diagnostic and exit nonzero. */ +FUNC_RESULT +AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) +{ + VALIDATE_FLAG (flag); + + if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file)) + return CALL_FUNC (file); + +#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD + errno = ENOTSUP; + return FUNC_FAIL; +#else + { + /* Be careful to choose names unlikely to conflict with + AT_FUNC_POST_FILE_PARAM_DECLS. */ + struct saved_cwd saved_cwd; + int saved_errno; + FUNC_RESULT err; + + { + char proc_buf[OPENAT_BUFFER_SIZE]; + char *proc_file = openat_proc_name (proc_buf, fd, file); + if (proc_file) + { + FUNC_RESULT proc_result = CALL_FUNC (proc_file); + int proc_errno = errno; + if (proc_file != proc_buf) + free (proc_file); + /* If the syscall succeeds, or if it fails with an unexpected + errno value, then return right away. Otherwise, fall through + and resort to using save_cwd/restore_cwd. */ + if (FUNC_FAIL != proc_result) + return proc_result; + if (! EXPECTED_ERRNO (proc_errno)) + { + errno = proc_errno; + return proc_result; + } + } + } + + if (save_cwd (&saved_cwd) != 0) + openat_save_fail (errno); + if (0 <= fd && fd == saved_cwd.desc) + { + /* If saving the working directory collides with the user's + requested fd, then the user's fd must have been closed to + begin with. */ + free_cwd (&saved_cwd); + errno = EBADF; + return FUNC_FAIL; + } + + if (fchdir (fd) != 0) + { + saved_errno = errno; + free_cwd (&saved_cwd); + errno = saved_errno; + return FUNC_FAIL; + } + + err = CALL_FUNC (file); + saved_errno = (err == FUNC_FAIL ? errno : 0); + + if (restore_cwd (&saved_cwd) != 0) + openat_restore_fail (errno); + + free_cwd (&saved_cwd); + + if (saved_errno) + errno = saved_errno; + return err; + } +#endif +} +#undef CALL_FUNC +#undef FUNC_RESULT +#undef FUNC_FAIL diff --git a/lib/euidaccess.c b/lib/euidaccess.c new file mode 100644 index 00000000000..ca2ceca5d22 --- /dev/null +++ b/lib/euidaccess.c @@ -0,0 +1,221 @@ +/* euidaccess -- check if effective user id can access file + + Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2012 Free + Software Foundation, Inc. + + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by David MacKenzie and Torbjorn Granlund. + Adapted for GNU C library by Roland McGrath. */ + +#ifndef _LIBC +# include +#endif + +#include +#include +#include +#include + +#include "root-uid.h" + +#if HAVE_LIBGEN_H +# include +#endif + +#include +#ifndef __set_errno +# define __set_errno(val) errno = (val) +#endif + +#if defined EACCES && !defined EACCESS +# define EACCESS EACCES +#endif + +#ifndef F_OK +# define F_OK 0 +# define X_OK 1 +# define W_OK 2 +# define R_OK 4 +#endif + + +#ifdef _LIBC + +# define access __access +# define getuid __getuid +# define getgid __getgid +# define geteuid __geteuid +# define getegid __getegid +# define group_member __group_member +# define euidaccess __euidaccess +# undef stat +# define stat stat64 + +#endif + +/* Return 0 if the user has permission of type MODE on FILE; + otherwise, return -1 and set 'errno'. + Like access, except that it uses the effective user and group + id's instead of the real ones, and it does not always check for read-only + file system, text busy, etc. */ + +int +euidaccess (const char *file, int mode) +{ +#if HAVE_FACCESSAT /* glibc, AIX 7, Solaris 11, Cygwin 1.7 */ + return faccessat (AT_FDCWD, file, mode, AT_EACCESS); +#elif defined EFF_ONLY_OK /* IRIX, OSF/1, Interix */ + return access (file, mode | EFF_ONLY_OK); +#elif defined ACC_SELF /* AIX */ + return accessx (file, mode, ACC_SELF); +#elif HAVE_EACCESS /* FreeBSD */ + return eaccess (file, mode); +#else /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */ + + uid_t uid = getuid (); + gid_t gid = getgid (); + uid_t euid = geteuid (); + gid_t egid = getegid (); + struct stat stats; + +# if HAVE_DECL_SETREGID && PREFER_NONREENTRANT_EUIDACCESS + + /* Define PREFER_NONREENTRANT_EUIDACCESS if you prefer euidaccess to + return the correct result even if this would make it + nonreentrant. Define this only if your entire application is + safe even if the uid or gid might temporarily change. If your + application uses signal handlers or threads it is probably not + safe. */ + + if (mode == F_OK) + return stat (file, &stats); + else + { + int result; + int saved_errno; + + if (uid != euid) + setreuid (euid, uid); + if (gid != egid) + setregid (egid, gid); + + result = access (file, mode); + saved_errno = errno; + + /* Restore them. */ + if (uid != euid) + setreuid (uid, euid); + if (gid != egid) + setregid (gid, egid); + + errno = saved_errno; + return result; + } + +# else + + /* The following code assumes the traditional Unix model, and is not + correct on systems that have ACLs or the like. However, it's + better than nothing, and it is reentrant. */ + + unsigned int granted; + if (uid == euid && gid == egid) + /* If we are not set-uid or set-gid, access does the same. */ + return access (file, mode); + + if (stat (file, &stats) != 0) + return -1; + + /* The super-user can read and write any file, and execute any file + that anyone can execute. */ + if (euid == ROOT_UID + && ((mode & X_OK) == 0 + || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))) + return 0; + + /* Convert the mode to traditional form, clearing any bogus bits. */ + if (R_OK == 4 && W_OK == 2 && X_OK == 1 && F_OK == 0) + mode &= 7; + else + mode = ((mode & R_OK ? 4 : 0) + + (mode & W_OK ? 2 : 0) + + (mode & X_OK ? 1 : 0)); + + if (mode == 0) + return 0; /* The file exists. */ + + /* Convert the file's permission bits to traditional form. */ + if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6) + && S_IRGRP == (4 << 3) && S_IWGRP == (2 << 3) && S_IXGRP == (1 << 3) + && S_IROTH == (4 << 0) && S_IWOTH == (2 << 0) && S_IXOTH == (1 << 0)) + granted = stats.st_mode; + else + granted = ((stats.st_mode & S_IRUSR ? 4 << 6 : 0) + + (stats.st_mode & S_IWUSR ? 2 << 6 : 0) + + (stats.st_mode & S_IXUSR ? 1 << 6 : 0) + + (stats.st_mode & S_IRGRP ? 4 << 3 : 0) + + (stats.st_mode & S_IWGRP ? 2 << 3 : 0) + + (stats.st_mode & S_IXGRP ? 1 << 3 : 0) + + (stats.st_mode & S_IROTH ? 4 << 0 : 0) + + (stats.st_mode & S_IWOTH ? 2 << 0 : 0) + + (stats.st_mode & S_IXOTH ? 1 << 0 : 0)); + + if (euid == stats.st_uid) + granted >>= 6; + else if (egid == stats.st_gid || group_member (stats.st_gid)) + granted >>= 3; + + if ((mode & ~granted) == 0) + return 0; + __set_errno (EACCESS); + return -1; + +# endif +#endif +} +#undef euidaccess +#ifdef weak_alias +weak_alias (__euidaccess, euidaccess) +#endif + +#ifdef TEST +# include +# include +# include + +char *program_name; + +int +main (int argc, char **argv) +{ + char *file; + int mode; + int err; + + program_name = argv[0]; + if (argc < 3) + abort (); + file = argv[1]; + mode = atoi (argv[2]); + + err = euidaccess (file, mode); + printf ("%d\n", err); + if (err != 0) + error (0, errno, "%s", file); + exit (0); +} +#endif diff --git a/lib/faccessat.c b/lib/faccessat.c new file mode 100644 index 00000000000..d11a3efaad6 --- /dev/null +++ b/lib/faccessat.c @@ -0,0 +1,45 @@ +/* Check the access rights of a file relative to an open directory. + Copyright (C) 2009-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* written by Eric Blake */ + +#include + +#include +#include + +#ifndef HAVE_ACCESS +/* Mingw lacks access, but it also lacks real vs. effective ids, so + the gnulib euidaccess module is good enough. */ +# undef access +# define access euidaccess +#endif + +/* Invoke access or euidaccess on file, FILE, using mode MODE, in the directory + open on descriptor FD. If possible, do it without changing the + working directory. Otherwise, resort to using save_cwd/fchdir, then + (access|euidaccess)/restore_cwd. If either the save_cwd or the + restore_cwd fails, then give a diagnostic and exit nonzero. + Note that this implementation only supports AT_EACCESS, although some + native versions also support AT_SYMLINK_NOFOLLOW. */ + +#define AT_FUNC_NAME faccessat +#define AT_FUNC_F1 euidaccess +#define AT_FUNC_F2 access +#define AT_FUNC_USE_F1_COND AT_EACCESS +#define AT_FUNC_POST_FILE_PARAM_DECLS , int mode, int flag +#define AT_FUNC_POST_FILE_ARGS , mode +#include "at-func.c" diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h new file mode 100644 index 00000000000..5fdac2313d0 --- /dev/null +++ b/lib/fcntl.in.h @@ -0,0 +1,347 @@ +/* Like , but with non-working flags defined to 0. + + Copyright (C) 2006-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* written by Paul Eggert */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if defined __need_system_fcntl_h +/* Special invocation convention. */ + +/* Needed before . + May also define off_t to a 64-bit type on native Windows. */ +#include +/* On some systems other than glibc, is a prerequisite of + . On glibc systems, we would like to avoid namespace pollution. + But on glibc systems, includes inside an + extern "C" { ... } block, which leads to errors in C++ mode with the + overridden from gnulib. These errors are known to be gone + with g++ version >= 4.3. */ +#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) +# include +#endif +#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _@GUARD_PREFIX@_FCNTL_H + +/* Needed before . + May also define off_t to a 64-bit type on native Windows. */ +#include +/* On some systems other than glibc, is a prerequisite of + . On glibc systems, we would like to avoid namespace pollution. + But on glibc systems, includes inside an + extern "C" { ... } block, which leads to errors in C++ mode with the + overridden from gnulib. These errors are known to be gone + with g++ version >= 4.3. */ +#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) +# include +#endif +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ + +#ifndef _@GUARD_PREFIX@_FCNTL_H +#define _@GUARD_PREFIX@_FCNTL_H + +#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */ +# include +#endif + +/* Native Windows platforms declare open(), creat() in . */ +#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \ + && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include +#endif + + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Declare overridden functions. */ + +#if @GNULIB_FCNTL@ +# if @REPLACE_FCNTL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fcntl +# define fcntl rpl_fcntl +# endif +_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...)); +_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...)); +# else +# if !@HAVE_FCNTL@ +_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...)); +# endif +_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...)); +# endif +_GL_CXXALIASWARN (fcntl); +#elif defined GNULIB_POSIXCHECK +# undef fcntl +# if HAVE_RAW_DECL_FCNTL +_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - " + "use gnulib module fcntl for portability"); +# endif +#endif + +#if @GNULIB_OPEN@ +# if @REPLACE_OPEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef open +# define open rpl_open +# endif +_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); +# else +_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); +# endif +/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a + default argument. _GL_CXXALIASWARN does not work in this case. */ +# if !defined __hpux +_GL_CXXALIASWARN (open); +# endif +#elif defined GNULIB_POSIXCHECK +# undef open +/* Assume open is always declared. */ +_GL_WARN_ON_USE (open, "open is not always POSIX compliant - " + "use gnulib module open for portability"); +#endif + +#if @GNULIB_OPENAT@ +# if @REPLACE_OPENAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef openat +# define openat rpl_openat +# endif +_GL_FUNCDECL_RPL (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...)); +# else +# if !@HAVE_OPENAT@ +_GL_FUNCDECL_SYS (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (openat, int, + (int fd, char const *file, int flags, /* mode_t mode */ ...)); +# endif +_GL_CXXALIASWARN (openat); +#elif defined GNULIB_POSIXCHECK +# undef openat +# if HAVE_RAW_DECL_OPENAT +_GL_WARN_ON_USE (openat, "openat is not portable - " + "use gnulib module openat for portability"); +# endif +#endif + + +/* Fix up the FD_* macros, only known to be missing on mingw. */ + +#ifndef FD_CLOEXEC +# define FD_CLOEXEC 1 +#endif + +/* Fix up the supported F_* macros. Intentionally leave other F_* + macros undefined. Only known to be missing on mingw. */ + +#ifndef F_DUPFD_CLOEXEC +# define F_DUPFD_CLOEXEC 0x40000000 +/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */ +# define GNULIB_defined_F_DUPFD_CLOEXEC 1 +#else +# define GNULIB_defined_F_DUPFD_CLOEXEC 0 +#endif + +#ifndef F_DUPFD +# define F_DUPFD 1 +#endif + +#ifndef F_GETFD +# define F_GETFD 2 +#endif + +/* Fix up the O_* macros. */ + +#if !defined O_DIRECT && defined O_DIRECTIO +/* Tru64 spells it 'O_DIRECTIO'. */ +# define O_DIRECT O_DIRECTIO +#endif + +#if !defined O_CLOEXEC && defined O_NOINHERIT +/* Mingw spells it 'O_NOINHERIT'. */ +# define O_CLOEXEC O_NOINHERIT +#endif + +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + +#ifndef O_DIRECT +# define O_DIRECT 0 +#endif + +#ifndef O_DIRECTORY +# define O_DIRECTORY 0 +#endif + +#ifndef O_DSYNC +# define O_DSYNC 0 +#endif + +#ifndef O_EXEC +# define O_EXEC O_RDONLY /* This is often close enough in older systems. */ +#endif + +#ifndef O_IGNORE_CTTY +# define O_IGNORE_CTTY 0 +#endif + +#ifndef O_NDELAY +# define O_NDELAY 0 +#endif + +#ifndef O_NOATIME +# define O_NOATIME 0 +#endif + +#ifndef O_NONBLOCK +# define O_NONBLOCK O_NDELAY +#endif + +/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero + value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY + or to 0 as fallback. */ +#if @GNULIB_NONBLOCKING@ +# if O_NONBLOCK +# define GNULIB_defined_O_NONBLOCK 0 +# else +# define GNULIB_defined_O_NONBLOCK 1 +# undef O_NONBLOCK +# define O_NONBLOCK 0x40000000 +# endif +#endif + +#ifndef O_NOCTTY +# define O_NOCTTY 0 +#endif + +#ifndef O_NOFOLLOW +# define O_NOFOLLOW 0 +#endif + +#ifndef O_NOLINK +# define O_NOLINK 0 +#endif + +#ifndef O_NOLINKS +# define O_NOLINKS 0 +#endif + +#ifndef O_NOTRANS +# define O_NOTRANS 0 +#endif + +#ifndef O_RSYNC +# define O_RSYNC 0 +#endif + +#ifndef O_SEARCH +# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */ +#endif + +#ifndef O_SYNC +# define O_SYNC 0 +#endif + +#ifndef O_TTY_INIT +# define O_TTY_INIT 0 +#endif + +#if O_ACCMODE != (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH) +# undef O_ACCMODE +# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH) +#endif + +/* For systems that distinguish between text and binary I/O. + O_BINARY is usually declared in fcntl.h */ +#if !defined O_BINARY && defined _O_BINARY + /* For MSC-compatible compilers. */ +# define O_BINARY _O_BINARY +# define O_TEXT _O_TEXT +#endif + +#if defined __BEOS__ || defined __HAIKU__ + /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */ +# undef O_BINARY +# undef O_TEXT +#endif + +#ifndef O_BINARY +# define O_BINARY 0 +# define O_TEXT 0 +#endif + +/* Fix up the AT_* macros. */ + +/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its + value exceeds INT_MAX, so its use as an int doesn't conform to the + C standard, and GCC and Sun C complain in some cases. If the bug + is present, undef AT_FDCWD here, so it can be redefined below. */ +#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553 +# undef AT_FDCWD +#endif + +/* Use the same bit pattern as Solaris 9, but with the proper + signedness. The bit pattern is important, in case this actually is + Solaris with the above workaround. */ +#ifndef AT_FDCWD +# define AT_FDCWD (-3041965) +#endif + +/* Use the same values as Solaris 9. This shouldn't matter, but + there's no real reason to differ. */ +#ifndef AT_SYMLINK_NOFOLLOW +# define AT_SYMLINK_NOFOLLOW 4096 +#endif + +#ifndef AT_REMOVEDIR +# define AT_REMOVEDIR 1 +#endif + +/* Solaris 9 lacks these two, so just pick unique values. */ +#ifndef AT_SYMLINK_FOLLOW +# define AT_SYMLINK_FOLLOW 2 +#endif + +#ifndef AT_EACCESS +# define AT_EACCESS 4 +#endif + + +#endif /* _@GUARD_PREFIX@_FCNTL_H */ +#endif /* _@GUARD_PREFIX@_FCNTL_H */ +#endif diff --git a/lib/getgroups.c b/lib/getgroups.c new file mode 100644 index 00000000000..f9d36236afe --- /dev/null +++ b/lib/getgroups.c @@ -0,0 +1,116 @@ +/* provide consistent interface to getgroups for systems that don't allow N==0 + + Copyright (C) 1996, 1999, 2003, 2006-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* written by Jim Meyering */ + +#include + +#include + +#include +#include +#include + +#if !HAVE_GETGROUPS + +/* Provide a stub that fails with ENOSYS, since there is no group + information available on mingw. */ +int +getgroups (int n _GL_UNUSED, GETGROUPS_T *groups _GL_UNUSED) +{ + errno = ENOSYS; + return -1; +} + +#else /* HAVE_GETGROUPS */ + +# undef getgroups +# ifndef GETGROUPS_ZERO_BUG +# define GETGROUPS_ZERO_BUG 0 +# endif + +/* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always + fails. On other systems, it returns the number of supplemental + groups for the process. This function handles that special case + and lets the system-provided function handle all others. However, + it can fail with ENOMEM if memory is tight. It is unspecified + whether the effective group id is included in the list. */ + +int +rpl_getgroups (int n, gid_t *group) +{ + int n_groups; + GETGROUPS_T *gbuf; + int saved_errno; + + if (n < 0) + { + errno = EINVAL; + return -1; + } + + if (n != 0 || !GETGROUPS_ZERO_BUG) + { + int result; + if (sizeof *group == sizeof *gbuf) + return getgroups (n, (GETGROUPS_T *) group); + + if (SIZE_MAX / sizeof *gbuf <= n) + { + errno = ENOMEM; + return -1; + } + gbuf = malloc (n * sizeof *gbuf); + if (!gbuf) + return -1; + result = getgroups (n, gbuf); + if (0 <= result) + { + n = result; + while (n--) + group[n] = gbuf[n]; + } + saved_errno = errno; + free (gbuf); + errno == saved_errno; + return result; + } + + n = 20; + while (1) + { + /* No need to worry about address arithmetic overflow here, + since the ancient systems that we're running on have low + limits on the number of secondary groups. */ + gbuf = malloc (n * sizeof *gbuf); + if (!gbuf) + return -1; + n_groups = getgroups (n, gbuf); + if (n_groups == -1 ? errno != EINVAL : n_groups < n) + break; + free (gbuf); + n *= 2; + } + + saved_errno = errno; + free (gbuf); + errno = saved_errno; + + return n_groups; +} + +#endif /* HAVE_GETGROUPS */ diff --git a/lib/group-member.c b/lib/group-member.c new file mode 100644 index 00000000000..5fcc7e01d0c --- /dev/null +++ b/lib/group-member.c @@ -0,0 +1,119 @@ +/* group-member.c -- determine whether group id is in calling user's group list + + Copyright (C) 1994, 1997-1998, 2003, 2005-2006, 2009-2012 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include +#include + +#include "xalloc-oversized.h" + +/* Most processes have no more than this many groups, and for these + processes we can avoid using malloc. */ +enum { GROUPBUF_SIZE = 100 }; + +struct group_info + { + gid_t *group; + gid_t groupbuf[GROUPBUF_SIZE]; + }; + +static void +free_group_info (struct group_info const *g) +{ + if (g->group != g->groupbuf) + free (g->group); +} + +static int +get_group_info (struct group_info *gi) +{ + int n_groups = getgroups (GROUPBUF_SIZE, gi->groupbuf); + gi->group = gi->groupbuf; + + if (n_groups < 0) + { + int n_group_slots = getgroups (0, NULL); + if (0 <= n_group_slots + && ! xalloc_oversized (n_group_slots, sizeof *gi->group)) + { + gi->group = malloc (n_group_slots * sizeof *gi->group); + if (gi->group) + n_groups = getgroups (n_group_slots, gi->group); + } + } + + /* In case of error, the user loses. */ + return n_groups; +} + +/* Return non-zero if GID is one that we have in our groups list. + Note that the groups list is not guaranteed to contain the current + or effective group ID, so they should generally be checked + separately. */ + +int +group_member (gid_t gid) +{ + int i; + int found; + struct group_info gi; + int n_groups = get_group_info (&gi); + + /* Search through the list looking for GID. */ + found = 0; + for (i = 0; i < n_groups; i++) + { + if (gid == gi.group[i]) + { + found = 1; + break; + } + } + + free_group_info (&gi); + + return found; +} + +#ifdef TEST + +char *program_name; + +int +main (int argc, char **argv) +{ + int i; + + program_name = argv[0]; + + for (i = 1; i < argc; i++) + { + gid_t gid; + + gid = atoi (argv[i]); + printf ("%d: %s\n", gid, group_member (gid) ? "yes" : "no"); + } + exit (0); +} + +#endif /* TEST */ diff --git a/lib/root-uid.h b/lib/root-uid.h new file mode 100644 index 00000000000..2379773c291 --- /dev/null +++ b/lib/root-uid.h @@ -0,0 +1,30 @@ +/* The user ID that always has appropriate privileges in the POSIX sense. + + Copyright 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Written by Paul Eggert. */ + +#ifndef ROOT_UID_H_ +#define ROOT_UID_H_ + +/* The user ID that always has appropriate privileges in the POSIX sense. */ +#ifdef __TANDEM +# define ROOT_UID 65535 +#else +# define ROOT_UID 0 +#endif + +#endif diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h new file mode 100644 index 00000000000..ad777d8dd79 --- /dev/null +++ b/lib/xalloc-oversized.h @@ -0,0 +1,38 @@ +/* xalloc-oversized.h -- memory allocation size checking + + Copyright (C) 1990-2000, 2003-2004, 2006-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef XALLOC_OVERSIZED_H_ +# define XALLOC_OVERSIZED_H_ + +# include + +/* Return 1 if an array of N objects, each of size S, cannot exist due + to size arithmetic overflow. S must be positive and N must be + nonnegative. This is a macro, not a function, so that it + works correctly even when SIZE_MAX < N. + + By gnulib convention, SIZE_MAX represents overflow in size + calculations, so the conservative dividend to use here is + SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. + However, malloc (SIZE_MAX) fails on all known hosts where + sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for + exactly-SIZE_MAX allocations on such hosts; this avoids a test and + branch when S is known to be 1. */ +# define xalloc_oversized(n, s) \ + ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) + +#endif /* !XALLOC_OVERSIZED_H_ */ diff --git a/m4/euidaccess.m4 b/m4/euidaccess.m4 new file mode 100644 index 00000000000..2de95b88ba8 --- /dev/null +++ b/m4/euidaccess.m4 @@ -0,0 +1,52 @@ +# euidaccess.m4 serial 15 +dnl Copyright (C) 2002-2012 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_NONREENTRANT_EUIDACCESS], +[ + AC_REQUIRE([gl_FUNC_EUIDACCESS]) + AC_CHECK_DECLS([setregid]) + AC_DEFINE([PREFER_NONREENTRANT_EUIDACCESS], [1], + [Define this if you prefer euidaccess to return the correct result + even if this would make it nonreentrant. Define this only if your + entire application is safe even if the uid or gid might temporarily + change. If your application uses signal handlers or threads it + is probably not safe.]) +]) + +AC_DEFUN([gl_FUNC_EUIDACCESS], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc to declare euidaccess(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS([euidaccess]) + if test $ac_cv_func_euidaccess = no; then + HAVE_EUIDACCESS=0 + fi +]) + +# Prerequisites of lib/euidaccess.c. +AC_DEFUN([gl_PREREQ_EUIDACCESS], [ + dnl Prefer POSIX faccessat over non-standard euidaccess. + AC_CHECK_FUNCS_ONCE([faccessat]) + dnl Try various other non-standard fallbacks. + AC_CHECK_HEADERS([libgen.h]) + AC_FUNC_GETGROUPS + + # Solaris 9 and 10 need -lgen to get the eaccess function. + # Save and restore LIBS so -lgen isn't added to it. Otherwise, *all* + # programs in the package would end up linked with that potentially-shared + # library, inducing unnecessary run-time overhead. + LIB_EACCESS= + AC_SUBST([LIB_EACCESS]) + gl_saved_libs=$LIBS + AC_SEARCH_LIBS([eaccess], [gen], + [test "$ac_cv_search_eaccess" = "none required" || + LIB_EACCESS=$ac_cv_search_eaccess]) + AC_CHECK_FUNCS([eaccess]) + LIBS=$gl_saved_libs +]) diff --git a/m4/faccessat.m4 b/m4/faccessat.m4 new file mode 100644 index 00000000000..82f3b1f8dde --- /dev/null +++ b/m4/faccessat.m4 @@ -0,0 +1,28 @@ +# serial 6 +# See if we need to provide faccessat replacement. + +dnl Copyright (C) 2009-2012 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Written by Eric Blake. + +AC_DEFUN([gl_FUNC_FACCESSAT], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc to declare faccessat(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS_ONCE([faccessat]) + if test $ac_cv_func_faccessat = no; then + HAVE_FACCESSAT=0 + fi +]) + +# Prerequisites of lib/faccessat.m4. +AC_DEFUN([gl_PREREQ_FACCESSAT], +[ + AC_CHECK_FUNCS([access]) +]) diff --git a/m4/fcntl_h.m4 b/m4/fcntl_h.m4 new file mode 100644 index 00000000000..cac28aeb283 --- /dev/null +++ b/m4/fcntl_h.m4 @@ -0,0 +1,50 @@ +# serial 15 +# Configure fcntl.h. +dnl Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +AC_DEFUN([gl_FCNTL_H], +[ + AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) + AC_REQUIRE([gl_FCNTL_O_FLAGS]) + gl_NEXT_HEADERS([fcntl.h]) + + dnl Ensure the type pid_t gets defined. + AC_REQUIRE([AC_TYPE_PID_T]) + + dnl Ensure the type mode_t gets defined. + AC_REQUIRE([AC_TYPE_MODE_T]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use, if it is not common + dnl enough to be declared everywhere. + gl_WARN_ON_USE_PREPARE([[#include + ]], [fcntl openat]) +]) + +AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_FCNTL_H_DEFAULTS], +[ + GNULIB_FCNTL=0; AC_SUBST([GNULIB_FCNTL]) + GNULIB_NONBLOCKING=0; AC_SUBST([GNULIB_NONBLOCKING]) + GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) + GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_FCNTL=1; AC_SUBST([HAVE_FCNTL]) + HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT]) + REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL]) + REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) + REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT]) +]) diff --git a/m4/getgroups.m4 b/m4/getgroups.m4 new file mode 100644 index 00000000000..17473af486b --- /dev/null +++ b/m4/getgroups.m4 @@ -0,0 +1,107 @@ +# serial 18 + +dnl From Jim Meyering. +dnl A wrapper around AC_FUNC_GETGROUPS. + +# Copyright (C) 1996-1997, 1999-2004, 2008-2012 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +m4_version_prereq([2.70], [] ,[ + +# This is taken from the following Autoconf patch: +# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9 +AC_DEFUN([AC_FUNC_GETGROUPS], +[ + AC_REQUIRE([AC_TYPE_GETGROUPS])dnl + AC_REQUIRE([AC_TYPE_SIZE_T])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles + AC_CHECK_FUNC([getgroups]) + + # If we don't yet have getgroups, see if it's in -lbsd. + # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1. + ac_save_LIBS=$LIBS + if test $ac_cv_func_getgroups = no; then + AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd]) + fi + + # Run the program to test the functionality of the system-supplied + # getgroups function only if there is such a function. + if test $ac_cv_func_getgroups = yes; then + AC_CACHE_CHECK([for working getgroups], [ac_cv_func_getgroups_works], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [AC_INCLUDES_DEFAULT], + [[/* On Ultrix 4.3, getgroups (0, 0) always fails. */ + return getgroups (0, 0) == -1;]]) + ], + [ac_cv_func_getgroups_works=yes], + [ac_cv_func_getgroups_works=no], + [case "$host_os" in # (( + # Guess yes on glibc systems. + *-gnu*) ac_cv_func_getgroups_works="guessing yes" ;; + # If we don't know, assume the worst. + *) ac_cv_func_getgroups_works="guessing no" ;; + esac + ]) + ]) + else + ac_cv_func_getgroups_works=no + fi + case "$ac_cv_func_getgroups_works" in + *yes) + AC_DEFINE([HAVE_GETGROUPS], [1], + [Define to 1 if your system has a working `getgroups' function.]) + ;; + esac + LIBS=$ac_save_LIBS +])# AC_FUNC_GETGROUPS + +]) + +AC_DEFUN([gl_FUNC_GETGROUPS], +[ + AC_REQUIRE([AC_TYPE_GETGROUPS]) + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + + AC_FUNC_GETGROUPS + if test $ac_cv_func_getgroups != yes; then + HAVE_GETGROUPS=0 + else + if test "$ac_cv_type_getgroups" != gid_t \ + || { case "$ac_cv_func_getgroups_works" in + *yes) false;; + *) true;; + esac + }; then + REPLACE_GETGROUPS=1 + AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if + getgroups(0,NULL) does not return the number of groups.]) + else + dnl Detect FreeBSD bug; POSIX requires getgroups(-1,ptr) to fail. + AC_CACHE_CHECK([whether getgroups handles negative values], + [gl_cv_func_getgroups_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], + [[int size = getgroups (0, 0); + gid_t *list = malloc (size * sizeof *list); + return getgroups (-1, list) != -1;]])], + [gl_cv_func_getgroups_works=yes], + [gl_cv_func_getgroups_works=no], + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_getgroups_works="guessing yes" ;; + # If we don't know, assume the worst. + *) gl_cv_func_getgroups_works="guessing no" ;; + esac + ])]) + case "$gl_cv_func_getgroups_works" in + *yes) ;; + *) REPLACE_GETGROUPS=1 ;; + esac + fi + fi + test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS" +]) diff --git a/m4/group-member.m4 b/m4/group-member.m4 new file mode 100644 index 00000000000..c393b5b1303 --- /dev/null +++ b/m4/group-member.m4 @@ -0,0 +1,29 @@ +# serial 14 + +# Copyright (C) 1999-2001, 2003-2007, 2009-2012 Free Software Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +dnl Written by Jim Meyering + +AC_DEFUN([gl_FUNC_GROUP_MEMBER], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc to declare group_member(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + dnl Do this replacement check manually because I want the hyphen + dnl (not the underscore) in the filename. + AC_CHECK_FUNC([group_member], , [ + HAVE_GROUP_MEMBER=0 + ]) +]) + +# Prerequisites of lib/group-member.c. +AC_DEFUN([gl_PREREQ_GROUP_MEMBER], +[ + AC_REQUIRE([AC_FUNC_GETGROUPS]) +]) From 8e8083185c417eedbaadf0b33c7089da72fe2250 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 19 Oct 2012 14:59:36 -0400 Subject: [PATCH 12/18] * lisp/minibuffer.el (minibuffer-force-complete): Make the next completion use the same completion-field (bug@12221). --- lisp/ChangeLog | 5 +++++ lisp/minibuffer.el | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f9d9ad4b03d..096e9a52916 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-10-19 Stefan Monnier + + * minibuffer.el (minibuffer-force-complete): Make the next completion use + the same completion-field (bug@12221). + 2012-10-19 Martin Rudalics * emacs-lisp/debug.el (debug): Record height of debugger window diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f464b42182d..f865a0269d4 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1134,7 +1134,23 @@ Repeated uses step through the possible completions." ;; through the previous possible completions. (let ((last (last all))) (setcdr last (cons (car all) (cdr last))) - (completion--cache-all-sorted-completions (cdr all))))))) + (completion--cache-all-sorted-completions (cdr all))) + ;; Make sure repeated uses cycle, even though completion--done might + ;; have added a space or something that moved us outside of the field. + ;; (bug#12221). + (let* ((table minibuffer-completion-table) + (pred minibuffer-completion-predicate) + (extra-prop completion-extra-properties) + (cmd + (lambda () "Cycle through the possible completions." + (interactive) + (let ((completion-extra-properties extra-prop)) + (completion-in-region start (point) table pred))))) + (set-temporary-overlay-map + (let ((map (make-sparse-keymap))) + (define-key map [remap completion-at-point] cmd) + (define-key map (vector last-command-event) cmd) + map))))))) (defvar minibuffer-confirm-exit-commands '(completion-at-point minibuffer-complete @@ -1557,7 +1573,6 @@ variables.") (let* ((exit-fun (plist-get completion-extra-properties :exit-function)) (pre-msg (and exit-fun (current-message)))) (cl-assert (memq finished '(exact sole finished unknown))) - ;; FIXME: exit-fun should receive `finished' as a parameter. (when exit-fun (when (eq finished 'unknown) (setq finished From f0a801750151bee7fdcf96dff272986e627fb3e3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 Oct 2012 12:25:18 -0700 Subject: [PATCH 13/18] Undo faccessat change. --- ChangeLog | 13 -- admin/ChangeLog | 8 - admin/merge-gnulib | 13 +- configure.ac | 4 +- lib/at-func.c | 146 ----------------- lib/euidaccess.c | 221 -------------------------- lib/faccessat.c | 45 ------ lib/fcntl.in.h | 347 ----------------------------------------- lib/getgroups.c | 116 -------------- lib/gnulib.mk | 97 +----------- lib/group-member.c | 119 -------------- lib/root-uid.h | 30 ---- lib/xalloc-oversized.h | 38 ----- m4/euidaccess.m4 | 52 ------ m4/faccessat.m4 | 28 ---- m4/fcntl_h.m4 | 50 ------ m4/getgroups.m4 | 107 ------------- m4/gnulib-comp.m4 | 105 ------------- m4/group-member.m4 | 29 ---- nt/ChangeLog | 7 - nt/inc/ms-w32.h | 7 +- src/ChangeLog | 29 ---- src/Makefile.in | 3 +- src/callproc.c | 4 +- src/charset.c | 3 +- src/conf_post.h | 4 - src/fileio.c | 97 +++++++++--- src/lisp.h | 1 - src/lread.c | 56 ++++--- src/process.c | 36 ++--- src/sysdep.c | 6 +- src/term.c | 4 +- src/w32.c | 18 +-- src/xrdb.c | 8 +- 34 files changed, 146 insertions(+), 1705 deletions(-) delete mode 100644 lib/at-func.c delete mode 100644 lib/euidaccess.c delete mode 100644 lib/faccessat.c delete mode 100644 lib/fcntl.in.h delete mode 100644 lib/getgroups.c delete mode 100644 lib/group-member.c delete mode 100644 lib/root-uid.h delete mode 100644 lib/xalloc-oversized.h delete mode 100644 m4/euidaccess.m4 delete mode 100644 m4/faccessat.m4 delete mode 100644 m4/fcntl_h.m4 delete mode 100644 m4/getgroups.m4 delete mode 100644 m4/group-member.m4 diff --git a/ChangeLog b/ChangeLog index c7fcd319af2..81eddade0a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,16 +1,3 @@ -2012-10-19 Paul Eggert - - Use faccessat, not access, when checking file permissions (Bug#12632). - * .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. - 2012-10-18 Stefan Monnier * Makefile.in ($(MAKEFILE_NAME)): Depend on src/lisp.mk as well. diff --git a/admin/ChangeLog b/admin/ChangeLog index 6d08bf7c37e..e21293d618d 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog @@ -1,11 +1,3 @@ -2012-10-19 Paul Eggert - - Use faccessat, not access, when checking file permissions (Bug#12632). - * 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. - 2012-10-12 Kenichi Handa * charsets/Makefile (JISC6226.map): Add missing mappings. diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 3c4d8e8058d..7fc0b5f4844 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -28,7 +28,7 @@ GNULIB_URL=git://git.savannah.gnu.org/gnulib.git GNULIB_MODULES=' alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 - dtoastr dtotimespec dup2 environ execinfo faccessat + dtoastr dtotimespec dup2 environ execinfo filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink @@ -39,12 +39,9 @@ GNULIB_MODULES=' ' GNULIB_TOOL_FLAGS=' - --avoid=at-internal - --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat - --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow - --avoid=openat-die --avoid=openat-h - --avoid=raise - --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types + --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat + --avoid=msvc-inval --avoid=msvc-nothrow + --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --conditional-dependencies --import --no-changelog --no-vc-files --makefile-name=gnulib.mk @@ -88,7 +85,7 @@ test -x "$gnulib_srcdir"/gnulib-tool || { } "$gnulib_srcdir"/gnulib-tool --dir="$src" $GNULIB_TOOL_FLAGS $GNULIB_MODULES && -rm -- "$src"m4/fcntl-o.m4 "$src"m4/gnulib-cache.m4 "$src"m4/warn-on-use.m4 && +rm -- "$src"m4/gnulib-cache.m4 "$src"m4/warn-on-use.m4 && cp -- "$gnulib_srcdir"/build-aux/texinfo.tex "$src"doc/misc && cp -- "$gnulib_srcdir"/build-aux/move-if-change "$src"build-aux && autoreconf -i -I m4 -- ${src:+"$src"} diff --git a/configure.ac b/configure.ac index 6b4c757ced5..5520dd6a903 100644 --- a/configure.ac +++ b/configure.ac @@ -572,8 +572,6 @@ else test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS" fi -# Avoid gnulib's tests for O_NOATIME and O_NOFOLLOW, as we don't use them. -AC_DEFUN([gl_FCNTL_O_FLAGS]) # Avoid gnulib's threadlib module, as we do threads our own way. AC_DEFUN([gl_THREADLIB]) @@ -2874,7 +2872,7 @@ AC_SUBST(BLESSMAIL_TARGET) AC_CHECK_FUNCS(gethostname \ closedir getrusage get_current_dir_name \ lrand48 setsid \ -fpathconf select getpagesize setlocale \ +fpathconf select euidaccess getpagesize setlocale \ utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \ __fpending strsignal setitimer \ sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ diff --git a/lib/at-func.c b/lib/at-func.c deleted file mode 100644 index 481eea475a1..00000000000 --- a/lib/at-func.c +++ /dev/null @@ -1,146 +0,0 @@ -/* Define at-style functions like fstatat, unlinkat, fchownat, etc. - Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* written by Jim Meyering */ - -#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ - -#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD -# include -# ifndef ENOTSUP -# define ENOTSUP EINVAL -# endif -#else -# include "openat.h" -# include "openat-priv.h" -# include "save-cwd.h" -#endif - -#ifdef AT_FUNC_USE_F1_COND -# define CALL_FUNC(F) \ - (flag == AT_FUNC_USE_F1_COND \ - ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \ - : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS)) -# define VALIDATE_FLAG(F) \ - if (flag & ~AT_FUNC_USE_F1_COND) \ - { \ - errno = EINVAL; \ - return FUNC_FAIL; \ - } -#else -# define CALL_FUNC(F) (AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS)) -# define VALIDATE_FLAG(F) /* empty */ -#endif - -#ifdef AT_FUNC_RESULT -# define FUNC_RESULT AT_FUNC_RESULT -#else -# define FUNC_RESULT int -#endif - -#ifdef AT_FUNC_FAIL -# define FUNC_FAIL AT_FUNC_FAIL -#else -# define FUNC_FAIL -1 -#endif - -/* Call AT_FUNC_F1 to operate on FILE, which is in the directory - open on descriptor FD. If AT_FUNC_USE_F1_COND is defined to a value, - AT_FUNC_POST_FILE_PARAM_DECLS must include a parameter named flag; - call AT_FUNC_F2 if FLAG is 0 or fail if FLAG contains more bits than - AT_FUNC_USE_F1_COND. Return int and fail with -1 unless AT_FUNC_RESULT - or AT_FUNC_FAIL are defined. If possible, do it without changing the - working directory. Otherwise, resort to using save_cwd/fchdir, - then AT_FUNC_F?/restore_cwd. If either the save_cwd or the restore_cwd - fails, then give a diagnostic and exit nonzero. */ -FUNC_RESULT -AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) -{ - VALIDATE_FLAG (flag); - - if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file)) - return CALL_FUNC (file); - -#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD - errno = ENOTSUP; - return FUNC_FAIL; -#else - { - /* Be careful to choose names unlikely to conflict with - AT_FUNC_POST_FILE_PARAM_DECLS. */ - struct saved_cwd saved_cwd; - int saved_errno; - FUNC_RESULT err; - - { - char proc_buf[OPENAT_BUFFER_SIZE]; - char *proc_file = openat_proc_name (proc_buf, fd, file); - if (proc_file) - { - FUNC_RESULT proc_result = CALL_FUNC (proc_file); - int proc_errno = errno; - if (proc_file != proc_buf) - free (proc_file); - /* If the syscall succeeds, or if it fails with an unexpected - errno value, then return right away. Otherwise, fall through - and resort to using save_cwd/restore_cwd. */ - if (FUNC_FAIL != proc_result) - return proc_result; - if (! EXPECTED_ERRNO (proc_errno)) - { - errno = proc_errno; - return proc_result; - } - } - } - - if (save_cwd (&saved_cwd) != 0) - openat_save_fail (errno); - if (0 <= fd && fd == saved_cwd.desc) - { - /* If saving the working directory collides with the user's - requested fd, then the user's fd must have been closed to - begin with. */ - free_cwd (&saved_cwd); - errno = EBADF; - return FUNC_FAIL; - } - - if (fchdir (fd) != 0) - { - saved_errno = errno; - free_cwd (&saved_cwd); - errno = saved_errno; - return FUNC_FAIL; - } - - err = CALL_FUNC (file); - saved_errno = (err == FUNC_FAIL ? errno : 0); - - if (restore_cwd (&saved_cwd) != 0) - openat_restore_fail (errno); - - free_cwd (&saved_cwd); - - if (saved_errno) - errno = saved_errno; - return err; - } -#endif -} -#undef CALL_FUNC -#undef FUNC_RESULT -#undef FUNC_FAIL diff --git a/lib/euidaccess.c b/lib/euidaccess.c deleted file mode 100644 index ca2ceca5d22..00000000000 --- a/lib/euidaccess.c +++ /dev/null @@ -1,221 +0,0 @@ -/* euidaccess -- check if effective user id can access file - - Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2012 Free - Software Foundation, Inc. - - This file is part of the GNU C Library. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* Written by David MacKenzie and Torbjorn Granlund. - Adapted for GNU C library by Roland McGrath. */ - -#ifndef _LIBC -# include -#endif - -#include -#include -#include -#include - -#include "root-uid.h" - -#if HAVE_LIBGEN_H -# include -#endif - -#include -#ifndef __set_errno -# define __set_errno(val) errno = (val) -#endif - -#if defined EACCES && !defined EACCESS -# define EACCESS EACCES -#endif - -#ifndef F_OK -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 -#endif - - -#ifdef _LIBC - -# define access __access -# define getuid __getuid -# define getgid __getgid -# define geteuid __geteuid -# define getegid __getegid -# define group_member __group_member -# define euidaccess __euidaccess -# undef stat -# define stat stat64 - -#endif - -/* Return 0 if the user has permission of type MODE on FILE; - otherwise, return -1 and set 'errno'. - Like access, except that it uses the effective user and group - id's instead of the real ones, and it does not always check for read-only - file system, text busy, etc. */ - -int -euidaccess (const char *file, int mode) -{ -#if HAVE_FACCESSAT /* glibc, AIX 7, Solaris 11, Cygwin 1.7 */ - return faccessat (AT_FDCWD, file, mode, AT_EACCESS); -#elif defined EFF_ONLY_OK /* IRIX, OSF/1, Interix */ - return access (file, mode | EFF_ONLY_OK); -#elif defined ACC_SELF /* AIX */ - return accessx (file, mode, ACC_SELF); -#elif HAVE_EACCESS /* FreeBSD */ - return eaccess (file, mode); -#else /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */ - - uid_t uid = getuid (); - gid_t gid = getgid (); - uid_t euid = geteuid (); - gid_t egid = getegid (); - struct stat stats; - -# if HAVE_DECL_SETREGID && PREFER_NONREENTRANT_EUIDACCESS - - /* Define PREFER_NONREENTRANT_EUIDACCESS if you prefer euidaccess to - return the correct result even if this would make it - nonreentrant. Define this only if your entire application is - safe even if the uid or gid might temporarily change. If your - application uses signal handlers or threads it is probably not - safe. */ - - if (mode == F_OK) - return stat (file, &stats); - else - { - int result; - int saved_errno; - - if (uid != euid) - setreuid (euid, uid); - if (gid != egid) - setregid (egid, gid); - - result = access (file, mode); - saved_errno = errno; - - /* Restore them. */ - if (uid != euid) - setreuid (uid, euid); - if (gid != egid) - setregid (gid, egid); - - errno = saved_errno; - return result; - } - -# else - - /* The following code assumes the traditional Unix model, and is not - correct on systems that have ACLs or the like. However, it's - better than nothing, and it is reentrant. */ - - unsigned int granted; - if (uid == euid && gid == egid) - /* If we are not set-uid or set-gid, access does the same. */ - return access (file, mode); - - if (stat (file, &stats) != 0) - return -1; - - /* The super-user can read and write any file, and execute any file - that anyone can execute. */ - if (euid == ROOT_UID - && ((mode & X_OK) == 0 - || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))) - return 0; - - /* Convert the mode to traditional form, clearing any bogus bits. */ - if (R_OK == 4 && W_OK == 2 && X_OK == 1 && F_OK == 0) - mode &= 7; - else - mode = ((mode & R_OK ? 4 : 0) - + (mode & W_OK ? 2 : 0) - + (mode & X_OK ? 1 : 0)); - - if (mode == 0) - return 0; /* The file exists. */ - - /* Convert the file's permission bits to traditional form. */ - if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6) - && S_IRGRP == (4 << 3) && S_IWGRP == (2 << 3) && S_IXGRP == (1 << 3) - && S_IROTH == (4 << 0) && S_IWOTH == (2 << 0) && S_IXOTH == (1 << 0)) - granted = stats.st_mode; - else - granted = ((stats.st_mode & S_IRUSR ? 4 << 6 : 0) - + (stats.st_mode & S_IWUSR ? 2 << 6 : 0) - + (stats.st_mode & S_IXUSR ? 1 << 6 : 0) - + (stats.st_mode & S_IRGRP ? 4 << 3 : 0) - + (stats.st_mode & S_IWGRP ? 2 << 3 : 0) - + (stats.st_mode & S_IXGRP ? 1 << 3 : 0) - + (stats.st_mode & S_IROTH ? 4 << 0 : 0) - + (stats.st_mode & S_IWOTH ? 2 << 0 : 0) - + (stats.st_mode & S_IXOTH ? 1 << 0 : 0)); - - if (euid == stats.st_uid) - granted >>= 6; - else if (egid == stats.st_gid || group_member (stats.st_gid)) - granted >>= 3; - - if ((mode & ~granted) == 0) - return 0; - __set_errno (EACCESS); - return -1; - -# endif -#endif -} -#undef euidaccess -#ifdef weak_alias -weak_alias (__euidaccess, euidaccess) -#endif - -#ifdef TEST -# include -# include -# include - -char *program_name; - -int -main (int argc, char **argv) -{ - char *file; - int mode; - int err; - - program_name = argv[0]; - if (argc < 3) - abort (); - file = argv[1]; - mode = atoi (argv[2]); - - err = euidaccess (file, mode); - printf ("%d\n", err); - if (err != 0) - error (0, errno, "%s", file); - exit (0); -} -#endif diff --git a/lib/faccessat.c b/lib/faccessat.c deleted file mode 100644 index d11a3efaad6..00000000000 --- a/lib/faccessat.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Check the access rights of a file relative to an open directory. - Copyright (C) 2009-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* written by Eric Blake */ - -#include - -#include -#include - -#ifndef HAVE_ACCESS -/* Mingw lacks access, but it also lacks real vs. effective ids, so - the gnulib euidaccess module is good enough. */ -# undef access -# define access euidaccess -#endif - -/* Invoke access or euidaccess on file, FILE, using mode MODE, in the directory - open on descriptor FD. If possible, do it without changing the - working directory. Otherwise, resort to using save_cwd/fchdir, then - (access|euidaccess)/restore_cwd. If either the save_cwd or the - restore_cwd fails, then give a diagnostic and exit nonzero. - Note that this implementation only supports AT_EACCESS, although some - native versions also support AT_SYMLINK_NOFOLLOW. */ - -#define AT_FUNC_NAME faccessat -#define AT_FUNC_F1 euidaccess -#define AT_FUNC_F2 access -#define AT_FUNC_USE_F1_COND AT_EACCESS -#define AT_FUNC_POST_FILE_PARAM_DECLS , int mode, int flag -#define AT_FUNC_POST_FILE_ARGS , mode -#include "at-func.c" diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h deleted file mode 100644 index 5fdac2313d0..00000000000 --- a/lib/fcntl.in.h +++ /dev/null @@ -1,347 +0,0 @@ -/* Like , but with non-working flags defined to 0. - - Copyright (C) 2006-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* written by Paul Eggert */ - -#if __GNUC__ >= 3 -@PRAGMA_SYSTEM_HEADER@ -#endif -@PRAGMA_COLUMNS@ - -#if defined __need_system_fcntl_h -/* Special invocation convention. */ - -/* Needed before . - May also define off_t to a 64-bit type on native Windows. */ -#include -/* On some systems other than glibc, is a prerequisite of - . On glibc systems, we would like to avoid namespace pollution. - But on glibc systems, includes inside an - extern "C" { ... } block, which leads to errors in C++ mode with the - overridden from gnulib. These errors are known to be gone - with g++ version >= 4.3. */ -#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) -# include -#endif -#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ - -#else -/* Normal invocation convention. */ - -#ifndef _@GUARD_PREFIX@_FCNTL_H - -/* Needed before . - May also define off_t to a 64-bit type on native Windows. */ -#include -/* On some systems other than glibc, is a prerequisite of - . On glibc systems, we would like to avoid namespace pollution. - But on glibc systems, includes inside an - extern "C" { ... } block, which leads to errors in C++ mode with the - overridden from gnulib. These errors are known to be gone - with g++ version >= 4.3. */ -#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) -# include -#endif -/* The include_next requires a split double-inclusion guard. */ -#@INCLUDE_NEXT@ @NEXT_FCNTL_H@ - -#ifndef _@GUARD_PREFIX@_FCNTL_H -#define _@GUARD_PREFIX@_FCNTL_H - -#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */ -# include -#endif - -/* Native Windows platforms declare open(), creat() in . */ -#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \ - && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) -# include -#endif - - -/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ - -/* The definition of _GL_ARG_NONNULL is copied here. */ - -/* The definition of _GL_WARN_ON_USE is copied here. */ - - -/* Declare overridden functions. */ - -#if @GNULIB_FCNTL@ -# if @REPLACE_FCNTL@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef fcntl -# define fcntl rpl_fcntl -# endif -_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...)); -_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...)); -# else -# if !@HAVE_FCNTL@ -_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...)); -# endif -_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...)); -# endif -_GL_CXXALIASWARN (fcntl); -#elif defined GNULIB_POSIXCHECK -# undef fcntl -# if HAVE_RAW_DECL_FCNTL -_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - " - "use gnulib module fcntl for portability"); -# endif -#endif - -#if @GNULIB_OPEN@ -# if @REPLACE_OPEN@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef open -# define open rpl_open -# endif -_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) - _GL_ARG_NONNULL ((1))); -_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); -# else -_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); -# endif -/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a - default argument. _GL_CXXALIASWARN does not work in this case. */ -# if !defined __hpux -_GL_CXXALIASWARN (open); -# endif -#elif defined GNULIB_POSIXCHECK -# undef open -/* Assume open is always declared. */ -_GL_WARN_ON_USE (open, "open is not always POSIX compliant - " - "use gnulib module open for portability"); -#endif - -#if @GNULIB_OPENAT@ -# if @REPLACE_OPENAT@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef openat -# define openat rpl_openat -# endif -_GL_FUNCDECL_RPL (openat, int, - (int fd, char const *file, int flags, /* mode_t mode */ ...) - _GL_ARG_NONNULL ((2))); -_GL_CXXALIAS_RPL (openat, int, - (int fd, char const *file, int flags, /* mode_t mode */ ...)); -# else -# if !@HAVE_OPENAT@ -_GL_FUNCDECL_SYS (openat, int, - (int fd, char const *file, int flags, /* mode_t mode */ ...) - _GL_ARG_NONNULL ((2))); -# endif -_GL_CXXALIAS_SYS (openat, int, - (int fd, char const *file, int flags, /* mode_t mode */ ...)); -# endif -_GL_CXXALIASWARN (openat); -#elif defined GNULIB_POSIXCHECK -# undef openat -# if HAVE_RAW_DECL_OPENAT -_GL_WARN_ON_USE (openat, "openat is not portable - " - "use gnulib module openat for portability"); -# endif -#endif - - -/* Fix up the FD_* macros, only known to be missing on mingw. */ - -#ifndef FD_CLOEXEC -# define FD_CLOEXEC 1 -#endif - -/* Fix up the supported F_* macros. Intentionally leave other F_* - macros undefined. Only known to be missing on mingw. */ - -#ifndef F_DUPFD_CLOEXEC -# define F_DUPFD_CLOEXEC 0x40000000 -/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */ -# define GNULIB_defined_F_DUPFD_CLOEXEC 1 -#else -# define GNULIB_defined_F_DUPFD_CLOEXEC 0 -#endif - -#ifndef F_DUPFD -# define F_DUPFD 1 -#endif - -#ifndef F_GETFD -# define F_GETFD 2 -#endif - -/* Fix up the O_* macros. */ - -#if !defined O_DIRECT && defined O_DIRECTIO -/* Tru64 spells it 'O_DIRECTIO'. */ -# define O_DIRECT O_DIRECTIO -#endif - -#if !defined O_CLOEXEC && defined O_NOINHERIT -/* Mingw spells it 'O_NOINHERIT'. */ -# define O_CLOEXEC O_NOINHERIT -#endif - -#ifndef O_CLOEXEC -# define O_CLOEXEC 0 -#endif - -#ifndef O_DIRECT -# define O_DIRECT 0 -#endif - -#ifndef O_DIRECTORY -# define O_DIRECTORY 0 -#endif - -#ifndef O_DSYNC -# define O_DSYNC 0 -#endif - -#ifndef O_EXEC -# define O_EXEC O_RDONLY /* This is often close enough in older systems. */ -#endif - -#ifndef O_IGNORE_CTTY -# define O_IGNORE_CTTY 0 -#endif - -#ifndef O_NDELAY -# define O_NDELAY 0 -#endif - -#ifndef O_NOATIME -# define O_NOATIME 0 -#endif - -#ifndef O_NONBLOCK -# define O_NONBLOCK O_NDELAY -#endif - -/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero - value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY - or to 0 as fallback. */ -#if @GNULIB_NONBLOCKING@ -# if O_NONBLOCK -# define GNULIB_defined_O_NONBLOCK 0 -# else -# define GNULIB_defined_O_NONBLOCK 1 -# undef O_NONBLOCK -# define O_NONBLOCK 0x40000000 -# endif -#endif - -#ifndef O_NOCTTY -# define O_NOCTTY 0 -#endif - -#ifndef O_NOFOLLOW -# define O_NOFOLLOW 0 -#endif - -#ifndef O_NOLINK -# define O_NOLINK 0 -#endif - -#ifndef O_NOLINKS -# define O_NOLINKS 0 -#endif - -#ifndef O_NOTRANS -# define O_NOTRANS 0 -#endif - -#ifndef O_RSYNC -# define O_RSYNC 0 -#endif - -#ifndef O_SEARCH -# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */ -#endif - -#ifndef O_SYNC -# define O_SYNC 0 -#endif - -#ifndef O_TTY_INIT -# define O_TTY_INIT 0 -#endif - -#if O_ACCMODE != (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH) -# undef O_ACCMODE -# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH) -#endif - -/* For systems that distinguish between text and binary I/O. - O_BINARY is usually declared in fcntl.h */ -#if !defined O_BINARY && defined _O_BINARY - /* For MSC-compatible compilers. */ -# define O_BINARY _O_BINARY -# define O_TEXT _O_TEXT -#endif - -#if defined __BEOS__ || defined __HAIKU__ - /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */ -# undef O_BINARY -# undef O_TEXT -#endif - -#ifndef O_BINARY -# define O_BINARY 0 -# define O_TEXT 0 -#endif - -/* Fix up the AT_* macros. */ - -/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its - value exceeds INT_MAX, so its use as an int doesn't conform to the - C standard, and GCC and Sun C complain in some cases. If the bug - is present, undef AT_FDCWD here, so it can be redefined below. */ -#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553 -# undef AT_FDCWD -#endif - -/* Use the same bit pattern as Solaris 9, but with the proper - signedness. The bit pattern is important, in case this actually is - Solaris with the above workaround. */ -#ifndef AT_FDCWD -# define AT_FDCWD (-3041965) -#endif - -/* Use the same values as Solaris 9. This shouldn't matter, but - there's no real reason to differ. */ -#ifndef AT_SYMLINK_NOFOLLOW -# define AT_SYMLINK_NOFOLLOW 4096 -#endif - -#ifndef AT_REMOVEDIR -# define AT_REMOVEDIR 1 -#endif - -/* Solaris 9 lacks these two, so just pick unique values. */ -#ifndef AT_SYMLINK_FOLLOW -# define AT_SYMLINK_FOLLOW 2 -#endif - -#ifndef AT_EACCESS -# define AT_EACCESS 4 -#endif - - -#endif /* _@GUARD_PREFIX@_FCNTL_H */ -#endif /* _@GUARD_PREFIX@_FCNTL_H */ -#endif diff --git a/lib/getgroups.c b/lib/getgroups.c deleted file mode 100644 index f9d36236afe..00000000000 --- a/lib/getgroups.c +++ /dev/null @@ -1,116 +0,0 @@ -/* provide consistent interface to getgroups for systems that don't allow N==0 - - Copyright (C) 1996, 1999, 2003, 2006-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* written by Jim Meyering */ - -#include - -#include - -#include -#include -#include - -#if !HAVE_GETGROUPS - -/* Provide a stub that fails with ENOSYS, since there is no group - information available on mingw. */ -int -getgroups (int n _GL_UNUSED, GETGROUPS_T *groups _GL_UNUSED) -{ - errno = ENOSYS; - return -1; -} - -#else /* HAVE_GETGROUPS */ - -# undef getgroups -# ifndef GETGROUPS_ZERO_BUG -# define GETGROUPS_ZERO_BUG 0 -# endif - -/* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always - fails. On other systems, it returns the number of supplemental - groups for the process. This function handles that special case - and lets the system-provided function handle all others. However, - it can fail with ENOMEM if memory is tight. It is unspecified - whether the effective group id is included in the list. */ - -int -rpl_getgroups (int n, gid_t *group) -{ - int n_groups; - GETGROUPS_T *gbuf; - int saved_errno; - - if (n < 0) - { - errno = EINVAL; - return -1; - } - - if (n != 0 || !GETGROUPS_ZERO_BUG) - { - int result; - if (sizeof *group == sizeof *gbuf) - return getgroups (n, (GETGROUPS_T *) group); - - if (SIZE_MAX / sizeof *gbuf <= n) - { - errno = ENOMEM; - return -1; - } - gbuf = malloc (n * sizeof *gbuf); - if (!gbuf) - return -1; - result = getgroups (n, gbuf); - if (0 <= result) - { - n = result; - while (n--) - group[n] = gbuf[n]; - } - saved_errno = errno; - free (gbuf); - errno == saved_errno; - return result; - } - - n = 20; - while (1) - { - /* No need to worry about address arithmetic overflow here, - since the ancient systems that we're running on have low - limits on the number of secondary groups. */ - gbuf = malloc (n * sizeof *gbuf); - if (!gbuf) - return -1; - n_groups = getgroups (n, gbuf); - if (n_groups == -1 ? errno != EINVAL : n_groups < n) - break; - free (gbuf); - n *= 2; - } - - saved_errno = errno; - free (gbuf); - errno = saved_errno; - - return n_groups; -} - -#endif /* HAVE_GETGROUPS */ diff --git a/lib/gnulib.mk b/lib/gnulib.mk index d2562a4dae1..23749331a83 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk @@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings MOSTLYCLEANFILES += core *.stackdump @@ -150,17 +150,6 @@ EXTRA_libgnu_a_SOURCES += dup2.c ## end gnulib module dup2 -## begin gnulib module euidaccess - -if gl_GNULIB_ENABLED_euidaccess - -endif -EXTRA_DIST += euidaccess.c - -EXTRA_libgnu_a_SOURCES += euidaccess.c - -## end gnulib module euidaccess - ## begin gnulib module execinfo BUILT_SOURCES += $(EXECINFO_H) @@ -186,50 +175,6 @@ EXTRA_libgnu_a_SOURCES += execinfo.c ## end gnulib module execinfo -## begin gnulib module faccessat - - -EXTRA_DIST += at-func.c faccessat.c - -EXTRA_libgnu_a_SOURCES += at-func.c faccessat.c - -## end gnulib module faccessat - -## begin gnulib module fcntl-h - -BUILT_SOURCES += fcntl.h - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) - $(AM_V_GEN)rm -f $@-t $@ && \ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's|@''GUARD_PREFIX''@|GL|g' \ - -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ - -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ - -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ - -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \ - -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \ - -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \ - -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \ - -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \ - -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \ - -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \ - -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \ - -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \ - -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \ - -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ - -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ - -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ - < $(srcdir)/fcntl.in.h; \ - } > $@-t && \ - mv $@-t $@ -MOSTLYCLEANFILES += fcntl.h fcntl.h-t - -EXTRA_DIST += fcntl.in.h - -## end gnulib module fcntl-h - ## begin gnulib module filemode libgnu_a_SOURCES += filemode.c @@ -238,17 +183,6 @@ EXTRA_DIST += filemode.h ## end gnulib module filemode -## begin gnulib module getgroups - -if gl_GNULIB_ENABLED_getgroups - -endif -EXTRA_DIST += getgroups.c - -EXTRA_libgnu_a_SOURCES += getgroups.c - -## end gnulib module getgroups - ## begin gnulib module getloadavg @@ -308,17 +242,6 @@ EXTRA_libgnu_a_SOURCES += gettimeofday.c ## end gnulib module gettimeofday -## begin gnulib module group-member - -if gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 - -endif -EXTRA_DIST += group-member.c - -EXTRA_libgnu_a_SOURCES += group-member.c - -## end gnulib module group-member - ## begin gnulib module ignore-value @@ -431,15 +354,6 @@ EXTRA_libgnu_a_SOURCES += readlink.c ## end gnulib module readlink -## begin gnulib module root-uid - -if gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c - -endif -EXTRA_DIST += root-uid.h - -## end gnulib module root-uid - ## begin gnulib module signal-h BUILT_SOURCES += signal.h @@ -1398,15 +1312,6 @@ EXTRA_DIST += verify.h ## end gnulib module verify -## begin gnulib module xalloc-oversized - -if gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec - -endif -EXTRA_DIST += xalloc-oversized.h - -## end gnulib module xalloc-oversized - mostlyclean-local: mostlyclean-generic @for dir in '' $(MOSTLYCLEANDIRS); do \ diff --git a/lib/group-member.c b/lib/group-member.c deleted file mode 100644 index 5fcc7e01d0c..00000000000 --- a/lib/group-member.c +++ /dev/null @@ -1,119 +0,0 @@ -/* group-member.c -- determine whether group id is in calling user's group list - - Copyright (C) 1994, 1997-1998, 2003, 2005-2006, 2009-2012 Free Software - Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#include - -/* Specification. */ -#include - -#include -#include -#include - -#include "xalloc-oversized.h" - -/* Most processes have no more than this many groups, and for these - processes we can avoid using malloc. */ -enum { GROUPBUF_SIZE = 100 }; - -struct group_info - { - gid_t *group; - gid_t groupbuf[GROUPBUF_SIZE]; - }; - -static void -free_group_info (struct group_info const *g) -{ - if (g->group != g->groupbuf) - free (g->group); -} - -static int -get_group_info (struct group_info *gi) -{ - int n_groups = getgroups (GROUPBUF_SIZE, gi->groupbuf); - gi->group = gi->groupbuf; - - if (n_groups < 0) - { - int n_group_slots = getgroups (0, NULL); - if (0 <= n_group_slots - && ! xalloc_oversized (n_group_slots, sizeof *gi->group)) - { - gi->group = malloc (n_group_slots * sizeof *gi->group); - if (gi->group) - n_groups = getgroups (n_group_slots, gi->group); - } - } - - /* In case of error, the user loses. */ - return n_groups; -} - -/* Return non-zero if GID is one that we have in our groups list. - Note that the groups list is not guaranteed to contain the current - or effective group ID, so they should generally be checked - separately. */ - -int -group_member (gid_t gid) -{ - int i; - int found; - struct group_info gi; - int n_groups = get_group_info (&gi); - - /* Search through the list looking for GID. */ - found = 0; - for (i = 0; i < n_groups; i++) - { - if (gid == gi.group[i]) - { - found = 1; - break; - } - } - - free_group_info (&gi); - - return found; -} - -#ifdef TEST - -char *program_name; - -int -main (int argc, char **argv) -{ - int i; - - program_name = argv[0]; - - for (i = 1; i < argc; i++) - { - gid_t gid; - - gid = atoi (argv[i]); - printf ("%d: %s\n", gid, group_member (gid) ? "yes" : "no"); - } - exit (0); -} - -#endif /* TEST */ diff --git a/lib/root-uid.h b/lib/root-uid.h deleted file mode 100644 index 2379773c291..00000000000 --- a/lib/root-uid.h +++ /dev/null @@ -1,30 +0,0 @@ -/* The user ID that always has appropriate privileges in the POSIX sense. - - Copyright 2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - Written by Paul Eggert. */ - -#ifndef ROOT_UID_H_ -#define ROOT_UID_H_ - -/* The user ID that always has appropriate privileges in the POSIX sense. */ -#ifdef __TANDEM -# define ROOT_UID 65535 -#else -# define ROOT_UID 0 -#endif - -#endif diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h deleted file mode 100644 index ad777d8dd79..00000000000 --- a/lib/xalloc-oversized.h +++ /dev/null @@ -1,38 +0,0 @@ -/* xalloc-oversized.h -- memory allocation size checking - - Copyright (C) 1990-2000, 2003-2004, 2006-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef XALLOC_OVERSIZED_H_ -# define XALLOC_OVERSIZED_H_ - -# include - -/* Return 1 if an array of N objects, each of size S, cannot exist due - to size arithmetic overflow. S must be positive and N must be - nonnegative. This is a macro, not a function, so that it - works correctly even when SIZE_MAX < N. - - By gnulib convention, SIZE_MAX represents overflow in size - calculations, so the conservative dividend to use here is - SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. - However, malloc (SIZE_MAX) fails on all known hosts where - sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for - exactly-SIZE_MAX allocations on such hosts; this avoids a test and - branch when S is known to be 1. */ -# define xalloc_oversized(n, s) \ - ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) - -#endif /* !XALLOC_OVERSIZED_H_ */ diff --git a/m4/euidaccess.m4 b/m4/euidaccess.m4 deleted file mode 100644 index 2de95b88ba8..00000000000 --- a/m4/euidaccess.m4 +++ /dev/null @@ -1,52 +0,0 @@ -# euidaccess.m4 serial 15 -dnl Copyright (C) 2002-2012 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_NONREENTRANT_EUIDACCESS], -[ - AC_REQUIRE([gl_FUNC_EUIDACCESS]) - AC_CHECK_DECLS([setregid]) - AC_DEFINE([PREFER_NONREENTRANT_EUIDACCESS], [1], - [Define this if you prefer euidaccess to return the correct result - even if this would make it nonreentrant. Define this only if your - entire application is safe even if the uid or gid might temporarily - change. If your application uses signal handlers or threads it - is probably not safe.]) -]) - -AC_DEFUN([gl_FUNC_EUIDACCESS], -[ - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - - dnl Persuade glibc to declare euidaccess(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - AC_CHECK_FUNCS([euidaccess]) - if test $ac_cv_func_euidaccess = no; then - HAVE_EUIDACCESS=0 - fi -]) - -# Prerequisites of lib/euidaccess.c. -AC_DEFUN([gl_PREREQ_EUIDACCESS], [ - dnl Prefer POSIX faccessat over non-standard euidaccess. - AC_CHECK_FUNCS_ONCE([faccessat]) - dnl Try various other non-standard fallbacks. - AC_CHECK_HEADERS([libgen.h]) - AC_FUNC_GETGROUPS - - # Solaris 9 and 10 need -lgen to get the eaccess function. - # Save and restore LIBS so -lgen isn't added to it. Otherwise, *all* - # programs in the package would end up linked with that potentially-shared - # library, inducing unnecessary run-time overhead. - LIB_EACCESS= - AC_SUBST([LIB_EACCESS]) - gl_saved_libs=$LIBS - AC_SEARCH_LIBS([eaccess], [gen], - [test "$ac_cv_search_eaccess" = "none required" || - LIB_EACCESS=$ac_cv_search_eaccess]) - AC_CHECK_FUNCS([eaccess]) - LIBS=$gl_saved_libs -]) diff --git a/m4/faccessat.m4 b/m4/faccessat.m4 deleted file mode 100644 index 82f3b1f8dde..00000000000 --- a/m4/faccessat.m4 +++ /dev/null @@ -1,28 +0,0 @@ -# serial 6 -# See if we need to provide faccessat replacement. - -dnl Copyright (C) 2009-2012 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# Written by Eric Blake. - -AC_DEFUN([gl_FUNC_FACCESSAT], -[ - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - - dnl Persuade glibc to declare faccessat(). - AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - - AC_CHECK_FUNCS_ONCE([faccessat]) - if test $ac_cv_func_faccessat = no; then - HAVE_FACCESSAT=0 - fi -]) - -# Prerequisites of lib/faccessat.m4. -AC_DEFUN([gl_PREREQ_FACCESSAT], -[ - AC_CHECK_FUNCS([access]) -]) diff --git a/m4/fcntl_h.m4 b/m4/fcntl_h.m4 deleted file mode 100644 index cac28aeb283..00000000000 --- a/m4/fcntl_h.m4 +++ /dev/null @@ -1,50 +0,0 @@ -# serial 15 -# Configure fcntl.h. -dnl Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Written by Paul Eggert. - -AC_DEFUN([gl_FCNTL_H], -[ - AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) - AC_REQUIRE([gl_FCNTL_O_FLAGS]) - gl_NEXT_HEADERS([fcntl.h]) - - dnl Ensure the type pid_t gets defined. - AC_REQUIRE([AC_TYPE_PID_T]) - - dnl Ensure the type mode_t gets defined. - AC_REQUIRE([AC_TYPE_MODE_T]) - - dnl Check for declarations of anything we want to poison if the - dnl corresponding gnulib module is not in use, if it is not common - dnl enough to be declared everywhere. - gl_WARN_ON_USE_PREPARE([[#include - ]], [fcntl openat]) -]) - -AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) - gl_MODULE_INDICATOR_SET_VARIABLE([$1]) - dnl Define it also as a C macro, for the benefit of the unit tests. - gl_MODULE_INDICATOR_FOR_TESTS([$1]) -]) - -AC_DEFUN([gl_FCNTL_H_DEFAULTS], -[ - GNULIB_FCNTL=0; AC_SUBST([GNULIB_FCNTL]) - GNULIB_NONBLOCKING=0; AC_SUBST([GNULIB_NONBLOCKING]) - GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) - GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_FCNTL=1; AC_SUBST([HAVE_FCNTL]) - HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT]) - REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL]) - REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) - REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT]) -]) diff --git a/m4/getgroups.m4 b/m4/getgroups.m4 deleted file mode 100644 index 17473af486b..00000000000 --- a/m4/getgroups.m4 +++ /dev/null @@ -1,107 +0,0 @@ -# serial 18 - -dnl From Jim Meyering. -dnl A wrapper around AC_FUNC_GETGROUPS. - -# Copyright (C) 1996-1997, 1999-2004, 2008-2012 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -m4_version_prereq([2.70], [] ,[ - -# This is taken from the following Autoconf patch: -# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9 -AC_DEFUN([AC_FUNC_GETGROUPS], -[ - AC_REQUIRE([AC_TYPE_GETGROUPS])dnl - AC_REQUIRE([AC_TYPE_SIZE_T])dnl - AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles - AC_CHECK_FUNC([getgroups]) - - # If we don't yet have getgroups, see if it's in -lbsd. - # This is reported to be necessary on an ITOS 3000WS running SEIUX 3.1. - ac_save_LIBS=$LIBS - if test $ac_cv_func_getgroups = no; then - AC_CHECK_LIB(bsd, getgroups, [GETGROUPS_LIB=-lbsd]) - fi - - # Run the program to test the functionality of the system-supplied - # getgroups function only if there is such a function. - if test $ac_cv_func_getgroups = yes; then - AC_CACHE_CHECK([for working getgroups], [ac_cv_func_getgroups_works], - [AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [AC_INCLUDES_DEFAULT], - [[/* On Ultrix 4.3, getgroups (0, 0) always fails. */ - return getgroups (0, 0) == -1;]]) - ], - [ac_cv_func_getgroups_works=yes], - [ac_cv_func_getgroups_works=no], - [case "$host_os" in # (( - # Guess yes on glibc systems. - *-gnu*) ac_cv_func_getgroups_works="guessing yes" ;; - # If we don't know, assume the worst. - *) ac_cv_func_getgroups_works="guessing no" ;; - esac - ]) - ]) - else - ac_cv_func_getgroups_works=no - fi - case "$ac_cv_func_getgroups_works" in - *yes) - AC_DEFINE([HAVE_GETGROUPS], [1], - [Define to 1 if your system has a working `getgroups' function.]) - ;; - esac - LIBS=$ac_save_LIBS -])# AC_FUNC_GETGROUPS - -]) - -AC_DEFUN([gl_FUNC_GETGROUPS], -[ - AC_REQUIRE([AC_TYPE_GETGROUPS]) - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - - AC_FUNC_GETGROUPS - if test $ac_cv_func_getgroups != yes; then - HAVE_GETGROUPS=0 - else - if test "$ac_cv_type_getgroups" != gid_t \ - || { case "$ac_cv_func_getgroups_works" in - *yes) false;; - *) true;; - esac - }; then - REPLACE_GETGROUPS=1 - AC_DEFINE([GETGROUPS_ZERO_BUG], [1], [Define this to 1 if - getgroups(0,NULL) does not return the number of groups.]) - else - dnl Detect FreeBSD bug; POSIX requires getgroups(-1,ptr) to fail. - AC_CACHE_CHECK([whether getgroups handles negative values], - [gl_cv_func_getgroups_works], - [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], - [[int size = getgroups (0, 0); - gid_t *list = malloc (size * sizeof *list); - return getgroups (-1, list) != -1;]])], - [gl_cv_func_getgroups_works=yes], - [gl_cv_func_getgroups_works=no], - [case "$host_os" in - # Guess yes on glibc systems. - *-gnu*) gl_cv_func_getgroups_works="guessing yes" ;; - # If we don't know, assume the worst. - *) gl_cv_func_getgroups_works="guessing no" ;; - esac - ])]) - case "$gl_cv_func_getgroups_works" in - *yes) ;; - *) REPLACE_GETGROUPS=1 ;; - esac - fi - fi - test -n "$GETGROUPS_LIB" && LIBS="$GETGROUPS_LIB $LIBS" -]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 9b2dcee1cfa..de2355d87c3 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -53,22 +53,17 @@ AC_DEFUN([gl_EARLY], # Code from module dtotimespec: # Code from module dup2: # Code from module environ: - # Code from module euidaccess: # Code from module execinfo: # Code from module extensions: AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) # Code from module extern-inline: - # Code from module faccessat: - # Code from module fcntl-h: # Code from module filemode: - # Code from module getgroups: # Code from module getloadavg: # Code from module getopt-gnu: # Code from module getopt-posix: # Code from module gettext-h: # Code from module gettime: # Code from module gettimeofday: - # Code from module group-member: # Code from module ignore-value: # Code from module include_next: # Code from module intprops: @@ -84,7 +79,6 @@ AC_DEFUN([gl_EARLY], # Code from module pselect: # Code from module pthread_sigmask: # Code from module readlink: - # Code from module root-uid: # Code from module signal-h: # Code from module snippet/_Noreturn: # Code from module snippet/arg-nonnull: @@ -126,7 +120,6 @@ AC_DEFUN([gl_EARLY], # Code from module utimens: # Code from module verify: # Code from module warnings: - # Code from module xalloc-oversized: ]) # This macro should be invoked from ./configure.ac, in the section @@ -163,14 +156,6 @@ AC_DEFUN([gl_INIT], gl_UNISTD_MODULE_INDICATOR([environ]) gl_EXECINFO_H AC_REQUIRE([gl_EXTERN_INLINE]) - gl_FUNC_FACCESSAT - if test $HAVE_FACCESSAT = 0; then - AC_LIBOBJ([faccessat]) - gl_PREREQ_FACCESSAT - fi - gl_MODULE_INDICATOR([faccessat]) - gl_UNISTD_MODULE_INDICATOR([faccessat]) - gl_FCNTL_H gl_FILEMODE gl_GETLOADAVG if test $HAVE_GETLOADAVG = 0; then @@ -284,53 +269,18 @@ AC_DEFUN([gl_INIT], gl_UNISTD_H gl_UTIMENS gl_gnulib_enabled_dosname=false - gl_gnulib_enabled_euidaccess=false - gl_gnulib_enabled_getgroups=false gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=false - gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false gl_gnulib_enabled_pathmax=false - gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false gl_gnulib_enabled_stat=false gl_gnulib_enabled_strtoll=false gl_gnulib_enabled_strtoull=false gl_gnulib_enabled_verify=false - gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false func_gl_gnulib_m4code_dosname () { if ! $gl_gnulib_enabled_dosname; then gl_gnulib_enabled_dosname=true fi } - func_gl_gnulib_m4code_euidaccess () - { - if ! $gl_gnulib_enabled_euidaccess; then - gl_FUNC_EUIDACCESS - if test $HAVE_EUIDACCESS = 0; then - AC_LIBOBJ([euidaccess]) - gl_PREREQ_EUIDACCESS - fi - gl_UNISTD_MODULE_INDICATOR([euidaccess]) - gl_gnulib_enabled_euidaccess=true - if test $HAVE_EUIDACCESS = 0; then - func_gl_gnulib_m4code_a9786850e999ae65a836a6041e8e5ed1 - fi - func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c - if test $HAVE_EUIDACCESS = 0; then - func_gl_gnulib_m4code_stat - fi - fi - } - func_gl_gnulib_m4code_getgroups () - { - if ! $gl_gnulib_enabled_getgroups; then - gl_FUNC_GETGROUPS - if test $HAVE_GETGROUPS = 0 || test $REPLACE_GETGROUPS = 1; then - AC_LIBOBJ([getgroups]) - fi - gl_UNISTD_MODULE_INDICATOR([getgroups]) - gl_gnulib_enabled_getgroups=true - fi - } func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 () { if ! $gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36; then @@ -339,24 +289,6 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=true fi } - func_gl_gnulib_m4code_a9786850e999ae65a836a6041e8e5ed1 () - { - if ! $gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1; then - gl_FUNC_GROUP_MEMBER - if test $HAVE_GROUP_MEMBER = 0; then - AC_LIBOBJ([group-member]) - gl_PREREQ_GROUP_MEMBER - fi - gl_UNISTD_MODULE_INDICATOR([group-member]) - gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=true - if test $HAVE_GROUP_MEMBER = 0; then - func_gl_gnulib_m4code_getgroups - fi - if test $HAVE_GROUP_MEMBER = 0; then - func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec - fi - fi - } func_gl_gnulib_m4code_pathmax () { if ! $gl_gnulib_enabled_pathmax; then @@ -364,12 +296,6 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_pathmax=true fi } - func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c () - { - if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then - gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=true - fi - } func_gl_gnulib_m4code_stat () { if ! $gl_gnulib_enabled_stat; then @@ -421,18 +347,6 @@ AC_DEFUN([gl_INIT], gl_gnulib_enabled_verify=true fi } - func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec () - { - if ! $gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec; then - gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=true - fi - } - if test $HAVE_FACCESSAT = 0; then - func_gl_gnulib_m4code_dosname - fi - if test $HAVE_FACCESSAT = 0; then - func_gl_gnulib_m4code_euidaccess - fi if test $REPLACE_GETOPT = 1; then func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 fi @@ -459,17 +373,12 @@ AC_DEFUN([gl_INIT], fi m4_pattern_allow([^gl_GNULIB_ENABLED_]) AM_CONDITIONAL([gl_GNULIB_ENABLED_dosname], [$gl_gnulib_enabled_dosname]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_euidaccess], [$gl_gnulib_enabled_euidaccess]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_getgroups], [$gl_gnulib_enabled_getgroups]) AM_CONDITIONAL([gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36], [$gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1]) AM_CONDITIONAL([gl_GNULIB_ENABLED_pathmax], [$gl_gnulib_enabled_pathmax]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c]) AM_CONDITIONAL([gl_GNULIB_ENABLED_stat], [$gl_gnulib_enabled_stat]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoull], [$gl_gnulib_enabled_strtoull]) AM_CONDITIONAL([gl_GNULIB_ENABLED_verify], [$gl_gnulib_enabled_verify]) - AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec]) # End of code from modules m4_ifval(gl_LIBSOURCES_LIST, [ m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || @@ -618,7 +527,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/alloca.in.h lib/allocator.c lib/allocator.h - lib/at-func.c lib/c-ctype.c lib/c-ctype.h lib/c-strcase.h @@ -630,16 +538,12 @@ AC_DEFUN([gl_FILE_LIST], [ lib/dtoastr.c lib/dtotimespec.c lib/dup2.c - lib/euidaccess.c lib/execinfo.c lib/execinfo.in.h - lib/faccessat.c - lib/fcntl.in.h lib/filemode.c lib/filemode.h lib/ftoastr.c lib/ftoastr.h - lib/getgroups.c lib/getloadavg.c lib/getopt.c lib/getopt.in.h @@ -648,7 +552,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/gettext.h lib/gettime.c lib/gettimeofday.c - lib/group-member.c lib/ignore-value.h lib/intprops.h lib/inttypes.in.h @@ -661,7 +564,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/pselect.c lib/pthread_sigmask.c lib/readlink.c - lib/root-uid.h lib/sha1.c lib/sha1.h lib/sha256.c @@ -703,28 +605,21 @@ AC_DEFUN([gl_FILE_LIST], [ lib/utimens.c lib/utimens.h lib/verify.h - lib/xalloc-oversized.h m4/00gnulib.m4 m4/alloca.m4 m4/c-strtod.m4 m4/clock_time.m4 m4/dup2.m4 m4/environ.m4 - m4/euidaccess.m4 m4/execinfo.m4 m4/extensions.m4 m4/extern-inline.m4 - m4/faccessat.m4 - m4/fcntl-o.m4 - m4/fcntl_h.m4 m4/filemode.m4 - m4/getgroups.m4 m4/getloadavg.m4 m4/getopt.m4 m4/gettime.m4 m4/gettimeofday.m4 m4/gnulib-common.m4 - m4/group-member.m4 m4/include_next.m4 m4/inttypes.m4 m4/largefile.m4 diff --git a/m4/group-member.m4 b/m4/group-member.m4 deleted file mode 100644 index c393b5b1303..00000000000 --- a/m4/group-member.m4 +++ /dev/null @@ -1,29 +0,0 @@ -# serial 14 - -# Copyright (C) 1999-2001, 2003-2007, 2009-2012 Free Software Foundation, Inc. - -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -dnl Written by Jim Meyering - -AC_DEFUN([gl_FUNC_GROUP_MEMBER], -[ - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - - dnl Persuade glibc to declare group_member(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - dnl Do this replacement check manually because I want the hyphen - dnl (not the underscore) in the filename. - AC_CHECK_FUNC([group_member], , [ - HAVE_GROUP_MEMBER=0 - ]) -]) - -# Prerequisites of lib/group-member.c. -AC_DEFUN([gl_PREREQ_GROUP_MEMBER], -[ - AC_REQUIRE([AC_FUNC_GETGROUPS]) -]) diff --git a/nt/ChangeLog b/nt/ChangeLog index f64cafe2e16..94d2ce18551 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog @@ -1,10 +1,3 @@ -2012-10-19 Paul Eggert - - Use faccessat, not access, when checking file permissions (Bug#12632). - * inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols. - (access): Remove. - (faccessat): New macro. - 2012-10-17 Eli Zaretskii * inc/pwd.h (getuid, geteuid): Add prototypes. diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h index 0f6b51d3915..dd2ae781cb8 100644 --- a/nt/inc/ms-w32.h +++ b/nt/inc/ms-w32.h @@ -124,10 +124,6 @@ extern char *getenv (); #define MAXPATHLEN _MAX_PATH #endif -/* Use values compatible with gnulib, as there's no reason to differ. */ -#define AT_FDCWD (-3041965) -#define AT_EACCESS 4 - #ifdef HAVE_NTGUI #define HAVE_WINDOW_SYSTEM 1 #define HAVE_MENUS 1 @@ -149,6 +145,8 @@ extern char *getenv (); #endif /* Calls that are emulated or shadowed. */ +#undef access +#define access sys_access #undef chdir #define chdir sys_chdir #undef chmod @@ -163,7 +161,6 @@ extern char *getenv (); #define dup sys_dup #undef dup2 #define dup2 sys_dup2 -#define faccessat sys_faccessat #define fopen sys_fopen #define link sys_link #define localtime sys_localtime diff --git a/src/ChangeLog b/src/ChangeLog index ee18650e992..5a1b4a5d8ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,32 +1,3 @@ -2012-10-19 Paul Eggert - - Use faccessat, not access, when checking file permissions (Bug#12632). - * Makefile.in (LIB_EACCESS): New macro. - (LIBES): Use it. - * callproc.c (init_callproc): - * charset.c (init_charset): - * fileio.c (check_existing, check_executable): - * lread.c (openp, load_path_check): - * process.c (allocate_pty): - * xrdb.c (file_p): - Use faccessat, not access or euidaccess. Use symbolic names - instead of integers for the flags, as they're portable now. - * charset.c, xrdb.c: Include , for the new flags used. - * 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. - * fileio.c (Ffile_directory_p, Fset_file_times): - * xrdb.c (file_p): Use file_directory_p. - * lisp.h (file_directory_p): New decl. - * 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. - * process.c, sysdep.c, term.c: All uses of '#ifdef O_NONBLOCK' - changed to '#if O_NONBLOCK', to accommodate gnulib O_* style. - * w32.c (sys_faccessat): Rename from sys_access and switch to - faccessat's API. All uses changed. - 2012-10-19 Kazuhiro Ito (tiny change) * font.c (Ffont_at): Fix previous change. diff --git a/src/Makefile.in b/src/Makefile.in index d034ad04796..c24e421bbbc 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -150,7 +150,6 @@ M17N_FLT_CFLAGS = @M17N_FLT_CFLAGS@ M17N_FLT_LIBS = @M17N_FLT_LIBS@ LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ -LIB_EACCESS=@LIB_EACCESS@ LIB_TIMER_TIME=@LIB_TIMER_TIME@ DBUS_CFLAGS = @DBUS_CFLAGS@ @@ -393,7 +392,7 @@ otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \ LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \ $(LIBX_OTHER) $(LIBSOUND) \ $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ - $(LIB_EACCESS) $(LIB_TIMER_TIME) $(DBUS_LIBS) \ + $(LIB_TIMER_TIME) $(DBUS_LIBS) \ $(LIB_EXECINFO) \ $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ diff --git a/src/callproc.c b/src/callproc.c index 5a9b32f08c3..b33882e54c2 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1597,13 +1597,13 @@ init_callproc (void) #endif { tempdir = Fdirectory_file_name (Vexec_directory); - if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0) + if (access (SSDATA (tempdir), 0) < 0) dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n", Vexec_directory); } tempdir = Fdirectory_file_name (Vdata_directory); - if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0) + if (access (SSDATA (tempdir), 0) < 0) dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n", Vdata_directory); diff --git a/src/charset.c b/src/charset.c index fe068e1d3bc..6b999824dab 100644 --- a/src/charset.c +++ b/src/charset.c @@ -28,7 +28,6 @@ along with GNU Emacs. If not, see . */ #define CHARSET_INLINE EXTERN_INLINE -#include #include #include #include @@ -2294,7 +2293,7 @@ init_charset (void) { Lisp_Object tempdir; tempdir = Fexpand_file_name (build_string ("charsets"), Vdata_directory); - if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0) + if (access (SSDATA (tempdir), 0) < 0) { /* This used to be non-fatal (dir_warning), but it should not happen, and if it does sooner or later it will cause some diff --git a/src/conf_post.h b/src/conf_post.h index eade536e6e1..aa008107ba6 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -169,10 +169,6 @@ extern void _DebPrint (const char *fmt, ...); #endif #endif -/* Tell gnulib to omit support for openat-related functions having a - first argument other than AT_FDCWD. */ -#define GNULIB_SUPPORT_ONLY_AT_FDCWD - #include #include diff --git a/src/fileio.c b/src/fileio.c index 3accb58a3eb..d47d7dd9e0b 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2425,7 +2425,15 @@ On Unix, this is a name starting with a `/' or a `~'. */) bool check_existing (const char *filename) { - return faccessat (AT_FDCWD, filename, F_OK, AT_EACCESS) == 0; +#ifdef DOS_NT + /* The full emulation of Posix 'stat' is too expensive on + DOS/Windows, when all we want to know is whether the file exists. + So we use 'access' instead, which is much more lightweight. */ + return (access (filename, F_OK) >= 0); +#else + struct stat st; + return (stat (filename, &st) >= 0); +#endif } /* Return true if file FILENAME exists and can be executed. */ @@ -2433,7 +2441,21 @@ check_existing (const char *filename) static bool check_executable (char *filename) { - return faccessat (AT_FDCWD, filename, X_OK, AT_EACCESS) == 0; +#ifdef DOS_NT + struct stat st; + if (stat (filename, &st) < 0) + return 0; + return ((st.st_mode & S_IEXEC) != 0); +#else /* not DOS_NT */ +#ifdef HAVE_EUIDACCESS + return (euidaccess (filename, 1) >= 0); +#else + /* Access isn't quite right because it uses the real uid + and we really want to test with the effective uid. + But Unix doesn't give us a right way to do it. */ + return (access (filename, 1) >= 0); +#endif +#endif /* not DOS_NT */ } /* Return true if file FILENAME exists and can be written. */ @@ -2442,16 +2464,15 @@ static bool check_writable (const char *filename) { #ifdef MSDOS - /* FIXME: an faccessat implementation should be added to the - DOS/Windows ports and this #ifdef branch should be removed. */ struct stat st; if (stat (filename, &st) < 0) return 0; return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); #else /* not MSDOS */ - bool res = faccessat (AT_FDCWD, filename, W_OK, AT_EACCESS) == 0; +#ifdef HAVE_EUIDACCESS + bool res = (euidaccess (filename, 2) >= 0); #ifdef CYGWIN - /* faccessat may have returned failure because Cygwin couldn't + /* euidaccess may have returned failure because Cygwin couldn't determine the file's UID or GID; if so, we return success. */ if (!res) { @@ -2462,6 +2483,14 @@ check_writable (const char *filename) } #endif /* CYGWIN */ return res; +#else /* not HAVE_EUIDACCESS */ + /* Access isn't quite right because it uses the real uid + and we really want to test with the effective uid. + But Unix doesn't give us a right way to do it. + Opening with O_WRONLY could work for an ordinary file, + but would lose for directories. */ + return (access (filename, 2) >= 0); +#endif /* not HAVE_EUIDACCESS */ #endif /* not MSDOS */ } @@ -2518,6 +2547,9 @@ See also `file-exists-p' and `file-attributes'. */) { Lisp_Object absname; Lisp_Object handler; + int desc; + int flags; + struct stat statbuf; CHECK_STRING (filename); absname = Fexpand_file_name (filename, Qnil); @@ -2529,8 +2561,31 @@ See also `file-exists-p' and `file-attributes'. */) return call2 (handler, Qfile_readable_p, absname); absname = ENCODE_FILE (absname); - return (faccessat (AT_FDCWD, SSDATA (absname), R_OK, AT_EACCESS) == 0 - ? Qt : Qnil); + +#if defined (DOS_NT) || defined (macintosh) + /* Under MS-DOS, Windows, and Macintosh, open does not work for + directories. */ + if (access (SDATA (absname), 0) == 0) + return Qt; + return Qnil; +#else /* not DOS_NT and not macintosh */ + flags = O_RDONLY; +#ifdef O_NONBLOCK + /* Opening a fifo without O_NONBLOCK can wait. + We don't want to wait. But we don't want to mess wth O_NONBLOCK + except in the case of a fifo, on a system which handles it. */ + desc = stat (SSDATA (absname), &statbuf); + if (desc < 0) + return Qnil; + if (S_ISFIFO (statbuf.st_mode)) + flags |= O_NONBLOCK; +#endif + desc = emacs_open (SSDATA (absname), flags, 0); + if (desc < 0) + return Qnil; + emacs_close (desc); + return Qt; +#endif /* not DOS_NT and not macintosh */ } /* Having this before file-symlink-p mysteriously caused it to be forgotten @@ -2567,7 +2622,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, /* The read-only attribute of the parent directory doesn't affect whether a file or directory can be created within it. Some day we should check ACLs though, which do affect this. */ - return file_directory_p (SDATA (dir)) ? Qt : Qnil; + return (access (SDATA (dir), D_OK) < 0) ? Qnil : Qt; #else return (check_writable (!NILP (dir) ? SSDATA (dir) : "") ? Qt : Qnil); @@ -2648,7 +2703,8 @@ Symbolic links to directories count as directories. See `file-symlink-p' to distinguish symlinks. */) (Lisp_Object filename) { - Lisp_Object absname; + register Lisp_Object absname; + struct stat st; Lisp_Object handler; absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory)); @@ -2661,20 +2717,9 @@ See `file-symlink-p' to distinguish symlinks. */) absname = ENCODE_FILE (absname); - return file_directory_p (SSDATA (absname)) ? Qt : Qnil; -} - -/* Return true if FILE is a directory or a symlink to a directory. */ -bool -file_directory_p (char const *file) -{ -#ifdef WINDOWSNT - /* This is cheaper than 'stat'. */ - return faccessat (AT_FDCWD, file, D_OK, AT_EACCESS) == 0; -#else - struct stat st; - return stat (file, &st) == 0 && S_ISDIR (st.st_mode); -#endif + if (stat (SSDATA (absname), &st) < 0) + return Qnil; + return S_ISDIR (st.st_mode) ? Qt : Qnil; } DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, @@ -2999,8 +3044,10 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of if (set_file_times (-1, SSDATA (encoded_absname), t, t)) { #ifdef MSDOS + struct stat st; + /* Setting times on a directory always fails. */ - if (file_directory_p (SSDATA (encoded_absname))) + if (stat (SSDATA (encoded_absname), &st) == 0 && S_ISDIR (st.st_mode)) return Qnil; #endif report_file_error ("Setting file times", Fcons (absname, Qnil)); diff --git a/src/lisp.h b/src/lisp.h index 897757cf462..01f6ca5e57c 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3178,7 +3178,6 @@ extern Lisp_Object close_file_unwind (Lisp_Object); extern Lisp_Object restore_point_unwind (Lisp_Object); extern _Noreturn void report_file_error (const char *, Lisp_Object); extern void internal_delete_file (Lisp_Object); -extern bool file_directory_p (const char *); extern void syms_of_fileio (void); extern Lisp_Object make_temp_name (Lisp_Object, bool); extern Lisp_Object Qdelete_file; diff --git a/src/lread.c b/src/lread.c index dedce50de2a..6d4c0d990af 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1404,7 +1404,7 @@ Returns the file's name in absolute form, or nil if not found. If SUFFIXES is non-nil, it should be a list of suffixes to append to file name when searching. If non-nil, PREDICATE is used instead of `file-readable-p'. -PREDICATE can also be an integer to pass to the faccessat(2) function, +PREDICATE can also be an integer to pass to the access(2) function, in which case file-name-handlers are ignored. This function will normally skip directories, so if you want it to find directories, make sure the PREDICATE function returns `dir-ok' for them. */) @@ -1442,6 +1442,7 @@ static Lisp_Object Qdir_ok; int openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate) { + int fd; ptrdiff_t fn_size = 100; char buf[100]; char *fn = buf; @@ -1496,6 +1497,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto { ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail)); Lisp_Object handler; + bool exists; /* Concatenate path element/specified name with the suffix. If the directory starts with /:, remove that. */ @@ -1519,7 +1521,6 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto handler = Ffind_file_name_handler (string, Qfile_exists_p); if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) { - bool exists; if (NILP (predicate)) exists = !NILP (Ffile_readable_p (string)); else @@ -1541,40 +1542,37 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto } else { - int fd; +#ifndef WINDOWSNT + struct stat st; +#endif const char *pfn; encoded_fn = ENCODE_FILE (string); pfn = SSDATA (encoded_fn); - - /* Check that we can access or open it. */ - if (NATNUMP (predicate)) - fd = (((XFASTINT (predicate) & ~INT_MAX) == 0 - && (faccessat (AT_FDCWD, pfn, XFASTINT (predicate), - AT_EACCESS) - == 0) - && ! file_directory_p (pfn)) - ? 1 : -1); - else +#ifdef WINDOWSNT + exists = access (pfn, F_OK) == 0 && access (pfn, D_OK) < 0; +#else + exists = (stat (pfn, &st) == 0 && ! S_ISDIR (st.st_mode)); +#endif + if (exists) { - struct stat st; - fd = emacs_open (pfn, O_RDONLY, 0); - if (0 <= fd - && (fstat (fd, &st) != 0 || S_ISDIR (st.st_mode))) + /* Check that we can access or open it. */ + if (NATNUMP (predicate)) + fd = (((XFASTINT (predicate) & ~INT_MAX) == 0 + && access (pfn, XFASTINT (predicate)) == 0) + ? 1 : -1); + else + fd = emacs_open (pfn, O_RDONLY, 0); + + if (fd >= 0) { - emacs_close (fd); - fd = -1; + /* We succeeded; return this descriptor and filename. */ + if (storeptr) + *storeptr = string; + UNGCPRO; + return fd; } } - - if (fd >= 0) - { - /* We succeeded; return this descriptor and filename. */ - if (storeptr) - *storeptr = string; - UNGCPRO; - return fd; - } } } if (absolute) @@ -4090,7 +4088,7 @@ load_path_check (void) if (STRINGP (dirfile)) { dirfile = Fdirectory_file_name (dirfile); - if (faccessat (AT_FDCWD, SSDATA (dirfile), F_OK, AT_EACCESS) != 0) + if (access (SSDATA (dirfile), 0) < 0) dir_warning ("Warning: Lisp directory `%s' does not exist.\n", XCAR (path_tail)); } diff --git a/src/process.c b/src/process.c index 572ab83de09..307e82819d6 100644 --- a/src/process.c +++ b/src/process.c @@ -204,7 +204,7 @@ static EMACS_INT update_tick; #ifndef NON_BLOCKING_CONNECT #ifdef HAVE_SELECT #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) -#if O_NONBLOCK || O_NDELAY +#if defined (O_NONBLOCK) || defined (O_NDELAY) #if defined (EWOULDBLOCK) || defined (EINPROGRESS) #define NON_BLOCKING_CONNECT #endif /* EWOULDBLOCK || EINPROGRESS */ @@ -651,7 +651,7 @@ allocate_pty (void) PTY_OPEN; #else /* no PTY_OPEN */ { -# if O_NONBLOCK +# ifdef O_NONBLOCK fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); # else fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0); @@ -668,7 +668,7 @@ allocate_pty (void) #else sprintf (pty_name, "/dev/tty%c%x", c, i); #endif /* no PTY_TTY_NAME_SPRINTF */ - if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0) + if (access (pty_name, 6) != 0) { emacs_close (fd); # ifndef __sgi @@ -1621,7 +1621,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) #if ! defined (USG) || defined (USG_SUBTTY_WORKS) /* On most USG systems it does not work to open the pty's tty here, then close it and reopen it in the child. */ -#if O_NOCTTY +#ifdef O_NOCTTY /* Don't let this terminal become our controlling terminal (in case we don't have one). */ 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) } #endif -#if O_NONBLOCK +#ifdef O_NONBLOCK fcntl (inchannel, F_SETFL, O_NONBLOCK); fcntl (outchannel, F_SETFL, O_NONBLOCK); #else -#if O_NDELAY +#ifdef O_NDELAY fcntl (inchannel, F_SETFL, O_NDELAY); fcntl (outchannel, F_SETFL, O_NDELAY); #endif @@ -1967,7 +1967,7 @@ create_pty (Lisp_Object process) #if ! defined (USG) || defined (USG_SUBTTY_WORKS) /* On most USG systems it does not work to open the pty's tty here, then close it and reopen it in the child. */ -#if O_NOCTTY +#ifdef O_NOCTTY /* Don't let this terminal become our controlling terminal (in case we don't have one). */ int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); @@ -1987,11 +1987,11 @@ create_pty (Lisp_Object process) } #endif /* HAVE_PTYS */ -#if O_NONBLOCK +#ifdef O_NONBLOCK fcntl (inchannel, F_SETFL, O_NONBLOCK); fcntl (outchannel, F_SETFL, O_NONBLOCK); #else -#if O_NDELAY +#ifdef O_NDELAY fcntl (inchannel, F_SETFL, O_NDELAY); fcntl (outchannel, F_SETFL, O_NDELAY); #endif @@ -2951,7 +2951,7 @@ usage: (make-network-process &rest ARGS) */) { /* Don't support network sockets when non-blocking mode is not available, since a blocked Emacs is not useful. */ -#if !O_NONBLOCK && !O_NDELAY +#if !defined (O_NONBLOCK) && !defined (O_NDELAY) error ("Network servers not supported"); #else is_server = 1; @@ -3217,7 +3217,7 @@ usage: (make-network-process &rest ARGS) */) #ifdef NON_BLOCKING_CONNECT if (is_non_blocking_client) { -#if O_NONBLOCK +#ifdef O_NONBLOCK ret = fcntl (s, F_SETFL, O_NONBLOCK); #else ret = fcntl (s, F_SETFL, O_NDELAY); @@ -3434,10 +3434,10 @@ usage: (make-network-process &rest ARGS) */) chan_process[inch] = proc; -#if O_NONBLOCK +#ifdef O_NONBLOCK fcntl (inch, F_SETFL, O_NONBLOCK); #else -#if O_NDELAY +#ifdef O_NDELAY fcntl (inch, F_SETFL, O_NDELAY); #endif #endif @@ -4169,10 +4169,10 @@ server_accept_connection (Lisp_Object server, int channel) chan_process[s] = proc; -#if O_NONBLOCK +#ifdef O_NONBLOCK fcntl (s, F_SETFL, O_NONBLOCK); #else -#if O_NDELAY +#ifdef O_NDELAY fcntl (s, F_SETFL, O_NDELAY); #endif #endif @@ -4873,11 +4873,11 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, #endif /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK, and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */ -#if O_NONBLOCK +#ifdef O_NONBLOCK else if (nread == -1 && errno == EAGAIN) ; #else -#if O_NDELAY +#ifdef O_NDELAY else if (nread == -1 && errno == EAGAIN) ; /* Note that we cannot distinguish between no input @@ -7363,7 +7363,7 @@ init_process_emacs (void) #ifdef HAVE_GETSOCKNAME ADD_SUBFEATURE (QCservice, Qt); #endif -#if O_NONBLOCK || O_NDELAY +#if defined (O_NONBLOCK) || defined (O_NDELAY) ADD_SUBFEATURE (QCserver, Qt); #endif diff --git a/src/sysdep.c b/src/sysdep.c index 8a31957d182..35beeaa7202 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1216,7 +1216,7 @@ reset_sys_modes (struct tty_display_info *tty_out) old_fcntl_owner[fileno (tty_out->input)]); } #endif /* F_SETOWN */ -#if O_NDELAY +#ifdef O_NDELAY fcntl (fileno (tty_out->input), F_SETFL, fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY); #endif @@ -2312,12 +2312,12 @@ serial_open (char *port) fd = emacs_open ((char*) port, O_RDWR -#if O_NONBLOCK +#ifdef O_NONBLOCK | O_NONBLOCK #else | O_NDELAY #endif -#if O_NOCTTY +#ifdef O_NOCTTY | O_NOCTTY #endif , 0); diff --git a/src/term.c b/src/term.c index 87ce5447b76..f7c87b7608d 100644 --- a/src/term.c +++ b/src/term.c @@ -3023,7 +3023,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) int fd; FILE *file; -#if O_IGNORE_CTTY +#ifdef O_IGNORE_CTTY if (!ctty) /* Open the terminal device. Don't recognize it as our controlling terminal, and don't make it the controlling tty @@ -3054,7 +3054,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) name); } -#if !O_IGNORE_CTTY +#ifndef O_IGNORE_CTTY if (!ctty) dissociate_if_controlling_tty (fd); #endif diff --git a/src/w32.c b/src/w32.c index 341f4d3fef3..5ac1bc3eb7c 100644 --- a/src/w32.c +++ b/src/w32.c @@ -1597,7 +1597,7 @@ init_environment (char ** argv) see if it succeeds. But I think that's too much to ask. */ /* MSVCRT's _access crashes with D_OK. */ - if (tmp && sys_faccessat (AT_FDCWD, tmp, D_OK, AT_EACCESS) == 0) + if (tmp && sys_access (tmp, D_OK) == 0) { char * var = alloca (strlen (tmp) + 8); sprintf (var, "TMPDIR=%s", tmp); @@ -2714,16 +2714,10 @@ logon_network_drive (const char *path) long file names. */ int -sys_faccessat (int dirfd, const char * path, int mode, int flags) +sys_access (const char * path, int mode) { DWORD attributes; - if (dirfd != AT_FDCWD) - { - errno = EINVAL; - return -1; - } - /* MSVCRT implementation of 'access' doesn't recognize D_OK, and its newer versions blow up when passed D_OK. */ path = map_w32_filename (path, NULL); @@ -2966,7 +2960,7 @@ sys_mktemp (char * template) { int save_errno = errno; p[0] = first_char[i]; - if (sys_faccessat (AT_FDCWD, template, F_OK, AT_EACCESS) < 0) + if (sys_access (template, 0) < 0) { errno = save_errno; return template; @@ -4017,7 +4011,7 @@ symlink (char const *filename, char const *linkname) { /* Non-absolute FILENAME is understood as being relative to LINKNAME's directory. We need to prepend that directory to - FILENAME to get correct results from sys_faccessat below, since + FILENAME to get correct results from sys_access below, since otherwise it will interpret FILENAME relative to the directory where the Emacs process runs. Note that make-symbolic-link always makes sure LINKNAME is a fully @@ -4031,10 +4025,10 @@ symlink (char const *filename, char const *linkname) strncpy (tem, linkfn, p - linkfn); tem[p - linkfn] = '\0'; strcat (tem, filename); - dir_access = sys_faccessat (AT_FDCWD, tem, D_OK, AT_EACCESS); + dir_access = sys_access (tem, D_OK); } else - dir_access = sys_faccessat (AT_FDCWD, filename, D_OK, AT_EACCESS); + dir_access = sys_access (filename, D_OK); /* Since Windows distinguishes between symlinks to directories and to files, we provide a kludgy feature: if FILENAME doesn't diff --git a/src/xrdb.c b/src/xrdb.c index 982a6e46a13..9d056a607e4 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -21,7 +21,6 @@ along with GNU Emacs. If not, see . */ #include -#include #include #include #include @@ -262,8 +261,11 @@ gethomedir (void) static int file_p (const char *filename) { - return (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) == 0 - && ! file_directory_p (filename)); + struct stat status; + + return (access (filename, 4) == 0 /* exists and is readable */ + && stat (filename, &status) == 0 /* get the status */ + && (S_ISDIR (status.st_mode)) == 0); /* not a directory */ } From 1a6e7e3807367b94c144d06fc2bdd1eb195731f7 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Fri, 19 Oct 2012 19:42:02 -0800 Subject: [PATCH 14/18] Unbreak starting an X11 frame from a non-X11 Emacs daemon --- lisp/ChangeLog | 6 ++++++ lisp/frame.el | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 096e9a52916..690aaa70eac 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2012-10-20 Daniel Colascione + + * frame.el (make-frame): Set x-display-name as we used to in order + to unbreak creating an X11 frame from an Emacs daemon started + without a display. + 2012-10-19 Stefan Monnier * minibuffer.el (minibuffer-force-complete): Make the next completion use diff --git a/lisp/frame.el b/lisp/frame.el index b7b61bcc576..7a54efc23e7 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -655,6 +655,8 @@ the new frame according to its own rules." (error "Don't know how to create a frame on window system %s" w)) (unless (get w 'window-system-initialized) + (unless x-display-name + (setq x-display-name display)) (funcall (cdr (assq w window-system-initialization-alist))) (put w 'window-system-initialized t)) From 4c9e95500fc913ad934e65c6625114e3f5532078 Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Fri, 19 Oct 2012 23:14:32 -0500 Subject: [PATCH 15/18] calc/calc-units.el (math-extract-units): Properly extract powers of units. --- lisp/ChangeLog | 5 +++++ lisp/calc/calc-units.el | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 690aaa70eac..7830f8312da 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-10-20 Jay Belanger + + * calc/calc-units.el (math-extract-units): Properly extract powers + of units. + 2012-10-20 Daniel Colascione * frame.el (make-frame): Set x-display-name as we used to in order diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el index 39f710f8322..58646ea114c 100644 --- a/lisp/calc/calc-units.el +++ b/lisp/calc/calc-units.el @@ -1481,10 +1481,16 @@ If COMP or STD is non-nil, put that in the units table instead." (mapcar 'math-remove-units (cdr expr)))))) (defun math-extract-units (expr) - (if (memq (car-safe expr) '(* /)) - (cons (car expr) - (mapcar 'math-extract-units (cdr expr))) - (if (math-check-unit-name expr) expr 1))) + (cond + ((memq (car-safe expr) '(* /)) + (cons (car expr) + (mapcar 'math-extract-units (cdr expr)))) + ((and + (eq (car-safe expr) '^) + (math-check-unit-name (nth 1 expr))) + expr) + ((math-check-unit-name expr) expr) + (t 1))) (defun math-build-units-table-buffer (enter-buffer) (if (not (and math-units-table math-units-table-buffer-valid From 2068905bb73c32afb4bb5e908b438fbd8b80bb64 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 20 Oct 2012 12:01:19 +0200 Subject: [PATCH 16/18] Fix bug #12395 with doc strings silently omitted from DOC on MS-Windows. lib-src/make-docfile.c (scan_lisp_file): Barf if called with a .el file other than one of a small list of supported un-compiled files. lib-src/makefile.w32-in (lisp1, lisp2): Name .elc files wherever they exist. lisp/loadup.el: Update comment about uncompiled Lisp files. --- lib-src/ChangeLog | 9 ++++++++ lib-src/make-docfile.c | 33 ++++++++++++++++++++++++++--- lib-src/makefile.w32-in | 46 ++++++++++++++++++++--------------------- lisp/ChangeLog | 4 ++++ lisp/loadup.el | 3 ++- 5 files changed, 68 insertions(+), 27 deletions(-) diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 1f28000e110..07fd4658172 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,12 @@ +2012-10-20 Eli Zaretskii + + Prevent silent omission of doc strings from uncompile Lisp files. + * make-docfile.c (scan_lisp_file): Barf if called with a .el file + other than one of a small list of supported un-compiled files. + + * makefile.w32-in (lisp1, lisp2): Name .elc files wherever they + exist. (Bug#12395) + 2012-10-17 Eli Zaretskii * ntlib.c: Include , to avoid compiler warning about diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 411b7057861..555a563d748 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -1025,9 +1025,9 @@ scan_c_file (char *filename, const char *mode) arglist, but the doc string must still have a backslash and newline immediately after the double quote. The only source files that must follow this convention are preloaded - uncompiled ones like loaddefs.el and bindings.el; aside - from that, it is always the .elc file that we look at, and they are no - problem because byte-compiler output follows this convention. + uncompiled ones like loaddefs.el; aside from that, it is always the .elc + file that we should look at, and they are no problem because byte-compiler + output follows this convention. The NAME and DOCSTRING are output. NAME is preceded by `F' for a function or `V' for a variable. An entry is output only if DOCSTRING has \ newline just after the opening ". @@ -1104,9 +1104,36 @@ scan_lisp_file (const char *filename, const char *mode) FILE *infile; register int c; char *saved_string = 0; + /* These are the only files that are loaded uncompiled, and must + follow the conventions of the doc strings expected by this + function. These conventions are automatically followed by the + byte compiler when it produces the .elc files. */ + static struct { + const char *fn; + size_t fl; + } uncompiled[] = { + { "loaddefs.el", sizeof("loaddefs.el") - 1 }, + { "loadup.el", sizeof("loadup.el") - 1 }, + { "charprop.el", sizeof("charprop.el") - 1 } + }; + int i, match; + size_t flen = strlen (filename); if (generate_globals) fatal ("scanning lisp file when -g specified", 0); + if (!strcmp (filename + flen - 3, ".el")) + { + for (i = 0, match = 0; i < sizeof(uncompiled)/sizeof(uncompiled[0]); i++) + { + if (!strcmp (filename + flen - uncompiled[i].fl, uncompiled[i].fn)) + { + match = 1; + break; + } + } + if (!match) + fatal ("uncompiled lisp file %s is not supported", filename); + } infile = fopen (filename, mode); if (infile == NULL) diff --git a/lib-src/makefile.w32-in b/lib-src/makefile.w32-in index ecc5fb866b3..640e8a7c468 100644 --- a/lib-src/makefile.w32-in +++ b/lib-src/makefile.w32-in @@ -209,38 +209,38 @@ lisp1= \ $(lispsource)emacs-lisp/map-ynp.elc \ $(lispsource)menu-bar.elc \ $(lispsource)international/mule.elc \ - $(lispsource)international/mule-conf.el \ + $(lispsource)international/mule-conf.elc \ $(lispsource)international/mule-cmds.elc \ $(lispsource)international/characters.elc \ $(lispsource)international/charprop.el \ $(lispsource)case-table.elc lisp2 = \ - $(lispsource)language/chinese.el \ - $(lispsource)language/cyrillic.el \ - $(lispsource)language/indian.el \ - $(lispsource)language/sinhala.el \ - $(lispsource)language/english.el \ + $(lispsource)language/chinese.elc \ + $(lispsource)language/cyrillic.elc \ + $(lispsource)language/indian.elc \ + $(lispsource)language/sinhala.elc \ + $(lispsource)language/english.elc \ $(lispsource)language/ethiopic.elc \ $(lispsource)language/european.elc \ - $(lispsource)language/czech.el \ - $(lispsource)language/slovak.el \ - $(lispsource)language/romanian.el \ - $(lispsource)language/greek.el \ + $(lispsource)language/czech.elc \ + $(lispsource)language/slovak.elc \ + $(lispsource)language/romanian.elc \ + $(lispsource)language/greek.elc \ $(lispsource)language/hebrew.elc \ - $(lispsource)language/japanese.el \ - $(lispsource)language/korean.el \ - $(lispsource)language/lao.el \ - $(lispsource)language/cham.el \ - $(lispsource)language/tai-viet.el \ - $(lispsource)language/thai.el \ + $(lispsource)language/japanese.elc \ + $(lispsource)language/korean.elc \ + $(lispsource)language/lao.elc \ + $(lispsource)language/cham.elc \ + $(lispsource)language/tai-viet.elc \ + $(lispsource)language/thai.elc \ $(lispsource)language/tibetan.elc \ - $(lispsource)language/vietnamese.el \ - $(lispsource)language/misc-lang.el \ - $(lispsource)language/utf-8-lang.el \ - $(lispsource)language/georgian.el \ - $(lispsource)language/khmer.el \ - $(lispsource)language/burmese.el \ + $(lispsource)language/vietnamese.elc \ + $(lispsource)language/misc-lang.elc \ + $(lispsource)language/utf-8-lang.elc \ + $(lispsource)language/georgian.elc \ + $(lispsource)language/khmer.elc \ + $(lispsource)language/burmese.elc \ $(lispsource)register.elc \ $(lispsource)replace.elc \ $(lispsource)simple.elc \ @@ -266,7 +266,7 @@ lisp2 = \ $(WINDOW_SUPPORT) \ $(lispsource)widget.elc \ $(lispsource)window.elc \ - $(lispsource)version.el + $(lispsource)version.elc # This is needed the first time we build the tree, since temacs.exe # does not exist yet, and the DOC rule needs it to rebuild DOC whenever diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7830f8312da..323ba976c80 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2012-10-20 Eli Zaretskii + + * loadup.el: Update comment about uncompiled Lisp files. (Bug#12395) + 2012-10-20 Jay Belanger * calc/calc-units.el (math-extract-units): Properly extract powers diff --git a/lisp/loadup.el b/lisp/loadup.el index e0f5c6265b9..e5f2cb014d3 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -38,7 +38,8 @@ ;; doc strings in the dumped Emacs.) Because of this: ;; ii) If the file is loaded uncompiled, it should (where possible) -;; obey the doc-string conventions expected by make-docfile. +;; obey the doc-string conventions expected by make-docfile. It +;; should also be added to the uncompiled[] list in make-docfile.c. ;;; Code: From 79e1997aa81717a59d134c677b1fdcf7eb12d257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Sat, 20 Oct 2012 19:34:06 +0800 Subject: [PATCH 17/18] * progmodes/flymake.el (flymake-create-temp-inplace): Use file-truename. Patch from: http://lists.gnu.org/archive/html/emacs-devel/2012-07/msg00444.html --- lisp/ChangeLog | 5 +++++ lisp/progmodes/flymake.el | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 323ba976c80..dfd18592d0e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-10-20 Chong Yidong + + * progmodes/flymake.el (flymake-create-temp-inplace): Use + file-truename. + 2012-10-20 Eli Zaretskii * loadup.el: Update comment about uncompiled Lisp files. (Bug#12395) diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 26d4a399c2d..2614af9ffa4 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -1535,10 +1535,11 @@ if ARG is omitted or nil." (error "Invalid file-name")) (or prefix (setq prefix "flymake")) - (let* ((temp-name (concat (file-name-sans-extension file-name) - "_" prefix - (and (file-name-extension file-name) - (concat "." (file-name-extension file-name)))))) + (let* ((ext (file-name-extension file-name)) + (temp-name (file-truename + (concat (file-name-sans-extension file-name) + "_" prefix + (and ext (concat "." ext)))))) (flymake-log 3 "create-temp-inplace: file=%s temp=%s" file-name temp-name) temp-name)) From 3503c798921ee6b8f1cc960d9406b69623eb5470 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sat, 20 Oct 2012 19:35:05 +0800 Subject: [PATCH 18/18] Fix last ChangeLog entry. --- lisp/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dfd18592d0e..96267eacb89 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,4 +1,4 @@ -2012-10-20 Chong Yidong +2012-10-20 Arne Jørgensen * progmodes/flymake.el (flymake-create-temp-inplace): Use file-truename.