From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Trent W. Buck" Newsgroups: gmane.emacs.bugs Subject: bug#57396: 28.1; emacs.socket (systemd-managed, but start-on-demand like ALTERNATE_EDITOR="") Date: Thu, 25 Aug 2022 13:52:33 +1000 Message-ID: <87lerdkmim.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9886"; mail-complaints-to="usenet@ciao.gmane.io" To: 57396@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 25 05:53:15 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oR3vd-0002Mr-MU for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 25 Aug 2022 05:53:13 +0200 Original-Received: from localhost ([::1]:56330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oR3vc-0005dc-67 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 24 Aug 2022 23:53:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oR3vS-0005dU-IC for bug-gnu-emacs@gnu.org; Wed, 24 Aug 2022 23:53:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oR3vS-0002fm-A0 for bug-gnu-emacs@gnu.org; Wed, 24 Aug 2022 23:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oR3vR-0002YI-QW for bug-gnu-emacs@gnu.org; Wed, 24 Aug 2022 23:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Trent W. Buck" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Aug 2022 03:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57396 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16613995689783 (code B ref -1); Thu, 25 Aug 2022 03:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Aug 2022 03:52:48 +0000 Original-Received: from localhost ([127.0.0.1]:48548 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oR3vD-0002Xi-Ij for submit@debbugs.gnu.org; Wed, 24 Aug 2022 23:52:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56310) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oR3v9-0002XY-C0 for submit@debbugs.gnu.org; Wed, 24 Aug 2022 23:52:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oR3v9-0005bH-6z for bug-gnu-emacs@gnu.org; Wed, 24 Aug 2022 23:52:43 -0400 Original-Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:51151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oR3v6-0002ex-Oz for bug-gnu-emacs@gnu.org; Wed, 24 Aug 2022 23:52:42 -0400 Original-Received: by mail-pj1-x1030.google.com with SMTP id g18so19087234pju.0 for ; Wed, 24 Aug 2022 20:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:to:from:from:to:cc; bh=ZvL/8DaOR6UTijD1ekZu6ZpEAGrg/AEp3AU/vRmJ7VI=; b=g+7qZDrBBmcLXnm+gAZdQkYFfjqVxD9go/3TeT1xJTEBXcD/4JXQ6XYczhYU/DLMUb UirDuh0Kn708lZdsvughLUGahDnnfIFjXJ5b/PsgBDui04IJQuCZZTpR0vW0K8/W97aV lPf1zDftz3jsIQHzLStfFGOIlBTjH0ugLed84V7X8AQqN3Ev1zg7mJlg/s0qxRMEXaKl Xu8RAgOr1qLYJCgK7jdXdNBMjh0CN6u2FWC0KvJthqVQXXMXBaXWCgATEdtM20/y3BfE RMjUayIg9TpyZDUjXGADV38gK0x2WBwJ9UnmQLZOivNxDvauRDbUXLBN9GqsPNXtmTcI idkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc; bh=ZvL/8DaOR6UTijD1ekZu6ZpEAGrg/AEp3AU/vRmJ7VI=; b=j4gucqKtyvN4+EJaAfEvlYyn4nY824a3C1R+4Z3OmAv4rOvfV7SVIQcQucHibh2k7/ 5KTSiFpqzUFd/dpSRhUV9mmdYpFjml600iQfoqwZyOsJRuBzmp1PHUwiR71i/t2St4FZ olNuIkD9/O59I/Kr+QT1dGh7qMYxV2UYL0PcvSdSVhyBpkMMzKnfNnAJxdvDmIru5rPN 1MiOxbYNDv0GMt4/+Q3HW5pKQ6DmEaaDu4l29OzZp3/YGFKE2jms8avgQh2jh+GRroHt hFwou0NzMbJPHZ4Y4g5tUXHxA9Vy5bEeCtstG+Iy274rmUtUoxzyKrlSeptIjFNWSdW4 0lMA== X-Gm-Message-State: ACgBeo3UAtkDvvcEPblW/HCGnZD/lUeHXU8ktC22mF3Dr4dal7MW6wh0 pY/dkZ9D7pFzJMWs/V8AGxBrWuSmxUA= X-Google-Smtp-Source: AA6agR5ndoUI9Zhw2ZjbWrWs/zd6ljeesPbwUsxzs2dUFbg5uZ/wMd5Wmrkwp+gI42J3WDc6s7u9Hg== X-Received: by 2002:a17:90b:3d92:b0:1fb:3854:69d2 with SMTP id pq18-20020a17090b3d9200b001fb385469d2mr11465171pjb.26.1661399559027; Wed, 24 Aug 2022 20:52:39 -0700 (PDT) Original-Received: from localhost (159-196-230-25.9fc4e6.mel.nbn.aussiebb.net. [159.196.230.25]) by smtp.gmail.com with ESMTPSA id w189-20020a6262c6000000b005363bc65bafsm10413741pfb.57.2022.08.24.20.52.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 20:52:38 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=trentbuck@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:240680 Archived-At: Right now there are three obvious ways to start emacs: 1. just run "emacs foo.txt" 2. "export ALTERNATE_EDITOR=", then "emacsclient foo.txt" 3. "systemctl enable --now emacs.service", then "emacsclient foo.txt" The benefit of #2 is that emacs only starts on-demand, i.e. if you turn on your computer and don't run Emacs for a week, you don't pay the ~80MB memory cost of "emacs --daemon" for a week. The drawback of #2 (compared to #3) is that emacs starts in an unpredictable environment -- it inherits whatever state (working directory, ~/.profile environment variables, &c) of the first process that ran emacsclient. For example, if it was run from "git commit" in xterm it might have completely different DISPLAY state to if it was run from gnome-shell's wayland launcher. Whether these are REALLY benefits and drawbacks is highly debatable. People with slow init.el probably hate on-demand launching. People with nontrivial ~/.profile don't want to faff about with systemd-specific environment.d(5). However. I'd like an option to have BOTH AT ONCE, i.e. a predictable-environment on-demand emacs --daemon. I think to do this, you need to do something like... 1. create an emacs.socket like [Socket] ListenStream=$XDG_RUNTIME_DIR/emacs/server 2. patch emacs --daemon like if fd 3 is already open, it must be because systemd opened the socket for us so just start using it otherwise, existing behaviour, open the socket ourselves At that point, anyone using emacs.service directly can carry on as before. But if emacs.socket stats emacs.service indirectly, it'll all Just Work. Here are examples of #2 from some other daemons: https://github.com/pantheon-systems/nginx/blob/master/nginx-systemd-socket-activation.patch#L284-L291 https://github.com/mirror/busybox/commit/9b3b9790b32d440eb89af5edda70a66b1829e861 https://github.com/unbit/uwsgi/blob/d58a832c81c2c96ae0f6e72614e1cc47f4b5d332/core/setup_utils.c#L6-L25 systemd documentation: https://www.freedesktop.org/software/systemd/man/daemon.html#Socket-Based%20Activation https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html PS: if you want to get REAL fancy, you could also have emacs automatically M-x kill-emacs if there were no open emacsclient and no open network processes (e.g. M-x irc) and no unsaved files. For example, on Debian 10+ cups-daemon does this by default. But that is probably a bit TOO clever :-)