1. 27 Aug, 2013 2 commits
    • Paul Eggert's avatar
      Simplify SELECT_TYPE-related code. · d486344e
      Paul Eggert authored
      Like EMACS_TIME, this portability layer is no longer needed, since
      Emacs has been using fd_set as a portability layer for some time.
      * sysselect.h (FD_SETSIZE): Rename from MAXDESC.  All uses changed.
      (SELECT_TYPE): Remove.  All uses changed to fd_set.
      (fd_set) [!FD_SET]: New typedef.
      d486344e
    • Paul Eggert's avatar
      Simplify EMACS_TIME-related code. · 43aac990
      Paul Eggert authored
      This portability layer is no longer needed, since Emacs has been
      using struct timespec as a portability layer for some time.
      Merge from gnulib, incorporating:
      2013-08-27 timespec: new convenience constants and function
      * src/atimer.h, src/buffer.h, src/dispextern.h, src/xgselect.h:
      Include <time.h> rather than "systime.h"; that's all that's needed now.
      * src/dispnew.c: Include <timespec.h> rather than "systime.h";
      that's all that's needed now.
      * src/systime.h (EMACS_TIME): Remove.  All uses changed to struct timespec.
      (EMACS_TIME_RESOLUTION): Remove.  All uses changed to
      TIMESPEC_RESOLUTION.
      (LOG10_EMACS_TIME_RESOLUTION): Remove.  All uses changed to
      LOG10_TIMESPEC_RESOLUTION.
      (EMACS_SECS, emacs_secs_addr): Remove.  All uses changed to tv_sec.
      (EMACS_NSECS): Remove.  All uses changed to tv_nsec.
      (make_emacs_time): Remove.  All used changed to make_timespec.
      (invalid_timespec): Rename from invalid_emacs_time.  All uses changed.
      (current_timespec): Rename from current_emacs_time.  All uses changed.
      (add_emacs_time): Remove.  All uses changed to timespec_add.
      (sub_emacs_time): Remove.  All uses change dot timespec_sub.
      (EMACS_TIME_SIGN): Remove.  All uses changed to timespec_sign.
      (timespec_valid_p): Rename from EMACS_TIME_VALID_P.  All uses changed.
      (EMACS_TIME_FROM_DOUBLE): Remove.  All uses changed to dtotimespec.
      (EMACS_TIME_TO_DOUBLE): Remove.  All uses changed to timespectod.
      (current_timespec): Rename from current_emacs_time.  All uses changed.
      (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove.  All uses
      changed to timespec_cmp.
      * src/xgselect.c: Include <timespec.h>, since our .h files don't.
      43aac990
  2. 24 Aug, 2013 1 commit
    • Paul Eggert's avatar
      System-dependent integer overflow fixes. · 9c05bccf
      Paul Eggert authored
      * process.c (Fset_process_window_size): Signal an error if
      the window size is outside the range supported by the lower level.
      * sysdep.c (set_window_size): Return negative on error,
      nonnegative on success, rather than -1, 0, 1 on not in system,
      failure, success.  This is simpler.  Caller changed.
      (serial_configure): Remove unnecessary initialization of local.
      (procfs_get_total_memory) [GNU_LINUX]: Don't assume system memory
      size fits in unsigned long; this isn't true on some 32-bit hosts.
      Avoid buffer overrun if some future version of /proc/meminfo has a
      variable name longer than 20 bytes.
      (system_process_attributes) [__FreeBSD__]:
      Don't assume hw.availpages fits in 'int'.
      9c05bccf
  3. 23 Aug, 2013 1 commit
    • Paul Eggert's avatar
      Don't let very long directory names overrun the stack. · c365c355
      Paul Eggert authored
      Fix some related minor problems involving "//", vfork.
      * callproc.c (encode_current_directory): New function.
      (call_process): Don't append "/"; not needed.
      * fileio.c (file_name_as_directory_slop): New constant.
      (file_name_as_directory): Allow SRC to be longer than SRCLEN;
      this can save the caller having to alloca.
      (Ffile_name_as_directory, Fdirectory_file_name, Fexpand_file_name):
      Use SAFE_ALLOCA, not alloca.
      (directory_file_name, Fexpand_file_name): Leave leading "//"
      alone, since it can be special even on POSIX platforms.
      * callproc.c (call_process):
      * process.c (Fformat_network_address):
      * sysdep.c (sys_subshell):
      Use encode_current_directory rather than rolling our own.
      (create_process): No need to encode directory; caller does that now.
      * process.h (encode_current_directory): New decl.
      * sysdep.c (sys_subshell): Work even if vfork trashes saved_handlers.
      Rework to avoid 'goto xyzzy;'.
      c365c355
  4. 22 Aug, 2013 1 commit
  5. 09 Aug, 2013 1 commit
    • Dmitry Antipov's avatar
      Use xstrdup and build_unibyte_string where applicable. · 309f24d1
      Dmitry Antipov authored
      * alloc.c (xstrdup): Tiny cleanup.  Add eassert.
      * xfns.c (x_window):
      * xrdb.c (x_get_customization_string):
      * xterm.c (xim_initialize):
      * w32fns.c (w32_window): Use xstrdup.
      (w32_display_monitor_attributes_list):
      * emacs.c (init_cmdargs):
      * keyboard.c (PUSH_C_STR):
      * nsfont.m (nsfont_open):
      * sysdep.c (system_process_attributes):
      * w32.c (system_process_attributes):
      * xdisp.c (message1, message1_nolog): Use build_unibyte_string.
      309f24d1
  6. 22 Jul, 2013 1 commit
  7. 19 Jul, 2013 1 commit
    • Paul Eggert's avatar
      * sysdep.c [GNU_LINUX]: Fix fd and memory leaks and similar issues. · ab9980cd
      Paul Eggert authored
      (procfs_ttyname): Don't use uninitialized storage if emacs_fopen
      or fscanf fails.
      (system_process_attributes): Prefer plain char to unsigned char
      when either will do.  Clean up properly if interrupted or if
      memory allocations fail.  Don't assume sscanf succeeds.  Remove
      no-longer-needed workaround to stop GCC from whining.  Read
      command-line once, instead of multiple times.  Check read status a
      bit more carefully.
      ab9980cd
  8. 16 Jul, 2013 2 commits
    • Paul Eggert's avatar
      Be simpler and more consistent about reporting I/O errors. · 4e604a5d
      Paul Eggert authored
      * fileio.c (Fcopy_file, Finsert_file_contents, Fwrite_region):
      Say "Read error" and "Write error", rather than "I/O error", or
      "IO error reading", or "IO error writing", when a read or write
      error occurs.
      * process.c (Fmake_network_process, wait_reading_process_output)
      (send_process, Fprocess_send_eof, wait_reading_process_output):
      Capitalize diagnostics consistently.  Put "failed foo" at the
      start of the diagnostic, so that we don't capitalize the
      function name "foo".  Consistently say "failed" for such
      diagnostics.
      * sysdep.c, w32.c (serial_open): Now accepts Lisp string, not C string.
      All callers changed.  This is so it can use report_file_error.
      * sysdep.c (serial_open, serial_configure): Capitalize I/O
      diagnostics consistently as above.
      4e604a5d
    • Paul Eggert's avatar
      Fix porting bug to older POSIXish platforms. · c7ddc792
      Paul Eggert authored
      * sysdep.c (emacs_pipe): New function, that implements
      pipe2 (fd, O_CLOEXEC) even on hosts that lack O_CLOEXEC.
      This should port better to CentOS 5 and to Mac OS X 10.6.
      All calls to pipe2 changed.
      
      Fixes: debbugs:14862
      c7ddc792
  9. 12 Jul, 2013 2 commits
    • Paul Eggert's avatar
      Minor EBADF fixes. · 7e649856
      Paul Eggert authored
      * process.c (create_process, wait_reading_process_output) [AIX]:
      Remove obsolete SIGHUP-related  code, as Emacs no longer disables
      SIGHUP, so EBADF is no longer acceptable here (it wouldn't work in
      a multithreaded environment anyway).
      * sysdep.c (emacs_close): It's not dangerous to invoke emacs_close (-1).
      7e649856
    • Paul Eggert's avatar
      Fix races with threads and file descriptors. · bacba3c2
      Paul Eggert authored
      * configure.ac (PTY_TTY_NAME_SPRINTF): Use emacs_close, not close.
      * src/callproc.c (Fcall_process_region):
      * src/dired.c (open_directory):
      * src/emacs.c (main, Fdaemon_initialized):
      * src/image.c (x_find_image_file):
      * src/inotify.c (Finotify_rm_watch):
      * src/lread.c (Flocate_file_internal):
      * src/process.c (Fnetwork_interface_list, Fnetwork_interface_info):
      * src/term.c (term_mouse_moveto, init_tty):
      * src/termcap.c (tgetent):
      * src/unexaix.c, src/unexcoff.c (report_error, report_error_1, adjust_lnnoptrs)
      * src/unexaix.c, src/unexcoff.c, src/unexcw.c, src/unexelf.c (unexec):
      * src/unexhp9k800.c, src/unexmacosx.c (unexec):
      * src/callproc.c (Fcall_process_region):
      Use emacs_close, not close.
      * src/sysdep.c (POSIX_CLOSE_RESTART, posix_close) [!POSIX_CLOSE_RESTART]:
      New macro and function, which emulates the POSIX_CLOSE_RESTART macro
      and posix_close function on current platforms (which all lack them).
      (emacs_close): Use it.  This should fix the races on GNU/Linux and
      on AIX and on future platforms that support POSIX_CLOSE_RESTART,
      and it should avoid closing random victim file descriptors on
      other platforms.
      bacba3c2
  10. 11 Jul, 2013 1 commit
    • Paul Eggert's avatar
      * sysdep.c, term.c, termcap.c, terminal.c: Integer-related minor fixes. · 653d4f43
      Paul Eggert authored
      * sysdep.c (emacs_get_tty): Return void, since nobody uses the value.
      (emacs_set_tty): Now static.
      * sysdep.c (emacs_set_tty, tabs_safe_p, emacs_close):
      * term.c (tty_capable_p, tty_default_color_capabilities)
      (get_tty_terminal, term_mouse_movement)
      (handle_one_term_event, init_tty, maybe_fatal):
      * termcap.c (tgetst1, struct termcap_buffer, valid_filename_p)
      (tgetent, scan_file, name_match, compare_contin):
      * terminal.c (get_terminal):
      Use bool for boolean.
      * sysdep.c (init_system_name): Don't overflow stack on huge hostname.
      Prefer char to unsigned char if either will do.
      * term.c (OUTPUT, turn_on_face): Omit unnecessary casts to int.
      (tty_write_glyphs): Prefer int to unsigned.
      (produce_glyphless_glyph): Remove 2nd (unused) int arg.
      All callers changed.
      * termcap.c (tprint, main) [TEST]: Remove non-working test.
      653d4f43
  11. 10 Jul, 2013 1 commit
    • Paul Eggert's avatar
      Port to C89. · 29abe551
      Paul Eggert authored
      * lib-src/ebrowse.c (USAGE): Remove macro with too-long string literal ...
      (usage_message): ... and replace it with this new static constant
      containing multiple literals.  All uses changed.
      * lib-src/emacsclient.c (print_help_and_exit):
      Rewrite to avoid string literals longer than the C89 limits.
      (start_daemon_and_retry_set_socket):
      Rewrite to avoid non-constant array initializer.
      * lib-src/make-docfile.c (enum global_type): Omit trailing comma.
      * src/bytecode.c (BYTE_CODE_THREADED): Do not define if __STRICT_ANSI__.
      (B__dummy__): New dummy symbol, to pacify C89.
      * src/dbusbind.c (XD_DEBUG_MESSAGE): Omit debugging on C89 hosts, since
      they can't grok varargs macros.
      * src/dispnew.c (add_window_display_history)
      (add_frame_display_history):
      * src/print.c (print_object):
      * src/xdisp.c (debug_method_add):
      Use %p printf format only for void pointers.
      * src/emacs.c (usage_message): New constant, replacing ...
      (USAGE1, USAGE2, USAGE3): Remove; they were too long for C89.
      (main): Adjust to usage reorg.
      * src/fns.c (syms_of_fns):
      * src/profiler.c (syms_of_profiler):
      Don't use non-constant struct initializers.
      * src/gnutls.h (gnutls_initstage_t):
      * src/lisp.h (enum Lisp_Fwd_Type):
      * src/lread.c (lisp_file_lexically_bound_p):
      * src/xsettings.c (anonymous enum):
      Remove trailing comma.
      * src/xsettings.c (apply_xft_settings): Use %f, not %lf; %lf is a C99ism.
      * src/lisp.h (ENUM_BF): Use unsigned if pedantic.
      (DEFUN_FUNCTION_INIT): New macro, that falls back on a cast if pre-C99.
      (DEFUN): Use it.
      * src/regex.c (const_re_char): New type, to pacify strict C89.
      All uses of 'const re_char' replaced to use it.
      * src/regex.h (_Restrict_): Rename from __restrict, to avoid clash
      with glibc when strict C89.  This change is imported from gnulib.
      All uses changed.
      (_Restrict_arr_): Rename from __restrict_arr, similarly.
      * src/sysdep.c (time_from_jiffies) [!HAVE_LONG_LONG_INT]:
      Omit GNU_LINUX implementation, since it requires long long.
      * src/xterm.c (x_draw_underwave):
      Do not assume the traditional order of struct's members.
      (x_term_init): Rewrite to avoid the need for non-constant structure
      initializers.
      29abe551
  12. 09 Jul, 2013 1 commit
    • Paul Eggert's avatar
      Handle errno and exit status a bit more carefully. · 4ebbdd67
      Paul Eggert authored
      * lib/ignore-value.h: Remove this gnulib-imported file.
      * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
      * admin/merge-gnulib (GNULIB_MODULES): Remove ignore-value.
      * src/callproc.c (child_setup) [!DOS_NT]: Don't try to stuff an error
      number into an exit status.  Instead, use EXIT_CANCELED.
      (child_setup) [!MSDOS]: Avoid possible deadlock with vfork.
      * src/callproc.c (relocate_fd):
      * src/emacs.c (close_output_streams, main):
      * src/process.c (create_process):
      * src/sysdep.c (sys_subshell) [!DOS_NT || !WINDOWSNT]:
      Use emacs_perror for simplicity.
      * src/callproc.c (relocate_fd, main):
      * src/sysdep.c (sys_subshell):
      Exit with EXIT_CANCELED etc., not 1, when exec setup fails.
      (shut_down_emacs): Use emacs_write, not write.
      * src/emacs.c, src/sysdep.c: Don't include <ignore-value.h>.
      * src/fileio.c (Fcopy_file, e_write):
      * src/nsterm.m (ns_select):
      * src/process.c (send_process):
      * src/sound.c (vox_write):
      Use emacs_write_sig, not emacs_write.
      * src/lisp.h (emacs_write_sig, emacs_perror): New decls.
      * src/process.h (EXIT_CANCELED), EXIT_CANNOT_INVOKE, EXIT_ENOENT):
      New constants.
      * src/sysdep.c (emacs_backtrace): Use emacs_write, not ignore_value
      of write.
      (emacs_full_write): New function.
      (emacs_write): Rewrite to use it.
      (emacswrite_sig, emacs_perror): New functions.
      * src/xrdb.c (fatal): Don't invoke perror, since errno might be garbage.
      4ebbdd67
  13. 07 Jul, 2013 1 commit
    • Paul Eggert's avatar
      Make file descriptors close-on-exec when possible. · 067428c1
      Paul Eggert authored
      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
      067428c1
  14. 06 Jul, 2013 1 commit
    • Paul Eggert's avatar
      Use emacs_open more consistently when opening files. · 406af475
      Paul Eggert authored
      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.
      406af475
  15. 02 Jul, 2013 2 commits
    • Paul Eggert's avatar
      9bd36682
    • Paul Eggert's avatar
      Remove some unused macros from 'configure'. · 57f8c490
      Paul Eggert authored
      * configure.ac (HAVE_SOUNDCARD_H, HAVE_LINUX_VERSION_H, HAVE_SPEED_T)
      (HAVE_GNUTLS_CALLBACK_CERTIFICATE_VERIFY)
      (HAVE_GNUTLS_CERTIFICATE_SET_VERIFY_FUNCTION, HAVE_UTIMES)
      (HAVE_LIBHESIOD, HAVE_LIBRESOLV, HAVE_LIBCOM_ERR, HAVE_LIBCRYPTO)
      (HAVE_LIBK5CRYPTO, HAVE_LIBKRB5, HAVE_LIBDES425, HAVE_LIBDES)
      (HAVE_LIBKRB4, HAVE_LIBKRB, HAVE_DES_H, HAVE_KERBEROSIV_DES_H)
      (HAVE_DEV_PTMX, DEVICE_SEP, USG5):
      Remove these macros, as they are not used.
      (sys_siglist): Remove macro; src/sysdep.c now does this.
      * src/sysdep.c (sys_siglist) [HAVE_DECL___SYS_SIGLIST]:
      Define to __sys_siglist.
      57f8c490
  16. 23 Jun, 2013 1 commit
    • Paul Eggert's avatar
      Try to avoid malloc SEGVs on Cygwin. · c7041908
      Paul Eggert authored
      * 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.
      
      Fixes: debbugs:14569
      c7041908
  17. 22 Jun, 2013 1 commit
    • Paul Eggert's avatar
      Clean up SIGCHLD handling a bit. · 0dfeed58
      Paul Eggert authored
      * process.c, process.h (catch_child_signal):
      Now always extern, even if !NS_IMPL_GNUSTEP.
      * process.c (catch_child_signal): Move glib tickler here from
      init_process_emacs, so that it's done earlier in Emacs
      initialization.  Also move the noninteractive && !initialized
      check here from init_process_emacs.  This is all a bit cleaner for
      GNUish platforms, and I hope it works around the Cygwin bug.
      * sysdep.c (init_signals): Invoke catch_child_signal here, so
      that glib signal handling is tickled before glib creates threads.
      
      Fixes: debbugs:14569
      0dfeed58
  18. 24 Mar, 2013 1 commit
    • Andreas Schwab's avatar
      Reorder conditions that are written backwards · 908589fd
      Andreas Schwab authored
      * alloc.c (xpalloc, Fgarbage_collect): Reorder conditions that are
      written backwards.
      * blockinput.h (input_blocked_p): Likewise.
      * bytecode.c (exec_byte_code): Likewise.
      * callproc.c (call_process_kill, call_process_cleanup)
      (Fcall_process): Likewise.
      * ccl.c (ccl_driver, resolve_symbol_ccl_program)
      (Fccl_execute_on_string): Likewise.
      * character.c (string_escape_byte8): Likewise.
      * charset.c (read_hex): Likewise.
      * cm.c (calccost): Likewise.
      * data.c (cons_to_unsigned): Likewise.
      * dired.c (directory_files_internal, file_name_completion):
      Likewise.
      * dispnew.c (scrolling_window, update_frame_1, Fsleep_for)
      (sit_for): Likewise.
      * doc.c (Fsubstitute_command_keys): Likewise.
      * doprnt.c (doprnt): Likewise.
      * editfns.c (hi_time, decode_time_components, Fformat): Likewise.
      * emacsgtkfixed.c: Likewise.
      * fileio.c (file_offset, Fwrite_region): Likewise.
      * floatfns.c (Fexpt, fmod_float): Likewise.
      * fns.c (larger_vector, make_hash_table, Fmake_hash_table):
      Likewise.
      * font.c (font_intern_prop): Likewise.
      * frame.c (x_set_alpha): Likewise.
      * gtkutil.c (get_utf8_string): Likewise.
      * indent.c (check_display_width): Likewise.
      * intervals.c (create_root_interval, rotate_right, rotate_left)
      (split_interval_right, split_interval_left)
      (adjust_intervals_for_insertion, delete_node)
      (interval_deletion_adjustment, adjust_intervals_for_deletion)
      (merge_interval_right, merge_interval_left, copy_intervals)
      (set_intervals_multibyte_1): Likewise.
      * keyboard.c (gobble_input, append_tool_bar_item): Likewise.
      * keymap.c (Fkey_description): Likewise.
      * lisp.h (FIXNUM_OVERFLOW_P, vcopy): Likewise.
      * lread.c (openp, read_integer, read1, string_to_number):
      Likewise.
      * menu.c (ensure_menu_items): Likewise.
      * minibuf.c (read_minibuf_noninteractive): Likewise.
      * print.c (printchar, strout): Likewise.
      * process.c (create_process, Faccept_process_output)
      (wait_reading_process_output, read_process_output, send_process)
      (wait_reading_process_output): Likewise.
      * profiler.c (make_log, handle_profiler_signal): Likewise.
      * regex.c (re_exec): Likewise.
      * regex.h: Likewise.
      * search.c (looking_at_1, Freplace_match): Likewise.
      * sysdep.c (get_child_status, procfs_ttyname)
      (procfs_get_total_memory): Likewise.
      * systime.h (EMACS_TIME_VALID_P): Likewise.
      * term.c (dissociate_if_controlling_tty): Likewise.
      * window.c (get_phys_cursor_glyph): Likewise.
      * xdisp.c (init_iterator, redisplay_internal, redisplay_window)
      (try_window_reusing_current_matrix, try_window_id, pint2hrstr):
      Likewise.
      * xfns.c (Fx_window_property): Likewise.
      * xmenu.c (set_frame_menubar): Likewise.
      * xselect.c (x_get_window_property, x_handle_dnd_message):
      Likewise.
      * xsmfns.c (smc_save_yourself_CB): Likewise.
      * xterm.c (x_scroll_bar_set_handle): Likewise.
      908589fd
  19. 13 Mar, 2013 2 commits
    • Paul Eggert's avatar
      File synchronization fixes. · 47d7532e
      Paul Eggert authored
      * 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
      47d7532e
    • Paul Eggert's avatar
      * sysdep.c: Remove a use of BSD_SYSTEM, which I'm trying to phase out. · 7fd8c501
      Paul Eggert authored
      Include <sys/param.h> unconditionally, as that works elsewhere and
      is simpler here.  Include <sys/sysctl.h> if DARWIN_OS ||
      __FreeBSD__, not if BSD_SYSTEM, since it's needed only for Darwin
      and FreeBSD now.
      7fd8c501
  20. 06 Mar, 2013 1 commit
  21. 05 Mar, 2013 3 commits
  22. 13 Feb, 2013 1 commit
    • Paul Eggert's avatar
      Minor getenv-related fixes. · 83be8524
      Paul Eggert authored
      * callproc.c (Fcall_process_region) [!DOS_NT]:
      Avoid unnecessary duplicate call to getenv.
      * callproc.c (init_callproc):
      * dispnew.c (init_display):
      * sysdep.c (sys_subshell):
      Omit unnecessary cast of getenv or egetenv.
      83be8524
  23. 01 Feb, 2013 1 commit
    • Paul Eggert's avatar
      Use fdopendir, fstatat and readlinkat, for efficiency. · 8654f9d7
      Paul Eggert authored
      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
      8654f9d7
  24. 11 Jan, 2013 2 commits
    • Paul Eggert's avatar
      emacsclient -t should not suspend Emacs server · b8956427
      Paul Eggert authored
      * lisp.h, sysdep.c (block_tty_out_signal, unblock_tty_out_signal):
      New functions.
      * term.c (init_tty): Use them instead of rolling our own code.
      * sysdep.c (tcsetpgrp_without_stopping): Likewise.  Here, this
      switches from 'signal' to 'pthread_sigmask', which is safer in
      multithreaded applications.
      * term.c (Fresume_tty): Don't bother dissociating if O_IGNORE_CTTY,
      which has already arranged for that.
      (dissociate_if_controlling_tty): If setsid fails, fall back on TIOCNOTTY.
      This is the main part of the bug fix.
      
      Fixes: debbugs:13387
      b8956427
    • Paul Eggert's avatar
      Fix SIGDANGER handlers, for AIX. · b6f960a0
      Paul Eggert authored
      * sysdep.c.c (handle_danger_signal, deliver_danger_signal) [SIGDANGER]:
      Move handlers here from emacs.c; they were out of place.
      
      Fixes: debbugs:13408
      b6f960a0
  25. 01 Jan, 2013 1 commit
  26. 16 Dec, 2012 1 commit
  27. 08 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Assume POSIX 1003.1-1988 or later for signal.h. · d983a10b
      Paul Eggert authored
      Exceptions: do not assume SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN,
      SIGTTOU, SIGUSR1, SIGUSR2, as Microsoft platforms lack these.
      * admin/CPP-DEFINES (SIGALRM, SIGCHLD, SIGHUP, SIGKILL, SIGPIPE, SIGQUIT):
      Remove.
      (SIGTRAP): Remove this one too, as config.h no longer defines it.
      * admin/merge-gnulib (GNULIB_MODULES): Add sig2str.
      * configure.ac (PTY_OPEN, PTY_TTY_NAME_SPRINTF):
      Use SIGCHLD rather than SIGCLD.
      * lib/sig2str.c, lib/sig2str.h, m4/sig2str.m4: New files, from gnulib.
      * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
      * lib/makefile.w32-in (GNULIBOBJS): Add $(BUILD)/sig2str.$(O).
      * src/process.c [subprocesses]: Include <c-ctype.h>, <sig2str.h>.
      (deleted_pid_list, Fdelete_process, create_process)
      (record_child_status_change, handle_child_signal, deliver_child_signal)
      (init_process_emacs, syms_of_process):
      Assume SIGCHLD is defined.
      (parse_signal): Remove.  All uses removed.
      (abbr_to_signal): New static function.
      (Fsignal_process): Use it to convert signal names to ints.
      * src/sysdep.c (sys_suspend) [!DOS_NT]: Use kill (0, ...) rather than
      kill (getpgrp (), ...).
      (emacs_sigaction_init): Assume SIGCHLD is defined.
      (init_signals): Assume SIGALRM, SIGCHLD, SIGHUP, SIGKILL,
      SIGPIPE, and SIGQUIT are defined.  Do not worry about SIGCLD any more.
      * src/syssignal.h (EMACS_KILLPG): Remove.
      All uses replaced by 'kill' with a negative pid.
      (SIGCHLD): Remove definition, as we now assume SIGCHLD.
      * src/w32proc.c (sys_kill): Support negative pids compatibly with POSIX.
      
      Fixes: debbugs:13026
      d983a10b
  28. 07 Dec, 2012 1 commit
  29. 03 Dec, 2012 1 commit
    • Paul Eggert's avatar
      Don't let call-process be a zombie factory. · bb5f74ee
      Paul Eggert authored
      Fixing this bug required some cleanup of the signal-handling code.
      As a side effect, this change also fixes a longstanding rare race
      condition whereby Emacs could mistakenly kill unrelated processes,
      and it fixes a bug where a second C-g does not kill a recalcitrant
      synchronous process in GNU/Linux and similar platforms.
      The patch should also fix the last vestiges of Bug#9488,
      a bug which has mostly been fixed on the trunk by other changes.
      * callproc.c, process.h (synch_process_alive, synch_process_death)
      (synch_process_termsig, sync_process_retcode):
      Remove.  All uses removed, to simplify analysis and so that
      less consing is done inside critical sections.
      * callproc.c (call_process_exited): Remove.  All uses replaced
      with !synch_process_pid.
      * callproc.c (synch_process_pid, synch_process_fd): New static vars.
      These take the role of what used to be in unwind-protect arg.
      All uses changed.
      (block_child_signal, unblock_child_signal):
      New functions, to avoid races that could kill innocent-victim processes.
      (call_process_kill, call_process_cleanup, Fcall_process): Use them.
      (call_process_kill): Record killed processes as deleted, so that
      zombies do not clutter up the system.  Do this inside a critical
      section, to avoid a race that would allow the clutter.
      (call_process_cleanup): Fix code so that the second C-g works again
      on common platforms such as GNU/Linux.
      (Fcall_process): Create the child process in a critical section,
      to fix a race condition.  If creating an asynchronous process,
      record it as deleted so that zombies do not clutter up the system.
      Do unwind-protect for WINDOWSNT too, as that's simpler in the
      light of these changes.  Omit unnecessary call to emacs_close
      before failure, as the unwind-protect code does that.
      * callproc.c (call_process_cleanup):
      * w32proc.c (waitpid): Simplify now that synch_process_alive is gone.
      * process.c (record_deleted_pid): New function, containing
      code refactored out of Fdelete_process.
      (Fdelete_process): Use it.
      (process_status_retrieved): Remove.  All callers changed to use
      child_status_change.
      (record_child_status_change): Remove, folding its contents into ...
      (handle_child_signal): ... this signal handler.  Now, this
      function is purely a handler for SIGCHLD, and is not called after
      a synchronous waitpid returns; the synchronous code is moved to
      wait_for_termination.  There is no need to worry about reaping
      more than one child now.
      * sysdep.c (get_child_status, child_status_changed): New functions.
      (wait_for_termination): Now takes int * status and bool
      interruptible arguments, too.  Do not record child status change;
      that's now the caller's responsibility.  All callers changed.
      Reimplement in terms of get_child_status.
      (wait_for_termination_1, interruptible_wait_for_termination):
      Remove.  All callers changed to use wait_for_termination.
      * syswait.h: Include <stdbool.h>, for bool.
      (record_child_status_change, interruptible_wait_for_termination):
      Remove decls.
      (record_deleted_pid, child_status_changed): New decls.
      (wait_for_termination): Adjust to API changes noted above.
      
      Fixes: debbugs:12980
      bb5f74ee
  30. 25 Nov, 2012 1 commit
  31. 24 Nov, 2012 1 commit
  32. 23 Nov, 2012 1 commit
    • Paul Eggert's avatar
      Fix a race condition with glib (Bug#8855). · 6d4e8f62
      Paul Eggert authored
      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'.
      6d4e8f62