From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Lucas Werkmeister Newsgroups: gmane.emacs.bugs Subject: bug#31498: [PATCH] Notify systemd in daemon-initialized and kill-emacs Date: Sat, 9 Jun 2018 12:56:16 +0200 Message-ID: <20180609105616.12927-1-mail@lucaswerkmeister.de> References: <20180518174031.12514-1-mail@lucaswerkmeister.de> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1528541705 19839 195.159.176.226 (9 Jun 2018 10:55:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 9 Jun 2018 10:55:05 +0000 (UTC) Cc: Noam Postavsky , Lucas Werkmeister To: 31498@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 09 12:55:01 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fRbWP-00053J-0B for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Jun 2018 12:55:01 +0200 Original-Received: from localhost ([::1]:39797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRbYW-0002dB-7i for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Jun 2018 06:57:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRbYP-0002cn-Pk for bug-gnu-emacs@gnu.org; Sat, 09 Jun 2018 06:57:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRbYM-0005na-Kn for bug-gnu-emacs@gnu.org; Sat, 09 Jun 2018 06:57:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60704) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRbYM-0005nW-Fd for bug-gnu-emacs@gnu.org; Sat, 09 Jun 2018 06:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fRbYM-0007Zd-7r for bug-gnu-emacs@gnu.org; Sat, 09 Jun 2018 06:57:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <20180518174031.12514-1-mail@lucaswerkmeister.de> Resent-From: Lucas Werkmeister Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Jun 2018 10:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31498 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 31498-submit@debbugs.gnu.org id=B31498.152854180629089 (code B ref 31498); Sat, 09 Jun 2018 10:57:02 +0000 Original-Received: (at 31498) by debbugs.gnu.org; 9 Jun 2018 10:56:46 +0000 Original-Received: from localhost ([127.0.0.1]:40368 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fRbY6-0007Z6-5S for submit@debbugs.gnu.org; Sat, 09 Jun 2018 06:56:46 -0400 Original-Received: from lucaswerkmeister.de ([94.130.58.99]:57170) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fRbY4-0007Yu-5M for 31498@debbugs.gnu.org; Sat, 09 Jun 2018 06:56:44 -0400 Original-Received: from theoden.lucaswerkmeister.de.home (unknown [IPv6:2a02:8109:92c0:22bb:d412:2b0:339e:ab21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mail@lucaswerkmeister.de) by lucaswerkmeister.de (Postfix) with ESMTPSA id 069A6399B2F; Sat, 9 Jun 2018 12:56:42 +0200 (CEST) Authentication-Results: lucaswerkmeister.de; dmarc=fail (p=none dis=none) header.from=lucaswerkmeister.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lucaswerkmeister.de; s=mail; t=1528541803; bh=oUTxy2SAu1LeGCgXRnlwFXlNgq8QY6v/YzpUcf+lZJM=; h=From:To:Cc:Subject:Date:Message-Id:From:Reply-To:Subject:Date:To: Cc:In-Reply-To:References:Message-Id:Sender:Content-Type: Content-Transfer-Encoding:Content-Disposition:Mime-Version; b=RhNPa1PLj5Jzx0c/hap9GDCNPTNnJavgCKLj7TEHr1FrDYSLjw0o3hMiwf4AuQNcn zQ2jw+dCou3DTndg1N9M6RavmSw4ptyaZagD3/oxGF6EE41LESFRK7NFFw7GSRUbEi DJIUv08jJ0kYyz5QhHZQIca58zWHKOE3wajelQmg= X-Mailer: git-send-email 2.17.1 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147236 Archived-At: With --[bg-]daemon and Type=forking, systemd will only consider the daemon to have fully started up once the original process exits, and will wait until then to start units depending on the Emacs service. To get the same functionality with --fg-daemon, use Type=notify instead of Type=simple and explicitly send a readiness notification to systemd at the point where the forked process would in --bg-daemon mode notify its parent process and cause it to exit. Similarly, notify systemd at the beginning of the shutdown process as well. (Both of these calls are successful no-ops if emacs was not started by systemd.) * etc/emacs.service: Update Type. * src/emacs.c (daemon-initialized): Call sd_notify(). * src/emacs.c (kill-emacs): Call sd_notify(). --- etc/emacs.service | 2 +- src/emacs.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/etc/emacs.service b/etc/emacs.service index b29177b120..dbcb6bc301 100644 --- a/etc/emacs.service +++ b/etc/emacs.service @@ -7,7 +7,7 @@ Description=Emacs text editor Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/ [Service] -Type=simple +Type=notify ExecStart=emacs --fg-daemon ExecStop=emacsclient --eval "(kill-emacs)" Environment=SSH_AUTH_SOCK=%t/keyring/ssh diff --git a/src/emacs.c b/src/emacs.c index 8633e934e5..cde20fc096 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -2017,6 +2017,10 @@ all of which are called before Emacs is actually killed. */ { int exit_code; +#ifdef HAVE_LIBSYSTEMD + sd_notify(0, "STOPPING=1"); +#endif /* HAVE_LIBSYSTEMD */ + /* Fsignal calls emacs_abort () if it sees that waiting_for_input is set. */ waiting_for_input = 0; @@ -2477,6 +2481,13 @@ from the parent process and its tty file descriptors. */) error ("This function can only be called after loading the init files"); #ifndef WINDOWSNT + if (daemon_type == 1) + { +#ifdef HAVE_LIBSYSTEMD + sd_notify(0, "READY=1"); +#endif /* HAVE_LIBSYSTEMD */ + } + if (daemon_type == 2) { int nfd; -- 2.17.1