From patchwork Fri Mar 9 12:44:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Moese X-Patchwork-Id: 883599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zyRsP1d6fz9sXK for ; Fri, 9 Mar 2018 23:44:24 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 041E53E749B for ; Fri, 9 Mar 2018 13:44:22 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id F3A3B3E71AB for ; Fri, 9 Mar 2018 13:44:20 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 9FD5E60222F for ; Fri, 9 Mar 2018 13:44:20 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0DF79AD38 for ; Fri, 9 Mar 2018 12:44:20 +0000 (UTC) From: Michael Moese To: ltp@lists.linux.it Date: Fri, 9 Mar 2018 13:44:17 +0100 Message-Id: <20180309124418.30271-3-mmoese@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180309124418.30271-1-mmoese@suse.de> References: <20180309124418.30271-1-mmoese@suse.de> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS, T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v6 2/3] Add a library wrapper for sigaction() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" In a multithreaded program, using signal() results in unspecified behavior. In this case, sigaction() has to be used to install a signal handler. Therefore, SAFE_SIGACTION() is added. Signed-off-by: Michael Moese --- include/tst_safe_macros.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index 06bff13c7..bf12e0719 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -397,6 +397,26 @@ static inline sighandler_t safe_signal(const char *file, const int lineno, #define SAFE_SIGNAL(signum, handler) \ safe_signal(__FILE__, __LINE__, (signum), (handler)) + + +static inline int safe_sigaction(const char *file, const int lineno, + int signum, const struct sigaction *act, + struct sigaction *oldact) +{ + int rval; + + rval = sigaction(signum, act, oldact); + + if (rval == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "sigaction(%d, %p, %p) failed", signum, act, oldact); + } + + return rval; +} +#define SAFE_SIGACTION(signum, act, oldact) \ + safe_sigaction(__FILE__, __LINE__, (signum), (act), (oldact)) + #define SAFE_EXECLP(file, arg, ...) do { \ execlp((file), (arg), ##__VA_ARGS__); \ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \