From: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 4/5] tst_safe_macros: add SAFE_GETGRNAM_FALLBACK()
Date: Mon, 10 Sep 2018 16:19:00 +0200 [thread overview]
Message-ID: <20180910141901.20541-4-cfamullaconrad@suse.de> (raw)
In-Reply-To: <20180910141901.20541-1-cfamullaconrad@suse.de>
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 <cfamullaconrad@suse.de>
---
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;
--
2.16.4
next prev parent reply other threads:[~2018-09-10 14:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-10 14:18 [LTP] [PATCH v2 1/5] setregid01: Convert to newlib Clemens Famulla-Conrad
2018-09-10 14:18 ` [LTP] [PATCH v2 2/5] tst_safe_macros: add SAFE_GETGRGID() Clemens Famulla-Conrad
2018-10-02 14:20 ` Cyril Hrubis
2018-10-02 23:23 ` Clemens Famulla-Conrad
2018-10-03 7:46 ` Cyril Hrubis
2018-09-10 14:18 ` [LTP] [PATCH v2 3/5] setregid02: Convert to newlib Clemens Famulla-Conrad
2018-09-10 14:19 ` Clemens Famulla-Conrad [this message]
2018-09-10 14:19 ` [LTP] [PATCH v2 5/5] setregid04: " Clemens Famulla-Conrad
2018-09-11 7:42 ` [LTP] [PATCH v2 1/5] setregid01: " Richard Palethorpe
2018-10-02 14:07 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180910141901.20541-4-cfamullaconrad@suse.de \
--to=cfamullaconrad@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox