This is a backport from the trunk, consisting of:
2012-11-17 Eli Zaretskii <eliz@gnu.org>
* nt/inc/sys/wait.h: New file, with prototype of waitpid and
definitions of macros it needs.
* nt/inc/ms-w32.h (wait): Don't define, 'wait' is not used anymore.
(sys_wait): Remove prototype.
* nt/config.nt (HAVE_SYS_WAIT_H): Define to 1.
* src/w32proc.c (create_child): Don't clip the PID of the child
process to fit into an Emacs integer, as this is no longer a
restriction.
(waitpid): Rename from sys_wait. Emulate a Posix 'waitpid' by
reaping only the process specified by PID argument, if that is
positive. Use PID instead of dead_child to know which process to
reap. Wait for the child to die only if WNOHANG is not in
OPTIONS.
(sys_select): Don't set dead_child.
* src/sysdep.c (wait_for_termination_1): Remove the WINDOWSNT portion,
as it is no longer needed.
* src/process.c (waitpid, WUNTRACED) [!WNOHANG]: Remove definitions,
no longer needed.
(record_child_status_change): Remove the setting of
record_at_most_one_child for the !WNOHANG case.
2012-11-03 Paul Eggert <eggert@cs.ucla.edu>
Fix a race condition that causes Emacs to mess up glib (Bug#8855).
This is a backport from the trunk.
The symptom is a diagnostic "GLib-WARNING **: In call to
g_spawn_sync(), exit status of a child process was requested but
SIGCHLD action was set to SIG_IGN and ECHILD was received by
waitpid(), so exit status can't be returned." The diagnostic
is partly wrong, as the SIGCHLD action is not set to SIG_IGN.
The real bug is a race condition between Emacs and glib: Emacs
does a waitpid (-1, ...) and reaps glib's subprocess by mistake,
so that glib can't find it. Work around the bug by invoking
waitpid only on subprocesses that Emacs itself creates.
* src/process.c (create_process, record_child_status_change):
Don't use special value -1 in pid field, as the caller now must
know the pid rather than having the callee infer it. The
inference was sometimes incorrect anyway, due to another race.
(create_process): Set new 'alive' member if child is created.
(process_status_retrieved): New function.
(record_child_status_change): Use it.
Accept negative 1st argument, which means to wait for the
processes that Emacs already knows about. Move special-case code
for DOS_NT (which lacks WNOHANG) here, from caller. Keep track of
processes that have already been waited for, by testing and
clearing new 'alive' member.
(CAN_HANDLE_MULTIPLE_CHILDREN): Remove, as record_child_status_change
now does this internally.
(handle_child_signal): Let record_child_status_change do all
the work, since we do not want to reap all exited child processes,
only the child processes that Emacs itself created.
* src/process.h (Lisp_Process): New boolean member 'alive'.
* admin/CPP-DEFINES (HAVE_CLOSEDIR, HAVE_DIRENT_H): Remove.
* admin/notes/copyright: Adjust to src/ndir.h -> nt/inc/dirent.h renaming.
* configure.ac: Do not check for dirent.h or closdir.
* nt/inc/dirent.h: Rename from ../src/ndir.h, with these changes:
(struct dirent): Rename from struct direct. All uses changed.
* nt/inc/sys/dir.h: Remove.
* src/dired.c: Assume HAVE_DIRENT_H.
(NAMLEN): Remove, replacing with ...
(dirent_namelen): New function. All uses changed. Use the GNU macro
_D_EXACT_NAMELEN if available, as it's faster than strlen.
(DIRENTRY): Remove, replacing all uses with 'struct dirent'.
(DIRENTRY_NONEMPTY): Remove. All callers now assume it's nonzero.
* src/makefile.w32-in (DIR_H): Remove. All uses replaced with
$(NT_INC)/dirent.h.
($(BLD)/w32.$(O)): Do not depend on $(SRC)/ndir.h.
* src/ndir.h: Rename to ../nt/inc/dirent.h.
* src/sysdep.h (closedir) [!HAVE_CLOSEDIR]: Remove.
Do not include <dirent.h>; no longer needed.
* src/w32.c: Include <dirent.h> rather than "ndir.h".
Fixes: debbugs:12958
* admin/CPP-DEFINES (O_RDONLY, O_RDWR, HAVE_FCNTL_H): Remove.
* admin/merge-gnulib (GNULIB_MODULES): Add fcntl-h.
* configure.ac: Do not check for fcntl.h.
* lib/gnulib.mk: Regenerate.
* lib-src/movemail.c, lib-src/update-game-score.c: Assume <fcntl.h> exists.
* nt/inc/sys/socket.h (O_NONBLOCK): Rename from O_NDELAY, since the
POSIX name for this flag is O_NONBLOCK. All uses changed.
* nt/inc/unistd.h (O_RDWR, O_NOCTTY): New macros. Like AT_FDCWD etc.
these really should be moved to a replacement <fcntl.h> if and
when that gets implemented. In the meantime, include <fcntl.h>
to make sure we don't override its definitions.
* src/callproc.c (relocate_fd): Assume F_DUPFD.
* src/emacs.c, src/term.c (O_RDWR): Remove.
* src/keyboard.c (tty_read_avail_input): Use O_NONBLOCK rather than
O_NDELAY, since O_NONBLOCK is the standard name for this flag.
* src/nsterm.m: Assume <fcntl.h> exists.
* src/process.c (NON_BLOCKING_CONNECT, allocate_pty, create_process)
(create_pty, Fmake_network_process, server_accept_connection)
(wait_reading_process_output, init_process_emacs):
Assume O_NONBLOCK.
(wait_reading_process_output): Put in a special case for WINDOWSNT
to mimick the older behavior where it had O_NDELAY but not O_NONBLOCK.
It's not clear this is needed, but it's a more-conservative change.
(create_process): Assume FD_CLOEXEC.
(create_process, create_pty): Assume O_NOCTTY.
* src/sysdep.c (init_sys_modes, reset_sys_modes): Assume F_SETFL.
(reset_sys_modes): Use O_NONBLOCK rather than O_NDELAY.
Omit if not DOS_NT, since F_GETFL is not defined there.
(serial_open): Assume O_NONBLOCK and O_NOCTTY.
* src/term.c: Include <fcntl.h>, for flags like O_NOCTTY.
(O_NOCTTY): Remove.
(init_tty): Assume O_IGNORE_CTTY is defined to 0 on platforms that
lack it, since gnulib guarantees this.
* src/w32.c (fcntl): Test for O_NONBLOCK rather than O_NDELAY.
Fixes: debbugs:12881
nt/inc/sys/wait.h: New file, with prototype of waitpid and
definitions of macros it needs.
nt/inc/ms-w32.h (wait): Don't define, 'wait' is not used anymore.
(sys_wait): Remove prototype.
nt/config.nt (HAVE_SYS_WAIT_H): Define to 1.
src/w32proc.c (create_child): Don't clip the PID of the child
process to fit into an Emacs integer, as this is no longer a
restriction.
(waitpid): Rename from sys_wait. Emulate a Posix 'waitpid' by
reaping only the process specified by PID argument, if that is
positive. Use PID instead of dead_child to know which process to
reap. Wait for the child to die only if WNOHANG is not in
OPTIONS.
(sys_select): Don't set dead_child.
src/sysdep.c (wait_for_termination_1): Remove the WINDOWSNT portion,
as it is no longer needed.
src/process.c (waitpid, WUNTRACED) [!WNOHANG]: Remove definitions,
no longer needed.
(record_child_status_change): Remove the setting of
record_at_most_one_child for the !WNOHANG case.
nt/inc/unistd.h (faccessat): Add prototype.
(AT_FDCWD, AT_EACCESS, AT_SYMLINK_NOFOLLOW): New macros; the first
2 moved from ms-w32.h.
nt/inc/ms-w32.h (AT_FDCWD, AT_EACCESS, faccessat): Remove macros.
src/w32.c (faccessat): Rename from sys_faccessat. (No need to use a
different name, as the MS runtime does not have such a function,
and probably never will.) All callers changed. Ignore DIRFD
value if PATH is an absolute file name, to match Posix spec
better. If AT_SYMLINK_NOFOLLOW is set in FLAGS, don't resolve
symlinks.
Fixes: debbugs:12632
This fixes a bug that has been present in Emacs since its creation.
It was reported by Chris Torek in 1983 even before GNU Emacs existed,
which must set some sort of record. (Torek's bug report was against
a predecessor of GNU Emacs, but GNU Emacs happened to have the
same common flaw.) See Torek's Usenet posting
"setuid/setgid programs & Emacs" Article-I.D.: sri-arpa.858
Posted: Fri Apr 8 14:18:56 1983.
* .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, check_writable)
(Ffile_readable_p):
* src/lread.c (openp, load_path_check):
* src/process.c (allocate_pty):
* src/xrdb.c (file_p):
Use effective UID when checking permissions, not real UID.
* src/callproc.c (init_callproc):
* src/charset.c (init_charset):
* src/lread.c (load_path_check, init_lread):
Test whether directories are accessible, not merely whether they exist.
* src/conf_post.h (GNULIB_SUPPORT_ONLY_AT_FDCWD): New macro.
* src/fileio.c (check_existing, check_executable, check_writable)
(Ffile_readable_p):
Use symbolic names instead of integers for the flags, as they're
portable now.
(check_writable): New arg AMODE. All uses changed.
Set errno on failure.
(Ffile_readable_p): Use faccessat, not stat + open + close.
(Ffile_writable_p): No need to call check_existing + check_writable.
Just call check_writable and then look at errno. This saves a syscall.
dir should never be nil; replace an unnecessary runtime check
with an eassert. When checking the parent directory of a nonexistent
file, check that the directory is searchable as well as writable, as
we can't create files in unsearchable directories.
(file_directory_p): New function, which uses 'stat' on most platforms
but faccessat with D_OK (for efficiency) if WINDOWSNT.
(Ffile_directory_p, Fset_file_times): Use it.
(file_accessible_directory_p): New function, which uses a single
syscall for efficiency.
(Ffile_accessible_directory_p): Use it.
* src/xrdb.c (file_p): Use file_directory_p.
* src/lisp.h (file_directory_p, file_accessible_directory_p): New decls.
* 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.
(dir_warning): First arg is now a usage string, not a format.
Use errno. All uses changed.
* src/nsterm.m (ns_term_init): Remove unnecessary call to file-readable
that merely introduced a race.
* src/process.c, src/sysdep.c, src/term.c: All uses of '#ifdef O_NONBLOCK'
changed to '#if O_NONBLOCK', to accommodate gnulib O_* style,
and similarly for the other O_* flags.
* src/w32.c (sys_faccessat): Rename from sys_access and switch to
faccessat's API. All uses changed.
* src/xrdb.c: Do not include <sys/stat.h>; no longer needed.
(magic_db): Rename from magic_file_p.
(magic_db, search_magic_path): Return an XrmDatabase rather than a
char *, so that we don't have to test for file existence
separately from opening the file for reading. This removes a race
fixes a permission-checking problem, and simplifies the code.
All uses changed.
(file_p): Remove; no longer needed.
Fixes: debbugs:12632
src/w32term.h (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK): Define for x64.
(SET_SCROLL_BAR_W32_WINDOW): Cast ID to intptr_t, for
compatibility with x64.
src/w32term.c (w32_draw_underwave): Don't use GCC extensions for
defining an XRectangle structure.
src/w32proc.c (RVA_TO_PTR, w32_executable_type): Fix pointer
arithmetics for compatibility with x64.
src/w32menu.c (add_menu_item): Use UINT_PTR instead of UINT, for
compatibility with x64.
src/w32heap.h: Adjust prototypes and declarations.
src/w32heap.c (RVA_TO_PTR, allocate_heap, sbrk, init_heap)
(round_heap): Use DWORD_PTR, ptrdiff_t and size_t instead of
DWORD, long, and unsigned long, for compatibility with x64.
(allocate_heap) [_WIN64]: Reserve 32GB of memory.
(sbrk): Argument is now of type ptrdiff_t.
src/w32fns.c (HMONITOR): Condition declaration on _WIN32_WINNT being
less than 0x0500.
(w32_msg_pump): Use WPARAM type for 'result'.
src/w32.c (init_environment, get_emacs_configuration): Support AMD64
architecture.
(init_ntproc): Cast arguments of _open_osfhandle to intptr_t, for
compatibility with x64.
src/vm-limit.c (lim_data): Now size_t.
(check_memory_limits): Adjust prototypes of real_morecore and
__morecore to receive argument of type ptrdiff_t. Use size_t for
five_percent and data_size.
src/unexw32.c: Use DWORD_PTR instead of DWORD for file-scope
variables, for compatibility with x64.
(rva_to_section, offset_to_section, relocate_offset)
(OFFSET_TO_RVA, RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET)
(PTR_TO_RVA, RVA_TO_PTR, OFFSET_TO_PTR, get_section_info)
(copy_executable_and_dump_data): Use DWORD_PTR instead of DWORD
for compatibility with x64.
src/sysdep.c (STDERR_FILENO): Define if not already defined.
src/ralloc.c (real_morecore): Argument type is now ptrdiff_t.
(__morecore): Argument type is now ptrdiff_t.
(ROUNDUP, MEM_ROUNDUP): Use size_t instead of 'unsigned long'.
(relinquish): Use ptrdiff_t type for 'excess'.
(r_alloc_sbrk): Argument type is now ptrdiff_t.
src/makefile.w32-in (HEAPSIZE): Get value from EMACS_HEAPSIZE.
(bootstrap-temacs-CMD, bootstrap-temacs-SH): Use $(EMACS_PURESIZE)
instead of a literal number.
src/gmalloc.c [WINDOWSNT]: Include w32heap.h.
(min): Define only if not already defined.
src/frame.c (x_report_frame_params): Use EMACS_UINT for the return
value of FRAME_X_WINDOW, to fit a 64-bit pointer on 64-bit Windows
hosts.
src/image.c (x_bitmap_pixmap): Return ptrdiff_t, not int, since
'bitmaps' is a pointer.
src/dispextern.h (x_bitmap_pixmap): Adjust prototype.
src/alloc.c (gdb_make_enums_visible): Now conditional on __GNUC__.
nt/makefile.w32-in ($(TRES)): Use $(EMACS_MANIFEST).
nt/inc/sys/socket.h: Don't map Winsock error codes to standard ones
that are already defined.
nt/inc/ms-w32.h (EMACS_INT, EMACS_UINT, EMACS_INT_MAX, PRIuMAX)
(pI, _INTPTR) [_MSC_VER]: Fix definitions for MSVC.
[_MSC_VER]: Add pragmas to suppress some MSVC warnings.
nt/preprep.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_move_sections, ADJUST_IMPORT_RVA, main): Use
DWORD_PTR instead of DWORD for compatibility with x64.
nt/nmake.defs: Support AMD64.
(EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST): New macros.
nt/gmake.defs: (EMACS_HEAPSIZE, EMACS_PURESIZE, EMACS_MANIFEST):
New macros.
nt/addsection.c (pfnCheckSumMappedFile, rva_to_section)
(offset_to_section, relocate_offset, OFFSET_TO_RVA)
(RVA_TO_OFFSET, RVA_TO_SECTION_OFFSET, PTR_TO_RVA)
(OFFSET_TO_PTR, ROUND_UP, ROUND_DOWN)
(copy_executable_and_add_section, main): Use DWORD_PTR instead of
DWORD, for compatibility with x64.
nt/emacs-x64.manifest: New file.
nt/emacs-x86.manifest: Renamed from emacs.manifest.
lib-src/ntlib.c (gettimeofday): Copy from src/w32.c. lib/gettime.
needs this function.
src/w32proc.c (sig_mask, crit_sig): New static variables.
(sys_signal): Support SIGALRM and SIGPROF.
(sigemptyset, sigaddset, sigfillset, sigprocmask)
(pthread_sigmask, setpgrp): Moved here from w32.c. sigaddset,
sigfillset, and sigprocmask are no longer no-ops.
(sigismember): New function.
(struct itimer_data): New definition.
(ticks_now, real_itimer, prof_itimer, clocks_min, crit_real)
(crit_prof): New static variables.
(MAX_SINGLE_SLEEP): New definition.
(timer_loop, stop_timer_thread, term_timers, init_timers)
(start_timer_thread, getitimer, setitimer): New functions.
(alarm): No longer a no-op, calls setitimer.
src/w32.c (term_ntproc): Call term_timers.
(init_ntproc): Make sure all signals are unblocked at startup, to
erase any traces of dumping. Call init_timers.
src/w32fns.c (hourglass_timer, HOURGLASS_ID): Remove.
Windows-specific code to display the hourglass mouse pointer is no
longer used.
(w32_wnd_proc): Remove code that handled the WM_TIMER message due
to hourglass timer expiration.
(start_hourglass, cancel_hourglass, DEFAULT_HOURGLASS_DELAY):
Remove, no longer used.
(w32_note_current_window, show_hourglass, hide_hourglass): New
functions, in support of hourglass cursor display similar to other
window systems.
(syms_of_w32fns): Don't initialize hourglass_timer.
src/xdisp.c (start_hourglass, cancel_hourglass): Now used on
WINDOWSNT as well.
(start_hourglass) [WINDOWSNT]: Call w32_note_current_window.
src/w32.h (init_timers, term_timers): Add prototypes.
nt/inc/sys/time.h (ITIMER_REAL, ITIMER_PROF): Define.
(struct itimerval): Define.
(getitimer, setitimer): Add prototypes.
nt/inc/ms-w32.h <sigset_t> [_MSVC_VER]: Make the typedef consistent
with MinGW.
(SA_RESTART, SIGPROF): Define.
nt/config.nt (HAVE_SETITIMER): Define to 1.
src/.gdbinit: Set breakpoint on terminate_due_to_signal, not on
fatal_error_backtrace.
src/w32proc.c (sys_kill): Undo last change: don't do anything when
invoked to deliver SIGABRT to our own process. This is now
handled by emacs_raise.
nt/inc/ms-w32.h (emacs_raise): Redefine to invoke emacs_abort.
Fixes: debbugs:12471
* nt/inc/ms-w32.h (emacs_raise): New macro.
* src/alloc.c (die):
* src/sysdep.c (emacs_abort) [HAVE_NTGUI]:
Avoid recursive loop if there's a fatal error in the function itself.
* src/atimer.c (pending_atimers):
* src/blockinput.h: Don't include "atimer.h"; no longer needed.
(interrupt_input_pending): Remove. All uses removed.
pending_signals now counts both atimers and ordinary interrupts.
This is less racy than having three separate pending-signal flags.
(block_input, unblock_input, totally_unblock_input, unblock_input_to)
(input_blocked_p):
Rename from their upper-case counterparts BLOCK_INPUT,
UNBLOCK_INPUT, TOTALLY_UNBLOCK_INPUT, UNBLOCK_INPUT_TO,
INPUT_BLOCKED_P, and turn into functions. All uses changed.
This makes it easier to access volatile variables more accurately.
(BLOCK_INPUT_RESIGNAL): Remove. All uses replaced by unblock_input ().
(input_blocked_p): Prefer this to 'interrupt_input_blocked', as
that's more reliable if the code is buggy and sets
interrupt_input_blocked to a negative value. All uses changed.
* src/atimer.c (deliver_alarm_signal):
Remove. No need to deliver this to the parent; any thread can
handle this signal now. All uses replaced by underlying handler.
* src/atimer.c (turn_on_atimers):
* src/dispnew.c (handle_window_change_signal):
* src/emacs.c (handle_danger_signal):
* src/keyboard.c (kbd_buffer_get_event):
Don't reestablish signal handler; not needed with sigaction.
* src/blockinput.h (UNBLOCK_INPUT_TO, TOTALLY_UNBLOCK_INPUT)
(UNBLOCK_INPUT_TO):
Rework to avoid unnecessary accesses to volatile variables.
(UNBLOCK_INPUT_TO): Now a function.
(totally_unblock_input, unblock_input): New decls.
* src/data.c (handle_arith_signal, deliver_arith_signal): Move to sysdep.c
(init_data): Remove. Necessary stuff now done in init_signal.
* src/emacs.c, src/xdisp.c: Include "atimer.h", since we invoke atimer functions.
* src/emacs.c (handle_fatal_signal, deliver_fatal_signal): Move to sysdep.c.
(fatal_error_code): Remove; no longer needed.
(terminate_due_to_signal): Rename from fatal_error_backtrace, since
it doesn't always backtrace. All uses changed. No need to reset
signal to default, since sigaction and/or die does that for us now.
Use emacs_raise (FOO), not kill (getpid (), FOO).
(main): Check more-accurately whether we're dumping.
Move fatal-error setup to sysdep.c
* src/floatfns.c: Do not include "syssignal.h"; no longer needed.
* src/gtkutil.c (xg_get_file_name, xg_get_font):
Remove no-longer-needed signal-mask manipulation.
* src/keyboard.c, src/process.c (POLL_FOR_INPUT):
Don't depend on USE_ASYNC_EVENTS, a symbol that is never defined.
* src/keyboard.c (read_avail_input): Remove.
All uses replaced by gobble_input.
(Ftop_level): Use TOTALLY_UNBLOCK_INPUT rather than open code.
(kbd_buffer_store_event_hold, gobble_input):
(record_asynch_buffer_change) [USABLE_SIGIO]:
(store_user_signal_events):
No need to mess with signal mask.
(gobble_input): If blocking input and there are terminals, simply
set pending_signals to 1 and return. All hooks changed to not
worry about whether input is blocked.
(process_pending_signals): Clear pending_signals before processing
them, in case a signal comes in while we're processing.
By convention callers now test pending_signals before calling us.
(UNBLOCK_INPUT_TO, unblock_input, totally_unblock_input):
New functions, to support changes to blockinput.h.
(handle_input_available_signal): Now extern.
(reinvoke_input_signal): Remove. All uses replaced by
handle_async_input.
(quit_count): Now volatile, since a signal handler uses it.
(handle_interrupt): Now takes bool IN_SIGNAL_HANDLER as arg. All
callers changed. Block SIGINT only if not already blocked.
Clear sigmask reliably, even if Fsignal returns, which it can.
Omit unnecessary accesses to volatile var.
(quit_throw_to_read_char): No need to restore sigmask.
* src/keyboard.c (gobble_input, handle_user_signal):
* src/process.c (wait_reading_process_output):
Call signal-handling code rather than killing ourselves.
* src/lisp.h: Include <float.h>, for...
(IEEE_FLOATING_POINT): New macro, moved here to avoid duplication.
(pending_signals): Now volatile.
(syms_of_data): Now const if IEEE floating point.
(handle_input_available_signal) [USABLE_SIGIO]:
(terminate_due_to_signal, record_child_status_change): New decls.
* src/process.c (create_process): Avoid disaster if memory is exhausted
while we're processing a vfork, by tightening the critical section
around the vfork.
(send_process_frame, process_sent_to, handle_pipe_signal)
(deliver_pipe_signal): Remove. No longer needed, as Emacs now
ignores SIGPIPE.
(send_process): No need for setjmp/longjmp any more, since the
SIGPIPE stuff is now gone. Instead, report an error if errno
is EPIPE.
(record_child_status_change): Now extern. PID and W are now args.
Return void, not bool. All callers changed.
* src/sysdep.c (wait_debugging) [(BSD_SYSTEM || HPUX) && !defined (__GNU__)]:
Remove. All uses removed. This bug should be fixed now in a
different way.
(wait_for_termination_1): Use waitpid rather than sigsuspend,
and record the child status change directly. This avoids the
need to futz with the signal mask.
(process_fatal_action): Move here from emacs.c.
(emacs_sigaction_flags): New function, containing
much of what used to be in emacs_sigaction_init.
(emacs_sigaction_init): Use it. Block nonfatal system signals that are
caught by emacs, to make races less likely.
(deliver_process_signal): Rename from handle_on_main_thread.
All uses changed.
(BACKTRACE_LIMIT_MAX): Now at top level.
(thread_backtrace_buffer, threadback_backtrace_pointers):
New static vars.
(deliver_thread_signal, deliver_fatal_thread_signal):
New functions, for more-accurate delivery of thread-specific signals.
(handle_fatal_signal, deliver_fatal_signal): Move here from emacs.c.
(deliver_arith_signal): Handle in this thread, not
in the main thread, since it's triggered by this thread.
(maybe_fatal_sig): New function.
(init_signals): New arg DUMPING so that we can be more accurate
about whether we're dumping. Caller changed.
Treat thread-specific signals differently from process-general signals.
Block all signals while handling fatal error; that's safer.
xsignal from SIGFPE only on non-IEEE hosts, treating it as fatal
on IEEE hosts.
When batch, ignore SIGHUP, SIGINT, SIGTERM if they were already ignored.
Ignore SIGPIPE unless batch.
(emacs_backtrace): Output backtrace for the appropriate thread,
which is not necessarily the main thread.
* src/syssignal.h: Include <stdbool.h>.
(emacs_raise): New macro.
* src/xterm.c (x_connection_signal): Remove; no longer needed
now that we use sigaction.
(x_connection_closed): No need to mess with sigmask now.
(x_initialize): No need to reset SIGPIPE handler here, since
init_signals does this for us now.
Fixes: debbugs:12471
Do not try to redefine the 'abort' function. Instead, redo
the code so that it calls 'emacs_abort' rather than 'abort'.
This removes the need for the NO_ABORT configure-time macro
and makes it easier to change the abort code to do a backtrace.
* configure.ac (NO_ABRT): Remove.
* admin/CPP-DEFINES (NO_ABORT): Remove.
* nt/inc/ms-w32.h (w32_abort) [HAVE_NTGUI]: Remove.
* src/.gdbinit: Just stop at emacs_abort, not at w32_abort or abort.
* src/emacs.c (abort) [!DOS_NT && !NO_ABORT]:
Remove; sysdep.c's emacs_abort now takes its place.
* src/lisp.h (emacs_abort): New decl. All calls from Emacs code to
'abort' changed to use 'emacs_abort'.
* src/msdos.c (dos_abort) [defined abort]: Remove; not used.
(abort) [!defined abort]: Rename to ...
(emacs_abort): ... new name.
* src/sysdep.c (emacs_abort) [!HAVE_NTGUI]: New function, taking
the place of the old 'abort' in emacs.c.
* src/w32.c, src/w32fns.c (abort): Do not #undef.
* src/w32.c (emacs_abort): Rename from w32_abort.
This change streamlines the window system selection code in
configure.in and moves many common function declarations from
window-specific headers to frame.h. It introduces a new TERM_HEADER
macro in config.h: we set this macro to the right header to use for
the window system for which we're compiling Emacs and have source
files include it indirectly. This way, we don't have to teach every
file about every window system.
(DOS_NT, MSDOS): New macros.
(WRETCODE, wait3): Remove.
* nt/inc/ms-w32.h (DOS_NT): Remove; defined in config.nt.
* lib-src/makefile.w32-in (LOCAL_FLAGS): Remove WINDOWSNT and DOS_NT,
they are always defined in config.h.
src/w32.c: Include winioctl.h and aclapi.h.
(is_symlink, chase_symlinks, enable_privilege, restore_privilege)
(revert_to_self): Forward declarations of static functions.
<static BOOL g_b_init_get_security_info>:
<g_b_init_create_symbolic_link>: New static flags.
(globals_of_w32): Initialize them to zero.
(GetSecurityInfo_Proc, CreateSymbolicLink_Proc): New typedefs.
(map_w32_filename): Improve commentary. Simplify switch.
(SYMBOLIC_LINK_FLAG_DIRECTORY): Define if not defined in system
headers (most versions of MinGW w32api don't).
(get_security_info, create_symbolic_link)
(get_file_security_desc_by_handle, is_symlink, chase_symlinks):
New functions.
(sys_access, sys_chmod): Call 'chase_symlinks' to resolve symlinks
in the argument file name.
(sys_access): Call unc_volume_file_attributes only if
GetFileAttributes fails with network-related error codes.
(sys_rename): Diagnose renaming of a symlink when the user doesn't
have the required privileges.
(get_file_security_desc_by_name): Renamed from
get_file_security_desc.
(stat_worker): New function, with most of the guts of 'stat', and
with addition of handling of symlinks and support for 'lstat'. If
possible, get file's attributes and security information by
handle, not by name. Produce S_IFLNK bit for symlinks, when
called from 'lstat'.
(stat, lstat): New functions, call 'stat_worker'.
(symlink, readlink, careadlinkat): Rewritten to create and resolve
symlinks when the underlying filesystem supports them.
lib/src/ntlib.c (lstat): New function, calls 'stat'.
nt/inc/sys/stat.h (S_IFLNK): Define.
(S_ISLNK): A non-trivial definition.
(lstat): Prototype instead of a macro that redirects to 'stat'.
lisp/files.el (file-truename): Don't skip symlink-chasing part on
windows-nt. Incorporate the resolution of 8+3 short aliases on
Windows into the loop that recursively chases symlinks. Compare
directory and its parent case-insensitively on MS-Windows and
MS-DOS.
etc/NEWS: Announce the symlink support on MS-Windows.
* nt/inc/ms-w32.h: Move here from ../src/s.
* nt/config.nt (config_opsysfile): Change to <ms-w32.h>.
* s/ms-w32.h: Move to ../nt/inc.
* src/makefile.w32-in (TAGS, TAGS-gmake, MS_W32_H):
Update for new ms-w32.h location.
* lib-src/makefile.w32-in (MS_W32_H): Update for new ms-w32.h location.
* lib/makefile.w32-in (MS_W32_H): Update for new ms-w32.h location.
* lisp/emacs-lisp/authors.el (authors-renamed-files-alist): Add ms-w32.h.
lib/makefile.w32-in ($(BLD)/dtotimespec.$(O)):
($(BLD)/timespec-add.$(O)):
($(BLD)/timespec-sub.$(O)): Don't depend on
$(EMACS_ROOT)/nt/inc/sys/time.h.
lib/stat-time.h:
lib/timespec.h:
lib/utimens.h: Revert last change.
src/makefile.w32-in (TIMESPEC_H): Remove nt/inc/sys/time.h.
(SYSTIME_H): Add nt/inc/sys/time.h.
src/systime.h [WINDOWSNT]: Include sys/time.h.
src/s/ms-w32.h (struct timespec): Definition moved from
nt/inc/sys/time.h. Suggested by Paul Eggert <eggert@cs.ucla.edu>.
nt/inc/sys/time.h (struct timespec): Don't define it here, it is
now defined in src/s/ms-w32.h.
Fixes: debbugs:9000
lib/makefile.w32-in ($(BLD)/md5.$(O)):
($(BLD)/sha1.$(O)):
($(BLD)/sha256.$(O)):
($(BLD)/sha512.$(O)): Depend on $(EMACS_ROOT)/nt/inc/stdalign.h.
Suggested by Christoph Scholtes <cschol2112@googlemail.com>.
lib/getopt_.h: Regenerate.
nt/inc/stdalign.h: New file.
Fixes: debbugs:11527
Parts of the changes by Fabrice Popineau <fabrice.popineau@supelec.fr>.
lib-src/makefile.w32-in (LOCAL_FLAGS): Add $(EMACS_EXTRA_C_FLAGS).
lib-src/emacsclient.c (main) <environ>: Remove declaration, already
pulled in by unistd.h on Posix hosts and stdlib.h on MS-Windows.
nt/inc/stdint.h (uint32_t, uint64_t) [_WIN64]: New typedefs.
(UINT64_MAX) [_WIN64]: Fix definition.
(uintmax_t, intmax_t): Fix definitions.
nt/inc/inttypes.h (strtoumax, strtoimax) [!__MINGW32__]: Provide
correct definitions.
nt/config.nt (HAVE_DECL_STRTOLL): Define.
(va_copy) [_WIN64]: Provide a better definition.
src/s/ms-w32.h (utimbuf) [_MSC_VER]: Don't define.
(snprintf) [_MSC_VER]: Redirect to _snprintf.
(strtoll) [_MSC_VER]: Redirect to _strtoi64.
(malloc, free, realloc, calloc): Redirect to e_* only when
compiling Emacs.
src/lisp.h (GCTYPEBITS): Move before first use.
(ALIGN_GCTYPEBITS) [_MSC_VER]: Define.
(DECL_ALIGN) [_MSC_VER]: Use it, as MSVC doesn't like bit ops in
this macro definition.
(tzname): Redirect to _tzname for all values of _MSC_VER.
Fixes: debbugs:9960
nt/inc/inttypes.h [!__MINGW32__]: Include stdint.h. Move the
definition of uintmax_t from here...
nt/inc/stdint.h (uintmax_t): ...to here.
(intptr_t) [!__GNUC__]: New typedef.
nt/inc/stdint.h: New file, to support compilation with tool chains
that do not have stdint.h (e.g. MSVC).
lib/makefile.w32-in: ($(BLD)/md5.$(O)): Added dependency on
$(EMACS_ROOT)/nt/inc/stdint.h.
inc/pwd.h (struct passwd): Change the types of pw_uid and pw_gid to unsigned.
(getpwuid): Argument is now unsigned.
uid_t is now unsigned.
ntlib.c (setuid): Argument is now unsigned.
(getuid): Return value is now unsigned.
(getpwuid): Argument is now unsigned.
(fchown): UID and GID arguments are now unsigned.
ntlib.h (fchown): UID and GID arguments are now unsigned.
(getuid): Return value is now unsigned.
(setuid): Argument is now unsigned.
(getpwuid): Remove prototype (it's declared in nt/inc/pwd.h).
w32.c (getpwuid): Change argument type to unsigned.
(struct w32_id): Change type of `rid' member to unsigned.
(w32_cached_id, w32_add_to_cache, get_name_and_id): Change type of
argument ID to unsigned. All callers changed.
(getuid, geteuid, getgid, getegid): Change return type to unsigned.