From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id iNEaJx1iQGZ6TgEAe85BDQ:P1 (envelope-from ) for ; Sun, 12 May 2024 08:30:53 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id iNEaJx1iQGZ6TgEAe85BDQ (envelope-from ) for ; Sun, 12 May 2024 08:30:53 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gnu.org header.s=fencepost-gnu-org header.b=OidAqGBq; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1715495453; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Q5F9wWwZfP7xTkmpms6vzaP9NiSdmKXSkcbfcoP9IM8=; b=Zdiex5oSKPlfbRXP3n6FzKrRX09mTpO4c5g3iSi8jJYouc/uO20Nzd9WmPny0fWdA8wWi3 c7FSbpxcjrcaUWcFtqxI9Yoc35mZDXVK0zKX+y6iI4G3tqRCfRGKdynju/NW8olSJpTg0A JQYgDc6s8GEpEuKPqqkYpbH1C3O8pAcGz7X2LIZWrArphm9eLLVnS5JrLQ9aSxHsENps1D lFPXnaetYi0tYBDG40v05SOAzVpJqZAkLMH3mGoHixC/Qv4U/EiE1nKniJ2tdc+q8ZDCH8 3YKNqv0pZDCqW+wV34oyabpRgR/haYvAMdbSW2Nuq9v/8If8L+Vk+PKaSKQxRw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gnu.org header.s=fencepost-gnu-org header.b=OidAqGBq; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1715495453; a=rsa-sha256; cv=none; b=UVz/rOmnOTq4Hlg+dFc8a/4X84Vp8GmVpu5QhwrtUhB6XnCROtyAix2CkBgIfwJygO0l8S mmnXjdTloslb5Zc8Ty9t+0f54thzgALPlArn+dQfI3N7qXUOb94OlIvbUB5uvmGct3OFfH V896qdf7tjwOnbBN3nKu39NwFKyuaqS3uN4l9EhskuIHPQm5p2+x3MhLyba+3Bh+Qe2dmg mFNG91piAVJHa311Mse0eZnnsP0ZPZ4tsRMUbyhIynWuFofCP2B+bN2ozlo663CaLxCIQO cq1YGuo1nTrqRdPyr3juJb7t3KXcmZrvi2HvW/ry3W1TlX0sXdwIR117mxLWKw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 458FE628E2 for ; Sun, 12 May 2024 08:30:53 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s62ia-0004I5-Ow; Sun, 12 May 2024 02:29:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s62iX-0004HX-Vt; Sun, 12 May 2024 02:29:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s62iU-0004hK-QJ; Sun, 12 May 2024 02:29:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=Q5F9wWwZfP7xTkmpms6vzaP9NiSdmKXSkcbfcoP9IM8=; b=OidAqGBqA+q19aK/Q55f uBBss5Nh99KcLvlhzTDSXiYM1ocaRftX+6dXPaC1uEgoV0EeuaTJUZSqEu8GpiV63igEmaiWM3EtX cDTRDfbEU1jhQ8UH0hmrWxp/PqwMXxvSNqFHJ9+3Qf7TZOj5hrEFG8pEllgHieasNmXURihcOosVp LzEcW1Ttdjp292/zBnkBDrtnBxVkaWNsVdARKmF671L3nXP7N9c3wb5a85T3AAuVbT5WML9WXeurB aC06gJqnE8Y9X7fRc1xKPMRwKYSscxUXS0iPvst+cQd2GGUkCsGDYLRIfDHgsHxGhXTiTimjCCIvF Mc2Gy9B6BI6vDQ==; Date: Sun, 12 May 2024 09:29:45 +0300 Message-Id: <86bk5b1r1i.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Graves Cc: monnier@iro.umontreal.ca, ludo@gnu.org, emacs-devel@gnu.org, andrew@trop.in, guix-devel@gnu.org, bjorn.bidar@thaodan.de, rudi@constantly.at, felix.lechner@lease-up.com In-Reply-To: <87msow7xrs.fsf@ngraves.fr> (emacs-devel@gnu.org) Subject: Re: [Nicolas Graves] [PATCH v6 01/10] rde: emacs: Start emacs in --daemon mode, with shepherd and pid-file References: <20240410234923.29319-2-ngraves@ngraves.fr> <875xwotg35.fsf@trop.in> <87zfu0m9ps.fsf@ngraves.fr> <87jzl22u5w.fsf@gnu.org> <87frvp4a4u.fsf@ngraves.fr> <87msow5cm8.fsf@ngraves.fr> <87msow7xrs.fsf@ngraves.fr> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -10.13 X-Spam-Score: -10.13 X-Migadu-Queue-Id: 458FE628E2 X-Migadu-Scanner: mx13.migadu.com X-TUID: CYEz0vSuttF9 > Cc: Ludovic Courtès , emacs-devel@gnu.org, > Andrew Tropin , guix-devel@gnu.org, bjorn.bidar@thaodan.de, > rudi@constantly.at, felix.lechner@lease-up.com > Date: Sun, 12 May 2024 01:07:51 +0200 > From: Nicolas Graves via "Emacs development discussions." > > A lightly cleaned-up version attached. Thanks. What was the motivation for this, again? > configure.ac | 19 +------ > lib/Makefile.in | 2 +- > lib/gnulib.mk.in | 2 - > lib/sd-socket.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++ > lib/sd-socket.h | 57 ++++++++++++++++++++ > msdos/sed1v2.inp | 3 -- > src/Makefile.in | 9 ++-- > src/deps.mk | 2 +- > src/emacs.c | 50 ++++++++--------- > 9 files changed, 226 insertions(+), 55 deletions(-) > create mode 100644 lib/sd-socket.c > create mode 100644 lib/sd-socket.h Your code is not from Gnulib, so it is wrong to place it in lib/. It should be in src/, and probably just an addition to sysdep.c. Then many of the changes to the build infrastructure will not be needed. > -HAVE_LIBSYSTEMD=no > -if test "${with_libsystemd}" = "yes" ; then > - dnl This code has been tested with libsystemd 222 and later. > - dnl FIXME: Find the earliest version number for which Emacs should work, > - dnl and change '222' to that number. > - EMACS_CHECK_MODULES([LIBSYSTEMD], [libsystemd >= 222], > - [HAVE_LIBSYSTEMD=yes], [HAVE_LIBSYSTEMD=no]) > - if test "${HAVE_LIBSYSTEMD}" = "yes"; then > - AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Define if using libsystemd.]) > - fi > -fi > - > -AC_SUBST([LIBSYSTEMD_LIBS]) > -AC_SUBST([LIBSYSTEMD_CFLAGS]) This test should be replaced by a test to determine whether the systemd interface should be compiled into Emacs. Not all of the supported platform can use it, so we need to determine that at configure time. > - > HAVE_JSON=no > JSON_OBJ= > > @@ -6652,7 +6636,7 @@ AC_DEFUN > optsep= > emacs_config_features= > for opt in ACL BE_APP CAIRO DBUS FREETYPE GCONF GIF GLIB GMP GNUTLS GPM GSETTINGS \ > - HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 \ > + HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBXML2 \ > M17N_FLT MODULES NATIVE_COMP NOTIFY NS OLDXMENU PDUMPER PGTK PNG RSVG SECCOMP \ > SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER \ > UNEXEC WEBP X11 XAW3D XDBE XFT XIM XINPUT2 XPM XWIDGETS X_TOOLKIT \ > @@ -6721,7 +6705,6 @@ AC_DEFUN > Does Emacs use -lm17n-flt? ${HAVE_M17N_FLT} > Does Emacs use -lotf? ${HAVE_LIBOTF} > Does Emacs use -lxft? ${HAVE_XFT} > - Does Emacs use -lsystemd? ${HAVE_LIBSYSTEMD} > Does Emacs use -ljansson? ${HAVE_JSON} > Does Emacs use -ltree-sitter? ${HAVE_TREE_SITTER} > Does Emacs use the GMP library? ${HAVE_GMP} The above summary of the configuration should still call out the result of the configure test for systemd interface, and I think the list of features should include some string which tells us whether systemd interface is supported. > -#ifdef HAVE_LIBSYSTEMD > /* Read the number of sockets passed through by systemd. */ > - int systemd_socket = sd_listen_fds (1); > - > - if (systemd_socket > 1) > - fputs (("\n" > - "Warning: systemd passed more than one socket to Emacs.\n" > - "Try 'Accept=false' in the Emacs socket unit file.\n"), > - stderr); > - else if (systemd_socket == 1 > - && (0 < sd_is_socket (SD_LISTEN_FDS_START, > - AF_UNSPEC, SOCK_STREAM, 1))) > - sockfd = SD_LISTEN_FDS_START; > -#endif /* HAVE_LIBSYSTEMD */ > + const char *fds = getenv("LISTEN_FDS"); > + if (fds) { > + int systemd_socket = strtol(fds, NULL, 0); > + if (systemd_socket > 1) > + fputs (("\n" > + "Warning: systemd passed more than one socket to Emacs.\n" > + "Try 'Accept=false' in the Emacs socket unit file.\n"), > + stderr); > + else if (systemd_socket == 1 > + && (0 < sd_is_socket (SD_LISTEN_FDS_START, SOCK_STREAM, 1))) > + sockfd = SD_LISTEN_FDS_START; > + } The new code to interface with systemd cannot be compiled unconditionally, it should have some #ifdef condition, determined by the configure script, because not all the platforms we support can use systemd. > @@ -2857,12 +2854,15 @@ DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 2, "P", > } > #endif > > -#ifdef HAVE_LIBSYSTEMD > /* Notify systemd we are shutting down, but only if we have notified > it about startup. */ > - if (daemon_type == -1) > - sd_notify(0, "STOPPING=1"); > -#endif /* HAVE_LIBSYSTEMD */ > + if (daemon_type == -1){ > + int r = sd_notify_stopping(); > + if (r < 0) { > + fprintf(stderr, "Failed to report termination to $NOTIFY_SOCKET: %s\n", strerror(-r)); > + exit (EXIT_FAILURE); > + } > + } Same here. > /* Fsignal calls emacs_abort () if it sees that waiting_for_input is > set. */ > @@ -3382,9 +3382,11 @@ DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0, > > if (daemon_type == 1) > { > -#ifdef HAVE_LIBSYSTEMD > - sd_notify(0, "READY=1"); > -#endif /* HAVE_LIBSYSTEMD */ > + int r = sd_notify_ready(); > + if (r < 0) { > + fprintf(stderr, "Failed to notify readiness to $NOTIFY_SOCKET: %s\n", strerror(-r)); > + exit (EXIT_FAILURE); > + } > } And here. > > Seems to work properly on my side with the following patch, on Guix with > > the shepherd service I sent a few weeks ago. The patch is actually > > pretty simple. How sure we are that the code you wrote will not need any significant maintenance due to changes in how systemd works? The significant advantage of using libsystemd is that the systemd developers take care of updating it as needed. With these changes, that burden is now on us. I don't think we'd be happy maintaining system-level code that have very little relevance to Emacs. > > - The sd_notify code is taken from > > https://www.freedesktop.org/software/systemd/man/devel/sd_notify.html#Notes I'm not sure what would be the legal aspects of such code borrowing.