diff mbox series

[v2] SAFE_MACROS: Add SAFE_GETGRNAM()

Message ID 1528975658-10511-1-git-send-email-huangjh.jy@cn.fujitsu.com
State Accepted
Delegated to: Petr Vorel
Headers show
Series [v2] SAFE_MACROS: Add SAFE_GETGRNAM() | expand

Commit Message

Jinhui Huang June 14, 2018, 11:27 a.m. UTC
From: Jinhui Huang <huangjh.jy@cn.fujitsu.com>

Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
---
 include/safe_macros_fn.h  |  3 +++
 include/tst_safe_macros.h |  3 +++
 lib/safe_macros.c         | 15 +++++++++++++++
 3 files changed, 21 insertions(+)

Comments

Petr Vorel June 15, 2018, 2:44 p.m. UTC | #1
Hi Jinhui,

> From: Jinhui Huang <huangjh.jy@cn.fujitsu.com>

> Signed-off-by: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
> ---

I accepted your patch, but had to adjusted it for use in new API only.
See following diff, hope you don't mind (removing cleanup parameter and moving
code into new API only functions).

Kind regards,
Petr

diff --git include/safe_macros_fn.h include/safe_macros_fn.h
index 74b3ec192..3df952811 100644
--- include/safe_macros_fn.h
+++ include/safe_macros_fn.h
@@ -42,9 +42,6 @@ char* safe_dirname(const char *file, const int lineno,
 char* safe_getcwd(const char *file, const int lineno,
                   void (*cleanup_fn)(void), char *buf, size_t size);
 
-struct group *safe_getgrnam(const char *file, const int lineno,
-			    void (*cleanup_fn)(void), const char *name);
-
 struct passwd* safe_getpwnam(const char *file, const int lineno,
                              void (*cleanup_fn)(void), const char *name);
 
diff --git include/tst_safe_macros.h include/tst_safe_macros.h
index a8c23934d..75c2a0803 100644
--- include/tst_safe_macros.h
+++ include/tst_safe_macros.h
@@ -30,6 +30,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 #include <dirent.h>
+#include <grp.h>
 
 #include "safe_macros_fn.h"
 
@@ -69,9 +70,6 @@ static inline int safe_dup(const char *file, const int lineno,
 #define SAFE_GETCWD(buf, size) \
 	safe_getcwd(__FILE__, __LINE__, NULL, (buf), (size))
 
-#define SAFE_GETGRNAM(name) \
-	safe_getgrnam(__FILE__, __LINE__, NULL, (name))
-
 #define SAFE_GETPWNAM(name) \
 	safe_getpwnam(__FILE__, __LINE__, NULL, (name))
 
@@ -434,6 +432,11 @@ int safe_getpriority(const char *file, const int lineno, int which, id_t who);
 #define SAFE_GETPRIORITY(which, who) \
 	safe_getpriority(__FILE__, __LINE__, (which), (who))
 
+struct group *safe_getgrnam(const char *file, const int lineno,
+			    const char *name);
+#define SAFE_GETGRNAM(name) \
+	safe_getgrnam(__FILE__, __LINE__, (name))
+
 int safe_setxattr(const char *file, const int lineno, const char *path,
             const char *name, const void *value, size_t size, int flags);
 #define SAFE_SETXATTR(path, name, value, size, flags) \
diff --git lib/safe_macros.c lib/safe_macros.c
index ea9e1f63c..abdeca013 100644
--- lib/safe_macros.c
+++ lib/safe_macros.c
@@ -15,7 +15,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <malloc.h>
-#include <grp.h>
 #include "test.h"
 #include "safe_macros.h"
 
@@ -112,20 +111,6 @@ char *safe_getcwd(const char *file, const int lineno, void (*cleanup_fn) (void),
 	return rval;
 }
 
-struct group *safe_getgrnam(const char *file, const int lineno,
-			    void (*cleanup_fn) (void), const char *name)
-{
-	struct group *rval;
-
-	rval = getgrnam(name);
-	if (rval == NULL) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			"%s:%d: getgrnam(%s) failed", file, lineno, name);
-	}
-
-	return rval;
-}
-
 struct passwd *safe_getpwnam(const char *file, const int lineno,
 			     void (*cleanup_fn) (void), const char *name)
 {
diff --git lib/tst_safe_macros.c lib/tst_safe_macros.c
index 034f91751..e152bff7f 100644
--- lib/tst_safe_macros.c
+++ lib/tst_safe_macros.c
@@ -138,3 +138,17 @@ int safe_sigaction(const char *file, const int lineno,
 
 	return rval;
 }
+
+struct group *safe_getgrnam(const char *file, const int lineno,
+			    const char *name)
+{
+	struct group *rval;
+
+	rval = getgrnam(name);
+	if (rval == NULL) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"getgrnam(%s) failed", name);
+	}
+
+	return rval;
+}
diff mbox series

Patch

diff --git a/include/safe_macros_fn.h b/include/safe_macros_fn.h
index 3df9528..74b3ec1 100644
--- a/include/safe_macros_fn.h
+++ b/include/safe_macros_fn.h
@@ -42,6 +42,9 @@  char* safe_dirname(const char *file, const int lineno,
 char* safe_getcwd(const char *file, const int lineno,
                   void (*cleanup_fn)(void), char *buf, size_t size);
 
+struct group *safe_getgrnam(const char *file, const int lineno,
+			    void (*cleanup_fn)(void), const char *name);
+
 struct passwd* safe_getpwnam(const char *file, const int lineno,
                              void (*cleanup_fn)(void), const char *name);
 
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 64cdbbf..a8c2393 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -69,6 +69,9 @@  static inline int safe_dup(const char *file, const int lineno,
 #define SAFE_GETCWD(buf, size) \
 	safe_getcwd(__FILE__, __LINE__, NULL, (buf), (size))
 
+#define SAFE_GETGRNAM(name) \
+	safe_getgrnam(__FILE__, __LINE__, NULL, (name))
+
 #define SAFE_GETPWNAM(name) \
 	safe_getpwnam(__FILE__, __LINE__, NULL, (name))
 
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index abdeca0..ea9e1f6 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -15,6 +15,7 @@ 
 #include <stdlib.h>
 #include <unistd.h>
 #include <malloc.h>
+#include <grp.h>
 #include "test.h"
 #include "safe_macros.h"
 
@@ -111,6 +112,20 @@  char *safe_getcwd(const char *file, const int lineno, void (*cleanup_fn) (void),
 	return rval;
 }
 
+struct group *safe_getgrnam(const char *file, const int lineno,
+			    void (*cleanup_fn) (void), const char *name)
+{
+	struct group *rval;
+
+	rval = getgrnam(name);
+	if (rval == NULL) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			"%s:%d: getgrnam(%s) failed", file, lineno, name);
+	}
+
+	return rval;
+}
+
 struct passwd *safe_getpwnam(const char *file, const int lineno,
 			     void (*cleanup_fn) (void), const char *name)
 {