From patchwork Thu Aug 3 22:04:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9879921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BC7BA603F4 for ; Thu, 3 Aug 2017 22:04:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9F542896C for ; Thu, 3 Aug 2017 22:04:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EBD928972; Thu, 3 Aug 2017 22:04:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9872C2896C for ; Thu, 3 Aug 2017 22:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbdHCWET (ORCPT ); Thu, 3 Aug 2017 18:04:19 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:59648 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751736AbdHCWES (ORCPT ); Thu, 3 Aug 2017 18:04:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=References:In-Reply-To:Message-Id:Date:Subject:To:From; bh=f1E0CZpHK3Ca6w3TJrQiVNilblfJVUeYniVAZcheQJo=; b=WR2mlsTNT7t5W451j3Y6Dxs0P7Ac123bjwm74wxrPI1pJCvuY5rM8hxGIjkm9JtkVrPoIK4iPTtDIH3tJqOEHney7SiYAfGcext3MUsSb5kyZeDNp5Zk+YI6a3M6NqcxJ8hYBRwm7YIjGR+Q5zdZ8uEcWjiY8fYVsJIc8pCYBts=; Received: from [10.0.0.156] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1ddOE3-0004XK-5q for linux-rdma@vger.kernel.org; Thu, 03 Aug 2017 16:04:15 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Subject: [PATCH rdma-core 2/4] rdma-ndd: Use sd_notify to synchronize bootup Date: Thu, 3 Aug 2017 16:04:04 -0600 Message-Id: <1501797846-8228-3-git-send-email-jgunthorpe@obsidianresearch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501797846-8228-1-git-send-email-jgunthorpe@obsidianresearch.com> References: <1501797846-8228-1-git-send-email-jgunthorpe@obsidianresearch.com> X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Tell systemd that rdma-ndd is ready once it has scanned and set the hostname of all currently present devices. Signed-off-by: Jason Gunthorpe --- rdma-ndd/CMakeLists.txt | 5 ++++- rdma-ndd/rdma-ndd.8.in | 3 +++ rdma-ndd/rdma-ndd.8.in.rst | 3 +++ rdma-ndd/rdma-ndd.c | 15 ++++++++++++--- rdma-ndd/rdma-ndd.service.in | 3 ++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/rdma-ndd/CMakeLists.txt b/rdma-ndd/CMakeLists.txt index 99e183e34ef758..e8419a6c93116f 100644 --- a/rdma-ndd/CMakeLists.txt +++ b/rdma-ndd/CMakeLists.txt @@ -7,7 +7,10 @@ rdma_sbin_executable(rdma-ndd rdma-ndd.c ) -target_link_libraries(rdma-ndd LINK_PRIVATE ${UDEV_LIBRARIES}) +target_link_libraries(rdma-ndd LINK_PRIVATE + ${SYSTEMD_LIBRARIES} + ${UDEV_LIBRARIES} + ) # FIXME Autogenerate from the .rst rdma_man_pages( diff --git a/rdma-ndd/rdma-ndd.8.in b/rdma-ndd/rdma-ndd.8.in index c0668d7f3eb62e..d6c75d3255d379 100644 --- a/rdma-ndd/rdma-ndd.8.in +++ b/rdma-ndd/rdma-ndd.8.in @@ -78,6 +78,9 @@ Run in the foreground instead of as a daemon .sp \fB\-d, \-\-debugging\fP Log additional debugging information to syslog +.sp +\fB\-\-systemd\fP +Enable systemd integration. .SH AUTHOR .INDENT 0.0 .TP diff --git a/rdma-ndd/rdma-ndd.8.in.rst b/rdma-ndd/rdma-ndd.8.in.rst index 12ba91b605501f..767f388e9ab925 100644 --- a/rdma-ndd/rdma-ndd.8.in.rst +++ b/rdma-ndd/rdma-ndd.8.in.rst @@ -74,6 +74,9 @@ Run in the foreground instead of as a daemon **-d, --debugging** Log additional debugging information to syslog +**--systemd** +Enable systemd integration. + AUTHOR ====== diff --git a/rdma-ndd/rdma-ndd.c b/rdma-ndd/rdma-ndd.c index 180cbb34a8e29b..418d1de9456b7d 100644 --- a/rdma-ndd/rdma-ndd.c +++ b/rdma-ndd/rdma-ndd.c @@ -49,6 +49,7 @@ #include #include +#include #include static struct udev *g_udev; @@ -237,7 +238,7 @@ static void process_udev_event(int ud_fd, const char *hostname) } } -static void monitor(void) +static void monitor(bool systemd) { char hostname[128]; int hn_fd; @@ -265,6 +266,9 @@ static void monitor(void) fds[1].fd = ud_fd; fds[1].events = POLLIN; + if (systemd) + sd_notify(0, "READY=1"); + while (1) { if (poll(fds, numfds, -1) <= 0) { syslog(LOG_ERR, "Poll %s failed; exiting\n", SYS_HOSTNAME); @@ -285,12 +289,14 @@ static void monitor(void) int main(int argc, char *argv[]) { bool foreground = false; + bool systemd = false; openlog(NULL, LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON); while (1) { static const struct option long_opts[] = { { "foreground", 0, NULL, 'f' }, + { "systemd", 0, NULL, 's' }, { "help", 0, NULL, 'h' }, { "debug", 0, NULL, 'd' }, { } @@ -304,6 +310,9 @@ int main(int argc, char *argv[]) case 'f': foreground = true; break; + case 's': + systemd = true; + break; case 'd': debugging = true; break; @@ -317,7 +326,7 @@ int main(int argc, char *argv[]) } } - if (!foreground) { + if (!foreground && !systemd) { if (daemon(0, 0) != 0) { syslog(LOG_ERR, "Failed to daemonize\n"); return EXIT_FAILURE; @@ -334,7 +343,7 @@ int main(int argc, char *argv[]) dbg_log("Node Descriptor format (%s)\n", g_nd_format); - monitor(); + monitor(systemd); return 0; } diff --git a/rdma-ndd/rdma-ndd.service.in b/rdma-ndd/rdma-ndd.service.in index ba6868cc13801a..56c5959505010f 100644 --- a/rdma-ndd/rdma-ndd.service.in +++ b/rdma-ndd/rdma-ndd.service.in @@ -3,6 +3,7 @@ Description=RDMA Node Description Daemon Documentation=man:rdma-ndd [Service] +Type=notify Restart=always -ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/rdma-ndd -f +ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/rdma-ndd --systemd