summaryrefslogtreecommitdiff
path: root/lib-src/emacsclient.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge from origin/emacs-26Paul Eggert2018-12-311-1/+1
|\ | | | | | | | | | | 2fcf2df Fix copyright years by hand 26bed8b Update copyright year to 2019 2814292 Fix value of default frame height. (Bug#33921)
| * Update copyright year to 2019Paul Eggert2019-01-011-1/+1
| | | | | | | | Run 'TZ=UTC0 admin/update-copyright $(git ls-files)'.
* | emacsclient: avoid background chatterPaul Eggert2018-12-061-18/+33
| | | | | | | | | | | | | | * lib-src/emacsclient.c (process_grouping): New function. (act_on_signals, main): Use it. (main): Omit "Waiting for Emacs..." and later "\n" messages if in background, since that messes up the screen.
* | Fix emacsclient hang when backgroundedPaul Eggert2018-12-061-15/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem reported by Kaushal Modi in: https://lists.gnu.org/r/emacs-devel/2018-12/msg00083.html The tcdrain call replaced an fdatasync call which had no effect on the tty, so removing it entirely shouldn’t cause problems. The fdatasync call replaced an fsync call which also had no effect on the tty, and the fsync call seems to be badly-merged revenant of emacsclient’s old (circa 2004) way of communicating to and from Emacs via FILE * streams, where fsync was apparently needed when talking to sockets. * lib-src/emacsclient.c [!DOS_NT]: Don’t include termios.h. (flush_stdout): Remove. All callers removed. (main): Do not drain the tty after "Waiting for Emacs..." message. There should be no need to drain, and draining it might send us a SIGTTOU. Do not fflush stdout just before exiting, as exiting does that for us.
* | emacsclient: fix typo on recent socket-leak changePaul Eggert2018-12-031-1/+1
| | | | | | | | | | | | | | | | This ports to POSIXish platforms like macOS that lack SOCK_CLOEXEC. Fix suggested by Eli Zaretskii in: https://lists.gnu.org/r/emacs-devel/2018-12/msg00055.html * lib-src/emacsclient.c (set_local_socket): Don’t use SOCK_CLOEXEC; that’s cloexec_socket’s job.
* | Fix WINDOWSNT/DOS_NT buildEli Zaretskii2018-12-031-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Recent changes in sysdep.c and emacsclient unnecessarily removed useful code from DOS_NT builds. This changeset reinstates that code. * nt/inc/ms-w32.h (tcdrain): Redirect to _commit. (fdatasync): No need to redirect anymore. * lib-src/emacsclient.c (flush_stdout): Don't avoid calling tcdrain on DOS_NT platforms. * src/sysdep.c (reset_sys_modes): Don't ifdef away the call to tcdrain on DOS_NT platforms.
* | emacsclient: don’t leak socket to child processesPaul Eggert2018-12-021-2/+21
| | | | | | | | | | | | * lib-src/emacsclient.c [!WINDOWSNT]: Include fcntl.h. (cloexec_socket): New function. (set_tcp_socket, set_local_socket): Use it.
* | Use tcdrain, not fdatasync, to drain ttysPaul Eggert2018-12-021-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fdatasync is for storage devices, not ttys. * admin/merge-gnulib (GNULIB_MODULES): Remove fdatasync. * lib/fdatasync.c, m4/fdatasync.m4: Remove. * lib-src/Makefile.in (LIB_FDATASYNC): * src/Makefile.in (LIB_FDATASYNC): Remove. All uses removed. * lib-src/emacsclient.c [!DOS_NT]: Include <termios.h>, for tcdrain. * lib-src/emacsclient.c (flush_stdout): * src/sysdep.c (reset_sys_modes): On ttys, use tcdrain instead of fdatasync (except don’t use either function if DOS_NT). * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* | emacsclient: fix symlink/socket racePaul Eggert2018-12-021-37/+41
| | | | | | | | | | | | | | | | | | * lib-src/emacsclient.c (socket_status): New arg UID. All uses changed. (set_local_socket): Don’t create the unbound socket unless the initial sanity checks on the socket file succeed; this simplifies cleaning it up. Check socket ownership again after connecting, to fix a race (Bug#33366).
* | emacsclient: prefer XDG_RUNTIME_DIR (Bug#33367)Paul Eggert2018-12-011-53/+77
| | | | | | | | | | | | | | | | | | | | * lib-src/emacsclient.c: Disable -Wformat-truncation=2, to avoid false alarms about the new snprintf calls. (local_sockname): New function. (set_local_socket): Use it. Prefer XDG_RUNTIME_DIR (if set) for location of socket directory. Avoid unnecessary memory allocation by using snprintf to destination. * lisp/server.el (server-socket-dir): Prefer XDG_RUNTIME_DIR if set.
* | Unbreak compilation of emacsclient on MS-WindowsEli Zaretskii2018-11-261-0/+2
| | | | | | | | | | | | * lib-src/emacsclient.c (main): Make "-suspend" handling conditional on !WINDOWSNT, as there's no SIGSTOP nor 'kill' there.
* | emacsclient: assume HAVE_INET_SOCKETSPaul Eggert2018-11-261-64/+48
| | | | | | | | | | | | | | | | | | | | | | * configure.ac (HAVE_INET_SOCKETS): Remove. * lib-src/emacsclient.c: Simplify by assuming HAVE_SOCKETS and HAVE_INET_SOCKETS, which are always true nowadays, except perhaps for MS-DOS and if so this program shouldn’t be built there anyway. Don’t bother including sys/types.h, as it’s not needed on modern systems (and syswait.h does it for us anyway). (main): Simplify by assuming SIGSTOP (which is always defined if SIGCONT is), and by assuming HAVE_SOCKETS && HAVE_INET_SOCKETS.
* | emacsclient: negate NO_SOCKETS_IN_FILE_SYSTEMPaul Eggert2018-11-261-16/+16
| | | | | | | | | | | | | | * lib-src/emacsclient.c (SOCKETS_IN_FILE_SYSTEM): Rename from NO_SOCKETS_IN_FILE_SYSTEM, with inverted sense. All uses changed. All uses were of the form ‘#ifndef NO_SOCKETS_IN_FILE_SYSTEM’, and it’s easier to read ‘#ifdef SOCKETS_IN_FILE_SYSTEM’.
* | emacsclient: fix some races on POSIX systemsPaul Eggert2018-11-261-85/+196
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix some longstanding race conditions due to emacsclient’s use of ‘signal’ instead of ‘sigaction’ and its use of nested signal handlers. These races could cause premature exit or incorrect commands sent to Emacs. * lib-src/emacsclient.c (signal) [!WINDOWSNT]: Do not undef. (emacs_socket): Remove this static variable. It is now a parameter. (send_to_emacs): Do not exit merely because ‘send’ was interrupted. Instead, act on the signal if possible, and then retry the ‘send’. (pass_signal_to_emacs): Remove; now done by act_on_signals. (reinstall_handler_if_needed, handle_sigttou, handle_sigwinch) (install_handler): New functions. (got_sigcont, got_sigtstp, got_sigttou, got_sigwinch): New globals, used for more-portable signal handling. (handle_sigcont, handle_sigtstp): Just set the static var; other actions are now done later by act_on_signals. (install_handler): New function that arranges for signals to never be reset to default, on modern POSIX platforms. This fixes some races. (act_on_signals): New function. When acting on SIGCONT, don’t bother calling getpgrp if tcgetpgrp fails. (start_daemon_and_retry_set_socket): Return the socket rather than setting a global variable. All uses changed. (flush_stdout): New function that acts on signals received while flushing. (main): Use it. emacs_socket is now a local var. Act on signals received during recv.
* | Avoid compilation warning in emacsclient.cEli Zaretskii2018-11-231-1/+3
| | | | | | | | | | * lib-src/emacsclient.c (set_tcp_socket): Avoid compilation warning in MS-Windows build.
* | emacsclient: fix child exit when exec failsPaul Eggert2018-11-231-9/+5
| | | | | | | | | | | | * lib-src/emacsclient.c (start_daemon_and_retry_set_socket): If the execvp of Emacs fails exit instead of having the child run on and do the work of the parent. Coalesce duplicate code.
* | emacsclient: one ‘main’ functionPaul Eggert2018-11-231-28/+19
| | | | | | | | | | * lib-src/emacsclient.c (main): Simplify by having just one ‘main’ function instead of two. Don’t assume argc is positive (!).
* | emacsclient: tidy socket failure cleanupPaul Eggert2018-11-221-27/+23
| | | | | | | | | | | | | | * lib-src/emacsclient.c (set_tcp_socket, set_local_socket): Close socket (instead of leaking it) when ‘connect’ fails. (socket_status): Return errno if stat fails and -1 if we don’t own. (set_local_socket): Simplify based on socket_status change.
* | emacsclient: coalesce WINDOWSNT-specific codePaul Eggert2018-11-221-10/+7
| | | | | | | | | | | | * lib-src/emacsclient.c (sock_err_message) [WINDOWSNT]: Do nothing if w32_window_app () && alternate_editor. Both callers changed.
* | emacsclient: sockaddr portability fixesPaul Eggert2018-11-221-21/+25
| | | | | | | | | | | | | | | | | | | | * lib-src/emacsclient.c (get_server_config, set_tcp_socket) (set_local_socket): Initialize any platform-specific extensions of struct to zero, just in case. (set_tcp_socket, set_local_socket): Don’t assume struct layout details that POSIX does not specify. Use union to sidestep some problems with strict aliasing. Remove unnecessary casts.
* | emacsclient: getopt minor cleanupPaul Eggert2018-11-211-9/+12
| | | | | | | | | | * lib-src/emacsclient.c (shortopts): New constant. (decode_options): Use it. Do not assume EOF == -1.
* | emacsclient: omit EXTRA_SPACE guessworkPaul Eggert2018-11-211-31/+31
| | | | | | | | | | | | | | | | | | * lib-src/emacsclient.c: Include <intprops.h>. (EXTRA_SPACE): Remove; code no longer guesses this is enough. (open_config): New function. (get_server_config): Use it. (set_local_socket): Compute upper bound of buffer size instead of guessing via EXTRA_SPACE.
* | emacsclient: take more care with int widthPaul Eggert2018-11-211-7/+10
| | | | | | | | | | | | | | * lib-src/emacsclient.c: Include inttypes.h, stddef.h. (emacs_pid, main): Don’t assume pid fits in int. (fail): Don’t assume pointer difference fits in int. (set_local_socket): Don’t assume uid fits in long.
* | emacsclient.c: use C99 to avoid {}Paul Eggert2018-11-211-110/+108
| | | | | | | | | | * lib-src/emacsclient.c (set_local_socket): Assume C99 decl-after-statement and reindent.
* | emacsclient: improve use of localsPaul Eggert2018-11-211-7/+6
| | | | | | | | | | * lib-src/emacsclient.c (main): Use smaller scopes for some locals.
* | emacsclient: fix unlikely crash with "&"Paul Eggert2018-11-211-51/+34
| | | | | | | | | | | | | | * lib-src/emacsclient.c (quote_argument): Mention *DATA in comment so it’s clear DATA must be non-null. (quote_argument, unquote_argument): Simplify. (unquote_argument): Don’t crash if the string ends in "&".
* | Fix last changeEli Zaretskii2018-11-191-0/+2
| | | | | | | | | | | | * lib-src/emacsclient.c (start_daemon_and_retry_set_socket) [!WINDOWSNT]: Condition usage of socket_name on NO_SOCKETS_IN_FILE_SYSTEM being undefined.
* | Avoid compiler warning in emacsclient.cEli Zaretskii2018-11-191-0/+2
| | | | | | | | | | | | * lib-src/emacsclient.c (socket_name): Define only if NO_SOCKETS_IN_FILE_SYSTEM is not defined, to avoid a compiler warning.
* | emacsclient.c: file name component fixesPaul Eggert2018-11-191-29/+6
| | | | | | | | | | | | | | | | * lib-src/emacsclient.c: Include <dosname.h>. (file_name_absolute_p): Remove, as a code duplicate. All uses replaced by IS_ABSOLUTE_FILE_NAME. (set_local_socket): Don’t treat \ as a file name separator on GNU and POSIX hosts.
* | emacsclient.c: reindent to fit in 80Paul Eggert2018-11-191-11/+17
| | | | | | | | * lib-src/emacsclient.c: Reindent slightly.
* | emacsclient.c: use C99 betterPaul Eggert2018-11-191-26/+22
| | | | | | | | | | | | * lib-src/emacsclient.c (get_current_dir_name) (send_to_emacs, set_tcp_socket, set_local_socket, main): Take advantage of C99 stmt before decl.
* | emacsclient.c: use STDOUT_FILENOPaul Eggert2018-11-191-5/+5
| | | | | | | | | | * lib-src/emacsclient.c (find_tty, handle_sigcont, main): Use STDOUT_FILENO instead of fileno (stdout) or magic 1.
* | emacsclient.c: use bool for booleanPaul Eggert2018-11-191-89/+78
| | | | | | | | | | | | | | | | | | * lib-src/emacsclient.c (nowait, quiet, suppress_output, eval, tty) (decode_options, file_name_absolute_p, get_server_config) (strprefix, find_tty, set_socket, main): Use bool for boolean. (create_frame): New static var, replacing the old current_frame and with inverted sense, as this is clearer.
* | emacsclient.c: make identifiers more localPaul Eggert2018-11-191-31/+34
| | | | | | | | | | | | | | | | | | | | | | * lib-src/emacsclient.c (progname, main_argc, main_argv): (nowait, quiet, suppress_output, eval, current_frame, display): (alt_display, parent_id, tty, alternate_editor, socket_name): (server_file, tramp_prefix, emacs_pid, frame_parameters): (longopts, xstrdup, send_bufffer, sblen, emacs_socket): Now static. (SEND_BUFFER_SIZE, send_buffer, sblen): Now local to send_to_emacs.
* | emacsclient.c: clean up preprocessing directivesPaul Eggert2018-11-191-82/+59
| | | | | | | | | | | | | | * lib-src/emacsclient.c [WINDOWSNT]: Omit duplicate stdlib.h include. Include min-max.h. (EXIT_SUCCESS, EXIT_FAILURE, min): Remove; no longer needed. (AUTH_KEY_LENGTH, SEND_BUFFER_SIZE): Now constants instead of macros.
* | Root emacsclient no longer connects to non-root socketsGlenn Morris2018-11-131-8/+3
| | | | | | | | | | | | * lib-src/emacsclient.c (set_local_socket): Don't ignore socket ownership when run by root. Ref: http://lists.gnu.org/r/emacs-devel/2018-11/msg00019.html
* | Add support in emacsclient for EMACS_SOCKET_NAMEDaniel Pittman2018-10-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the '--socket-name' argument is unspecified, the environment variable 'EMACS_SOCKET_NAME' is now consulted with the same semantics. This mirrors the behavior of the '--server-file' argument, and allows for easier configuration of emacsclient when the socket is in a location other than 'TMPDIR' or '/tmp'. * emacsclient.c (set_socket): Add support for the EMACS_SOCKET_NAME environment variable. (Bug#33095) * misc.texi (emacsclient Options): * emacsclient.1: Document the EMACS_SOCKET_NAME environment variable. * etc/NEWS: Announce the new feature. Copyright-paperwork-exempt: yes
* | Merge from origin/emacs-26Glenn Morris2018-08-101-1/+3
|\| | | | | | | | | | | | | | | 5afbf62 Fix emacsclient check for term.el buffer (Bug#21041) 5132a58 Improve documentation of 'set-fontset-font' cd90325 Improve documentation of M-? 155a885 Reinterpret Esperanto characters in iso-transl as iso-8859-3. a0ef733 Fix Flyspell mode when several languages are mixed in a buffer
| * Fix emacsclient check for term.el buffer (Bug#21041)Noam Postavsky2018-08-081-1/+3
| | | | | | | | | | | | * lib-src/emacsclient.c (find_tty): Check for any TERM value with prefix of "eterm", not just "eterm" itself. Also check for ",term:" in INSIDE_EMACS value.
| * Port --enable-gcc-warnings to GCC 8Paul Eggert2018-04-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | Backport from master. * lib-src/emacsclient.c (fail): Do not dereference a null pointer. * src/frame.c (delete_frame): Add a decl with UNINIT to work around GCC bug 85563. * src/menu.h (finish_menu_items): Do not use attribute const. * src/regex.c (analyze_first): Use FALLTHROUGH, not a comment.
* | Port --enable-gcc-warnings to GCC 8Paul Eggert2018-04-281-11/+14
|/ | | | | | | | | | | | | | | | | | | | | * configure.ac: Do not use GCC 8’s new -Wcast-align flag. * lib-src/ebrowse.c (xmalloc): * lib-src/emacsclient.c (xmalloc, xstrdup): * lib-src/etags.c (xmalloc): * lib-src/make-docfile.c (xmalloc): * lib-src/movemail.c (xmalloc): * src/dispnew.c (new_glyph_pool): * src/regex.c (xmalloc): * src/term.c (tty_menu_create): * src/tparam.h (tparam): Use ATTRIBUTE_MALLOC. Also see GCC bug 85562. * lib-src/emacsclient.c (fail): Do not dereference a null pointer. * src/frame.c (delete_frame): Add a decl with UNINIT to work around GCC bug 85563. * src/menu.h (finish_menu_items): Do not use attribute const. * src/regex.c (analyze_first): Use FALLTHROUGH, not a comment.
* Update copyright year to 2018Paul Eggert2018-01-011-1/+1
| | | | Run admin/update-copyright.
* Prefer HTTPS to FTP and HTTP in documentationPaul Eggert2017-09-131-1/+1
| | | | | | | | | | | | | Most of this change is to boilerplate commentary such as license URLs. This change was prompted by ftp://ftp.gnu.org's going-away party, planned for November. Change these FTP URLs to https://ftp.gnu.org instead. Make similar changes for URLs to other organizations moving away from FTP. Also, change HTTP to HTTPS for URLs to gnu.org and fsf.org when this works, as this will further help defend against man-in-the-middle attacks (for this part I omitted the MS-DOS and MS-Windows sources and the test tarballs to keep the workload down). HTTPS is not fully working to lists.gnu.org so I left those URLs alone for now.
* Add support for arguments in emacsclient's ALTERNATE_EDITOR (Bug #25082)Reuben Thomas2017-08-301-18/+66
| | | | | | | | | | | | | | | | * lib-src/emacsclient.c (fail): Parse ALTERNATE_EDITOR, or corresponding command-line argument, into quote- or space-separated tokens. If a token starts with a quote, then it naturally is expected to end with a quote; escaping is not supported. This is enough to cope with the typical case of requiring the initial path to be quoted, common on Windows where it may contain spaces. * etc/NEWS: Document. * doc/emacs/misc.texi: Likewise. * doc/man/emacsclient.1: Tweak to remove the implication that only an editor can be specified (the manual already mentions a “command”). Fix a small error where “EDITOR” is referred to rather than “ALTERNATE_EDITOR”. * test/lib-src/emacsclient-tests.el: Add tests.
* Revert "Add support for arguments in ALTERNATE_EDITOR to emacsclient"Reuben Thomas2017-08-071-55/+18
| | | | This reverts commit 28f1fe97daa13e13714e6c43c9a6fbb0c0e99a26.
* Add support for arguments in ALTERNATE_EDITOR to emacsclientReuben Thomas2017-08-071-18/+55
| | | | | | | * lib-src/emacsclient.c (fail): Parse ALTERNATE_EDITOR, or corresponding command-line argument, into space-separated tokens. * etc/NEWS: Document. * test/lib-src/emacsclient-tests.el: Add a test.
* Use unlocked stdio more systematicallyPaul Eggert2017-06-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This can improve performance significantly on stdio-bottlenecked code. E.g., make-docfile is 3x faster on my Fedora 25 x86-64 desktop. * admin/merge-gnulib (GNULIB_MODULES): Add unlocked-io. * lib-src/ebrowse.c, lib-src/emacsclient.c, lib-src/etags.c: * lib-src/hexl.c, lib-src/make-docfile.c, lib-src/movemail.c: * lib-src/profile.c, lib-src/update-game-score.c: Include unlocked-io.h instead of stdio.h, since these programs are single-threaded. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib/unlocked-io.h, m4/unlocked-io.m4: New files, copied from Gnulib. * src/charset.c, src/cm.c, src/emacs.c, src/image.c, src/keyboard.c: * src/lread.c, src/term.c: Include sysstdio.h, possibly instead of stdio.h, to define the unlocked functions if the system does not provide them. * src/charset.c, src/lread.c (getc_unlocked): Remove, since sysstdio.h now defines it if needed. * src/cm.c (cmputc, cmcheckmagic): * src/dispnew.c (update_frame, update_frame_with_menu) (update_frame_1, Fsend_string_to_terminal, Fding, bitch_at_user): * src/emacs.c (main, Fdump_emacs): * src/fileio.c (Fdo_auto_save, Fset_binary_mode): * src/image.c (slurp_file, png_read_from_file, png_load_body) (our_stdio_fill_input_buffer): * src/keyboard.c (record_char, kbd_buffer_get_event, handle_interrupt): * src/lread.c (readbyte_from_file): * src/minibuf.c (read_minibuf_noninteractive): * src/print.c (printchar_to_stream, strout) (Fredirect_debugging_output): * src/sysdep.c (reset_sys_modes, procfs_ttyname) (procfs_get_total_memory): * src/term.c (tty_ring_bell, tty_send_additional_strings) (tty_set_terminal_modes, tty_reset_terminal_modes) (tty_update_end, tty_clear_end_of_line, tty_write_glyphs) (tty_write_glyphs_with_face, tty_insert_glyphs) (tty_menu_activate): * src/xfaces.c (Fx_load_color_file): Use unlocked stdio when it should be safe. * src/sysstdio.h (clearerr_unlocked, feof_unlocked, ferror_unlocked) (fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked) (fread_unlocked, fwrite_unlocked, getc_unlocked, getchar_unlocked) (putc_unlocked, putchar_unloced): Provide substitutes if not declared.
* Free cwd when no longer neededPaul Eggert2017-05-311-3/+2
| | | | * lib-src/emacsclient.c (main): Don’t dally when freeing cwd.
* Fix memory leak of cwd string in emacsclient (Bug#26628)Anders Waldenborg2017-05-311-0/+2
| | | | | | | | * lib-src/emacsclient.c (main): emacsclient retrieves the current working directory using get_current_dir_name which returns a newly allocated string. Make sure this string is freed before exiting. Copyright-paperwork-exempt: yes
* Support remote editing in emacsclient via TrampEli Zaretskii2017-05-191-2/+18
| | | | | | | | | | | | | | * lib-src/emacsclient.c (main, decode_options) (print_help_and_exit, longopts): New option '--tramp' / '-T' which specifies how emacs should use tramp to find remote files. * doc/emacs/misc.texi (TCP Emacs server): New subsection describing the various knobs to tune server.el for TCP opereation. (emacsclient Options): Reference "TCP Emacs server" from description of --server-file. Document the new '--tramp' / '-T' options. * doc/emacs/emacs.texi (Top): Update the top-level menu. * etc/NEWS: Mention the new option.