Make file descriptors close-on-exec when possible.
[bpt/emacs.git] / src / ChangeLog
index 9c5bb38..07285d5 100644 (file)
@@ -1,3 +1,315 @@
+2013-07-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Make file descriptors close-on-exec when possible (Bug#14803).
+       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.
+       * alloc.c (valid_pointer_p) [!WINDOWSNT]:
+       * callproc.c (Fcall_process) [!MSDOS]:
+       * emacs.c (main) [!DOS_NT]:
+       * nsterm.m (ns_term_init):
+       * process.c (create_process):
+       Use 'pipe2' with O_CLOEXEC instead of 'pipe'.
+       * emacs.c (Fcall_process_region) [HAVE_MKOSTEMP]:
+       * filelock.c (create_lock_file) [HAVE_MKOSTEMP]:
+       Prefer mkostemp with O_CLOEXEC to mkstemp.
+       * callproc.c (relocate_fd) [!WINDOWSNT]:
+       * 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.
+       * filelock.c (create_lock_file) [! HAVE_MKOSTEMP]:
+       Make the resulting file descriptor close-on-exec.
+       * lisp.h, lread.c, process.c (close_load_descs, close_process_descs):
+       * lread.c (load_descriptor_list, load_descriptor_unwind):
+       Remove; no longer needed.  All uses removed.
+       * 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.
+       * sysdep.c (emacs_open, emacs_fopen):
+       Make new-created descriptor close-on-exec.
+       * w32.c (fcntl): Support F_DUPFD_CLOEXEC well enough for Emacs.
+       * w32.c, w32.h (pipe2): Rename from 'pipe', with new flags arg.
+
+2013-07-07  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsterm.m (sendEvent:): Propagate keyboard events to modal windows
+       for NS_IMPL_GNUSTEP.
+
+2013-07-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix openp errno handling.
+       * callproc.c (Fcall_process): Preserve openp errno around close.
+       * lread.c (openp): Set errno when returning -1, as some callers
+       expect this.
+
+2013-07-06  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsterm.m (sendEvent:): Handle NSAPP_DATA2_RUNFILEDIALOG.
+
+       * nsterm.h (NSSavePanel): Update comment.
+       (NSAPP_DATA2_RUNFILEDIALOG): Define.
+       (ns_run_file_dialog): Declare.
+
+       * nsfns.m: Remove panelOK.
+       (ns_fd_data): New.
+       (ns_run_file_dialog): New function.
+       (Fns_read_file_name): Fill in ns_fd_data, post an event and start the
+       event loop, so file dialog is popped up by ns_run_file_dialog, called
+       by sendEvent (Bug#14578).
+       (EmacsSavePanel, EmacsOpenPanel): Remove ok and cancel methods.
+
+2013-07-06  Eli Zaretskii  <eliz@gnu.org>
+
+       * xdisp.c (default_line_pixel_height): New function.
+       (pos_visible_p, move_it_vertically_backward, try_scrolling)
+       (try_cursor_movement, redisplay_window, try_window)
+       (try_window_id): Use it instead of FRAME_LINE_HEIGHT.  (Bug#14771)
+
+       * window.c (window_scroll_pixel_based): use
+       default_line_pixel_height.
+
+       * dispextern.h (default_line_pixel_height): Add prototype.
+
+       * frame.c (x_set_line_spacing): Accept a float value for
+       line-spacing parameter, per the documentation.
+
+       * data.c (Fmultibyte_string_p): Doc fix.
+
+2013-07-05  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Use emacs_open more consistently when opening files.
+       This handles EINTR more consistently now, and makes it easier
+       to introduce other uniform changes to file descriptor handling.
+       * src/systdio.h: New file.
+       * src/buffer.c (mmap_init):
+       * cygw32.c (chdir_to_default_directory):
+       * dispnew.c (Fopen_termscript):
+       * emacs.c (Fdaemon_initialized):
+       * fileio.c (Fdo_auto_save):
+       * image.c (slurp_file, png_load_body, jpeg_load_body):
+       * keyboard.c (Fopen_dribble_file):
+       * lread.c (Fload):
+       * print.c (Fredirect_debugging_output):
+       * sysdep.c (get_up_time, procfs_ttyname, procfs_get_total_memory):
+       * termcap.c (tgetent):
+       * unexaix.c, unexcoff.c (unexec, adjust_lnnoptrs):
+       * unexcw.c, unexelf.c, unexhp9k800.c, unexmacosx.c (unexec):
+       * w32term.c (w32_initialize) [CYGWIN]:
+       * xfaces.c (Fx_load_color_file):
+       Use emacs_open instead of plain open, and emacs_fopen instead of
+       plain fopen.
+       * dispnew.c, fileio.c, image.c, keyboard.c, lread.c, print.c, sysdep.c:
+       * xfaces.c: Include sysstdio.h rather than stdio.h, for emacs_fopen.
+       * callproc.c (default_output_mode): New constant.
+       (Fcall_process): Use it to call emacs_open instead of plain creat.
+       * dispnew.c (Fopen_termscript): Fix minor race in opening termscript.
+       * sysdep.c (emacs_open): Add commentary and don't call file name "path".
+       (emacs_fopen): New function.
+       * unexaix.c, unexcoff.c, unexelf.c, unexhp9k800.c, unexmacosx.c:
+       Include <lisp.h>, for emacs_open.
+       * unexelf.c (fatal): Remove decl; not needed with <lisp.h> included.
+
+       Remove duplicate #include directives.
+       * alloc.c [GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES]:
+       * xfaces.c:
+       Don't include stdio.h twice.
+       * buffer.c [USE_MMAP_FOR_BUFFERS]:
+       Don't include sys/types.h or stdio.h twice.
+       * fileio.c [WINDOWSNT | MSDOS]: Don't include fcntl.h twice.
+       * lread.c: Don't include coding.h twice.
+       * nsfont.m: Don't include frame.h twice.
+       * process.c [HAVE_RES_INIT]: Don't include <netinet/in.h> twice.
+       * ralloc.c: Don't include <unistd.h> twice.
+       * xdisp.c: Don't include font.h twice.
+       * xterm.c: Don't include fontset.h twice.
+       * xterm.h [USE_X_TOOLKIT]: Don't include X11/StringDefs.h twice.
+
+2013-07-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Scale ImageMagick images more carefully.
+       * image.c (scale_image_size) [HAVE_IMAGEMAGICK]: New function.
+       (compute_image_size): Use it.  Define only if HAVE_IMAGEMAGICK.
+       Be more careful about avoiding undefined behavior after
+       integer overflow and division by zero.
+
+2013-07-04  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+       * w32fns.c (Qgeometry, Qworkarea, Qmm_size, Qframes): New variables.
+       (syms_of_w32fns): DEFSYM them.
+       (MONITORINFOF_PRIMARY, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN)
+       (CCHDEVICENAME): Define macros if not defined.
+       (struct MONITOR_INFO_EX): New struct.
+       (MonitorEnum_Proc, EnumDisplayMonitors_Proc): New prototypes.
+       (enum_display_monitors_fn): New variable.
+       (globals_of_w32fns): Initialize it.
+       (Fx_display_pixel_width, Fx_display_pixel_height)
+       (Fx_display_mm_height, Fx_display_mm_width): Mention behavior on
+       multi-monitor setups in docstrings.
+       (Fx_display_mm_height, Fx_display_mm_width): Approximate whole
+       screen size by primary monitor's millimeter per pixel.
+       (w32_monitor_enum, w32_display_monitor_attributes_list)
+       (w32_display_monitor_attributes_list_fallback)
+       (Fw32_display_monitor_attributes_list): New functions.
+       (syms_of_w32fns): Defsubr Sw32_display_monitor_attributes_list.
+
+       * w32term.c (SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN): Define macros
+       if not defined.
+       (x_display_pixel_height, x_display_pixel_width): Use GetSystemMetrics.
+
+2013-07-04  Michael Albinus  <michael.albinus@gmx.de>
+
+       * fileio.c (Qfile_notify_error): New error symbol.
+
+       * gfilenotify.c (Fgfile_add_watch, Fgfile_rm_watch):
+       * inotify.c (inotify_callback, symbol_to_inotifymask)
+       (Finotify_add_watch, Finotify_rm_watch): Use it.
+       (inotifyevent_to_event): Exchange order of cookie and file name.
+       (Finotify_add_watch): Adapt docstring.
+
+       * lisp.h (Qfile_notify_error): Declare.
+
+2013-07-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Try again to fix FreeBSD bug re multithreaded memory alloc (Bug#14569).
+       * emacs.c (main) [HAVE_PTHREAD && !SYSTEM_MALLOC && !DOUG_LEA_MALLOC]:
+       Do not clear _malloc_thread_enabled_p, undoing the previous change,
+       which did not work (see <http://bugs.gnu.org/14569#307>).
+       (main): Do not invoke malloc_enable_thread if (! CANNOT_DUMP
+       && (!noninteractive || initialized)).  This attempts to thread
+       the needle between the Scylla of FreeBSD and the Charybdis of Cygwin.
+
+2013-07-04  Juanma Barranquero  <lekktu@gmail.com>
+
+       * image.c (x_to_xcolors) [HAVE_NTGUI]: Remove unused var `hdc'.
+       (x_build_heuristic_mask) [HAVE_NTGUI]: Remove unused var `frame_dc'.
+
+2013-07-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Try to fix FreeBSD bug re multithreaded memory allocation (Bug#14569).
+       * emacs.c (main) [HAVE_PTHREAD && !SYSTEM_MALLOC && !DOUG_LEA_MALLOC]:
+       Clear _malloc_thread_enabled_p at startup.  Reported by Ashish SHUKLA in
+       <http://lists.gnu.org/archive/html/emacs-devel/2013-07/msg00088.html>.
+
+2013-07-02  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * sysdep.c (sys_siglist) [HAVE_DECL___SYS_SIGLIST]:
+       Define to __sys_siglist.
+
+2013-07-02  Eli Zaretskii  <eliz@gnu.org>
+
+       * xdisp.c (IT_OVERFLOW_NEWLINE_INTO_FRINGE): Don't disallow
+       word-wrap, so that overflow-newline-into-fringe would work in
+       visual-line-mode.  (Bug#2749)
+       (move_it_in_display_line_to): When the last scanned display
+       element fits exactly on the display line, and
+       overflow-newline-into-fringe is non-nil, but wrap_it is valid,
+       don't return MOVE_NEWLINE_OR_CR, but instead back up to the last
+       wrap point and return MOVE_LINE_CONTINUED.  Fixes problems with
+       finding buffer position that corresponds to pixel coordinates,
+       e.g. in buffer_posn_from_coords.
+
+2013-07-02  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * process.c (handle_child_signal): Call catch_child_signal if
+       NS_IMPL_GNUSTEP.
+
+2013-07-02  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Don't convert function pointers to void * and back.
+       It isn't portable C, and it's easy enough to avoid.
+       * alloc.c: Verify SAVE_FUNCPOINTER bits, too.
+       (make_save_value): Add support for SAVE_FUNCPOINTER.
+       * keymap.c (map_keymap_char_table_item, map_keymap_internal):
+       * print.c (print_object):
+       Distinguish function from object pointers.
+       * lisp.h (SAVE_FUNCPOINTER): New constant.
+       (SAVE_SLOT_BITS): Adjust to it.
+       (SAVE_TYPE_FUNCPTR_PTR_OBJ): New constant, replacing
+       SAVE_TYPE_PTR_PTR_OBJ.  Change the only use.
+       (voidfuncptr): New typedef.
+       (struct Lisp_Save_Value): New member data[0].funcpointer.
+       (XSAVE_FUNCPOINTER): New function.
+
+       Simplify buildobj processing.
+       * Makefile.in (buildobj.h): Make it a sequence of strings each
+       followed by comma, rather than a single string.  Put it into a
+       .tmp file in case there's an error while generating it.
+       (gl-stamp): Use .tmp for temp files.
+       (mostlyclean): Clean .tmp files.
+       * doc.c (buildobj): Move to just the routine that needs it.
+       It's now an array of strings, so processing is simpler.
+
+2013-07-01  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix bug re noninteractive multithreaded memory allocation (Bug#14569).
+       * emacs.c (malloc_enable_thread): Hoist extern decl to top level.
+       (main) [HAVE_PTHREAD && !SYSTEM_MALLOC && !DOUG_LEA_MALLOC]:
+       Invoke malloc_enable_thread even when not interactive.
+       Problem reported by Ken Brown in <http://bugs.gnu.org/14569#275>.
+       * process.c (init_process_emacs) [CYGWIN]: Tickle glib even
+       in this case, since the underlying bug has now been fixed.
+
+2013-07-01  Juanma Barranquero  <lekktu@gmail.com>
+
+       * emacs.c (Fkill_emacs): Expand Vauto_save_list_file_name before
+       unlinking it (bug#14691).
+
+2013-06-30  Michal Nazarewicz  <mina86@mina86.com>
+
+       * buffer.c (FKill_buffer): Run `kill-buffer-query-functions'
+       before checking whether buffer is modified.  This lets
+       `kill-buffer-query-functions' cancel killing of the buffer or save
+       its content before `kill-buffer' asks user the "Buffer %s
+       modified; kill anyway?" question.
+
+2013-06-30  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsfns.m (handlePanelKeys): Don't process Command+Function keys.
+       Let the super performKeyEquivalent deal with them (Bug#14747).
+
+2013-06-30  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * widget.c (resize_cb): Remove unused local.
+
+       Do not use GTK 3 if it exists but cannot be compiled.
+       * xmenu.c (x_menu_wait_for_event) [!USE_GTK]:
+       * xterm.c (x_error_handler) [!USE_GTK]:
+       Do not use GTK 3.
+
+       * intervals.c (get_local_map): Actually clip POSITION (Bug#14753).
+
+2013-06-30  Eli Zaretskii  <eliz@gnu.org>
+
+       * intervals.c (get_local_map): Instead of aborting, clip POSITION
+       to the valid range of values.  (Bug#14753)
+
+       * xdisp.c (Fmove_point_visually): Invalidate the cursor position
+       when moving point by using the current glyph matrix.  This avoids
+       the need to force redisplay when this function is called in a
+       loop.
+
+2013-06-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix minor problems found by static checking.
+       * coding.c (encode_inhibit_flag, inhibit_flag): New functions.
+       Redo the latter's body to sidestep GCC parenthesization warnings.
+       (setup_coding_system, detect_coding, detect_coding_system): Use them.
+       * coding.c (detect_coding, detect_coding_system):
+       * coding.h (struct undecided_spec):
+       Use bool for boolean.
+       * image.c (QCmax_width, QCmax_height): Now static.
+       * xdisp.c (Fmove_point_visually): Remove unused local.
+
+2013-06-29  Eli Zaretskii  <eliz@gnu.org>
+
+       * xdisp.c (Fmove_point_visually): New function.
+
 2013-06-28  Kenichi Handa  <handa@gnu.org>
 
        * coding.h (define_coding_undecided_arg_index): New enum.
@@ -6,7 +318,7 @@
        coding_attr_undecided_inhibit_iso_escape_detection,
        coding_attr_undecided_prefer_utf_8.
        (undecided_spec): New struct.
-       (struct coding_system): New member `undecied' of the member
+       (struct coding_system): New member `undecided' of the member
        `spec'.
 
        * coding.c (setup_coding_system): Handle CODING->spec.undecided.
        (Fdefine_coding_system_internal): New coding system properties
        :inhibit-null-byte-detection, :inhibit-iso-escape-detection, and
        :prefer-utf-8.
-       (syms_of_coding): Adjusted for coding_arg_undecided_max.
+       (syms_of_coding): Adjust for coding_arg_undecided_max.
+
+2013-06-28  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * image.c (x_from_xcolors): Remove unused local.
+
+2013-06-28  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+       Defer image data transfer between X client and server until actual
+       display happens.
+
+       * dispextern.h (struct image) [HAVE_X_WINDOWS]: New members `ximg'
+       and `mask_img'.
+
+       * image.c (Destroy_Image): Remove.
+       (x_clear_image_1): New arg `flags' instead of 3 bools `pixmap_p',
+       `mask_p', and `colors_p'.  All uses changed.
+       (x_clear_image_1) [HAVE_X_WINDOWS]: Destroy `ximg' and `mask_img'.
+       (CLEAR_IMAGE_PIXMAP, CLEAR_IMAGE_MASK, CLEAR_IMAGE_COLORS):
+       New macros for `flags' arg to x_clear_image_1.
+       (postprocess_image, xpm_load_image, x_build_heuristic_mask)
+       (png_load_body): Use x_clear_image_1 instead of Free_Pixmap.
+       (ZPixmap, XGetImage) [HAVE_NS]: Remove.
+       (image_get_x_image_or_dc, image_unget_x_image_or_dc)
+       (image_get_x_image, image_unget_x_image): New functions or macros.
+       (image_background, image_background_transparent, x_to_xcolors)
+       (x_build_heuristic_mask): Use image_get_x_image_or_dc instead of
+       XGetImage or CreateCompatibleDC.  Use image_unget_x_image_or_dc
+       instead of Destroy_Image.
+       (image_create_x_image_and_pixmap, image_put_x_image): New functions.
+       (xpm_load_image, x_from_xcolors, x_build_heuristic_mask, pbm_load)
+       (png_load_body, jpeg_load_body, tiff_load, gif_load)
+       (imagemagick_load_image, svg_load_image): Use them instead of
+       x_create_x_image_and_pixmap, and x_put_x_image followed by
+       x_destroy_x_image, respectively.
+       (xpm_load) [HAVE_XPM && !HAVE_NTGUI]: Use XpmReadFileToImage and
+       XpmCreateImageFromBuffer instead of XpmReadFileToPixmap and
+       XpmCreatePixmapFromBuffer.  Create pixmaps.  Fill background and
+       background_transparent fields.
+       (image_sync_to_pixmaps) [HAVE_X_WINDOWS]: New function.
+       (prepare_image_for_display, x_disable_image) [HAVE_X_WINDOWS]: Use it.
+
+2013-06-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Do not tickle glib SIGCHLD handling if Cygwin (Bug#14569).
+       This mostly consists of undoing recent changes.
+       * callproc.c (Fcall_process):
+       * process.c (create_process):
+       Do not worry about catching SIGCHLD here, undoing previous change.
+       * nsterm.m (ns_term_init): Re-catch SIGCHLD, undoing previous change.
+       * process.c, process.h (catch_child_signal):
+       No longer extern if !NS_IMPL_GNUSTEP, undoing 06-22 change.
+       * process.c (catch_child_handler): Don't worry about being called
+       lazily and do not assume caller has blocked SIGCHLD, undoing
+       previous change.  Move first-time stuff back to
+       init_process_emacs, undoing 06-22 change.  If CYGWIN, do not
+       tickle glib, as that causes Cygwin bootstrap to fail.  Do not
+       set lib_child_handler if it's already initialized, which may
+       help avoid problems on GNUStep.
+
+2013-06-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       A more-conservative workaround for Cygwin SIGCHLD issues (Bug#14569).
+       * callproc.c (Fcall_process):
+       * process.c (create_process):
+       Make sure SIGCHLD is caught before we fork,
+       since Emacs startup no arranges to catch SIGCHLD.
+       * process.c (lib_child_handler): Initialize to null, not to
+       dummy_handler.
+       (catch_child_signal): Allow self to be called lazily.
+       Do nothing if it's already been called.
+       Assume caller has blocked SIGCHLD (all callers do now).
+       * emacs.c (main): Do not catch SIGCHLD here; defer it until
+       just before it's really needed.
+       * nsterm.m (ns_term_init): No need to re-catch SIGCHLD here,
+       since it hasn't been caught yet.
+
+2013-06-23  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+       * image.c (compute_image_size): New function to implement
+       :max-width and :max-height.
+       (imagemagick_load_image): Use it.
+
+2013-06-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Try to avoid malloc SEGVs on Cygwin (Bug#14569).
+       * callproc.c, process.h (block_child_signal, unblock_child_signal):
+       Now extern.
+       * emacs.c (main): Catch SIGCHLD just before initializing gfilenotify.
+       * process.c (catch_child_signal): Block SIGCHLD while futzing with
+       the SIGCHLD handler, since the code is not atomic and (due to glib)
+       signals may be arriving now.
+       * sysdep.c (init_signals): Do not catch child signals here;
+       'main' now does that later, at a safer time.
 
 2013-06-22  Paul Eggert  <eggert@cs.ucla.edu>
 
        * textprop.c (property_set_type): New enum.
        (add_properties): Allow appending/prepending text properties.
        (add_text_properties_1): Factored out of Fadd_text_properties.
-       (Fadd_text_properties): Moved all the code into
+       (Fadd_text_properties): Move all the code into
        add_text_properties_1.
        (Fadd_face_text_property): New function that calls
        add_text_properties_1.
        (Fxw_color_values): Use EmacsCGFloat
        (Fns_display_monitor_attributes_list): Only get screen number for
        Cocoa.
-       (getDirectory, getFilename): Removed from EmacsOpenPanel and
+       (getDirectory, getFilename): Remove from EmacsOpenPanel and
        EmacsSavePanel.
        (EmacsOpenPanel:ok:): Use ns_filename_from_panel and
        ns_directory_from_panel.