From patchwork Thu Aug 23 16:36:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Tao X-Patchwork-Id: 1368211 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id BB8F5DF2AB for ; Thu, 23 Aug 2012 16:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753174Ab2HWQhK (ORCPT ); Thu, 23 Aug 2012 12:37:10 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:50320 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753048Ab2HWQhJ (ORCPT ); Thu, 23 Aug 2012 12:37:09 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so1781864pbb.19 for ; Thu, 23 Aug 2012 09:37:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=oMrECXRvHbbbqoJy/1WRzKhecct5P0Mzs03T8QP2N80=; b=jjb3LSoCiyZUY/40lbdXhuqxMqmL3ADYW4ZSENFidBnmvQE6smyGY4LYZ/+S7325IA r6EFsrMrFGLMbxhIdfMa3GQCDl6wIwwR1GcaYRP9FlePeDB6NIvODY2tuwdp7ul9mkC4 ZwhJVFeSS52D9WuzwK+7rdMOFsAHCAqs3yGjBNt/fzxAvEKMTi/mExFD3sk6rNrmvPfX dVScgZxkMAEmWzLHw1LOsbpB6pw3e0gX54xONRAj7IPRvFzpZ2IzhcVoafUaIoSEEDX+ ykYD5YIZ6jixrsuuCf5wWTbnevwjLQGAlAvD8RYbARGXz/NroI9LuTQjK0oD+mfBTlaA FVJg== Received: by 10.68.234.73 with SMTP id uc9mr5838941pbc.158.1345739829412; Thu, 23 Aug 2012 09:37:09 -0700 (PDT) Received: from debian-sid.localdomain ([123.118.157.62]) by mx.google.com with ESMTPS id oc2sm6302375pbb.69.2012.08.23.09.37.05 (version=SSLv3 cipher=OTHER); Thu, 23 Aug 2012 09:37:08 -0700 (PDT) From: Peng Tao To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org, Peng Tao Subject: [PATCH-Resend 2/2] blkmapd: proper signal handling Date: Fri, 24 Aug 2012 00:36:32 +0800 Message-Id: <1345739792-2385-2-git-send-email-bergwolf@gmail.com> X-Mailer: git-send-email 1.7.1.262.g5ef3d In-Reply-To: <1345739792-2385-1-git-send-email-bergwolf@gmail.com> References: <1345739792-2385-1-git-send-email-bergwolf@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Peng Tao --- utils/blkmapd/device-discovery.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c index 8eddf50..df4627e 100644 --- a/utils/blkmapd/device-discovery.c +++ b/utils/blkmapd/device-discovery.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,7 @@ struct bl_disk *visible_disk_list; int bl_watch_fd, bl_pipe_fd, nfs_pipedir_wfd, rpc_pipedir_wfd; +int pidfd = -1; struct bl_disk_path *bl_get_path(const char *filepath, struct bl_disk_path *paths) @@ -431,10 +433,20 @@ static int bl_event_helper(void) return ret; } +void sig_die(int signal) +{ + if (pidfd >= 0) { + close(pidfd); + unlink(PID_FILE); + } + BL_LOG_ERR("exit on signal(%d)\n", signal); + exit(1); +} + /* Daemon */ int main(int argc, char **argv) { - int pidfd = -1, opt, dflag = 0, fg = 0, ret = 1; + int opt, dflag = 0, fg = 0, ret = 1; struct stat statbuf; char pidbuf[64]; @@ -479,6 +491,10 @@ int main(int argc, char **argv) write(pidfd, pidbuf, strlen(pidbuf)); } + signal(SIGINT, sig_die); + signal(SIGTERM, sig_die); + signal(SIGHUP, SIG_IGN); + if (dflag) { bl_discover_devices(); exit(0);