1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00
Commit Graph

212 Commits

Author SHA1 Message Date
Eli Zaretskii
d133cf8394 Support non-blocking connect on MS-Windows (Bug#20207)
Based on ideas from Kim F. Storm <storm@cua.dk>, see
 http://lists.gnu.org/archive/html/emacs-devel/2006-12/msg00873.html.

 src/w32proc.c (reader_thread): If the FILE_CONNECT flag is set, call
 '_sys_wait_connect'.  If it returns STATUS_CONNECT_FAILED, exit
 the thread with code 2.
 (sys_select): Support 'wfds' in addition to 'rfds'.  If a
 descriptor in 'wfds' has its bit set, but the corresponding
 fd_info member doesn't have its FILE_CONNECT flag set, ignore the
 descriptor.  Otherwise, acknowledge a successful non-blocking
 connect by resetting the FILE_CONNECT flag and setting cp->status
 to STATUS_READ_ACKNOWLEDGED.
 src/w32.h (STATUS_CONNECT_FAILED): New enumeration value.
 (struct _child_process): New member 'errcode'.
 (FILE_CONNECT): New flag.
 (_sys_wait_connect): Add prototype.
 src/w32.c (pfn_WSAEnumNetworkEvents): New function pointer.
 (init_winsock): Load WSAEnumNetworkEvents from winsock DLL.
 (set_errno): Map WSAEWOULDBLOCK and WSAENOTCONN.
 (sys_connect): Support non-blocking 'connect' calls by setting the
 FILE_CONNECT flag in the fd_info member and returning EINPROGRESS.
 (_sys_read_ahead): Add debug message if this function is called
 for a descriptor that waits for a non-blocking connect to complete.
 (_sys_wait_connect): New function.
 (sys_read): Support STATUS_CONNECT_FAILED.  Return the error code
 recorded by _sys_wait_connect when the non-blocking connect
 failed.  Don't call WSAGetLastError before a call to set_errno had
 a chance to use its value, since WSAGetLastError clears the last
 error.

 nt/inc/ms-w32.h (BROKEN_NON_BLOCKING_CONNECT): Don't define.
2015-03-27 12:44:31 +03:00
Mark Laws
805fe50708 Support daemon mode on MS-Windows (bug#19688)
src/emacs.c <w32_daemon_event> [WINDOWSNT]: New global var.
 (main) [WINDOWSNT]: Initialize it to NULL.  Create the event to
 signal clients we are ready for connections.
 (Fdaemon_initialized): Use DAEMON_RUNNING.
 [WINDOWSNT]: MS-Windows specific code to signal clients we are
 ready for connections.
 src/lisp.h (DAEMON_RUNNING): New macro, encapsulates Posix and
 MS-Windows conditions for running in daemon mode.
 src/minibuf.c (read_minibuf): Use DAEMON_RUNNING.
 src/keyboard.c (kbd_buffer_get_event): Use DAEMON_RUNNING.
 src/dispnew.c (init_display) [WINDOWSNT]: Initialize frames/terminal
 even in daemon mode.

 nt/inc/ms-w32.h (W32_DAEMON_EVENT): New macro.

 lib-src/emacsclient.c (decode_options) [WINDOWSNT]: Don't reject empty
 arguments for --alternate-editor.
 (print_help_and_exit) [WINDOWSNT]: Don't refrain from advertising
 empty arguments for --alternate-editor.
 (start_daemon_and_retry_set_socket) [WINDOWSNT]: MS-Windows
 specific code to start Emacs in daemon mode and wait for it to be
 ready for client connections.

 lisp/server.el (server-process-filter): Force GUI frames on
 MS-Windows in daemon mode, even if a TTY frame was requested.
 lisp/frameset.el (frameset-keep-original-display-p): Don't assume
 windows-nt cannot be in daemon mode.
 lisp/frame.el (window-system-for-display): Don't assume windows-nt
 cannot be in daemon mode.
2015-02-27 12:43:30 +02:00
Paul Eggert
7e09ef09a4 Update copyright year to 2015
Run admin/update-copyright.
2015-01-01 14:26:41 -08:00
Ted Zlatanov
ba4502fe14 Merge branch 'emacs-24'
Conflicts:
	nt/addsection.c
	nt/inc/ms-w32.h
	src/w32.c
2014-11-26 21:31:11 -05:00
Oscar Fuentes
81e0cca7bb Define MINGW_W64 and use it instead of _W64
... for detecting MinGW-w64. _W64 is not specific of MinGW-w64, it is
defined for compatibility with MS VC++.

	* nt/inc/ms-w32.h: Define MINGW_W64.

	* admin/CPP-DEFINES: Mention MINGW_W64.

	* nt/addpm.c: Use it.

	* nt/addsection.c: Use it.

	* nt/preprep.c: Use it.

	* src/w32.c: Use MINGW_W64 instead of _W64

	* src/w32term.c: Likewise.
2014-11-17 23:10:00 +01:00
Dmitry Antipov
ea633fff4c * configure.ac (POLL_FOR_INPUT): Define with HAVE_WINDOW_SYSTEM.
* nt/inc/ms-w32.h (POLL_FOR_INPUT): Likewise.
* src/keyboard.c, src/process.c: Do not define POLL_FOR_INPUT here
because it will be defined in generated config.h if needed.
2014-06-05 10:24:54 +04:00
Fabrice Popineau
587fd086a0 Use mmap(2) emulation for buffer text on MS-Windows.
src/Makefile.in (C_HEAP_SWITCH): Get the predefined heap size from
 configure.
 (ADDSECTION, MINGW_TEMACS_POST_LINK): Remove, no longer used.
 src/lisp.h (NONPOINTER_BITS): Modify the condition to define to zero
 for MinGW, since it no longer uses gmalloc.
 src/buffer.c: Do not define mmap allocations functions for Windows.
 Remove mmap_find which is unused. Remove mmap_set_vars which does
 nothing useful.
 [WINDOWSNT]: Include w32heap.h.
 (init_buffer): Always allocate new memory for buffers.
 src/emacs.c: Remove mmap_set_vars calls.
 src/image.c (free_image): Undef free for Windows because it is
 redirected to our private version.
 src/unexw32.c (COPY_PROC_CHUNK): Use %p format for 64bits
 compatibility.
 (copy_executable_and_dump_data): Remove dumping the heap section.
 (unexec): Restore using_dynamic_heap after dumping.
 src/w32heap.c (dumped_data_commit, malloc_after_dump)
 (malloc_before_dump, realloc_after_dump, realloc_before_dump)
 (free_after_dump, free_before_dump, mmap_alloc, mmap_realloc)
 (mmap_free): New functions.
 src/w32heap.h: Declare dumped_data and mmap_* function prototypes.

 nt/inc/ms-w32.h: Switch to the system heap allocation scheme
 instead of GNU malloc and ralloc.
 nt/inc/sys/mman.h: New file.
 nt/INSTALL: Update for the new build requirements.

 etc/NEWS: Mention build changes on MS-Windows.

 configure.ac (C_HEAP_SWITCH) define for different values of
 dumped heap size depending on 32/64bits arch on Windows.
 Don't check for pthreads.h on MinGW32/64, it gets in the way.
 Use mmap(2) for buffers and system malloc for MinGW32/64.
2014-05-27 20:31:17 +03:00
Eli Zaretskii
e3188b2df1 Fix redefinition warning in MinGW64 build.
nt/inc/ms-w32.h (lseek): Define only if not already a macro.
 Suggested by Fabrice Popineau <fabrice.popineau@gmail.com>.
2014-04-21 09:37:21 +03:00
Claudio Bley
f0b5cd897f Fix MS-Windows build with MinGW runtime 4.x.
nt/inc/sys/stat.h (_WSTAT_DEFINED): Define, to avoid compilation
 failures when wchar.h is included.
2014-01-11 16:48:51 +02:00
Fabrice Popineau
e05d3a05bf Fix minor build problems related to MinGW64.
configure.ac: Read $srcdir/nt/mingw-cfg.site when $MSYSTEM is
 "MINGW64" as well.

 nt/inc/ms-w32.h (pthread_sigmask): Undefine if defined, for MinGW64.

 src/unexw32.c (_start) [__MINGW64__]: Define to __start.
2014-01-11 15:36:06 +02:00
Paul Eggert
06827ec842 Spelling fixes.
* mail/unrmail.el (unrmail-mbox-format): Choice is mboxo, not mboxro.
* woman.el (woman-mark-horizontal-position):
Rename from woman-mark-horizonal-position.  Use changed.
2014-01-09 23:10:37 -08:00
Paul Eggert
ba3189039a Update copyright year to 2014 by running admin/update-copyright. 2014-01-01 07:43:34 +00:00
Fabrice Popineau
bd717ca4f4 Minor fixes for MinGW64 build.
configure.ac (canonical, C_SWITCH_SYSTEM): Support a 64-bit
 MinGW64 build on MS-Windows.

 nt/inc/ms-w32.h (sys_kill): Fix prototype.

 src/w32term.c (w32_initialize): Use LCID and LOWORD.
 src/w32proc.c (create_child): Use pid_t for 5th argument.
 (IsValidLocale): Don't provide prototype for MinGW64.
 (Fw32_get_valid_keyboard_layouts, Fw32_get_keyboard_layout)
 (Fw32_set_keyboard_layout): Use HKL and HIWORD/LOWORD.
 src/w32heap.c (allocate_heap) [_WIN64]: Use "ull", not "i64", which
 MinGW64 doesn't support.
 src/lisp.h (EMACS_INT) [_WIN64]: Define for the MinGW64 build.
2013-12-31 18:01:34 +02:00
Eli Zaretskii
1b7259fce2 Fix bug #16299 with assertion violation in set-default-file-modes on Windows.
src/w32.c (sys_umask): New function.

 nt/inc/ms-w32.h (umask) [emacs]: Redirect to sys_umask.
2013-12-30 19:51:28 +02:00
Eli Zaretskii
ce1d7b61f1 Merge from trunk. 2013-12-07 19:21:57 +02:00
Stefan Monnier
7cdf484be3 * configure.ac (HAVE_MENUS): Remove.
* src/xmenu.c (Fmenu_or_popup_active_p):
* src/window.c (Fset_window_configuration):
* src/menu.c (Fx_popup_menu, Fx_popup_dialog):
* src/keyboard.c (record_menu_key, read_char_x_menu_prompt):
* src/fns.c (Fyes_or_no_p):
* src/editfns.c (Fmessage_box, Fmessage_or_box):
* src/alloc.c (make_save_ptr_ptr):
* src/xdisp.c, src/w32menu.c, src/term.c, src/xterm.h, src/xterm.c:
Remove HAVE_MENUS.
2013-11-28 20:22:40 -05:00
Eli Zaretskii
0b9de7cd60 Dirent functions and directory-files are converted and work. 2013-11-09 14:49:02 +02:00
Eli Zaretskii
03d58cca81 Start; wrote conversion from UTF-8 to UTF-16 and ANSI. 2013-10-19 21:17:01 +03:00
Eli Zaretskii
279066b2b3 Attempt to fix time_t related problems with MinGW 4.0 runtime.
nt/inc/mingw_time.h: New file.
 nt/inc/ms-w32.h: Include mingw_time.h instead of doing its job.

 src/w32proc.c: Include mingw_time.h.
 src/w32.c: Include mingw_time.h.
2013-10-14 19:23:10 +03:00
Eli Zaretskii
2f4586ad04 Make the MinGW32 build compatible with MinGW runtime 4.x.
nt/inc/dirent.h (struct dirent) [__MINGW_MAJOR_VERSION >= 4]: Make
 the layout of 'struct dirent' be compatible with MinGW32 runtime
 versions 4.0 and later.
 nt/inc/ms-w32.h (__MINGW_MAJOR_VERSION, __MINGW_MINOR_VERSION)
 (__MINGW_PATCHLEVEL) [!__MINGW64_VERSION_MAJOR]: Define, if not
 defined, but not for MinGW64.
 (_USE_32BIT_TIME_T) [__MINGW64_VERSION_MAJOR]: Define, to force
 use of 32-bit time_t type.
2013-10-12 16:11:14 +03:00
Eli Zaretskii
6e9fb70cdf Fix MS-Windows build.
src/callproc.c: 
 src/emacs.c: 
 src/filelock.c: 
 src/process.c: 
 src/sysdep.c: 
 src/w32.c: Reshuffle Windows-specific headers to avoid errors with
 redefinition of fd_set etc.
 src/process.c: Don't use num_pending_connects when
 NON_BLOCKING_CONNECT is not defined.
 src/sysselect.h: Move definitions of FD_* macros and of SELECT_TYPE
 here from w32.h.
 src/w32proc.c (sys_select): Adjust the argument types to what
 thread.h expects.

 nt/inc/sys/socket.h: Include stdint.h.  Include sysselect.h instead
 of w32.h.
2013-08-26 21:42:11 +03:00
Eli Zaretskii
484ab23924 Minor fix of the last commit. 2013-08-04 18:43:10 +03:00
Eli Zaretskii
63f5c6c20d Implement mkostemp for MS-Windows.
nt/mingw-cfg.site (ac_cv_func_mkostemp): New var with value of "yes".
 nt/inc/ms-w32.h (mkostemp): Declare prototype.
 nt/config.nt (HAVE_MKOSTEMP): Define to 1.

 src/w32.c (mkostemp): New function.
 (mktemp): Remove, no longer used.  Most of the code reused in mkostemp.

Fixes: debbugs:15015
2013-08-04 18:32:12 +03:00
Eli Zaretskii
1d44267275 MS-Windows followup for 2013-07-07T18:00:14Z!eggert@cs.ucla.edu.
nt/inc/sys/socket.h (F_SETFD, O_CLOEXEC, F_DUPFD_CLOEXEC)
 (FD_CLOEXEC): New macros.

 src/w32.c (sys_dup): Declare prototype.

 src/filelock.c:
 src/emacs.c:
 src/callproc.c [WINDOWSNT]: Include sys/socket.h.
2013-07-07 21:48:16 +03:00
Paul Eggert
067428c171 Make file descriptors close-on-exec when possible.
This simplifies Emacs a bit, since it no longer needs to worry
about closing file descriptors by hand in some cases.
It also fixes some unlikely races.  Not all such races, as
libraries often open files internally without setting
close-on-exec, but it's an improvement.
* admin/merge-gnulib (GNULIB_MODULES): Add fcntl, pipe2.
(GNULIB_TOOL_FLAGS): Avoid binary-io, close.  Do not avoid fcntl.
* configure.ac (mkostemp): New function to check for.
(PTY_OPEN): Pass O_CLOEXEC to posix_openpt.
* lib/fcntl.c, lib/getdtablesize.c, lib/pipe2.c, m4/fcntl.m4:
* m4/getdtablesize.m4, m4/pipe2.m4: New files, taken from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* nt/gnulib.mk: Remove empty gl_GNULIB_ENABLED_verify section;
otherwise, gnulib-tool complains given close-on-exec changes.
* nt/inc/ms-w32.h (pipe): Remove.
* nt/mingw-cfg.site (ac_cv_func_fcntl, gl_cv_func_fcntl_f_dupfd_cloexec)
(gl_cv_func_fcntl_f_dupfd_works, ac_cv_func_pipe2): New vars.
* src/alloc.c (valid_pointer_p) [!WINDOWSNT]:
* src/callproc.c (Fcall_process) [!MSDOS]:
* src/emacs.c (main) [!DOS_NT]:
* src/nsterm.m (ns_term_init):
* src/process.c (create_process):
Use 'pipe2' with O_CLOEXEC instead of 'pipe'.
* src/emacs.c (Fcall_process_region) [HAVE_MKOSTEMP]:
* src/filelock.c (create_lock_file) [HAVE_MKOSTEMP]:
Prefer mkostemp with O_CLOEXEC to mkstemp.
* src/callproc.c (relocate_fd) [!WINDOWSNT]:
* src/emacs.c (main): Use F_DUPFD_CLOEXEC, not plain F_DUPFD.
No need to use fcntl (..., F_SETFD, FD_CLOEXEC), since we're
now using pipe2.
* src/filelock.c (create_lock_file) [! HAVE_MKOSTEMP]:
Make the resulting file descriptor close-on-exec.
* src/lisp.h, src/lread.c, src/process.c (close_load_descs, close_process_descs):
* src/lread.c (load_descriptor_list, load_descriptor_unwind):
Remove; no longer needed.  All uses removed.
* src/process.c (SOCK_CLOEXEC): Define to 0 if not supplied by system.
(close_on_exec, accept4, process_socket) [!SOCK_CLOEXEC]:
New functions.
(socket) [!SOCK_CLOEXEC]: Supply a substitute.
(Fmake_network_process, Fnetwork_interface_list):
(Fnetwork_interface_info, server_accept_connection):
Make newly-created socket close-on-exec.
* src/sysdep.c (emacs_open, emacs_fopen):
Make new-created descriptor close-on-exec.
* src/w32.c (fcntl): Support F_DUPFD_CLOEXEC well enough for Emacs.
* src/w32.c, src/w32.h (pipe2): Rename from 'pipe', with new flags arg.

Fixes: debbugs:14803
2013-07-07 11:00:14 -07:00
Eli Zaretskii
e2d8a6f0a2 Attempt to resolve gettimeofday compilation errors with MinGW64.
src/w32.c (gettimeofday): Make the signature identical to prototype
 in nt/inc/sys/time.h.

 nt/inc/sys/time.h (struct timeval): Remove the _W64 guards.
2013-06-03 20:15:44 +03:00
Eli Zaretskii
32e2d7287f Fix compilation error on MinGW64 due to nt/inc/sys/time.h.
nt/inc/sys/time.h [!_TIMEZONE_DEFINED]: Define _TIMEZONE_DEFINED to
 avoid multiple definition errors on MinGW64.
2013-06-01 10:07:22 +03:00
Eli Zaretskii
2a157a5d33 Fix compile errors in nt/inc/sys/time.h when using nt/configure.bat.
nt/inc/sys/time.h (gettimeofday): Use '__restrict' instead of
 'restrict', which is a C99 extension.  See
 http://lists.gnu.org/archive/html/emacs-devel/2013-05/msg00588.html
 and the following discussion for the problem this caused in the
 old nt/configure.bat build.
2013-05-31 11:47:18 +03:00
Eli Zaretskii
721c9e8a68 Define SIZE_MAX for MSVC, part of bug #14409.
nt/inc/stdint.h (SIZE_MAX) [!__GNUC__]: Define.
2013-05-16 20:31:25 +03:00
Eli Zaretskii
9e5b5c7934 Fixed nt/mingw-cfg.site to pass the configure step. 2013-05-15 20:06:26 +03:00
Eli Zaretskii
d14365f941 Merge from trunk, configury not fixed yet. 2013-05-15 19:15:07 +03:00
Paul Eggert
ffdc270a76 Use Gnulib ACL implementation, for benefit of Solaris etc.
* configure.ac: Remove -with-acl option, since Gnulib does that for
us now.
(LIBACL_LIBS): Remove; no longer needed.
* lib/Makefile.am (CLEANFILES, SUFFIXES): New (empty) macros,
for the benefit of the new ACL implementation.
* lib/makefile.w32-in (GNULIBOBJS): Add $(BLD)/acl-errno-valid.$(O).
($(BLD)/acl-errno-valid.$(O)): New rule.
* lib/acl-errno-valid.c, lib/acl-internal.h, lib/acl.h:
* lib/acl_entries.c, lib/errno.in.h, lib/file-has-acl.c:
* lib/qcopy-acl.c, lib/qset-acl.c, m4/acl.m4, m4/errno_h.m4:
New files, taken from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* admin/merge-gnulib (GNULIB_MODULES): Add qacl.
(GNULIB_TOOL_FLAGS): Do not avoid errno.
* etc/NEWS: Emacs is no longer limited to POSIX ACLs.  --disable-acl,
not --without-acl, since we're now using Gnulib's implementation.
* nt/config.nt (HAVE_ACL_SET_FILE): Rename from HAVE_POSIX_ACL.
* nt/inc/ms-w32.h (EOPNOTSUPP): New macro.
* src/Makefile.in (LIB_ACL): New macro.
(LIBACL_LIBS): Remove.
(LIBES): Use LIB_ACL, not LIBACL_LIBS.
* src/fileio.c: Include <acl.h>.
Use HAVE_ACL_SET_FILE rather than HAVE_POSIX_ACL.
(ACL_NOT_WELL_SUPPORTED): Remove.  All uses replaced by
!acl_errno_valid.
(Fcopy_file) [!WINDOWSNT]: Use qcopy_acl instead of rolling
it ourselves.

Fixes: debbugs:14295
2013-05-07 14:34:03 -07:00
Eli Zaretskii
86e9346005 Fixed misc compilation warnings and errors. Dumping errors out. 2013-04-01 19:28:53 +03:00
Eli Zaretskii
a74b0e1bdf Added nt/gnulib.mk and removed kludges from ms-w32.h and ntlib.h. 2013-03-31 17:04:49 +03:00
Eli Zaretskii
7c4026b6ad Finished with lib-src compilation, except emacsclientw and emacsclient.res.
Next -- compilation in nt/, and then problems in src/.
2013-03-30 20:00:51 +03:00
Eli Zaretskii
fff1aa4e84 Fixed compilation problems in lib/. 2013-03-30 15:25:48 +03:00
Eli Zaretskii
8934438ad1 Fixed redefinition of EMACS_CONFIGURATION. 2013-03-30 14:10:41 +03:00
Eli Zaretskii
dc4cb8d518 Merge from trunk. 2013-03-30 10:24:44 +03:00
Eli Zaretskii
98f3b8c6be Move MS-Windows definition of TERM_HEADER from ms-w32.h to config.nt.
nt/inc/ms-w32.h (TERM_HEADER): Remove definition.
 nt/config.nt (TERM_HEADER): Move the definition to "w32term.h" from
 ms-w32.h.
2013-03-30 10:10:58 +03:00
Eli Zaretskii
627d532608 Merge from trunk. 2013-03-30 09:34:05 +03:00
Eli Zaretskii
668284362c Enable the 'copysign' primitive on MS-Windows.
nt/inc/ms-w32.h (copysign) [_MSC_VER]: Redirect to _copysign.
 nt/config.nt (HAVE_COPYSIGN): Define.
2013-03-30 09:12:49 +03:00
Eli Zaretskii
cb11bd957d Finished with config.nt diffs. Problem with mmsystem.h remains. 2013-03-29 22:53:25 +03:00
Eli Zaretskii
5d611e0450 Use 'restrict' in gettimeofday arguments, and make ms-w32.h compatible. 2013-03-28 22:51:26 +02:00
Eli Zaretskii
97dababa47 Fix the gettimeofday_timezone test. 2013-03-28 22:20:40 +02:00
Eli Zaretskii
d76bf86f43 Merge from trunk and resolve conflicts. 2013-03-28 20:13:59 +02:00
Eli Zaretskii
e0c3eb8913 Avoid MinGW64 compiler warnings.
nt/inc/ms-w32.h (sys_localtime) [_W64]: Provide a prototype, to
 avoid MinGW64 compiler warnings in editfns.c.
2013-03-27 10:40:24 +02:00
Eli Zaretskii
ee0fb40e7c Fix _setjmp calls for MinGW64.
nt/config.nt: Don't undefine HAVE__SETJMP here.
 nt/inc/ms-w32.h (HAVE__SETJMP) [_W64]: Undefine for MinGW64 here..
2013-03-26 22:30:43 +02:00
Eli Zaretskii
be3a31b22b Fix problem with _setjmp in MinGW64-compiled Emacs.
nt/inc/ms-w32.h (USE_NO_MINGW_SETJMP_TWO_ARGS): Don't define.
 nt/config.nt (HAVE__SETJMP) [!_W64]: Don't define for MinGW64, as
 its _setjmp accepts 2 arguments.
2013-03-26 19:32:52 +02:00
Eli Zaretskii
a18d7de614 Fix more MinGW64 incompatibilities.
Reported by ׃scar Fuentes in

  http://lists.gnu.org/archive/html/emacs-devel/2013-03/msg00733.html

 nt/inc/ms-w32.h (_WIN32_WINNT) [!_W64]: Don't define for MinGW64.
 nt/inc/sys/stat.h (chmod): Remove _CRTIMP from prototype.

 src/w32.c (_PROCESS_MEMORY_COUNTERS_EX) [_WIN32_WINNT < 0x0500]:
 Define only for _WIN32_WINNT less than 0x0500.
2013-03-26 15:45:01 +02:00
Eli Zaretskii
b88b62dec9 Fix more incompatibilities between MinGW.org and MinGW64 headers
Reported by ׃scar Fuentes in
  http://lists.gnu.org/archive/html/emacs-devel/2013-03/msg00699.html
and in
  http://lists.gnu.org/archive/html/emacs-devel/2013-03/msg00707.html.

 nt/inc/ms-w32.h (USE_NO_MINGW_SETJMP_TWO_ARGS) [_W64]: Define to 1.
 For MinGW64, include sys/types.h and time.h.
 nt/inc/sys/time.h (struct timeval) [!_W64]: Guard definition with _W64.
 (struct timezone) [!_TIMEZONE_DEFINED]: Guard definition with
 _TIMEZONE_DEFINED.
 nt/addpm.c (_WIN32_IE) [_W64]: For MinGW64, don't define to 0x400.
 nt/inc/sys/stat.h: Remove _CRTIMP from prototypes of fstat, stat,
 lstat, and fstatat.

 lib-src/ntlib.c (struct timespec) [!_TIMEZONE_DEFINED]: Define the
 struct only if _TIMEZONE_DEFINED is not defined.

 src/w32term.c (WCRANGE, GLYPHSET): Don't define if _W64 is defined.
 src/w32.c (REPARSE_DATA_BUFFER): Guard with
 MAXIMUM_REPARSE_DATA_BUFFER_SIZE being defined.
2013-03-26 10:21:27 +02:00
Eli Zaretskii
553fabe73a Fix incompatibilities between MinGW.org and MinGW64 headers
Problems were reported by ׃scar Fuentes in
 
  http://lists.gnu.org/archive/html/emacs-devel/2013-03/msg00611.html.

 nt/inc/ms-w32.h (struct timespec): Don't define if
 _TIMESPEC_DEFINED is already defined.
 (sigset_t) [!_POSIX]: Typedef for MinGW64.
 (_WIN32_WINNT, WIN32_LEAN_AND_MEAN): Move definitions before
 including the first system header, to avoid redefinition if some
 system header defines a default value.
 nt/inc/sys/time.h (struct itimerval): Don't define if
 _TIMESPEC_DEFINED is already defined.
2013-03-25 15:48:37 +02:00
Eli Zaretskii
53761081f7 Fix problems with MSVC build reported in bug #13939.
nt/inc/stdint.h (UINTPTR_MAX): Define.
 nt/nmake.defs (libc): Fix syntax of !if conditional.
2013-03-16 10:55:38 +02:00
Paul Eggert
47d7532e09 File synchronization fixes.
* admin/CPP-DEFINES (BSD_SYSTEM, HAVE_FSYNC): Remove.
* admin/merge-gnulib (GNULIB_MODULES): Add fsync, fdatasync.
* configure.ac (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed.
(fsync): Remove check; now done by gnulib.
* lib/fdatasync.c, lib/fsync.c, m4/fdatasync.m4, m4/fsync.m4:
New files, from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* lib-src/Makefile.in (LIB_FDATASYNC): New macro.
(emacsclient${EXEEXT}): Use it.
* lib-src/emacsclient.c (main): Use fdatasync, not fsync, since we don't
care about metadata.  Keep trying if interrupted.
* lib-src/movemail.c (main, popmail): Don't worry about BSD_SYSTEM, since
fsync is available everywhere (or there is a substitute).  Don't
report an error if fsync returns EINVAL.
* nt/inc/ms-w32.h (fdatasync): New macro, suggested by Eli Zaretskii.
* src/Makefile.in (LIB_FDATASYNC): New macro.
(LIBES): Use it.
* src/conf_post.h (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed.
* src/fileio.c (Fwrite_region, write_region_inhibit_fsync):
Don't worry about HAVE_FSYNC, since a substitute fsync is
available if the system lacks one.
(Fwrite_regin): Retry fsync if interrupted.

Fixes: debbugs:13944
2013-03-13 11:42:22 -07:00
Paul Eggert
707431575a FILE's lock is now always .#FILE and may be a regular file.
* etc/NEWS: Document this.
* nt/inc/unistd.h (O_NOFOLLOW): New macro.
* src/filelock.c: Include <c-ctype.h>.
(MAX_LFINFO): New top-level constant.
(lock_info_type): Remove members pid, boot_time.  Add members at,
dot, colon.  Change user member to be the entire buffer, not a
pointer.  This allows us to handle the case where a foreign
pid or boot time exceeds the local range.  All uses changed.
(LINKS_MIGHT_NOT_WORK): New constant.
(FREE_LOCK_INFO): Remove, as the pieces no longer need freeing.
(defined_WINDOWSNT): Remove.
(MAKE_LOCK_NAME, file_in_lock_file_name):
Always use .#FILE (not .#-FILE) for the file lock,
even if it is a regular file.
(rename_lock_file): New function.
(create_lock_file): Use it.
(create_lock_file, read_lock_data):
Prefer a symbolic link for the lock file, falling back on a
regular file if symlinks don't work.  Do not try to create
symlinks on MS-Windows, due to security hassles.  Stick with
POSIXish functions (open, read, write, close, fchmod, readlink, symlink,
link, rename, unlink, mkstemp) when creating locks, as a GNUish
host may be using a Windowsish file system, and cannot use
MS-Windows-only system calls.  Fall back on mktemp if mkstemp
doesn't work.  Don't fail merely because of a symlink-contents
length limit in the current file system; fall back on regular
files.  Increase the symlink contents length limit to 8 KiB, this
should be big enough for any real use and doesn't crunch the
stack.
(create_lock_file, lock_file_1, read_lock_data):
Simplify allocation of lock file buffers now that they fit in 8 KiB.
(lock_file_1): Return error number, not bool.  All callers changed.
(ELOOP): New macro, if not already defined.
(read_lock_data): Return size of lock file contents, not Lisp object.
All callers changed.  Handle a race condition if some other process
replaces a regular-file lock with a symlink lock or vice versa,
while we're trying to read the lock.
(current_lock_owner): Parse contents more carefully, to help avoid
confusing a regular-file lock with some other application's use
of the file.  Check for lock file contents being too long, or
not parsing correctly.
(current_lock_owner, lock_file):
Allow foreign pid and boot times that exceed the local range.
(current_lock_owner, lock_if_free, lock_file):
Simplify allocation of lock file contents.
* src/w32.c (sys_rename_replace): New function, containing most of
the contents of the old sys_rename.
(sys_rename): Use it.
(fchmod): New dummy function.
* src/w32.h (sys_rename_replace, fchmod): New decls.

Fixes: debbugs:13807
2013-03-05 14:35:41 -08:00
Eli Zaretskii
343a2aefb5 Implement CLASH_DETECTION for MS-Windows.
src/filelock.c [WINDOWSNT]: Include w32.h.
 (MAKE_LOCK_NAME): Don't use 'lock', it clashes with MS runtime
 function of that name.  Up-case the macro arguments.
 (IS_LOCK_FILE): New macro.
 (fill_in_lock_file_name): Use IS_LOCK_FILE instead of S_ISLNK.
 (create_lock_file): New function, with body extracted from
 lock_file_1.
 [WINDOWSNT]: Implement lock files by writing a regular file with
 the lock information as its contents.
 (read_lock_data): New function, on Posix platforms just calls
 emacs_readlinkat.
 [WINDOWSNT]: Read the lock info from the file.
 (current_lock_owner): Call read_lock_data instead of calling
 emacs_readlinkat directly.
 (lock_file) [WINDOWSNT]: Run the file name through
 dostounix_filename.
 src/w32proc.c (sys_kill): Support the case of SIG = 0, in which case
 just check if the process by that PID exists.
 src/w32.c (sys_open): Don't reset the _O_CREAT flag if _O_EXCL is
 also present, as doing so will fail to error out if the file
 already exists.
 src/makefile.w32-in ($(BLD)/filelock.$(O)): Depend on src/w32.h.

 nt/inc/ms-w32.h (BOOT_TIME_FILE): Define.
 nt/config.nt (CLASH_DETECTION): Define to 1.

 lisp/emacs-lisp/bytecomp.el (byte-recompile-directory): Reject files
 that match "\`\.#", to avoid compiling lock files, even if they
 are readable (as they are on MS-Windows).

 doc/emacs/files.texi (Interlocking): Don't refer to symlinks as the
 exclusive means of locking files.

 etc/NEWS: Mention support for lock files on MS-Windows.
2013-02-25 19:36:03 +02:00
Eli Zaretskii
c793958519 Remove functions and macros unused on MS-Windows.
src/w32.c (sys_chown): Remove unused function.

 nt/inc/ms-w32.h (chown, logb): Remove, unused.
2013-02-16 16:16:07 +02:00
Eli Zaretskii
cd91fb4b0a Don't use __STDC__ on MS-Windows unless necessary (Bug #9066).
nt/inc/ms-w32.h (__STDC__): Fiddle with value only for MSVC.

 src/w32term.c <input_signal_count>: Declare 'volatile' unconditionally.
2013-02-16 15:59:37 +02:00
Eli Zaretskii
8c0905acd1 MS-Windows followup for 2013-02-11T23:37:18Z!eggert@cs.ucla.edu.
lib/makefile.w32-in (GNULIBOBJS): Add $(BLD)/memrchr.$(O).
 ($(BLD)/memrchr.$(O)): New dependency.

 nt/inc/ms-w32.h: Add prototype for memrchr.
2013-02-12 05:52:04 +02:00
Paul Eggert
8654f9d7d6 Use fdopendir, fstatat and readlinkat, for efficiency.
On my host, this speeds up directory-files-and-attributes by a
factor of 3, when applied to Emacs's src directory.
These functions are standardized by POSIX and are common these
days; fall back on a (slower) gnulib implementation if the host
is too old to supply them.
* .bzrignore: Add lib/dirent.h.
* lib/Makefile.am (libgnu_a_SOURCES): Add openat-die.c, save-cwd.c.
* lib/careadlinkat.c, lib/careadlinkat.h: Merge from gnulib,
incorporating: 2013-01-29 careadlinkat: do not provide careadlinkatcwd.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* lib/dirent.in.h, lib/fdopendir.c, lib/fstatat.c, lib/openat-priv.h:
* lib/openat-proc.c, lib/openat.h, m4/dirent_h.m4, m4/fdopendir.m4:
* m4/fstatat.m4: New files, from gnulib.
* lib/openat-die.c, lib/save-cwd.c, lib/save-cwd.h: New files.
These last three are specific to Emacs and are not copied from gnulib.
They are simpler than the gnulib versions and are tuned for Emacs.
* admin/merge-gnulib (GNULIB_MODULES): Add fdopendir, fstatat, readlinkat.
(GNULIB_TOOL_FLAGS): Do not avoid at-internal, openat-h.
Avoid dup, open, opendir.
* nt/inc/sys/stat.h (fstatat):
* nt/inc/unistd.h (readlinkat): New decls.
* src/conf_post.h (GNULIB_SUPPORT_ONLY_AT_FDCWD): Remove.
* src/dired.c: Include <fcntl.h>.
(open_directory): New function, which uses open and fdopendir
rather than opendir.  DOS_NT platforms still use opendir, though.
(directory_files_internal, file_name_completion): Use it.
(file_attributes): New function, with most of the old Ffile_attributes.
(directory_files_internal, Ffile_attributes): Use it.
(file_attributes, file_name_completion_stat): First arg is now fd,
not dir name.  All uses changed.  Use fstatat rather than lstat +
stat.
(file_attributes): Use emacs_readlinkat rather than Ffile_symlink_p.
* src/fileio.c: Include <allocator.h>, <careadlinkat.h>.
(emacs_readlinkat): New function, with much of the old
Ffile_symlink_p, but with an fd argument for speed.
It uses readlinkat rather than careadlinkatcwd, so that it
need not assume the working directory.
(Ffile_symlink_p): Use it.
* src/filelock.c (current_lock_owner): Use emacs_readlinkat
rather than emacs_readlink.
* src/lisp.h (emacs_readlinkat): New decl.
(READLINK_BUFSIZE, emacs_readlink): Remove.
* src/sysdep.c: Do not include <allocator.h>, <careadlinkat.h>.
(emacs_norealloc_allocator, emacs_readlink): Remove.
This stuff is moved to fileio.c.
* src/w32.c (fstatat, readlinkat): New functions.
(careadlinkat): Don't check that fd == AT_FDCWD.
(careadlinkatcwd): Remove; no longer needed.

Fixes: debbugs:13539
2013-01-31 22:30:51 -08:00
Eli Zaretskii
cf01a35981 Make opendir on MS-Windows accept a 'const char *'.
src/w32.c (opendir): Now accepts a 'const char *'.

 nt/inc/dirent.h (opendir): Update prototype.
2013-01-28 16:41:08 +02:00
Eli Zaretskii
99a7a59166 MS-Windows followup to bugfix #13387.
nt/inc/unistd.h (O_IGNORE_CTTY): Define, as it is unconditionally
 used in term.c.
2013-01-11 11:33:54 +02:00
Paul Eggert
09b8afb6c8 Update copyright dates to 2013. 2013-01-02 08:30:50 -08:00
Paul Eggert
0877d0dc24 Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca 2013-01-02 08:13:04 -08:00
Paul Eggert
ab422c4d68 Update copyright notices for 2013. 2013-01-01 09:11:05 +00:00
Eli Zaretskii
c1860cdc02 Fix the MS-Windows build.
nt/inc/sys/stat.h (S_ISMPX): Define to zero, to accommodate changes
 in lib/filemode.c that broke the MS-Windows build.
 Suggested by Andy Moreton <andrewjmoreton@gmail.com>.
2012-12-24 17:56:17 +02:00
Eli Zaretskii
66447e07c1 Support Posix ACL APIs on MS-Windows.
src/w32.c: Include sddl.h and sys/acl.h.
 (SDDL_REVISION_1): Define if not already defined.
 (g_b_init_get_security_descriptor_dacl)
 (g_b_init_convert_sd_to_sddl, g_b_init_convert_sddl_to_sd)
 (g_b_init_is_valid_security_descriptor)
 (g_b_init_set_file_security): New static flags.
 (globals_of_w32): Initialize them to zero.
 (SetFileSecurity_Name): New string constant.
 (SetFileSecurity_Proc, GetSecurityDescriptorDacl_Proc)
 (ConvertStringSecurityDescriptorToSecurityDescriptor_Proc)
 (ConvertSecurityDescriptorToStringSecurityDescriptor_Proc)
 (IsValidSecurityDescriptor_Proc): New typedefs.
 (get_file_security, get_security_descriptor_owner)
 (get_security_descriptor_group): Set errno to ENOTSUP.
 (set_file_security, get_security_descriptor_dacl)
 (is_valid_security_descriptor, convert_sd_to_sddl)
 (convert_sddl_to_sd, acl_valid, acl_to_text, acl_from_text)
 (acl_free, acl_get_file, acl_set_file): New functions.
 src/fileio.c (Fcopy_file) [WINDOWSNT]: Support copying ACLs.

 nt/inc/sys/acl.h: New file.
 nt/inc/ms-w32.h (ENOTSUP): Define if undefined.
 nt/config.nt (HAVE_POSIX_ACL): Define.

 doc/lispref/files.texi (File Attributes, Changing Files): Update to include
 MS-Windows support for ACLs.
2012-12-17 21:14:34 +02:00
Eli Zaretskii
b07286179e Fix bug #13079 on MS-Windows with temp files not being deleted.
src/w32.h (_child_process): New members input_file and
 pending_deletion.
 (register_child): First argument is now pid_t.
 (record_infile, record_pending_deletion): New prototypes.
 src/w32proc.c (new_child): Initialize input_file and
 pending_deletion members of the child.
 (delete_child): Delete the child's temporary input file, if any,
 that is pending deletion.
 (register_child): First argument is now pid_t.
 (record_infile, record_pending_deletion): New functions.
 (reap_subprocess): Fix a typo in DebPrint string.
 (sys_spawnve, sys_kill): Use pid_t for PID arguments.
 src/fileio.c (internal_delete_file): Return an int again: non-zero
 if delete-file succeeds, zero otherwise.
 src/lisp.h (internal_delete_file): Adjust prototype.
 src/callproc.c (Fcall_process): Don't overwrite infile with result
 of DECODE_FILE.
 [WINDOWSNT] If BUFFER is an integer, i.e. we are launching an
 asynchronous subprocess, record the name of the input file name,
 if any.
 (delete_temp_file) [WINDOWSNT]: If internal_delete_file fails to
 delete the file, record it as pending deletion when the subprocess
 exits.

 nt/inc/ms-w32.h (sys_unlink): Provide prototype.
2012-12-15 15:38:21 +02:00
Eli Zaretskii
5c207910c4 Speed up most calls to 'stat' and 'lstat' on MS-Windows.
src/w32.c (stat_worker): If w32_stat_get_owner_group is zero, do not
 try to get accurate owner and group information from NT file
 security APIs.  This is to make most callers of 'stat' and
 'lstat', which don't need that information, much faster.
 src/dired.c (Ffile_attributes) [WINDOWSNT]: Set
 w32_stat_get_owner_group to a non-zero value, to request accurate
 owner and group information from 'lstat'.

 nt/inc/sys/stat.h: Declare w32_stat_get_owner_group.
2012-12-14 16:05:01 +02:00
Eli Zaretskii
8d1a544c11 Provide a prototype for unsetenv on MS-Windows.
nt/inc/unistd.h (unsetenv): Provide a prototype.
2012-12-10 00:10:18 +02:00
Eli Zaretskii
a16e75cd3c Fix putenv and unsetenv on MS-Windows.
src/w32.c (unsetenv): Return 0 if the input string is too long.

 nt/inc/ms-w32.h (sys_putenv): Add prototype.

Fixes: debbugs:13070
2012-12-08 20:27:37 +02:00
Eli Zaretskii
75ceee0567 Provide unsetenv for MS-Windows and make putenv Posix-compatible.
src/w32.c (unsetenv, sys_putenv): New functions.

 nt/inc/ms-w32.h (putenv): Redirect to sys_putenv.
 nt/config.nt (HAVE_UNSETENV): Define to 1.

Fixes: debbugs:13070
2012-12-08 13:32:10 +02:00
Eli Zaretskii
9e821c83d3 Fixed configure.ac and headers in nt/inc. Emulated functions not handled yet. 2012-11-24 18:02:07 +02:00
Paul Eggert
d454751173 Revert recent change for Bug#8855.
As reported by Harald Hanche-Olsen in
<http://lists.gnu.org/archive/html/emacs-devel/2012-11/msg00445.html>
the change introduces a further bug, of creating lots of zombie
processes in some cases.  Further work is needed to come up with a
better fix for Bug#8855.
2012-11-24 00:24:11 -08:00
Paul Eggert
6d4e8f62e9 Fix a race condition with glib (Bug#8855).
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'.
2012-11-23 14:20:31 -08:00
Paul Eggert
95ef7787fb Assume POSIX 1003.1-1988 or later for dirent.h.
* 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
2012-11-22 23:48:43 -08:00
Glenn Morris
6ef2e5ef52 Merge from emacs-24; up to 2012-11-17T22:12:47Z!eggert@cs.ucla.edu 2012-11-20 20:47:55 -08:00
Eli Zaretskii
3b0108c5ba Yet more fixes for bug #12878 with MSVC build.
nt/inc/stdint.h (INTPTR_MIN): Define for MSVC.
2012-11-20 19:07:55 +02:00
Eli Zaretskii
88c4a13c3b More fixes for bug #12878 with MS-Windows MSVC build.
src/xdisp.c (start_hourglass) [HAVE_NTGUI]: Don't mix declaration of
 w32_note_current_window with code.  (Backport from trunk.)
 src/w32.c (FILE_DEVICE_FILE_SYSTEM, METHOD_BUFFERED)
 (FILE_ANY_ACCESS, CTL_CODE, FSCTL_GET_REPARSE_POINT) [_MSC_VER]:
 Define for the MSVC compiler.
 src/w32term.h (EnumSystemLocalesW) [_MSC_VER]: Add a missing
 semi-colon.

 nt/inc/stdint.h (PTRDIFF_MIN) [!__GNUC__]: Define for MSVC.
2012-11-19 19:34:21 +02:00
Eli Zaretskii
031b541f19 Fix latest changes in nt/inc/unistd.h.
nt/inc/unistd.h: Don't include fcntl.h and don't define O_RDWR.

Fixes: debbugs:12881
2012-11-18 18:54:31 +02:00
Paul Eggert
49cdacdad3 Assume POSIX 1003.1-1988 or later for fcntl.h.
* 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
2012-11-17 14:12:47 -08:00
Eli Zaretskii
22bae83fa8 Fix bug #12829 with aborts on MS-Windows when several child processes die.
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-17 18:46:45 +02:00
Eli Zaretskii
14f207289c MS-Windows followup for 2012-11-14T04:55:41Z!eggert@cs.ucla.edu, regarding faccessat.
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
2012-11-14 19:22:55 +02:00
Paul Eggert
73dcdb9f30 Use faccessat, not access, when checking file permissions.
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
2012-11-13 20:55:41 -08:00
Juanma Barranquero
8e2417bfc0 Fix typos. 2012-11-05 18:29:30 +01:00
Eli Zaretskii
4f3f021d65 Avoid compiler warnings in the MS-Windows build.
nt/inc/unistd.h (tcgetpgrp, setsid): Provide prototypes.
2012-11-05 18:21:18 +02:00
Eli Zaretskii
7e8b50d9e5 Fix MS-Windows build broken by fixing bug #12776 on Posix platforms.
src/w32proc.c (getpgrp, setpgid): New functions.

 nt/inc/unistd.h (setpgid, getpgrp): Provide prototypes.
 nt/config.nt (GETPGRP_VOID): Define to 1.
2012-11-01 16:21:45 +02:00
Eli Zaretskii
a68089e4a4 Fix warnings when compiling on MS-Windows with -std=gnu99.
src/makefile.w32-in ($(BLD)/w32.$(O)): 
 ($(BLD)/vm-limit.$(O)): 
 ($(BLD)/term.$(O)): 
 ($(BLD)/unexw32.$(O)): 
 ($(BLD)/fileio.$(O)): 
 ($(BLD)/dispnew.$(O)): Update dependencies.
 src/w32term.h (w32_initialize_display_info, initialize_w32_display):
 Add prototypes.
 src/w32proc.c: Include ctype.h.
 src/w32.h (init_environment, check_windows_init_file)
 (syms_of_ntproc, syms_of_ntterm, dostounix_filename)
 (unixtodos_filename, init_winsock, srandom, random, sys_pipe)
 (set_process_dir, sys_spawnve, register_child, sys_sleep, getwd)
 (sys_link): Add prototypes.
 src/w32.c: Include w32select.h.
 (sys_access, e_malloc, sys_select): Add prototypes.
 (emacs_gnutls_pull): 'timeout' is now EMACS_TIME, not struct timeval.
 src/vm-limit.c [WINDOWSNT]: Include w32heap.h.
 src/unexw32.c: Include lisp.h and w32.h.
 src/term.c [WINDOWSNT]: Include w32term.h.
 src/process.c [WINDOWSNT]: Add prototype of sys_select.
 src/fileio.c [WINDOWSNT]: Include w32.h.
 src/dispnew.c [WINDOWSNT]: Include w32.h.

 nt/inc/pwd.h (getuid, geteuid): Add prototypes.
 nt/inc/ms-w32.h (sys_wait, _getpid, gmtgime_r, localtime_r)
 (signal_handler, sys_signal, sigemptyset, sigfillset, sigprocmask)
 (pthread_sigmask, sigismember, setpgrp, sigaction, alarm)
 (sys_kill, getpagesize): Add prototypes for emulated functions.
 nt/inc/grp.h (getgid, getegid): Add prototypes.
 nt/gmake.defs (DEBUG_CFLAGS) [NOOPT]: Add -std=gnu99.
 nt/configure.bat (chkapiN): Avoid compiler warning in junk.c when
 compiling with -std=gnu99.
 nt/config.nt (CHECK_LISP_OBJECT_TYPE): Don't undef, so that it
 could be used via --cflags switch to configure.bat.
2012-10-17 21:02:44 +02:00
Fabrice Popineau
62aba0d497 Support x64 build on MS-Windows with MSVC.
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.
2012-09-30 23:36:42 +02:00
Eli Zaretskii
c06c382ae4 Support atimers and CPU profiler via profile.c on MS-Windows.
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.
2012-09-30 17:49:05 +02:00
Eli Zaretskii
5101529e98 Clean-up left-overs after 2012-09-23T08:44:20Z!eggert@cs.ucla.edu wrt signal handling.
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
2012-09-23 19:34:30 +02:00
Paul Eggert
4d7e6e51dd Simplify and avoid signal-handling races.
* 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
2012-09-23 01:44:20 -07:00
Eli Zaretskii
3e6d6928bd MS-Windows followup for 2012-09-07T01:27:44Z!eggert@cs.ucla.edu, signal-handler cleanup.
src/w32proc.c (sigaction): New function, emulates Posix 'sigaction'.
 src/w32.c (sigemptyset): Empty the set.
 (sigsetmask, sigmask, sigblock, sigunblock): Remove unused functions.

 nt/inc/ms-w32.h (struct sigaction): Declare sa_handler __cdecl.

Fixes: debbugs:12327
2012-09-07 11:20:07 +03:00
Paul Eggert
1088b9226e Simplify redefinition of 'abort' (Bug#12316).
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.
2012-09-04 10:34:54 -07:00
Daniel Colascione
17a2cbbd76 Refactor window-system configuration
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.
2012-08-31 22:38:52 -08:00
Juanma Barranquero
a8ab93b0f6 * nt/config.nt: Sync with autogen/config.nt.
(BROKEN_GETWD, DISPNEW_NEEDS_STDIO_EXT): New macros.
(PENDING_OUTPUT_COUNT): Move definition to inc/ms-w32.h.

* nt/inc/ms-w32.h (PENDING_OUTPUT_COUNT): Define.
2012-08-07 13:03:48 +02:00
Juanma Barranquero
3fbc4b542c * nt/config.nt: Sync with autogen/config.in.
(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.
2012-08-03 14:16:40 +02:00
Eli Zaretskii
6dad71783c Support symlinks on latest versions of MS-Windows.
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.
2012-08-03 13:23:30 +03:00
Glenn Morris
837b365b2a Move NT-specific include file to the NT include directory
* 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.
2012-08-01 23:19:48 -07:00
Eli Zaretskii
55a6cca64f MS-Windows followup for 2012-07-28T23:05:32Z!eggert@cs.ucla.edu.
nt/inc/stdalign.h (_Alignas, alignas): Define.
 src/makefile.w32-in (LISP_H): Add $(NT_INC)/stdalign.h.

Fixes: debbugs:9772
2012-07-29 18:43:09 +03:00
Eli Zaretskii
696056c280 Improve port of struct timespec to MS-Windows.
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
2012-06-24 20:21:20 +03:00