From patchwork Thu Apr 7 23:20:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 8777941 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0BDBAC0554 for ; Thu, 7 Apr 2016 23:23:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3335D20251 for ; Thu, 7 Apr 2016 23:23:26 +0000 (UTC) Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC4702020F for ; Thu, 7 Apr 2016 23:23:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u37NKS9q021634; Thu, 7 Apr 2016 19:20:28 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u37NKRq7027924 for ; Thu, 7 Apr 2016 19:20:27 -0400 Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u37NKPKP027129; Thu, 7 Apr 2016 19:20:25 -0400 Received: by redhat.com (sSMTP sendmail emulation); Thu, 07 Apr 2016 18:20:25 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Thu, 7 Apr 2016 18:20:02 -0500 Message-Id: <1460071212-21018-9-git-send-email-bmarzins@redhat.com> In-Reply-To: <1460071212-21018-1-git-send-email-bmarzins@redhat.com> References: <1460071212-21018-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH v2 08/18] multipathd: fail if pidfile can't be created X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Right now, multipathd ignores failures from pidfile_create. This means that multiple multipathd processes can be running at the same time. If someone runs "multipathd" and doesn't add a command after it, a new process will be created, even if one is already running. To avoid this, multipathd needs to actually fail if the pidfile can't be created or locked. Since we only really need the pidfile to keep from launching multiple processes, we can create in earlier in startup. This patch moves pidfile_create to as soon as we can be sure that we can log an error message, and fails multipathd if the create fails. Signed-off-by: Benjamin Marzinski --- multipathd/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 8f4fb58..06876b9 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1768,7 +1768,7 @@ child (void * param) #ifdef USE_SYSTEMD unsigned long checkint; #endif - int rc, pid_rc; + int rc; char *envp; mlockall(MCL_CURRENT | MCL_FUTURE); @@ -1786,6 +1786,12 @@ child (void * param) log_thread_start(&log_attr); pthread_attr_destroy(&log_attr); } + if (pidfile_create(DEFAULT_PIDFILE, daemon_pid)) { + condlog(1, "failed to create pidfile"); + if (logsink == 1) + log_thread_stop(); + exit(1); + } running_state = DAEMON_START; @@ -1905,10 +1911,6 @@ child (void * param) } pthread_attr_destroy(&misc_attr); - /* Startup complete, create logfile */ - pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid); - /* Ignore errors, we can live without */ - running_state = DAEMON_RUNNING; #ifdef USE_SYSTEMD sd_notify(0, "READY=1\nSTATUS=running"); @@ -1959,10 +1961,8 @@ child (void * param) dm_lib_exit(); /* We're done here */ - if (!pid_rc) { - condlog(3, "unlink pidfile"); - unlink(DEFAULT_PIDFILE); - } + condlog(3, "unlink pidfile"); + unlink(DEFAULT_PIDFILE); condlog(2, "--------shut down-------");