From patchwork Mon Sep 10 14:19:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Clemens Famulla-Conrad X-Patchwork-Id: 968062 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 ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4289Ct1Zv6z9s3Z for ; Tue, 11 Sep 2018 00:19:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B9BAC3E62E4 for ; Mon, 10 Sep 2018 16:19:35 +0200 (CEST) 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 [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 047943E62B2 for ; Mon, 10 Sep 2018 16:19:27 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id B4131600127 for ; Mon, 10 Sep 2018 16:19:26 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 620EEB000 for ; Mon, 10 Sep 2018 14:19:26 +0000 (UTC) From: Clemens Famulla-Conrad To: ltp@lists.linux.it Date: Mon, 10 Sep 2018 16:19:00 +0200 Message-Id: <20180910141901.20541-4-cfamullaconrad@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180910141901.20541-1-cfamullaconrad@suse.de> References: <20180910141901.20541-1-cfamullaconrad@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 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 v2 4/5] tst_safe_macros: add SAFE_GETGRNAM_FALLBACK() 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" This function retrieves the group by name. If the group doesn't exists fall back to the second name given. If the second group doesn't exists, exit with TBROK. Signed-off-by: Clemens Famulla-Conrad --- include/tst_safe_macros.h | 5 +++++ lib/tst_safe_macros.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index d457ae92a..e8b68ce9d 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -441,6 +441,11 @@ struct group *safe_getgrnam(const char *file, const int lineno, #define SAFE_GETGRNAM(name) \ safe_getgrnam(__FILE__, __LINE__, (name)) +struct group *safe_getgrnam_fallback(const char *file, const int lineno, + const char *name, const char *fallback); +#define SAFE_GETGRNAM_FALLBACK(name, fallback) \ + safe_getgrnam_fallback(__FILE__, __LINE__, (name), (fallback)) + struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid); #define SAFE_GETGRGID(gid) \ safe_getgrgid(__FILE__, __LINE__, (gid)) diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c index 2e041c460..83994cdea 100644 --- a/lib/tst_safe_macros.c +++ b/lib/tst_safe_macros.c @@ -153,6 +153,22 @@ struct group *safe_getgrnam(const char *file, const int lineno, return rval; } +struct group *safe_getgrnam_fallback(const char *file, const int lineno, + const char *name, const char *fallback) +{ + struct group *rval; + + rval = getgrnam(name); + if (rval == NULL) { + tst_res_(file, lineno, TINFO, + "getgrnam(%s) failed - try fallback %s", + name, fallback); + rval = safe_getgrnam(file, lineno, fallback); + } + + return rval; +} + struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid) { struct group *rval;