* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through systemd socket @ 2016-08-13 16:35 Vladimir Lomov 2016-08-15 2:25 ` Paul Eggert 2018-01-07 21:55 ` bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, " Paul Eggert 0 siblings, 2 replies; 15+ messages in thread From: Vladimir Lomov @ 2016-08-13 16:35 UTC (permalink / raw) To: 24218 Hello, first of all I not sure if this is a bug report or more likely it is a feature request. Recently Emacs got code to start daemon by means of systemd. For this one needs to create two files: `emacs.socket` and `emacs.service`, for example, the content of these files can be found in the manual. The problem is that when emacs daemon is started this way any it's client doesn't have correct values for `server-name` and `server-socket-dir` variables. Moreover, attemp to set these variables manually in `.emacs` triggers (that is not surprise, I think) failure in emacs daemon start. I think it should be possible to set these variables to correct values in `.emacs` that don't cause failure in emacs daemon start, especially taking into account that there is `:use-external-socket` variable. To illustrate the situation consider the following `emacs.socket` file [Socket] ListenStream=%t/emacs [Install] WantedBy=sockets.target almost litteraly copied from Emacs manual and following `emacs.service` file [Unit] Description=Emacs [Service] Type=forking ExecStart=/path/to/emacs --daemon ExecStop=/path/to/emacsclient --eval "(kill-emacs)" Restart=always [Install] WantedBy=default.target If one starts `emacs.socket` file $ systemctl --user start emacs.socket and connect to the daemon (which is not started yet) by means of the socket file assuming that `.emacs` is empty $ emacsclient -c -s /run/user/1000/emacs then all is Ok except the values of `server-name` and `server-socket-dir`: they are wrong (they have "default" values: `server` and `/tmp/emacs1000`). If one would use `.emacs` with settings of these variables (setq server-name "emacs" server-socket-dir "/run/user/1000") and run the same command for `emacsclient` in clean conditions (this means that `service` and `socket` must be stopped before that and `socket` must be started again) one finds that daemon is not started. P.S. Sorry if this description isn't clean enough. In GNU Emacs 25.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.20.8) of 2016-08-11 built on smoon6-1.vl-lomov.ru Repository revision: cd3524061346dec4ec820c98b6ca8046eda290c3 Windowing system distributor 'The X.Org Foundation', version 11.0.11804000 Recent messages: Auto-saving...done Saving file /home/vladimir/works/org/.git/COMMIT_EDITMSG... bzip2ing .COMMIT_EDITMSG.~undo-tree~.bz2...done Wrote /home/vladimir/works/org/.git/.COMMIT_EDITMSG.~undo-tree~.bz2 Wrote /home/vladimir/works/org/.git/COMMIT_EDITMSG Git finished [2 times] Type C-h i to view popup manual, ? to describe an argument or action. Running git push -v origin master:refs/heads/master [2 times] Git finished [2 times] When done with this frame, type C-x 5 0 Configured using: 'configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libexecdir=/usr/lib --with-x-toolkit=gtk3 --without-gconf 'CFLAGS=-march=x86-64 -mtune=native -O2 -pipe -fstack-protector-strong' LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro CPPFLAGS=-D_FORTIFY_SOURCE=2' Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 LIBSYSTEMD Important settings: value of $LC_COLLATE: C value of $LANG: ru_RU.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: global-undo-tree-mode: t undo-tree-mode: t diff-auto-refine-mode: t magit-auto-revert-mode: t global-git-commit-mode: t global-auto-complete-mode: t auto-complete-mode: t pdf-occur-global-minor-mode: t shell-dirtrack-mode: t ido-everywhere: t display-time-mode: t show-paren-mode: t tooltip-mode: t global-eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t column-number-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: /usr/share/emacs/site-lisp/org/org-list hides /usr/share/emacs/25.1.50/lisp/org/org-list /usr/share/emacs/site-lisp/org/org-element hides /usr/share/emacs/25.1.50/lisp/org/org-element /usr/share/emacs/site-lisp/org/org-mouse hides /usr/share/emacs/25.1.50/lisp/org/org-mouse /usr/share/emacs/site-lisp/org/org-attach hides /usr/share/emacs/25.1.50/lisp/org/org-attach /usr/share/emacs/site-lisp/org/org-agenda hides /usr/share/emacs/25.1.50/lisp/org/org-agenda /usr/share/emacs/site-lisp/org/ob-screen hides /usr/share/emacs/25.1.50/lisp/org/ob-screen /usr/share/emacs/site-lisp/org/ox-html hides /usr/share/emacs/25.1.50/lisp/org/ox-html /usr/share/emacs/site-lisp/org/ob-sass hides /usr/share/emacs/25.1.50/lisp/org/ob-sass /usr/share/emacs/site-lisp/org/ob-ditaa hides /usr/share/emacs/25.1.50/lisp/org/ob-ditaa /usr/share/emacs/site-lisp/org/ob-keys hides /usr/share/emacs/25.1.50/lisp/org/ob-keys /usr/share/emacs/site-lisp/org/ob-core hides /usr/share/emacs/25.1.50/lisp/org/ob-core /usr/share/emacs/site-lisp/org/ob-ocaml hides /usr/share/emacs/25.1.50/lisp/org/ob-ocaml /usr/share/emacs/site-lisp/org/ob-comint hides /usr/share/emacs/25.1.50/lisp/org/ob-comint /usr/share/emacs/site-lisp/org/ob-ruby hides /usr/share/emacs/25.1.50/lisp/org/ob-ruby /usr/share/emacs/site-lisp/org/ob-calc hides /usr/share/emacs/25.1.50/lisp/org/ob-calc /usr/share/emacs/site-lisp/org/ob-plantuml hides /usr/share/emacs/25.1.50/lisp/org/ob-plantuml /usr/share/emacs/site-lisp/org/org-macro hides /usr/share/emacs/25.1.50/lisp/org/org-macro /usr/share/emacs/site-lisp/org/org-irc hides /usr/share/emacs/25.1.50/lisp/org/org-irc /usr/share/emacs/site-lisp/org/org-inlinetask hides /usr/share/emacs/25.1.50/lisp/org/org-inlinetask /usr/share/emacs/site-lisp/org/ox-beamer hides /usr/share/emacs/25.1.50/lisp/org/ox-beamer /usr/share/emacs/site-lisp/org/org-info hides /usr/share/emacs/25.1.50/lisp/org/org-info /usr/share/emacs/site-lisp/org/org-indent hides /usr/share/emacs/25.1.50/lisp/org/org-indent /usr/share/emacs/site-lisp/org/ox-ascii hides /usr/share/emacs/25.1.50/lisp/org/ox-ascii /usr/share/emacs/site-lisp/org/org-id hides /usr/share/emacs/25.1.50/lisp/org/org-id /usr/share/emacs/site-lisp/org/org-habit hides /usr/share/emacs/25.1.50/lisp/org/org-habit /usr/share/emacs/site-lisp/org/org-gnus hides /usr/share/emacs/25.1.50/lisp/org/org-gnus /usr/share/emacs/site-lisp/org/org-footnote hides /usr/share/emacs/25.1.50/lisp/org/org-footnote /usr/share/emacs/site-lisp/org/org-timer hides /usr/share/emacs/25.1.50/lisp/org/org-timer /usr/share/emacs/site-lisp/org/org-feed hides /usr/share/emacs/25.1.50/lisp/org/org-feed /usr/share/emacs/site-lisp/org/ox hides /usr/share/emacs/25.1.50/lisp/org/ox /usr/share/emacs/site-lisp/org/org-faces hides /usr/share/emacs/25.1.50/lisp/org/org-faces /usr/share/emacs/site-lisp/org/ox-texinfo hides /usr/share/emacs/25.1.50/lisp/org/ox-texinfo /usr/share/emacs/site-lisp/org/org-eshell hides /usr/share/emacs/25.1.50/lisp/org/org-eshell /usr/share/emacs/site-lisp/org/org-table hides /usr/share/emacs/25.1.50/lisp/org/org-table /usr/share/emacs/site-lisp/org/org-entities hides /usr/share/emacs/25.1.50/lisp/org/org-entities /usr/share/emacs/site-lisp/org/org-src hides /usr/share/emacs/25.1.50/lisp/org/org-src /usr/share/emacs/site-lisp/org/org-rmail hides /usr/share/emacs/25.1.50/lisp/org/org-rmail /usr/share/emacs/site-lisp/org/org-docview hides /usr/share/emacs/25.1.50/lisp/org/org-docview /usr/share/emacs/site-lisp/org/org-protocol hides /usr/share/emacs/25.1.50/lisp/org/org-protocol /usr/share/emacs/site-lisp/org/org-datetree hides /usr/share/emacs/25.1.50/lisp/org/org-datetree /usr/share/emacs/site-lisp/org/org-plot hides /usr/share/emacs/25.1.50/lisp/org/org-plot /usr/share/emacs/site-lisp/org/org-ctags hides /usr/share/emacs/25.1.50/lisp/org/org-ctags /usr/share/emacs/site-lisp/org/ox-publish hides /usr/share/emacs/25.1.50/lisp/org/ox-publish /usr/share/emacs/site-lisp/org/org-crypt hides /usr/share/emacs/25.1.50/lisp/org/org-crypt /usr/share/emacs/site-lisp/org/ox-org hides /usr/share/emacs/25.1.50/lisp/org/ox-org /usr/share/emacs/site-lisp/org/org-compat hides /usr/share/emacs/25.1.50/lisp/org/org-compat /usr/share/emacs/site-lisp/org/org-pcomplete hides /usr/share/emacs/25.1.50/lisp/org/org-pcomplete /usr/share/emacs/site-lisp/org/org-colview hides /usr/share/emacs/25.1.50/lisp/org/org-colview /usr/share/emacs/site-lisp/org/org-clock hides /usr/share/emacs/25.1.50/lisp/org/org-clock /usr/share/emacs/site-lisp/org/ox-odt hides /usr/share/emacs/25.1.50/lisp/org/ox-odt /usr/share/emacs/site-lisp/org/org-capture hides /usr/share/emacs/25.1.50/lisp/org/org-capture /usr/share/emacs/site-lisp/org/org-mobile hides /usr/share/emacs/25.1.50/lisp/org/org-mobile /usr/share/emacs/site-lisp/org/org-bibtex hides /usr/share/emacs/25.1.50/lisp/org/org-bibtex /usr/share/emacs/site-lisp/org/org-mhe hides /usr/share/emacs/25.1.50/lisp/org/org-mhe /usr/share/emacs/site-lisp/org/org-bbdb hides /usr/share/emacs/25.1.50/lisp/org/org-bbdb /usr/share/emacs/site-lisp/org/ox-md hides /usr/share/emacs/25.1.50/lisp/org/ox-md /usr/share/emacs/site-lisp/org/org-macs hides /usr/share/emacs/25.1.50/lisp/org/org-macs /usr/share/emacs/site-lisp/org/org-archive hides /usr/share/emacs/25.1.50/lisp/org/org-archive /usr/share/emacs/site-lisp/org/org-w3m hides /usr/share/emacs/25.1.50/lisp/org/org-w3m /usr/share/emacs/site-lisp/org/org hides /usr/share/emacs/25.1.50/lisp/org/org /usr/share/emacs/site-lisp/org/ob hides /usr/share/emacs/25.1.50/lisp/org/ob /usr/share/emacs/site-lisp/org/ob-tangle hides /usr/share/emacs/25.1.50/lisp/org/ob-tangle /usr/share/emacs/site-lisp/org/ox-man hides /usr/share/emacs/25.1.50/lisp/org/ox-man /usr/share/emacs/site-lisp/org/ob-table hides /usr/share/emacs/25.1.50/lisp/org/ob-table /usr/share/emacs/site-lisp/org/ox-latex hides /usr/share/emacs/25.1.50/lisp/org/ox-latex /usr/share/emacs/site-lisp/org/ob-sqlite hides /usr/share/emacs/25.1.50/lisp/org/ob-sqlite /usr/share/emacs/site-lisp/org/ox-icalendar hides /usr/share/emacs/25.1.50/lisp/org/ox-icalendar /usr/share/emacs/site-lisp/org/ob-sql hides /usr/share/emacs/25.1.50/lisp/org/ob-sql /usr/share/emacs/site-lisp/org/ob-shen hides /usr/share/emacs/25.1.50/lisp/org/ob-shen /usr/share/emacs/site-lisp/org/ob-scheme hides /usr/share/emacs/25.1.50/lisp/org/ob-scheme /usr/share/emacs/site-lisp/org/ob-scala hides /usr/share/emacs/25.1.50/lisp/org/ob-scala /usr/share/emacs/site-lisp/org/ob-python hides /usr/share/emacs/25.1.50/lisp/org/ob-python /usr/share/emacs/site-lisp/org/ob-ref hides /usr/share/emacs/25.1.50/lisp/org/ob-ref /usr/share/emacs/site-lisp/org/ob-lisp hides /usr/share/emacs/25.1.50/lisp/org/ob-lisp /usr/share/emacs/site-lisp/org/ob-fortran hides /usr/share/emacs/25.1.50/lisp/org/ob-fortran /usr/share/emacs/site-lisp/org/ob-exp hides /usr/share/emacs/25.1.50/lisp/org/ob-exp /usr/share/emacs/site-lisp/org/ob-perl hides /usr/share/emacs/25.1.50/lisp/org/ob-perl /usr/share/emacs/site-lisp/org/ob-lilypond hides /usr/share/emacs/25.1.50/lisp/org/ob-lilypond /usr/share/emacs/site-lisp/org/ob-eval hides /usr/share/emacs/25.1.50/lisp/org/ob-eval /usr/share/emacs/site-lisp/org/ob-org hides /usr/share/emacs/25.1.50/lisp/org/ob-org /usr/share/emacs/site-lisp/org/ob-ledger hides /usr/share/emacs/25.1.50/lisp/org/ob-ledger /usr/share/emacs/site-lisp/org/ob-emacs-lisp hides /usr/share/emacs/25.1.50/lisp/org/ob-emacs-lisp /usr/share/emacs/site-lisp/org/ob-maxima hides /usr/share/emacs/25.1.50/lisp/org/ob-maxima /usr/share/emacs/site-lisp/org/ob-haskell hides /usr/share/emacs/25.1.50/lisp/org/ob-haskell /usr/share/emacs/site-lisp/org/ob-dot hides /usr/share/emacs/25.1.50/lisp/org/ob-dot /usr/share/emacs/site-lisp/org/ob-mscgen hides /usr/share/emacs/25.1.50/lisp/org/ob-mscgen /usr/share/emacs/site-lisp/org/ob-js hides /usr/share/emacs/25.1.50/lisp/org/ob-js /usr/share/emacs/site-lisp/org/ob-matlab hides /usr/share/emacs/25.1.50/lisp/org/ob-matlab /usr/share/emacs/site-lisp/org/ob-java hides /usr/share/emacs/25.1.50/lisp/org/ob-java /usr/share/emacs/site-lisp/org/ob-css hides /usr/share/emacs/25.1.50/lisp/org/ob-css /usr/share/emacs/site-lisp/org/ob-octave hides /usr/share/emacs/25.1.50/lisp/org/ob-octave /usr/share/emacs/site-lisp/org/ob-latex hides /usr/share/emacs/25.1.50/lisp/org/ob-latex /usr/share/emacs/site-lisp/org/ob-lob hides /usr/share/emacs/25.1.50/lisp/org/ob-lob /usr/share/emacs/site-lisp/org/ob-io hides /usr/share/emacs/25.1.50/lisp/org/ob-io /usr/share/emacs/site-lisp/org/ob-clojure hides /usr/share/emacs/25.1.50/lisp/org/ob-clojure /usr/share/emacs/site-lisp/org/ob-makefile hides /usr/share/emacs/25.1.50/lisp/org/ob-makefile /usr/share/emacs/site-lisp/org/ob-gnuplot hides /usr/share/emacs/25.1.50/lisp/org/ob-gnuplot /usr/share/emacs/site-lisp/org/ob-R hides /usr/share/emacs/25.1.50/lisp/org/ob-R /usr/share/emacs/site-lisp/org/ob-awk hides /usr/share/emacs/25.1.50/lisp/org/ob-awk /usr/share/emacs/site-lisp/org/ob-C hides /usr/share/emacs/25.1.50/lisp/org/ob-C /usr/share/emacs/site-lisp/org/ob-picolisp hides /usr/share/emacs/25.1.50/lisp/org/ob-picolisp /usr/share/emacs/site-lisp/org/ob-asymptote hides /usr/share/emacs/25.1.50/lisp/org/ob-asymptote /usr/share/emacs/site-lisp/org/org-loaddefs hides /usr/share/emacs/25.1.50/lisp/org/org-loaddefs /usr/share/emacs/site-lisp/org/org-version hides /usr/share/emacs/25.1.50/lisp/org/org-version /usr/share/emacs/site-lisp/org/org-install hides /usr/share/emacs/25.1.50/lisp/org/org-install Features: (shadow sort spook cookie1 mail-extr emacsbug sendmail linum cal-move parse-time calc-map calc-stat calc-vec calc-ext calc-menu calc-aent calc calc-loaddefs calc-macs org-table cdlatex texmathp org-annotate-file org-id org-habit org-info org-docview doc-view org-bibtex bibtex org-bbdb vc-git thingatpt flymake magit-version undo-tree diff magit-blame magit-stash magit-bisect magit-remote magit-commit magit-sequence magit package url-handlers magit-apply magit-wip magit-log magit-diff smerge-mode diff-mode magit-core magit-autorevert autorevert filenotify magit-process magit-popup magit-mode magit-git crm magit-section magit-utils git-commit help-fns radix-tree log-edit message subr-x puny rfc822 mml mml-sec epa epg epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log with-editor tramp-sh server dash auto-complete-config auto-complete popup calfw-ical url url-proxy url-privacy url-expand url-methods url-history url-cookie url-domsuf url-util url-parse url-vars mailcap icalendar diary-lib diary-loaddefs calfw-org org-capture org-agenda calfw holidays hol-loaddefs cl ob-shell ob-R ob-perl ob-latex ob-asymptote ob-gnuplot ox-odt rng-loc rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns nxml-enc xmltok nxml-util ox-latex ox-icalendar ox-html table ox-ascii ox-publish ox preview-latex tex-site auto-loads pdf-sync pdf-outline pdf-occur ibuf-ext ibuffer ibuffer-loaddefs pdf-links pdf-isearch let-alist pdf-history pdf-annot tablist tablist-filter semantic/wisent/comp semantic/wisent semantic/wisent/wisent semantic/util-modes semantic/util semantic semantic/tag semantic/lex semantic/fw mode-local cedet org-element avl-tree org org-macro org-footnote org-pcomplete org-list org-faces org-entities noutline outline org-version ob-emacs-lisp ob ob-tangle org-src ob-ref ob-lob ob-table ob-keys ob-exp ob-comint tramp tramp-compat tramp-loaddefs trampver ucs-normalize shell pcomplete auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs password-cache ob-core ob-eval org-compat org-macs org-loaddefs find-func cal-menu calendar cal-loaddefs pdf-misc imenu pdf-tools compile comint ansi-color ring cus-edit cus-start cus-load wid-edit pdf-view jka-compr pdf-cache pdf-info tq pdf-util image-mode dired+ image-dired format-spec image-file dired-aux bookmark+ bookmark+-key edmacro kmacro easy-mmode advice derived dired-x dired dired-loaddefs bookmark+-1 bookmark+-bmu bookmark+-lit bookmark pp ido seq byte-opt gv bytecomp byte-compile cl-extra cconv quail help-mode easymenu cl-loaddefs pcase cl-lib time flyspell ispell time-date paren mule-util cyril-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote dbusbind inotify dynamic-setting system-font-setting font-render-setting move-toolbar gtk x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 496832 58236) (symbols 48 50535 0) (miscs 40 177 481) (strings 32 118385 14977) (string-bytes 1 3804225) (vectors 16 78228) (vector-slots 8 1869287 211061) (floats 8 507 374) (intervals 56 1311 69) (buffers 976 23)) -- WBR, Vladimir Lomov SUN Microsystems: The Network IS the Load Average. EuroFed ASPIC Attorney General Pipe bomb undercover Leuken-Baden Federal Aviation Administration Reflection Palestine Liberation Organization Chemical burn Incident SWS 22nd SAS Sugar Grove Dirty bomb -- ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through systemd socket 2016-08-13 16:35 bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through systemd socket Vladimir Lomov @ 2016-08-15 2:25 ` Paul Eggert 2018-01-07 21:55 ` bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, " Paul Eggert 1 sibling, 0 replies; 15+ messages in thread From: Paul Eggert @ 2016-08-15 2:25 UTC (permalink / raw) To: Matthew Leach; +Cc: 24218, Vladimir Lomov Matthew, can you please look at: http://bugs.gnu.org/24218 and follow up as seems appropriate? You can reply to this email to add to the bug-report log. Thanks. ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2016-08-13 16:35 bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through systemd socket Vladimir Lomov 2016-08-15 2:25 ` Paul Eggert @ 2018-01-07 21:55 ` Paul Eggert 2018-01-08 3:50 ` Eli Zaretskii 1 sibling, 1 reply; 15+ messages in thread From: Paul Eggert @ 2018-01-07 21:55 UTC (permalink / raw) To: Matthew Leach; +Cc: 24218, Vladimir Lomov [-- Attachment #1: Type: text/plain, Size: 428 bytes --] Matthew proposed a patch for this here: https://lists.gnu.org/r/emacs-devel/2017-12/msg00903.html which I am attaching in git form (see first attached patch). I also propose the second attached patch as a followup. It makes some of the newly-added features "private" (since they don't seem to be generally useful) and moves the low-level initialization code from emacs.c to process.c which is a more-natural home for it. [-- Attachment #2: 0001-Fix-server-name-and-server-socket-dir-for-Bug-24218.patch --] [-- Type: text/x-patch, Size: 8505 bytes --] From 8debb5cd9ada5a8dc7d4a1e5300e7b913fe1e09b Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Sun, 7 Jan 2018 13:47:12 -0800 Subject: [PATCH 1/2] Fix `server-name' and `server-socket-dir' for Bug#24218 * lisp/server.el: (server-external-socket-initialised): New (server-name): Compute server name from `get-external-sockname'. (server-socket-dir): Compute socket dir from `get-external-sockname'. (server-start): Don't check for existing server when an uninitialised external socket has been passed to Emacs. * src/emacs.c: (main): Obtain socket name via getsockname and pass to `init_process_emacs'. * src/lisp.h: (init_process_emacs): Add second parameter. * src/process.c: (external_sock_name): New. (get-external-sockname): New. (init_process_emacs): Set `external_sock_name' to `sockname' parameter. --- lisp/server.el | 56 ++++++++++++++++++++++++++++++++++++-------------------- src/emacs.c | 16 +++++++++++++--- src/lisp.h | 2 +- src/process.c | 19 ++++++++++++++++++- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index ac0d701851..e8b53530c9 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,8 +251,16 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -;;;###autoload -(defcustom server-name "server" +(defvar server-external-socket-initialised nil + "When an external socket is passed into Emacs, we need to call +`server-start' in order to initialise the connection. This flag +prevents multiple initialisations when an external socket has +been consumed.") + +(defcustom server-name + (if (get-external-sockname) + (file-name-nondirectory (get-external-sockname)) + "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be changed while a server is running." @@ -263,8 +271,10 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (and (featurep 'make-network-process '(:family local)) - (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))) + (if (get-external-sockname) + (file-name-directory (get-external-sockname)) + (and (featurep 'make-network-process '(:family local)) + (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. If local sockets are not supported, this is nil.") @@ -618,23 +628,29 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Delete the socket files made by previous server invocations. - (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file - (ignore-errors - (let (delete-by-moving-to-trash) - (delete-file server-file))) - (setq server-mode nil) ;; already set by the minor mode code - (display-warning - 'server - (concat "Unable to start the Emacs server.\n" - (format "There is an existing Emacs server, named %S.\n" - server-name) - (substitute-command-keys - "To start the server in this Emacs process, stop the existing + ;; Check to see if an uninitialised external socket has been + ;; passed in, if that is the case, skip checking + ;; `server-running-p' as this will return the wrong result. + (if (and (get-external-sockname) + (not server-external-socket-initialised)) + (setq server-external-socket-initialised t) + ;; Delete the socket files made by previous server invocations. + (if (not (eq t (server-running-p server-name))) + ;; Remove any leftover socket or authentication file + (ignore-errors + (let (delete-by-moving-to-trash) + (delete-file server-file))) + (setq server-mode nil) ;; already set by the minor mode code + (display-warning + 'server + (concat "Unable to start the Emacs server.\n" + (format "There is an existing Emacs server, named %S.\n" + server-name) + (substitute-command-keys + "To start the server in this Emacs process, stop the existing server or call `\\[server-force-delete]' to forcibly disconnect it.")) - :warning) - (setq leave-dead t)) + :warning) + (setq leave-dead t))) ;; If this Emacs already had a server, clear out associated status. (while server-clients (server-delete-client (car server-clients))) diff --git a/src/emacs.c b/src/emacs.c index 20ced26283..1af09166b6 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,6 +60,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_LIBSYSTEMD # include <systemd/sd-daemon.h> # include <sys/socket.h> +# include <sys/un.h> #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1002,6 +1003,7 @@ main (int argc, char **argv) int sockfd = -1; + char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1061,8 +1063,16 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNSPEC, SOCK_STREAM, 1))) - sockfd = SD_LISTEN_FDS_START; + AF_UNIX, SOCK_STREAM, 1))) + { + struct sockaddr_un sockaddr; + socklen_t sockaddr_sz = sizeof(sockaddr); + + sockfd = SD_LISTEN_FDS_START; + + if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) + sockname = strdup(sockaddr.sun_path); + } #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1656,7 +1666,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd); + init_process_emacs (sockfd, sockname); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index 3eb6e0d3c1..2e9002a226 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4313,7 +4313,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int); +extern void init_process_emacs (int, char *); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index d4440e472d..da8e5714b0 100644 --- a/src/process.c +++ b/src/process.c @@ -276,6 +276,10 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; +/* The name (path) of the socket that was passed to Emacs, when + `external_sock_fd' is not -1. */ +static const char *external_sock_name = NULL; + /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -7974,10 +7978,21 @@ restore_nofile_limit (void) } \f +DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, + doc: /* Return the path of an external socket passed to Emacs. +Otherwise return nil. */) + (void) +{ + if (external_sock_name) + return make_string(external_sock_name, strlen(external_sock_name)); + else + return Qnil; +} + /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd) +init_process_emacs (int sockfd, char *sockname) { #ifdef subprocesses int i; @@ -8012,6 +8027,7 @@ init_process_emacs (int sockfd) #endif external_sock_fd = sockfd; + external_sock_name = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8306,4 +8322,5 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); + defsubr (&Sget_external_sockname); } -- 2.14.3 [-- Attachment #3: 0002-Minor-cleanups-for-server-name-fix-Bug-24218.patch --] [-- Type: text/x-patch, Size: 9315 bytes --] From 51e1d2919b261be0c734ab3a19b3478fb52f43c1 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Sun, 7 Jan 2018 13:47:12 -0800 Subject: [PATCH 2/2] Minor cleanups for server-name fix (Bug#24218) * lisp/server.el (server--external-socket-initialized): Rename from server-external-socket-initialised, since it should be private and Emacs uses American spelling. All uses changed. * src/emacs.c, src/lisp.h: Revert previous changes, as the initialization is now done in src/process.c, which already includes the relevant files. * src/process.c (union u_sockaddr): Move decl to top level. (external_sock_name, Fget_external_sockname): Remove, replacing with Vinternal__external_sockname. All uses changed. (init_process_emacs): Deduce socket name ourselves rather than have main.c do it. Use conv_sockaddr_to_lisp instead of doing it by hand. Conditionalize it on HAVE_GETSOCKNAME. --- lisp/server.el | 24 ++++++++++++------------ src/emacs.c | 16 +++------------- src/lisp.h | 2 +- src/process.c | 58 ++++++++++++++++++++++++++++++---------------------------- 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index e8b53530c9..c867fde832 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,15 +251,15 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -(defvar server-external-socket-initialised nil +(defvar server--external-socket-initialized nil "When an external socket is passed into Emacs, we need to call -`server-start' in order to initialise the connection. This flag -prevents multiple initialisations when an external socket has +`server-start' in order to initialize the connection. This flag +prevents multiple initializations when an external socket has been consumed.") (defcustom server-name - (if (get-external-sockname) - (file-name-nondirectory (get-external-sockname)) + (if internal--external-sockname + (file-name-nondirectory internal--external-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if (get-external-sockname) - (file-name-directory (get-external-sockname)) + (if internal--external-sockname + (file-name-directory internal--external-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -628,15 +628,15 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Check to see if an uninitialised external socket has been + ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and (get-external-sockname) - (not server-external-socket-initialised)) - (setq server-external-socket-initialised t) + (if (and internal--external-sockname + (not server--external-socket-initialized)) + (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file + ;; Remove any leftover socket or authentication file. (ignore-errors (let (delete-by-moving-to-trash) (delete-file server-file))) diff --git a/src/emacs.c b/src/emacs.c index 1af09166b6..20ced26283 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,7 +60,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_LIBSYSTEMD # include <systemd/sd-daemon.h> # include <sys/socket.h> -# include <sys/un.h> #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1003,7 +1002,6 @@ main (int argc, char **argv) int sockfd = -1; - char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1063,16 +1061,8 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNIX, SOCK_STREAM, 1))) - { - struct sockaddr_un sockaddr; - socklen_t sockaddr_sz = sizeof(sockaddr); - - sockfd = SD_LISTEN_FDS_START; - - if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) - sockname = strdup(sockaddr.sun_path); - } + AF_UNSPEC, SOCK_STREAM, 1))) + sockfd = SD_LISTEN_FDS_START; #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1666,7 +1656,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd, sockname); + init_process_emacs (sockfd); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index 2e9002a226..3eb6e0d3c1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4313,7 +4313,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int, char *); +extern void init_process_emacs (int); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index da8e5714b0..2613dd2be0 100644 --- a/src/process.c +++ b/src/process.c @@ -160,6 +160,18 @@ static bool kbd_is_on_hold; when exiting. */ bool inhibit_sentinels; +union u_sockaddr +{ + struct sockaddr sa; + struct sockaddr_in in; +#ifdef AF_INET6 + struct sockaddr_in6 in6; +#endif +#ifdef HAVE_LOCAL_SOCKETS + struct sockaddr_un un; +#endif +}; + #ifdef subprocesses #ifndef SOCK_CLOEXEC @@ -276,10 +288,6 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; -/* The name (path) of the socket that was passed to Emacs, when - `external_sock_fd' is not -1. */ -static const char *external_sock_name = NULL; - /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -4679,16 +4687,7 @@ server_accept_connection (Lisp_Object server, int channel) struct Lisp_Process *ps = XPROCESS (server); struct Lisp_Process *p; int s; - union u_sockaddr { - struct sockaddr sa; - struct sockaddr_in in; -#ifdef AF_INET6 - struct sockaddr_in6 in6; -#endif -#ifdef HAVE_LOCAL_SOCKETS - struct sockaddr_un un; -#endif - } saddr; + union u_sockaddr saddr; socklen_t len = sizeof saddr; ptrdiff_t count; @@ -7978,21 +7977,10 @@ restore_nofile_limit (void) } \f -DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, - doc: /* Return the path of an external socket passed to Emacs. -Otherwise return nil. */) - (void) -{ - if (external_sock_name) - return make_string(external_sock_name, strlen(external_sock_name)); - else - return Qnil; -} - /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd, char *sockname) +init_process_emacs (int sockfd) { #ifdef subprocesses int i; @@ -8027,7 +8015,18 @@ init_process_emacs (int sockfd, char *sockname) #endif external_sock_fd = sockfd; - external_sock_name = sockname; + Lisp_Object sockname = Qnil; +# if HAVE_GETSOCKNAME + if (0 <= sockfd) + { + union u_sockaddr sa; + socklen_t salen = sizeof sa; + if (getsockname (sockfd, &sa.sa, &salen) == 0) + sockname = conv_sockaddr_to_lisp (&sa.sa, salen); + } +# endif + Vinternal__external_sockname = sockname; + max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8220,6 +8219,10 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); + DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + doc: /* Name of external socket passed to Emacs, or nil if none. */); + Vinternal__external_sockname = Qnil; + DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); @@ -8322,5 +8325,4 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); - defsubr (&Sget_external_sockname); } -- 2.14.3 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-07 21:55 ` bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, " Paul Eggert @ 2018-01-08 3:50 ` Eli Zaretskii 2018-01-08 4:24 ` Paul Eggert 2018-01-09 19:53 ` Matthew Leach 0 siblings, 2 replies; 15+ messages in thread From: Eli Zaretskii @ 2018-01-08 3:50 UTC (permalink / raw) To: Paul Eggert; +Cc: 24218, matthew, lomov.vl > From: Paul Eggert <eggert@cs.ucla.edu> > Date: Sun, 7 Jan 2018 13:55:04 -0800 > Cc: 24218@debbugs.gnu.org, Vladimir Lomov <lomov.vl@gmail.com> > > Matthew proposed a patch for this here: > > https://lists.gnu.org/r/emacs-devel/2017-12/msg00903.html > > which I am attaching in git form (see first attached patch). I also > propose the second attached patch as a followup. It makes some of the > newly-added features "private" (since they don't seem to be generally > useful) and moves the low-level initialization code from emacs.c to > process.c which is a more-natural home for it. Thanks. I'm not an expert on this stuff, so I have only minor comments: . Please update the :version tag of server-name, to reflect the fact that its default value changes . This needs a NEWS entry, and I think the description of server-name in the manual should be updated to mention this facility . internal--external-sockname should be documented in the ELisp manual (a better name that doesn't use both "internal" and "external" will be appreciated) ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-08 3:50 ` Eli Zaretskii @ 2018-01-08 4:24 ` Paul Eggert 2018-01-08 18:33 ` Eli Zaretskii 2018-01-09 19:53 ` Matthew Leach 1 sibling, 1 reply; 15+ messages in thread From: Paul Eggert @ 2018-01-08 4:24 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 24218, matthew, lomov.vl Eli Zaretskii wrote: > . internal--external-sockname should be documented in the ELisp > manual (a better name that doesn't use both "internal" and > "external" will be appreciated) The "internal--" prefix is intended to mean "for Emacs internal use only", i.e., that it should not be documented in the manual. ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-08 4:24 ` Paul Eggert @ 2018-01-08 18:33 ` Eli Zaretskii 2018-01-08 18:42 ` Paul Eggert 0 siblings, 1 reply; 15+ messages in thread From: Eli Zaretskii @ 2018-01-08 18:33 UTC (permalink / raw) To: Paul Eggert; +Cc: 24218, matthew, lomov.vl > Cc: matthew@mattleach.net, 24218@debbugs.gnu.org, lomov.vl@gmail.com > From: Paul Eggert <eggert@cs.ucla.edu> > Date: Sun, 7 Jan 2018 20:24:57 -0800 > > Eli Zaretskii wrote: > > . internal--external-sockname should be documented in the ELisp > > manual (a better name that doesn't use both "internal" and > > "external" will be appreciated) > > The "internal--" prefix is intended to mean "for Emacs internal use only" That's exactly why I made the comment about the name: IMO, this variable's purpose is inconsistent with its being for internal use only. ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-08 18:33 ` Eli Zaretskii @ 2018-01-08 18:42 ` Paul Eggert 2018-01-08 19:14 ` Eli Zaretskii 0 siblings, 1 reply; 15+ messages in thread From: Paul Eggert @ 2018-01-08 18:42 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 24218, matthew, lomov.vl On 01/08/2018 10:33 AM, Eli Zaretskii wrote: > this > variable's purpose is inconsistent with its being for internal use > only. What purpose do you see for the variable, other than its use in Emacs's own Lisp code? ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-08 18:42 ` Paul Eggert @ 2018-01-08 19:14 ` Eli Zaretskii 2018-01-08 19:23 ` Paul Eggert 0 siblings, 1 reply; 15+ messages in thread From: Eli Zaretskii @ 2018-01-08 19:14 UTC (permalink / raw) To: Paul Eggert; +Cc: 24218, matthew, lomov.vl > Cc: matthew@mattleach.net, 24218@debbugs.gnu.org, lomov.vl@gmail.com > From: Paul Eggert <eggert@cs.ucla.edu> > Date: Mon, 8 Jan 2018 10:42:28 -0800 > > On 01/08/2018 10:33 AM, Eli Zaretskii wrote: > > this > > variable's purpose is inconsistent with its being for internal use > > only. > > What purpose do you see for the variable, other than its use in Emacs's > own Lisp code? How many seconds do you think it will take Emacs hackers (in the good meaning of the word) to discover this variable and start (ab)using it? ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-08 19:14 ` Eli Zaretskii @ 2018-01-08 19:23 ` Paul Eggert 0 siblings, 0 replies; 15+ messages in thread From: Paul Eggert @ 2018-01-08 19:23 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 24218, matthew, lomov.vl On 01/08/2018 11:14 AM, Eli Zaretskii wrote: > How many seconds do you think it will take Emacs hackers (in the good > meaning of the word) to discover this variable and start (ab)using it? I don't think they'll need to use the variable, which is why I suggested that it be labeled as internal. ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-08 3:50 ` Eli Zaretskii 2018-01-08 4:24 ` Paul Eggert @ 2018-01-09 19:53 ` Matthew Leach 2018-01-24 23:00 ` Paul Eggert 1 sibling, 1 reply; 15+ messages in thread From: Matthew Leach @ 2018-01-09 19:53 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 24218, lomov.vl, Paul Eggert [-- Attachment #1: Type: text/plain, Size: 1316 bytes --] Eli Zaretskii <eliz@gnu.org> writes: >> From: Paul Eggert <eggert@cs.ucla.edu> >> Date: Sun, 7 Jan 2018 13:55:04 -0800 >> Cc: 24218@debbugs.gnu.org, Vladimir Lomov <lomov.vl@gmail.com> >> >> Matthew proposed a patch for this here: >> >> https://lists.gnu.org/r/emacs-devel/2017-12/msg00903.html >> >> which I am attaching in git form (see first attached patch). I also >> propose the second attached patch as a followup. It makes some of the >> newly-added features "private" (since they don't seem to be generally >> useful) and moves the low-level initialization code from emacs.c to >> process.c which is a more-natural home for it. Thanks for the cleanup patch Paul! > > Thanks. I'm not an expert on this stuff, so I have only minor > comments: > > . Please update the :version tag of server-name, to reflect the fact > that its default value changes > . This needs a NEWS entry, and I think the description of > server-name in the manual should be updated to mention this > facility Please see the attached patch that should address these points. > > . internal--external-sockname should be documented in the ELisp > manual (a better name that doesn't use both "internal" and > "external" will be appreciated) May I suggest `internal--daemon-sockname'? Thanks, -- Matt [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Update-server-name-version-tag-and-document-sockname.patch --] [-- Type: text/x-patch, Size: 2181 bytes --] From 5dc51350e7e744f26236e0018112d2eed2dbcc93 Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Tue, 9 Jan 2018 19:45:30 +0000 Subject: [PATCH] Update `server-name' :version tag and document sockname support * lisp/server.el: (server-name): Update :version tag. * etc/NEWS: Document that `server-name' and `server-socket-dir' automatically update. * doc/misc.texi: (Emacs Server): Likewise. --- doc/emacs/misc.texi | 5 +++++ etc/NEWS | 3 +++ lisp/server.el | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 633e1e881d..c9b8f08252 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1654,6 +1654,11 @@ Emacs Server @samp{foo}. The @code{emacsclient} program can specify a server by name, using the @samp{-s} option (@pxref{emacsclient Options}). + If Emacs is passed a socket by an external program --- for example +by systemd socket activation --- the value of @code{server-name} and +@code{server-socket-dir} is automatically updated to reflect the name +and path of the socket. + If you want to run multiple Emacs daemons (@pxref{Initial Options}), you can give each daemon its own server name like this: diff --git a/etc/NEWS b/etc/NEWS index f6f36dfc85..66cb0834c5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -194,6 +194,9 @@ as new-style, bind the new variable 'force-new-style-backquotes' to t. \f * Lisp Changes in Emacs 27.1 +** The `server-name' and `server-socket-dir' variables are set when a +socket has been pased to Emacs (Bug#24218). + ** Internal parsing commands now use syntax-ppss and disregard open-paren-in-column-0-is-defun-start. This affects mostly things like forward-comment, scan-sexps, and forward-sexp when parsing backward. diff --git a/lisp/server.el b/lisp/server.el index c867fde832..16b3f8e4e2 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -266,7 +266,7 @@ server-name changed while a server is running." :group 'server :type 'string - :version "23.1") + :version "27.1") ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. -- 2.15.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-09 19:53 ` Matthew Leach @ 2018-01-24 23:00 ` Paul Eggert 2018-01-25 19:34 ` Matthew Leach 0 siblings, 1 reply; 15+ messages in thread From: Paul Eggert @ 2018-01-24 23:00 UTC (permalink / raw) To: Matthew Leach, Eli Zaretskii; +Cc: 24218, lomov.vl On 01/09/2018 11:53 AM, Matthew Leach wrote: > May I suggest `internal--daemon-sockname'? Yes, that sounds good. Can you prepare a patch along those lines? Sorry, I lost track of this bug report. It'd be nice if you could re-propose a self-contained set of patches that address all the issues raised so far. Thanks. ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-24 23:00 ` Paul Eggert @ 2018-01-25 19:34 ` Matthew Leach 2018-02-10 16:07 ` Paul Eggert 0 siblings, 1 reply; 15+ messages in thread From: Matthew Leach @ 2018-01-25 19:34 UTC (permalink / raw) To: Paul Eggert; +Cc: 24218, lomov.vl [-- Attachment #1: Type: text/plain, Size: 434 bytes --] Paul Eggert <eggert@cs.ucla.edu> writes: > On 01/09/2018 11:53 AM, Matthew Leach wrote: >> May I suggest `internal--daemon-sockname'? > > Yes, that sounds good. Can you prepare a patch along those lines? > Sorry, I lost track of this bug report. It'd be nice if you could > re-propose a self-contained set of patches that address all the issues > raised so far. Thanks. Sure, please see the attached patch series. Thanks, -- Matt [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Fix-server-name-and-server-socket-dir-for-Bug-24218.patch --] [-- Type: text/x-patch, Size: 8507 bytes --] From e098a2dd17bf9a0701a58f2321c369380d81254e Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Sun, 7 Jan 2018 13:47:12 -0800 Subject: [PATCH 1/4] Fix `server-name' and `server-socket-dir' for (Bug#24218) * lisp/server.el: (server-external-socket-initialised): New (server-name): Compute server name from `get-external-sockname'. (server-socket-dir): Compute socket dir from `get-external-sockname'. (server-start): Don't check for existing server when an uninitialised external socket has been passed to Emacs. * src/emacs.c: (main): Obtain socket name via getsockname and pass to `init_process_emacs'. * src/lisp.h: (init_process_emacs): Add second parameter. * src/process.c: (external_sock_name): New. (get-external-sockname): New. (init_process_emacs): Set `external_sock_name' to `sockname' parameter. --- lisp/server.el | 56 ++++++++++++++++++++++++++++++++++++-------------------- src/emacs.c | 16 +++++++++++++--- src/lisp.h | 2 +- src/process.c | 19 ++++++++++++++++++- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index ac0d701851..e8b53530c9 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,8 +251,16 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -;;;###autoload -(defcustom server-name "server" +(defvar server-external-socket-initialised nil + "When an external socket is passed into Emacs, we need to call +`server-start' in order to initialise the connection. This flag +prevents multiple initialisations when an external socket has +been consumed.") + +(defcustom server-name + (if (get-external-sockname) + (file-name-nondirectory (get-external-sockname)) + "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be changed while a server is running." @@ -263,8 +271,10 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (and (featurep 'make-network-process '(:family local)) - (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))) + (if (get-external-sockname) + (file-name-directory (get-external-sockname)) + (and (featurep 'make-network-process '(:family local)) + (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. If local sockets are not supported, this is nil.") @@ -618,23 +628,29 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Delete the socket files made by previous server invocations. - (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file - (ignore-errors - (let (delete-by-moving-to-trash) - (delete-file server-file))) - (setq server-mode nil) ;; already set by the minor mode code - (display-warning - 'server - (concat "Unable to start the Emacs server.\n" - (format "There is an existing Emacs server, named %S.\n" - server-name) - (substitute-command-keys - "To start the server in this Emacs process, stop the existing + ;; Check to see if an uninitialised external socket has been + ;; passed in, if that is the case, skip checking + ;; `server-running-p' as this will return the wrong result. + (if (and (get-external-sockname) + (not server-external-socket-initialised)) + (setq server-external-socket-initialised t) + ;; Delete the socket files made by previous server invocations. + (if (not (eq t (server-running-p server-name))) + ;; Remove any leftover socket or authentication file + (ignore-errors + (let (delete-by-moving-to-trash) + (delete-file server-file))) + (setq server-mode nil) ;; already set by the minor mode code + (display-warning + 'server + (concat "Unable to start the Emacs server.\n" + (format "There is an existing Emacs server, named %S.\n" + server-name) + (substitute-command-keys + "To start the server in this Emacs process, stop the existing server or call `\\[server-force-delete]' to forcibly disconnect it.")) - :warning) - (setq leave-dead t)) + :warning) + (setq leave-dead t))) ;; If this Emacs already had a server, clear out associated status. (while server-clients (server-delete-client (car server-clients))) diff --git a/src/emacs.c b/src/emacs.c index 20ced26283..1af09166b6 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,6 +60,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_LIBSYSTEMD # include <systemd/sd-daemon.h> # include <sys/socket.h> +# include <sys/un.h> #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1002,6 +1003,7 @@ main (int argc, char **argv) int sockfd = -1; + char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1061,8 +1063,16 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNSPEC, SOCK_STREAM, 1))) - sockfd = SD_LISTEN_FDS_START; + AF_UNIX, SOCK_STREAM, 1))) + { + struct sockaddr_un sockaddr; + socklen_t sockaddr_sz = sizeof(sockaddr); + + sockfd = SD_LISTEN_FDS_START; + + if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) + sockname = strdup(sockaddr.sun_path); + } #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1656,7 +1666,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd); + init_process_emacs (sockfd, sockname); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index 3eb6e0d3c1..2e9002a226 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4313,7 +4313,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int); +extern void init_process_emacs (int, char *); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index d4440e472d..da8e5714b0 100644 --- a/src/process.c +++ b/src/process.c @@ -276,6 +276,10 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; +/* The name (path) of the socket that was passed to Emacs, when + `external_sock_fd' is not -1. */ +static const char *external_sock_name = NULL; + /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -7974,10 +7978,21 @@ restore_nofile_limit (void) } \f +DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, + doc: /* Return the path of an external socket passed to Emacs. +Otherwise return nil. */) + (void) +{ + if (external_sock_name) + return make_string(external_sock_name, strlen(external_sock_name)); + else + return Qnil; +} + /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd) +init_process_emacs (int sockfd, char *sockname) { #ifdef subprocesses int i; @@ -8012,6 +8027,7 @@ init_process_emacs (int sockfd) #endif external_sock_fd = sockfd; + external_sock_name = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8306,4 +8322,5 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); + defsubr (&Sget_external_sockname); } -- 2.16.1 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-Minor-cleanups-for-server-name-fix-Bug-24218.patch --] [-- Type: text/x-patch, Size: 9315 bytes --] From a4872a8e24027a0c8cc925140c3d3cda95c096e1 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Sun, 7 Jan 2018 13:47:12 -0800 Subject: [PATCH 2/4] Minor cleanups for server-name fix (Bug#24218) * lisp/server.el (server--external-socket-initialized): Rename from server-external-socket-initialised, since it should be private and Emacs uses American spelling. All uses changed. * src/emacs.c, src/lisp.h: Revert previous changes, as the initialization is now done in src/process.c, which already includes the relevant files. * src/process.c (union u_sockaddr): Move decl to top level. (external_sock_name, Fget_external_sockname): Remove, replacing with Vinternal__external_sockname. All uses changed. (init_process_emacs): Deduce socket name ourselves rather than have main.c do it. Use conv_sockaddr_to_lisp instead of doing it by hand. Conditionalize it on HAVE_GETSOCKNAME. --- lisp/server.el | 24 ++++++++++++------------ src/emacs.c | 16 +++------------- src/lisp.h | 2 +- src/process.c | 58 ++++++++++++++++++++++++++++++---------------------------- 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index e8b53530c9..c867fde832 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,15 +251,15 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -(defvar server-external-socket-initialised nil +(defvar server--external-socket-initialized nil "When an external socket is passed into Emacs, we need to call -`server-start' in order to initialise the connection. This flag -prevents multiple initialisations when an external socket has +`server-start' in order to initialize the connection. This flag +prevents multiple initializations when an external socket has been consumed.") (defcustom server-name - (if (get-external-sockname) - (file-name-nondirectory (get-external-sockname)) + (if internal--external-sockname + (file-name-nondirectory internal--external-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if (get-external-sockname) - (file-name-directory (get-external-sockname)) + (if internal--external-sockname + (file-name-directory internal--external-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -628,15 +628,15 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Check to see if an uninitialised external socket has been + ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and (get-external-sockname) - (not server-external-socket-initialised)) - (setq server-external-socket-initialised t) + (if (and internal--external-sockname + (not server--external-socket-initialized)) + (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file + ;; Remove any leftover socket or authentication file. (ignore-errors (let (delete-by-moving-to-trash) (delete-file server-file))) diff --git a/src/emacs.c b/src/emacs.c index 1af09166b6..20ced26283 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,7 +60,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_LIBSYSTEMD # include <systemd/sd-daemon.h> # include <sys/socket.h> -# include <sys/un.h> #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1003,7 +1002,6 @@ main (int argc, char **argv) int sockfd = -1; - char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1063,16 +1061,8 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNIX, SOCK_STREAM, 1))) - { - struct sockaddr_un sockaddr; - socklen_t sockaddr_sz = sizeof(sockaddr); - - sockfd = SD_LISTEN_FDS_START; - - if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) - sockname = strdup(sockaddr.sun_path); - } + AF_UNSPEC, SOCK_STREAM, 1))) + sockfd = SD_LISTEN_FDS_START; #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1666,7 +1656,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd, sockname); + init_process_emacs (sockfd); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index 2e9002a226..3eb6e0d3c1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4313,7 +4313,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int, char *); +extern void init_process_emacs (int); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index da8e5714b0..2613dd2be0 100644 --- a/src/process.c +++ b/src/process.c @@ -160,6 +160,18 @@ static bool kbd_is_on_hold; when exiting. */ bool inhibit_sentinels; +union u_sockaddr +{ + struct sockaddr sa; + struct sockaddr_in in; +#ifdef AF_INET6 + struct sockaddr_in6 in6; +#endif +#ifdef HAVE_LOCAL_SOCKETS + struct sockaddr_un un; +#endif +}; + #ifdef subprocesses #ifndef SOCK_CLOEXEC @@ -276,10 +288,6 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; -/* The name (path) of the socket that was passed to Emacs, when - `external_sock_fd' is not -1. */ -static const char *external_sock_name = NULL; - /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -4679,16 +4687,7 @@ server_accept_connection (Lisp_Object server, int channel) struct Lisp_Process *ps = XPROCESS (server); struct Lisp_Process *p; int s; - union u_sockaddr { - struct sockaddr sa; - struct sockaddr_in in; -#ifdef AF_INET6 - struct sockaddr_in6 in6; -#endif -#ifdef HAVE_LOCAL_SOCKETS - struct sockaddr_un un; -#endif - } saddr; + union u_sockaddr saddr; socklen_t len = sizeof saddr; ptrdiff_t count; @@ -7978,21 +7977,10 @@ restore_nofile_limit (void) } \f -DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, - doc: /* Return the path of an external socket passed to Emacs. -Otherwise return nil. */) - (void) -{ - if (external_sock_name) - return make_string(external_sock_name, strlen(external_sock_name)); - else - return Qnil; -} - /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd, char *sockname) +init_process_emacs (int sockfd) { #ifdef subprocesses int i; @@ -8027,7 +8015,18 @@ init_process_emacs (int sockfd, char *sockname) #endif external_sock_fd = sockfd; - external_sock_name = sockname; + Lisp_Object sockname = Qnil; +# if HAVE_GETSOCKNAME + if (0 <= sockfd) + { + union u_sockaddr sa; + socklen_t salen = sizeof sa; + if (getsockname (sockfd, &sa.sa, &salen) == 0) + sockname = conv_sockaddr_to_lisp (&sa.sa, salen); + } +# endif + Vinternal__external_sockname = sockname; + max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8220,6 +8219,10 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); + DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + doc: /* Name of external socket passed to Emacs, or nil if none. */); + Vinternal__external_sockname = Qnil; + DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); @@ -8322,5 +8325,4 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); - defsubr (&Sget_external_sockname); } -- 2.16.1 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #4: 0003-Update-server-name-version-document-sockname-Bug-242.patch --] [-- Type: text/x-patch, Size: 2183 bytes --] From 6a82f66d62e2669335419815504a276facfe0bf2 Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Tue, 9 Jan 2018 19:45:30 +0000 Subject: [PATCH 3/4] Update `server-name' :version & document sockname (Bug#24218) * lisp/server.el: (server-name): Update :version tag. * etc/NEWS: Document that `server-name' and `server-socket-dir' automatically update. * doc/misc.texi: (Emacs Server): Likewise. --- doc/emacs/misc.texi | 5 +++++ etc/NEWS | 3 +++ lisp/server.el | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 633e1e881d..c9b8f08252 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1654,6 +1654,11 @@ Emacs Server @samp{foo}. The @code{emacsclient} program can specify a server by name, using the @samp{-s} option (@pxref{emacsclient Options}). + If Emacs is passed a socket by an external program --- for example +by systemd socket activation --- the value of @code{server-name} and +@code{server-socket-dir} is automatically updated to reflect the name +and path of the socket. + If you want to run multiple Emacs daemons (@pxref{Initial Options}), you can give each daemon its own server name like this: diff --git a/etc/NEWS b/etc/NEWS index f6f36dfc85..66cb0834c5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -194,6 +194,9 @@ as new-style, bind the new variable 'force-new-style-backquotes' to t. \f * Lisp Changes in Emacs 27.1 +** The `server-name' and `server-socket-dir' variables are set when a +socket has been pased to Emacs (Bug#24218). + ** Internal parsing commands now use syntax-ppss and disregard open-paren-in-column-0-is-defun-start. This affects mostly things like forward-comment, scan-sexps, and forward-sexp when parsing backward. diff --git a/lisp/server.el b/lisp/server.el index c867fde832..16b3f8e4e2 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -266,7 +266,7 @@ server-name changed while a server is running." :group 'server :type 'string - :version "23.1") + :version "27.1") ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. -- 2.16.1 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #5: 0004-Rename-internal-external-sockname-and-document-Bug-2.patch --] [-- Type: text/x-patch, Size: 4489 bytes --] From 6bc1562dfc674df50f4947653be6e1a4cd436ccf Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Thu, 25 Jan 2018 19:24:14 +0000 Subject: [PATCH 4/4] Rename internal--external-sockname and document (Bug#24218) * lisp/server.el: Rename `internal--external-sockname' to `internal-daemon-sockname'. * src/process.c: Likewise. * doc/lispref/processes.texi: Document `internal-daemon-sockname'. --- doc/lispref/processes.texi | 17 ++++++++++++++--- lisp/server.el | 10 +++++----- src/process.c | 6 +++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 8a8425cb84..7f078e950f 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -2860,9 +2860,9 @@ Network Feature Testing @node Misc Network @section Misc Network Facilities - These additional functions are useful for creating and operating -on network connections. Note that they are supported only on some -systems. + These additional functions and variables are useful for creating and +operating on network connections. Note that they are supported only +on some systems. @defun network-interface-list This function returns a list describing the network interfaces @@ -2911,6 +2911,17 @@ Misc Network @code{:@var{p}} suffix. @end defun +@defvar internal--daemon-sockname +This variable is set to the full path of the socket that has been +passed to Emacs during socket activation. This is then used to update +the @code{server-name} and @code{server-socket-dir} variables to +reflect the name and path of the socket that was used to launch the +Emacs daemon process. + +If Emacs wasn't started with socket activation, the value of this +variable is @code{nil}. +@end defvar + @node Serial Ports @section Communicating with Serial Ports @cindex @file{/dev/tty} diff --git a/lisp/server.el b/lisp/server.el index 16b3f8e4e2..4e0afa26f9 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -258,8 +258,8 @@ server--external-socket-initialized been consumed.") (defcustom server-name - (if internal--external-sockname - (file-name-nondirectory internal--external-sockname) + (if internal-daemon-sockname + (file-name-nondirectory internal-daemon-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if internal--external-sockname - (file-name-directory internal--external-sockname) + (if internal-daemon-sockname + (file-name-directory internal-daemon-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -631,7 +631,7 @@ server-start ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and internal--external-sockname + (if (and internal-daemon-sockname (not server--external-socket-initialized)) (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. diff --git a/src/process.c b/src/process.c index 2613dd2be0..48854e24b4 100644 --- a/src/process.c +++ b/src/process.c @@ -8025,7 +8025,7 @@ init_process_emacs (int sockfd) sockname = conv_sockaddr_to_lisp (&sa.sa, salen); } # endif - Vinternal__external_sockname = sockname; + Vinternal_daemon_sockname = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8219,9 +8219,9 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); - DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + DEFVAR_LISP ("internal-daemon-sockname", Vinternal_daemon_sockname, doc: /* Name of external socket passed to Emacs, or nil if none. */); - Vinternal__external_sockname = Qnil; + Vinternal_daemon_sockname = Qnil; DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); -- 2.16.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-01-25 19:34 ` Matthew Leach @ 2018-02-10 16:07 ` Paul Eggert 2018-02-12 14:24 ` Matthew Leach 0 siblings, 1 reply; 15+ messages in thread From: Paul Eggert @ 2018-02-10 16:07 UTC (permalink / raw) To: Matthew Leach; +Cc: 24218, lomov.vl [-- Attachment #1: Type: text/plain, Size: 653 bytes --] Matthew Leach wrote: > Paul Eggert <eggert@cs.ucla.edu> writes: > >> On 01/09/2018 11:53 AM, Matthew Leach wrote: >>> May I suggest `internal--daemon-sockname'? >> >> Yes, that sounds good. Can you prepare a patch along those lines? > > Sure, please see the attached patch series. Thanks, but aren't there some more places where the variable needs to be renamed to internal--daemon-sockname? Also, I would rather not document it in the Emacs Lisp reference manual, as it is an internal detail that outside code shouldn't depend on. Proposed further patch attached (it's the last of the attachments, which contain all the patches for this bug). [-- Attachment #2: 0001-Fix-server-name-and-server-socket-dir-for-Bug-24218.patch --] [-- Type: text/x-patch, Size: 8483 bytes --] From b71632dbba803c2cd22e9f18231d4eb38b1521f9 Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Sat, 10 Feb 2018 07:44:13 -0800 Subject: [PATCH 1/5] Fix `server-name' and `server-socket-dir' for (Bug#24218) * lisp/server.el: (server-external-socket-initialised): New (server-name): Compute server name from `get-external-sockname'. (server-socket-dir): Compute socket dir from `get-external-sockname'. (server-start): Don't check for existing server when an uninitialised external socket has been passed to Emacs. * src/emacs.c: (main): Obtain socket name via getsockname and pass to `init_process_emacs'. * src/lisp.h: (init_process_emacs): Add second parameter. * src/process.c: (external_sock_name): New. (get-external-sockname): New. (init_process_emacs): Set `external_sock_name' to `sockname' parameter. --- lisp/server.el | 56 ++++++++++++++++++++++++++++++++++++-------------------- src/emacs.c | 16 +++++++++++++--- src/lisp.h | 2 +- src/process.c | 19 ++++++++++++++++++- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index d91a51e..d2406e2 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,8 +251,16 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -;;;###autoload -(defcustom server-name "server" +(defvar server-external-socket-initialised nil + "When an external socket is passed into Emacs, we need to call +`server-start' in order to initialise the connection. This flag +prevents multiple initialisations when an external socket has +been consumed.") + +(defcustom server-name + (if (get-external-sockname) + (file-name-nondirectory (get-external-sockname)) + "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be changed while a server is running." @@ -263,8 +271,10 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (and (featurep 'make-network-process '(:family local)) - (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))) + (if (get-external-sockname) + (file-name-directory (get-external-sockname)) + (and (featurep 'make-network-process '(:family local)) + (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. If local sockets are not supported, this is nil.") @@ -618,23 +628,29 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Delete the socket files made by previous server invocations. - (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file - (ignore-errors - (let (delete-by-moving-to-trash) - (delete-file server-file))) - (setq server-mode nil) ;; already set by the minor mode code - (display-warning - 'server - (concat "Unable to start the Emacs server.\n" - (format "There is an existing Emacs server, named %S.\n" - server-name) - (substitute-command-keys - "To start the server in this Emacs process, stop the existing + ;; Check to see if an uninitialised external socket has been + ;; passed in, if that is the case, skip checking + ;; `server-running-p' as this will return the wrong result. + (if (and (get-external-sockname) + (not server-external-socket-initialised)) + (setq server-external-socket-initialised t) + ;; Delete the socket files made by previous server invocations. + (if (not (eq t (server-running-p server-name))) + ;; Remove any leftover socket or authentication file + (ignore-errors + (let (delete-by-moving-to-trash) + (delete-file server-file))) + (setq server-mode nil) ;; already set by the minor mode code + (display-warning + 'server + (concat "Unable to start the Emacs server.\n" + (format "There is an existing Emacs server, named %S.\n" + server-name) + (substitute-command-keys + "To start the server in this Emacs process, stop the existing server or call `\\[server-force-delete]' to forcibly disconnect it.")) - :warning) - (setq leave-dead t)) + :warning) + (setq leave-dead t))) ;; If this Emacs already had a server, clear out associated status. (while server-clients (server-delete-client (car server-clients))) diff --git a/src/emacs.c b/src/emacs.c index 8ea61b7..c423faf 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,6 +60,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_LIBSYSTEMD # include <systemd/sd-daemon.h> # include <sys/socket.h> +# include <sys/un.h> #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1002,6 +1003,7 @@ main (int argc, char **argv) int sockfd = -1; + char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1061,8 +1063,16 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNSPEC, SOCK_STREAM, 1))) - sockfd = SD_LISTEN_FDS_START; + AF_UNIX, SOCK_STREAM, 1))) + { + struct sockaddr_un sockaddr; + socklen_t sockaddr_sz = sizeof(sockaddr); + + sockfd = SD_LISTEN_FDS_START; + + if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) + sockname = strdup(sockaddr.sun_path); + } #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1660,7 +1670,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd); + init_process_emacs (sockfd, sockname); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index a7f0a1d..0bd0e5e 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4316,7 +4316,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int); +extern void init_process_emacs (int, char *); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index 2cc2c86..405c06d 100644 --- a/src/process.c +++ b/src/process.c @@ -276,6 +276,10 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; +/* The name (path) of the socket that was passed to Emacs, when + `external_sock_fd' is not -1. */ +static const char *external_sock_name = NULL; + /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -7972,10 +7976,21 @@ restore_nofile_limit (void) } \f +DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, + doc: /* Return the path of an external socket passed to Emacs. +Otherwise return nil. */) + (void) +{ + if (external_sock_name) + return make_string(external_sock_name, strlen(external_sock_name)); + else + return Qnil; +} + /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd) +init_process_emacs (int sockfd, char *sockname) { #ifdef subprocesses int i; @@ -8010,6 +8025,7 @@ init_process_emacs (int sockfd) #endif external_sock_fd = sockfd; + external_sock_name = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8304,4 +8320,5 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); + defsubr (&Sget_external_sockname); } -- 2.7.4 [-- Attachment #3: 0002-Minor-cleanups-for-server-name-fix-Bug-24218.patch --] [-- Type: text/x-patch, Size: 9291 bytes --] From dd3e2ccd71a137ec549fdfe6b9c5201c62f5f978 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Sat, 10 Feb 2018 07:44:13 -0800 Subject: [PATCH 2/5] Minor cleanups for server-name fix (Bug#24218) * lisp/server.el (server--external-socket-initialized): Rename from server-external-socket-initialised, since it should be private and Emacs uses American spelling. All uses changed. * src/emacs.c, src/lisp.h: Revert previous changes, as the initialization is now done in src/process.c, which already includes the relevant files. * src/process.c (union u_sockaddr): Move decl to top level. (external_sock_name, Fget_external_sockname): Remove, replacing with Vinternal__external_sockname. All uses changed. (init_process_emacs): Deduce socket name ourselves rather than have main.c do it. Use conv_sockaddr_to_lisp instead of doing it by hand. Conditionalize it on HAVE_GETSOCKNAME. --- lisp/server.el | 24 ++++++++++++------------ src/emacs.c | 16 +++------------- src/lisp.h | 2 +- src/process.c | 58 ++++++++++++++++++++++++++++++---------------------------- 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index d2406e2..70ac51e 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,15 +251,15 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -(defvar server-external-socket-initialised nil +(defvar server--external-socket-initialized nil "When an external socket is passed into Emacs, we need to call -`server-start' in order to initialise the connection. This flag -prevents multiple initialisations when an external socket has +`server-start' in order to initialize the connection. This flag +prevents multiple initializations when an external socket has been consumed.") (defcustom server-name - (if (get-external-sockname) - (file-name-nondirectory (get-external-sockname)) + (if internal--external-sockname + (file-name-nondirectory internal--external-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if (get-external-sockname) - (file-name-directory (get-external-sockname)) + (if internal--external-sockname + (file-name-directory internal--external-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -628,15 +628,15 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Check to see if an uninitialised external socket has been + ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and (get-external-sockname) - (not server-external-socket-initialised)) - (setq server-external-socket-initialised t) + (if (and internal--external-sockname + (not server--external-socket-initialized)) + (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file + ;; Remove any leftover socket or authentication file. (ignore-errors (let (delete-by-moving-to-trash) (delete-file server-file))) diff --git a/src/emacs.c b/src/emacs.c index c423faf..8ea61b7 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,7 +60,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_LIBSYSTEMD # include <systemd/sd-daemon.h> # include <sys/socket.h> -# include <sys/un.h> #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1003,7 +1002,6 @@ main (int argc, char **argv) int sockfd = -1; - char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1063,16 +1061,8 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNIX, SOCK_STREAM, 1))) - { - struct sockaddr_un sockaddr; - socklen_t sockaddr_sz = sizeof(sockaddr); - - sockfd = SD_LISTEN_FDS_START; - - if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) - sockname = strdup(sockaddr.sun_path); - } + AF_UNSPEC, SOCK_STREAM, 1))) + sockfd = SD_LISTEN_FDS_START; #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1670,7 +1660,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd, sockname); + init_process_emacs (sockfd); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index 0bd0e5e..a7f0a1d 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4316,7 +4316,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int, char *); +extern void init_process_emacs (int); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index 405c06d..8396a93 100644 --- a/src/process.c +++ b/src/process.c @@ -160,6 +160,18 @@ static bool kbd_is_on_hold; when exiting. */ bool inhibit_sentinels; +union u_sockaddr +{ + struct sockaddr sa; + struct sockaddr_in in; +#ifdef AF_INET6 + struct sockaddr_in6 in6; +#endif +#ifdef HAVE_LOCAL_SOCKETS + struct sockaddr_un un; +#endif +}; + #ifdef subprocesses #ifndef SOCK_CLOEXEC @@ -276,10 +288,6 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; -/* The name (path) of the socket that was passed to Emacs, when - `external_sock_fd' is not -1. */ -static const char *external_sock_name = NULL; - /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -4677,16 +4685,7 @@ server_accept_connection (Lisp_Object server, int channel) struct Lisp_Process *ps = XPROCESS (server); struct Lisp_Process *p; int s; - union u_sockaddr { - struct sockaddr sa; - struct sockaddr_in in; -#ifdef AF_INET6 - struct sockaddr_in6 in6; -#endif -#ifdef HAVE_LOCAL_SOCKETS - struct sockaddr_un un; -#endif - } saddr; + union u_sockaddr saddr; socklen_t len = sizeof saddr; ptrdiff_t count; @@ -7976,21 +7975,10 @@ restore_nofile_limit (void) } \f -DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, - doc: /* Return the path of an external socket passed to Emacs. -Otherwise return nil. */) - (void) -{ - if (external_sock_name) - return make_string(external_sock_name, strlen(external_sock_name)); - else - return Qnil; -} - /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd, char *sockname) +init_process_emacs (int sockfd) { #ifdef subprocesses int i; @@ -8025,7 +8013,18 @@ init_process_emacs (int sockfd, char *sockname) #endif external_sock_fd = sockfd; - external_sock_name = sockname; + Lisp_Object sockname = Qnil; +# if HAVE_GETSOCKNAME + if (0 <= sockfd) + { + union u_sockaddr sa; + socklen_t salen = sizeof sa; + if (getsockname (sockfd, &sa.sa, &salen) == 0) + sockname = conv_sockaddr_to_lisp (&sa.sa, salen); + } +# endif + Vinternal__external_sockname = sockname; + max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8218,6 +8217,10 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); + DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + doc: /* Name of external socket passed to Emacs, or nil if none. */); + Vinternal__external_sockname = Qnil; + DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); @@ -8320,5 +8323,4 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); - defsubr (&Sget_external_sockname); } -- 2.7.4 [-- Attachment #4: 0003-Update-server-name-version-document-sockname-Bug-242.patch --] [-- Type: text/x-patch, Size: 1044 bytes --] From 705e134823603689cc2fb0a58719bd13eb13250c Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Sat, 10 Feb 2018 07:47:45 -0800 Subject: [PATCH 3/5] Update `server-name' :version & document sockname (Bug#24218) * lisp/server.el: (server-name): Update :version tag. * etc/NEWS: Document that `server-name' and `server-socket-dir' automatically update. * doc/misc.texi: (Emacs Server): Likewise. --- etc/NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 8fed15a..772dff7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -248,6 +248,9 @@ forward-comment, scan-sexps, and forward-sexp when parsing backward. The new variable 'comment-use-syntax-ppss' can be set to nil to recover the old behavior if needed. +** The `server-name' and `server-socket-dir' variables are set when a +socket has been pased to Emacs (Bug#24218). + --- ** The 'file-system-info' function is now available on all platforms. instead of just Microsoft platforms. This fixes a 'get-free-disk-space' -- 2.7.4 [-- Attachment #5: 0004-Rename-internal-external-sockname-and-document-Bug-2.patch --] [-- Type: text/x-patch, Size: 4470 bytes --] From 84288f3afb711ac27219263aed5c2caa45608d32 Mon Sep 17 00:00:00 2001 From: Matthew Leach <matthew@mattleach.net> Date: Sat, 10 Feb 2018 07:47:45 -0800 Subject: [PATCH 4/5] Rename internal--external-sockname and document (Bug#24218) * lisp/server.el: Rename `internal--external-sockname' to `internal-daemon-sockname'. * src/process.c: Likewise. * doc/lispref/processes.texi: Document `internal-daemon-sockname'. --- doc/lispref/processes.texi | 17 ++++++++++++++--- lisp/server.el | 10 +++++----- src/process.c | 6 +++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index af177e0..07317dd 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -2862,9 +2862,9 @@ Network Feature Testing @node Misc Network @section Misc Network Facilities - These additional functions are useful for creating and operating -on network connections. Note that they are supported only on some -systems. + These additional functions and variables are useful for creating and +operating on network connections. Note that they are supported only +on some systems. @defun network-interface-list This function returns a list describing the network interfaces @@ -2913,6 +2913,17 @@ Misc Network @code{:@var{p}} suffix. @end defun +@defvar internal--daemon-sockname +This variable is set to the full path of the socket that has been +passed to Emacs during socket activation. This is then used to update +the @code{server-name} and @code{server-socket-dir} variables to +reflect the name and path of the socket that was used to launch the +Emacs daemon process. + +If Emacs wasn't started with socket activation, the value of this +variable is @code{nil}. +@end defvar + @node Serial Ports @section Communicating with Serial Ports @cindex @file{/dev/tty} diff --git a/lisp/server.el b/lisp/server.el index 70ac51e..744568a 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -258,8 +258,8 @@ server--external-socket-initialized been consumed.") (defcustom server-name - (if internal--external-sockname - (file-name-nondirectory internal--external-sockname) + (if internal-daemon-sockname + (file-name-nondirectory internal-daemon-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if internal--external-sockname - (file-name-directory internal--external-sockname) + (if internal-daemon-sockname + (file-name-directory internal-daemon-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -631,7 +631,7 @@ server-start ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and internal--external-sockname + (if (and internal-daemon-sockname (not server--external-socket-initialized)) (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. diff --git a/src/process.c b/src/process.c index 8396a93..fe55a48 100644 --- a/src/process.c +++ b/src/process.c @@ -8023,7 +8023,7 @@ init_process_emacs (int sockfd) sockname = conv_sockaddr_to_lisp (&sa.sa, salen); } # endif - Vinternal__external_sockname = sockname; + Vinternal_daemon_sockname = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8217,9 +8217,9 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); - DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + DEFVAR_LISP ("internal-daemon-sockname", Vinternal_daemon_sockname, doc: /* Name of external socket passed to Emacs, or nil if none. */); - Vinternal__external_sockname = Qnil; + Vinternal_daemon_sockname = Qnil; DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); -- 2.7.4 [-- Attachment #6: 0005-Finish-renaming-to-internal-daemon-sockname.patch --] [-- Type: text/x-patch, Size: 4496 bytes --] From f5a3f2a5d79308473cd8aa360b2ff1bd72b7f734 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Sat, 10 Feb 2018 08:03:33 -0800 Subject: [PATCH 5/5] Finish renaming to internal--daemon-sockname * doc/lispref/processes.texi (Misc Network): Omit discussion of internal--daemon-sockname, as non-Emacs code shouldn't rely on it. * src/process.c (syms_of_process): Rename internal-daemon-sockname to internal--daemon-sockname. All uses changed. --- doc/lispref/processes.texi | 17 +++-------------- lisp/server.el | 10 +++++----- src/process.c | 6 +++--- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 07317dd..af177e0 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -2862,9 +2862,9 @@ Network Feature Testing @node Misc Network @section Misc Network Facilities - These additional functions and variables are useful for creating and -operating on network connections. Note that they are supported only -on some systems. + These additional functions are useful for creating and operating +on network connections. Note that they are supported only on some +systems. @defun network-interface-list This function returns a list describing the network interfaces @@ -2913,17 +2913,6 @@ Misc Network @code{:@var{p}} suffix. @end defun -@defvar internal--daemon-sockname -This variable is set to the full path of the socket that has been -passed to Emacs during socket activation. This is then used to update -the @code{server-name} and @code{server-socket-dir} variables to -reflect the name and path of the socket that was used to launch the -Emacs daemon process. - -If Emacs wasn't started with socket activation, the value of this -variable is @code{nil}. -@end defvar - @node Serial Ports @section Communicating with Serial Ports @cindex @file{/dev/tty} diff --git a/lisp/server.el b/lisp/server.el index 744568a..d393388 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -258,8 +258,8 @@ server--external-socket-initialized been consumed.") (defcustom server-name - (if internal-daemon-sockname - (file-name-nondirectory internal-daemon-sockname) + (if internal--daemon-sockname + (file-name-nondirectory internal--daemon-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if internal-daemon-sockname - (file-name-directory internal-daemon-sockname) + (if internal--daemon-sockname + (file-name-directory internal--daemon-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -631,7 +631,7 @@ server-start ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and internal-daemon-sockname + (if (and internal--daemon-sockname (not server--external-socket-initialized)) (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. diff --git a/src/process.c b/src/process.c index fe55a48..2ec10b1 100644 --- a/src/process.c +++ b/src/process.c @@ -8023,7 +8023,7 @@ init_process_emacs (int sockfd) sockname = conv_sockaddr_to_lisp (&sa.sa, salen); } # endif - Vinternal_daemon_sockname = sockname; + Vinternal__daemon_sockname = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8217,9 +8217,9 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); - DEFVAR_LISP ("internal-daemon-sockname", Vinternal_daemon_sockname, + DEFVAR_LISP ("internal--daemon-sockname", Vinternal__daemon_sockname, doc: /* Name of external socket passed to Emacs, or nil if none. */); - Vinternal_daemon_sockname = Qnil; + Vinternal__daemon_sockname = Qnil; DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); -- 2.7.4 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-02-10 16:07 ` Paul Eggert @ 2018-02-12 14:24 ` Matthew Leach 2018-02-12 20:58 ` Paul Eggert 0 siblings, 1 reply; 15+ messages in thread From: Matthew Leach @ 2018-02-12 14:24 UTC (permalink / raw) To: Paul Eggert; +Cc: 24218, lomov.vl Paul Eggert <eggert@cs.ucla.edu> writes: > Matthew Leach wrote: >> Paul Eggert <eggert@cs.ucla.edu> writes: >> >>> On 01/09/2018 11:53 AM, Matthew Leach wrote: >>>> May I suggest `internal--daemon-sockname'? >>> >>> Yes, that sounds good. Can you prepare a patch along those lines? >> >> Sure, please see the attached patch series. > > Thanks, but aren't there some more places where the variable needs to > be renamed to internal--daemon-sockname? Oops - I missed an additional `-' on the variable name. > Also, I would rather not document it in the Emacs Lisp reference > manual, as it is an internal detail that outside code shouldn't depend > on. That sounds fine; I wasn't aware that internal variables shouldn't be documented in the Emacs List Reference Manual. > Proposed further patch attached (it's the last of the attachments, > which contain all the patches for this bug). This last patch looks good to me. Thanks, -- Matt ^ permalink raw reply [flat|nested] 15+ messages in thread
* bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket 2018-02-12 14:24 ` Matthew Leach @ 2018-02-12 20:58 ` Paul Eggert 0 siblings, 0 replies; 15+ messages in thread From: Paul Eggert @ 2018-02-12 20:58 UTC (permalink / raw) To: Matthew Leach; +Cc: 24218-done, lomov.vl On 02/12/2018 06:24 AM, Matthew Leach wrote: > This last patch looks good to me. Thanks for checking; I installed the patches into 'master' and am marking this bug as done. ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2018-02-12 20:58 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-08-13 16:35 bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through systemd socket Vladimir Lomov 2016-08-15 2:25 ` Paul Eggert 2018-01-07 21:55 ` bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, " Paul Eggert 2018-01-08 3:50 ` Eli Zaretskii 2018-01-08 4:24 ` Paul Eggert 2018-01-08 18:33 ` Eli Zaretskii 2018-01-08 18:42 ` Paul Eggert 2018-01-08 19:14 ` Eli Zaretskii 2018-01-08 19:23 ` Paul Eggert 2018-01-09 19:53 ` Matthew Leach 2018-01-24 23:00 ` Paul Eggert 2018-01-25 19:34 ` Matthew Leach 2018-02-10 16:07 ` Paul Eggert 2018-02-12 14:24 ` Matthew Leach 2018-02-12 20:58 ` Paul Eggert
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.