public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 2/5] tst_safe_macros: add SAFE_GETGRGID()
@ 2018-10-08  7:16 Clemens Famulla-Conrad
  2018-10-08  7:16 ` [LTP] [PATCH v3 3/5] setregid02: Convert to newlib Clemens Famulla-Conrad
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Clemens Famulla-Conrad @ 2018-10-08  7:16 UTC (permalink / raw)
  To: ltp

Add tst safe wrapper for getgrgid() function.

Zero errno before calling getgrnam() or getgrgid() to get the
correct errno printed in tst_brk_(TERRNO).

Signed-off-by: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
---
 include/tst_safe_macros.h |  4 ++++
 lib/tst_safe_macros.c     | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 413226eaf..0e5a6d304 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -441,6 +441,10 @@ struct group *safe_getgrnam(const char *file, const int lineno,
 #define SAFE_GETGRNAM(name) \
 	safe_getgrnam(__FILE__, __LINE__, (name))
 
+struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid);
+#define SAFE_GETGRGID(gid) \
+	safe_getgrgid(__FILE__, __LINE__, (gid))
+
 ssize_t safe_getxattr(const char *file, const int lineno, const char *path,
 	const char *name, void *value, size_t size);
 #define SAFE_GETXATTR(path, name, value, size) \
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 17384f32c..e1d4fd124 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -144,6 +144,7 @@ struct group *safe_getgrnam(const char *file, const int lineno,
 {
 	struct group *rval;
 
+	errno = 0;
 	rval = getgrnam(name);
 	if (rval == NULL) {
 		tst_brk_(file, lineno, TBROK | TERRNO,
@@ -153,6 +154,20 @@ struct group *safe_getgrnam(const char *file, const int lineno,
 	return rval;
 }
 
+struct group *safe_getgrgid(const char *file, const int lineno, gid_t gid)
+{
+	struct group *rval;
+
+	errno = 0;
+	rval = getgrgid(gid);
+	if (rval == NULL) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"getgrgid(%li) failed", (long)gid);
+	}
+
+	return rval;
+}
+
 int safe_chroot(const char *file, const int lineno, const char *path)
 {
 	int rval;
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-10-11 13:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-08  7:16 [LTP] [PATCH v3 2/5] tst_safe_macros: add SAFE_GETGRGID() Clemens Famulla-Conrad
2018-10-08  7:16 ` [LTP] [PATCH v3 3/5] setregid02: Convert to newlib Clemens Famulla-Conrad
2018-10-11 13:33   ` Cyril Hrubis
2018-10-08  7:16 ` [LTP] [PATCH v3 4/5] tst_safe_macros: add SAFE_GETGRNAM_FALLBACK() Clemens Famulla-Conrad
2018-10-11 13:34   ` Cyril Hrubis
2018-10-08  7:16 ` [LTP] [PATCH v3 5/5] setregid04: Convert to newlib Clemens Famulla-Conrad
2018-10-11 13:34   ` Cyril Hrubis
2018-10-11 13:32 ` [LTP] [PATCH v3 2/5] tst_safe_macros: add SAFE_GETGRGID() Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox