From patchwork Thu Jul 14 02:51:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 9228827 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 618D160868 for ; Thu, 14 Jul 2016 02:51:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4823E26861 for ; Thu, 14 Jul 2016 02:51:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ACF3280B0; Thu, 14 Jul 2016 02:51:16 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 ADC4226861 for ; Thu, 14 Jul 2016 02:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751046AbcGNCvO (ORCPT ); Wed, 13 Jul 2016 22:51:14 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34799 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750950AbcGNCvO (ORCPT ); Wed, 13 Jul 2016 22:51:14 -0400 Received: by mail-pf0-f195.google.com with SMTP id g202so4093023pfb.1 for ; Wed, 13 Jul 2016 19:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=4ZxOMhuo0ZVnsKSS/0UxOmvdhNMk43fgJBU+j9W2EkE=; b=MW4i9v/jWQS4M9gcS9MJOHtJFwI7N8BseBU6cNmdbNbIzQ1y0INQwA9QKrUC9WZP6t Zun1bTXye0Auv4kAFvznhWEDX3AHbJWbuy+s/MmtxDwbnliF7uVdc7Sa0qm7cuGQIJ5c G49t0dettUi3W8FNbAuFWYLe+BEViQLFYNngeQ1iS/k+/ZulIKtAft5VcQ80Ql1QlhCl 3tommjUtS5e59+Fv6CMMlbpy8ErDTw35GTBJNKoj5hHGN+lBEa5I+C5rG069ZT6nXG7u 1JAqpBReHfcSFCZZ0UfZfRpy6pOf+OD5rJUxdy13jZlPHPI+1wAHITAg8Ju57a+BRiDI 2VLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=4ZxOMhuo0ZVnsKSS/0UxOmvdhNMk43fgJBU+j9W2EkE=; b=XeiyIr/zZYCd+oh1qDtf1gsQBTWxMhtnrbvqOs9IOOqiJQz1Dn2pNFi/EeRNmG33vS 4nanoDd45RllQaHk0Dlobhh/SY7RODpGBxZl7S/IkmuQ+kbIEkwuBJv938KdRi1z9Pan 1EhtcdbMUAT6XYmmijg03OoF9Zf8+L+VBo8a/ol1s1UOBMeETf8/uvTCZsyzW5BipOP/ HR6sip3D3afqXKh7fan2Ti0yfGKKscL6bcoT8fGEcf3zVbSzEIxyXH0wcqaJmfVcDm5O tMQP1tY3WYsH94WQ+T2EV8dwRpws9zlnviwPaa8FRubuzrjV/jQKWKPCSsC5Wtq+MaWP n1dg== X-Gm-Message-State: ALyK8tJMNYI0kOipevwCTeQJKoVwKboVl8QFQRJq8o9oCcRr5yU+4lIw8Yo44vcT0/VXXQ== X-Received: by 10.98.10.148 with SMTP id 20mr8839418pfk.154.1468464673288; Wed, 13 Jul 2016 19:51:13 -0700 (PDT) Received: from [192.168.99.7] ([191.101.234.188]) by smtp.googlemail.com with ESMTPSA id x66sm7550394pfi.84.2016.07.13.19.51.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2016 19:51:12 -0700 (PDT) To: Steve Dickson Cc: linux-nfs@vger.kernel.org, Kinglong Mee From: Kinglong Mee Subject: [PATCH 1/2] blkmapd: Let running correctly when pid file exists Message-ID: Date: Thu, 14 Jul 2016 10:51:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Blkmapd cannot run until blkmapd.pid is unlinked. This patch lets checking exists based on lockf without stat. # ps -ajx | grep blkmapd 1644 9126 9125 1644 pts/1 9125 S+ 0 0:00 grep --color=auto blkmapd # ll /var/run/blkmapd -rw-r--r--. 1 root root 5 Jul 14 09:51 /var/run/blkmapd.pid # blkmapd Pid file /var/run/blkmapd.pid already existed Signed-off-by: Kinglong Mee --- utils/blkmapd/device-discovery.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c index 052d582..50e2746 100644 --- a/utils/blkmapd/device-discovery.c +++ b/utils/blkmapd/device-discovery.c @@ -436,7 +436,6 @@ static void usage(void) int main(int argc, char **argv) { int opt, dflag = 0, fg = 0, ret = 1; - struct stat statbuf; char pidbuf[64]; while ((opt = getopt(argc, argv, "hdf")) != -1) { @@ -460,11 +459,6 @@ int main(int argc, char **argv) if (fg) { openlog("blkmapd", LOG_PERROR, 0); } else { - if (!stat(PID_FILE, &statbuf)) { - fprintf(stderr, "Pid file %s already existed\n", PID_FILE); - exit(1); - } - if (daemon(0, 0) != 0) { fprintf(stderr, "Daemonize failed\n"); exit(1); @@ -478,7 +472,7 @@ int main(int argc, char **argv) } if (lockf(pidfd, F_TLOCK, 0) < 0) { - BL_LOG_ERR("Lock pid file %s failed\n", PID_FILE); + BL_LOG_ERR("Already running; Exiting!"); close(pidfd); exit(1); }