From patchwork Mon Sep 10 09:11:24 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: 967932 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=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4282NQ499yz9s3x for ; Mon, 10 Sep 2018 19:11:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D25163E6287 for ; Mon, 10 Sep 2018 11:11:31 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 1E7A73E6264 for ; Mon, 10 Sep 2018 11:11:30 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id C50CD100134F for ; Mon, 10 Sep 2018 11:11:29 +0200 (CEST) Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 24B8DAE7D for ; Mon, 10 Sep 2018 09:11:29 +0000 (UTC) From: Clemens Famulla-Conrad To: ltp@lists.linux.it Date: Mon, 10 Sep 2018 11:11:24 +0200 Message-Id: <20180910091124.12256-1-cfamullaconrad@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180910090933.12080-1-cfamullaconrad@suse.de> References: <20180910090933.12080-1-cfamullaconrad@suse.de> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH v1 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 not exists fall back to the second name given. If the second group dosn'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..614b6b4b5 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, name); + } + + return rval; +} + struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid) { struct group *rval;