summaryrefslogtreecommitdiff
path: root/lib-src/emacsclient.c
Commit message (Collapse)AuthorAgeFilesLines
* Avoid using %n in emacsclientOmar Polo2021-08-221-4/+3
| | | | * lib-src/emacsclient.c (local_sockname): Avoid using %n (bug#50155).
* Redo emacsclient socket symlink-attack checkingPaul Eggert2021-07-231-79/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * admin/merge-gnulib (GNULIB_MODULES): Add file-has-acl. * lib/file-has-acl.c: New file, copied from Gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib-src/emacsclient.c: Include acl.h, for file_has_acl. (O_PATH): Default to O_SEARCH, which is good enough here. (union local_sockaddr): New type. (socket_status): Remove, replacing with ... (connect_socket): New function. All callers changed. This function checks for ownership and permissions issues with the parent directory of the socket file, instead of checking the owner of the socket (which does not help security). (socknamesize): Move to file scope. (local_sockname): New arg S. No need to pass socknamesize. UID arg is now uid_t. All callers changed. Get file descriptor of parent directory of socket, to foil some symlink attacks. Do not follow symlinks to that directory. (set_local_socket): Create the socket here instead of on each attempt to connect it. Fall back from XDG_RUNTIME_DIR to /tmp only if the former fails due to ENOENT. Adjust permission-failure diagnostic to match changed behavior. This addresses Bug#33847, which complained about emacsclient in a safer XDG environment not connecting to an Emacs server running in a less-safe enviroment outside XDG. The patch fixes a longstanding issue with emacsclient permission checking. It’s ineffective to look at the permission of the socket file itself; on some platforms, these permissions are ignored anyway. What matters are the permissions on the parent directory of the socket file, as these are what make symlink attacks possible. Change the permissions check accordingly, and also refuse to follow symlinks to that parent directory. These changes make it OK for emacsclient to fall back from XDG_RUNTIME_DIR to the traditionally less-safe /tmp/emacsNNNN directories, since /tmp is universally sticky nowadays.
* Update copyright year to 2021Paul Eggert2021-01-011-1/+1
| | | | Run "TZ=UTC0 admin/update-copyright".
* Adjust to recent Gnulib changesPaul Eggert2020-12-251-27/+12
| | | | | | | | | | | | | | | | | | | | | | The latest Gnulib merge brought in free-posix, which causes 'free' to preserve errno. This lets us simplify some Emacs code that calls 'free'. * admin/merge-gnulib (GNULIB_MODULES): Add free-posix. This module is pulled in by canonicalize-lgpl anyway, so we might as well rely on it. * lib-src/emacsclient.c (get_current_dir_name): Sync better with src/sysdep.c. * lib-src/etags.c (process_file_name, etags_mktmp): * lib-src/update-game-score.c (unlock_file): * src/fileio.c (file_accessible_directory_p): * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by assuming that 'free' preserves errno. * src/alloc.c (malloc_unblock_input): Preserve errno, so that xfree preserves errno. * src/sysdep.c (get_current_dir_name_or_unreachable): Simplify by using strdup instead of malloc+memcpy. No need for realloc (and the old code leaked memory anyway on failure); just use free+malloc.
* Don't output emacsclient warning if both -a and --quietLars Ingebrigtsen2020-08-131-5/+11
| | | | | | * lib-src/emacsclient.c (set_local_socket): Don't output the warning if both -a and --quiet are specified (bug#16117). Inspired by a patch from Scott Turner <srt19170@gmail.com>.
* Stop using newly-deprecated dosname Gnulib modulePaul Eggert2020-03-281-1/+1
| | | | | | | | | Code is supposed to use the filename module now. * admin/merge-gnulib (GNULIB_MODULES): Replace dosname with filename. * lib/dosname.h: Remove this forwarding stub. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib-src/emacsclient.c, src/fileio.c: Include filename.h instead of dosname.h.
* Make emacs prefer an existing ~/.emacs.d to an existing XDG locationRobert Pluim2020-01-161-8/+9
| | | | | | | | | | | | | | | * doc/emacs/custom.texi (Find Init): Update description of how Emacs finds its init file directory and the interaction with $XDG_CONFIG_HOME (Early Init File): Correct XDG location of early-init.el * etc/NEWS: Update description to make it clear the ~/.emacs.d is preferred, even if the XDG location exists. * lisp/startup.el: Prefer ~/.emacs.d even if the XDG location exists. * lib-src/emacsclient.c (open_config): Prefer home directory the XDG location.
* Update copyright year to 2020Paul Eggert2020-01-011-1/+1
| | | | Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
* Revert "emacsclient: ignore --eval parameters when starting alternate editor"Lars Ingebrigtsen2019-09-151-5/+1
| | | | | | This reverts commit 6fe661342a24edcaea255c3ba9a37613031554da. The alternate editor may be Emacs, which is useful when you want to eval something in an existing Emacs (if it exists), or in a new Emacs if there's no server running.
* emacsclient: adjust to new config file locationPaul Eggert2019-08-301-15/+32
| | | | | | | * lib-src/emacsclient.c (open_config): New arg XDG, to respect XDG_CONFIG_HOME, consistently with Emacs proper. Caller changed. Use XDG convention if available, falling back on the old names if not.
* emacsclient: ignore --eval parameters when starting alternate editorLars Ingebrigtsen2019-06-271-1/+5
| | | | | | * lib-src/emacsclient.c (fail): If the user said --eval, don't pass those arguments to the alternate editor as file names. Suggested by a patch from Scott Turner (bug#11474).
* Fix PATH_MAX change to lib-src/emacsclient.cJuanma Barranquero2019-06-261-0/+1
| | | | * lib-src/emacsclient.c (get_current_dir_name): Declare pwdlen.
* Prefer PATH_MAX to MAXPATHLENPaul Eggert2019-06-251-6/+16
| | | | | | | | | | | | | | | | PATH_MAX is standardized, MAXPATHLEN is not. Also, the Gnulib pathmax module fixes some rare bugs with PATH_MAX. So prefer PATH_MAX to MAXPATHLEN unless we know the latter is also correct (for some platform-specific code). * admin/merge-gnulib (GNULIB_MODULES): Add pathmax. This module was already present, as a dependency of canonicalize-lgpl, but now Emacs is using it directly. Sort. * lib-src/emacsclient.c: Include stdint.h, pathmax.h. (get_current_dir_name): Sync to current src/sysdep.c. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * src/sysdep.c: Include pathmax.h. (get_current_dir_name_or_unreachable): Use PATH_MAX instead of MAXPATHLEN.
* Simplify lib-src version printingPaul Eggert2019-06-201-5/+1
| | | | | | | | | | | | | | | | * lib-src/Makefile.in (etags_cflags): Remove. All uses replaced by a simple ‘-o $@’. (ebrowse${EXEEXT}, emacsclient${EXEEXT}, emacsclientw${EXEEXT}): Omit -DVERSION= option. * lib-src/ebrowse.c (VERSION): * lib-src/emacsclient.c (VERSION): * lib-src/etags.c (EMACS_NAME, VERSION): Remove. All uses replaced by PACKAGE_NAME and PACKAGE_VERSION. * lib-src/ebrowse.c (version): * lib-src/etags.c (print_version): Use fputs to output the version info, since that’s fputs_unlocked. * lib-src/etags.c (PROGRAM_NAME): New macro. (print_version): Use it.
* Improve port to platforms lacking euidaccess (Bug#35406)Paul Eggert2019-04-241-1/+1
| | | | | | | * lib-src/emacsclient.c (set_local_socket): Use faccessat with AT_EACCESS instead of using euidaccess. * admin/merge-gnulib, lib/gnulib.mk.in, m4/gnulib-comp.m4: Revert previous change.
* Improve XDG_RUNTIME_DIR diagnosticPaul Eggert2019-04-201-5/+23
| | | | | | | * lib-src/emacsclient.c (set_local_socket): If there appears to be an XDG runtime directory for the user but XDG_RUNTIME_DIR is unset, suggest setting it while warning about potential security issues (Bug#35300).
* 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.