@@ -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))
@@ -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;
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(+)