SAFE_MACROS: Add SAFE_GETGRNAM()
PATCH 1/2 SAFE_MACROS: Add SAFE_GETGRNAM()
--- include/old/safe_macros.h | 3 +++ include/safe_macros_fn.h | 3 +++ include/tst_safe_macros.h | 9 +++------ lib/safe_macros.c | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-)
include/old/safe_macros.h +3 -0
@@ -44,6 +44,9 @@#define SAFE_GETPWNAM (cleanup_fn, name) \ safe_getpwnam(__FILE__, __LINE__, cleanup_fn, (name)) +#define SAFE_GETGRNAM (cleanup_fn, name) \ + safe_getgrnam(__FILE__, __LINE__, cleanup_fn, (name)) +#define SAFE_GETRUSAGE (cleanup_fn, who, usage) \ safe_getrusage(__FILE__, __LINE__, (cleanup_fn), (who), (usage))
include/safe_macros_fn.h +3 -0
@@ -45,6 +45,9 @@ char* safe_getcwd(const char *file, const int lineno,struct passwd *safe_getpwnam (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *name); +struct group *safe_getgrnam (const char *file,const int lineno, +void (*cleanup_fn)(void ),const char *name); +int safe_getrusage (const char *file,const int lineno,void (*cleanup_fn)(void ),int who,struct rusage *usage);
include/tst_safe_macros.h +3 -6
@@ -72,6 +72,9 @@ static inline int safe_dup(const char *file, const int lineno,#define SAFE_GETPWNAM (name) \ safe_getpwnam(__FILE__, __LINE__, NULL, (name)) +#define SAFE_GETGRNAM (name) \ + safe_getgrnam(__FILE__, __LINE__, NULL, (name)) +#define SAFE_GETRUSAGE (who, usage) \ safe_getrusage(__FILE__, __LINE__, NULL, (who), (usage))
@@ -397,12 +400,6 @@ static inline sighandler_t safe_signal(const char *file, const int lineno,#define SAFE_SIGNAL (signum, handler) \ safe_signal(__FILE__, __LINE__, (signum), (handler)) -int safe_sigaction (const char *file,const int lineno, -int signum,const struct sigaction *act, -struct sigaction *oldact); -#define SAFE_SIGACTION (signum, act, oldact) \ - safe_sigaction(__FILE__, __LINE__, (signum), (act), (oldact)) -#define SAFE_EXECLP (file, arg, ...) do { \ execlp((file), (arg), ##__VA_ARGS__); \ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \
lib/safe_macros.c +15 -0
@@ -15,6 +15,7 @@#include <stdlib.h> #include <unistd.h> #include <malloc.h> +#include <grp.h> #include "test.h" #include "safe_macros.h"
@@ -126,6 +127,20 @@ struct passwd *safe_getpwnam(const char *file, const int lineno,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; +} +int safe_getrusage (const char *file,const int lineno,void (*cleanup_fn) (void ),int who,struct rusage *usage)
Signature · 1 line
1.8.3.1
PATCH 2/2 Make use of SAFE_GETGRNAM()
--- testcases/kernel/syscalls/chmod/chmod05.c | 4 +--- testcases/kernel/syscalls/chmod/chmod07.c | 3 +-- testcases/kernel/syscalls/creat/creat08.c | 16 +++++----------- testcases/kernel/syscalls/fchmod/fchmod02.c | 4 +--- testcases/kernel/syscalls/fchmod/fchmod05.c | 5 +---- testcases/kernel/syscalls/open/open10.c | 14 ++++---------- testcases/kernel/syscalls/setregid/setregid02.c | 5 +---- testcases/kernel/syscalls/setregid/setregid03.c | 5 +---- testcases/kernel/syscalls/setregid/setregid04.c | 6 ++---- 9 files changed, 17 insertions(+), 45 deletions(-)
testcases/kernel/syscalls/chmod/chmod05.c +1 -3
@@ -187,9 +187,7 @@ void setup(void)tst_brkm (TBROK |TERRNO , cleanup,"getpwnam(\"nobody\") failed" ); - bin_group =getgrnam ("bin" ); -if (bin_group ==NULL ) -tst_brkm (TBROK |TERRNO , cleanup,"getgrnam(\"bin\") failed" ); + bin_group =SAFE_GETGRNAM (cleanup,"bin" );/* * Create a test directory under temporary directory with specified
testcases/kernel/syscalls/chmod/chmod07.c +1 -2
@@ -174,8 +174,7 @@ void setup(void) user1_uid = ltpuser->pw_uid;/* Get the group id of guest user - ltpuser1 */ -if ((ltpgroup =getgrnam (LTPGRP )) ==NULL ) -tst_brkm (TBROK , cleanup,"getgrnam failed" ); + ltpgroup =SAFE_GETGRNAM (cleanup,LTPGRP ); group1_gid = ltpgroup->gr_gid; fd =SAFE_OPEN (cleanup,TESTFILE ,O_RDWR |O_CREAT ,FILE_MODE );
testcases/kernel/syscalls/creat/creat08.c +5 -11
@@ -119,18 +119,12 @@ int main(int ac, char **av)/* * Get the group IDs of group1 and group2. */ -if ((group =getgrnam ("nobody" )) ==NULL ) { -if ((group =getgrnam ("nogroup" )) ==NULL ) { -tst_brkm (TBROK |TERRNO , cleanup, -"getgrnam(\"nobody\") and " -"getgrnam(\"nogroup\") failed" ); - } - } + group =getgrnam ("nobody" ); +if (group ==NULL ) + group =SAFE_GETGRNAM (cleanup,"nogroup" ); + group1_gid = group->gr_gid; -if ((group =getgrnam ("bin" )) ==NULL ) { -tst_brkm (TBROK |TERRNO , cleanup, -"getgrnam(\"bin\") failed" ); - } + group =SAFE_GETGRNAM (cleanup,"bin" ); group2_gid = group->gr_gid;/*--------------------------------------------------------------*/
testcases/kernel/syscalls/fchmod/fchmod02.c +1 -3
@@ -177,9 +177,7 @@ void setup(void) user1_uid = ltpuser->pw_uid;/* Get the group id of guest user - ltpuser1 */ -if ((ltpgroup =getgrnam (LTPGRP )) ==NULL ) { -tst_brkm (TBROK , cleanup,"%s not in /etc/group" ,LTPGRP ); - } + ltpgroup =SAFE_GETGRNAM (cleanup,LTPGRP ); group1_gid = ltpgroup->gr_gid;/*
testcases/kernel/syscalls/fchmod/fchmod05.c +1 -4
@@ -178,10 +178,7 @@ void setup(void)tst_brkm (TBROK , cleanup,"Couldn't find uid of nobody: %s" ,strerror (errno)); - bin_group =getgrnam ("bin" ); -if (!bin_group) -tst_brkm (TBROK , cleanup, -"Couldn't find gid of bin: %s" ,strerror (errno)); + bin_group =SAFE_GETGRNAM (cleanup,"bin" );/* * Create a test directory under temporary directory with specified
testcases/kernel/syscalls/open/open10.c +4 -10
@@ -42,6 +42,7 @@#include <grp.h> #include <pwd.h> #include "test.h" +#include "safe_macros.h" char *TCID ="open10" ;int TST_TOTAL =1 ;
@@ -106,18 +107,11 @@ int main(int ac, char *av[])* Get the group IDs of group1 and group2. */ group =getgrnam ("nobody" ); -if (group ==NULL ) { - group =getgrnam ("nogroup" ); -if (group ==NULL ) { -tst_brkm (TBROK , cleanup, -"nobody/nogroup not in /etc/group" ); - } - } - group1_gid = group->gr_gid; - group =getgrnam ("bin" );if (group ==NULL ) -tst_brkm (TBROK , cleanup,"bin not in /etc/group" ); + group =SAFE_GETGRNAM (cleanup,"nogroup" ); + group1_gid = group->gr_gid; + group =SAFE_GETGRNAM (cleanup,"bin" ); group2_gid = group->gr_gid;/*
testcases/kernel/syscalls/setregid/setregid02.c +1 -4
@@ -148,10 +148,7 @@ static void setup(void)static struct group get_group_by_name (const char *name) { -struct group *ret =getgrnam (name); - -if (ret ==NULL ) -tst_brkm (TBROK |TERRNO ,NULL ,"getgrnam(\"%s\") failed" , name); +struct group *ret =SAFE_GETGRNAM (NULL , name);GID16_CHECK (ret->gr_gid, setregid,NULL );
testcases/kernel/syscalls/setregid/setregid03.c +1 -4
@@ -186,10 +186,7 @@ static void setup(void) nobody = *(getpwnam ("nobody" ));#define GET_GID (group) do { \ - junk = getgrnam(#group); \ - if (junk == NULL) { \ - tst_brkm(TBROK, NULL, "%s must be a valid group", #group); \ - } \ + junk = SAFE_GETGRNAM(NULL, #group); \ GID16_CHECK(junk->gr_gid, setregid, NULL); \ group = *(junk); \ } while (0)
testcases/kernel/syscalls/setregid/setregid04.c +2 -4
@@ -30,6 +30,7 @@#include "test.h" #include "compat_16.h" +#include "safe_macros.h" TCID_DEFINE (setregid04);
@@ -111,10 +112,7 @@ int main(int ac, char **av) }#define SAFE_GETGROUP (GROUPNAME ) \ - if (getgrnam(#GROUPNAME) == NULL) { \ - tst_brkm(TBROK, NULL, "Couldn't find the `" #GROUPNAME "' group"); \ - } \ - GROUPNAME ## _gr = *(getgrnam(#GROUPNAME)); + GROUPNAME ## _gr = *(SAFE_GETGRNAM(NULL, #GROUPNAME));static void setup (void ) {
Signature · 1 line
1.8.3.1
PATCH 2/2 Make use of SAFE_GETGRNAM()
Hi Jinhui,
Quoted 12 lines
Signed-off-by Jinhui Huang <[email protected]>--- testcases/kernel/syscalls/chmod/chmod05.c | 4 +--- testcases/kernel/syscalls/chmod/chmod07.c | 3 +-- testcases/kernel/syscalls/creat/creat08.c | 16 +++++----------- testcases/kernel/syscalls/fchmod/fchmod02.c | 4 +--- testcases/kernel/syscalls/fchmod/fchmod05.c | 5 +---- testcases/kernel/syscalls/open/open10.c | 14 ++++---------- testcases/kernel/syscalls/setregid/setregid02.c | 5 +---- testcases/kernel/syscalls/setregid/setregid03.c | 5 +---- testcases/kernel/syscalls/setregid/setregid04.c | 6 ++---- 9 files changed, 17 insertions(+), 45 deletions(-)
I took only change in fchmod02 and adjusted it into new API.
Thanks for both patches!
Kind regards,
Petr
kernel/syscalls/fchmod/fchmod02.c +1 -3
@@ -54,9 +54,7 @@ static void setup(void)struct group *ltpgroup; ltpuser =SAFE_GETPWNAM (LTPUSER ); - ltpgroup =getgrnam (LTPGRP ); -if (ltpgroup ==NULL ) -tst_brk (TBROK ,"%s not in /etc/group" ,LTPGRP ); + ltpgroup =SAFE_GETGRNAM (LTPGRP ); fd =SAFE_OPEN (TESTFILE ,O_RDWR |O_CREAT ,FILE_MODE );SAFE_CHOWN (TESTFILE , ltpuser->pw_uid, ltpgroup->gr_gid);
PATCH 1/2 SAFE_MACROS: Add SAFE_GETGRNAM()
In reply to Jinhui HuangHi Jinhui,
Quoted 13 lines
Signed-off-by Jinhui Huang <[email protected]>--- include/old/safe_macros.h | 3 +++ include/safe_macros_fn.h | 3 +++ include/tst_safe_macros.h | 9 +++------ lib/safe_macros.c | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-)include/old/safe_macros.h +0
-0
include/old/safe_macros.h line 48
Quoted 5 lines
include/old/safe_macros.h +2
-0@@ -44,6 +44,9 @@#define SAFE_GETPWNAM (cleanup_fn, name) \ safe_getpwnam(__FILE__, __LINE__, cleanup_fn, (name)) +#define SAFE_GETGRNAM (cleanup_fn, name) \ + safe_getgrnam(__FILE__, __LINE__, cleanup_fn, (name))
Can you please sort it alphabetically (i.e. put SAFE_GETGRNAM() before SAFE_GETPWNAM())?
@Cyril: Do we want to change also safe_macros.h ?
Quoted 9 lines
include/old/safe_macros.h +1
-0+#define SAFE_GETRUSAGE (cleanup_fn, who, usage) \ safe_getrusage(__FILE__, __LINE__, (cleanup_fn), (who), (usage))include/safe_macros_fn.h +0
-0
include/safe_macros_fn.h char* safe_getcwd(const char *file, const int lineno, · line 49
Quoted 5 lines
include/safe_macros_fn.h +2
-0@@ -45,6 +45,9 @@ char* safe_getcwd(const char *file, const int lineno,struct passwd *safe_getpwnam (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *name); +struct group *safe_getgrnam (const char *file,const int lineno, +void (*cleanup_fn)(void ),const char *name);
Again, sort it alphabetically please.
Quoted 9 lines
include/safe_macros_fn.h +1
-0+int safe_getrusage (const char *file,const int lineno,void (*cleanup_fn)(void ),int who,struct rusage *usage);include/tst_safe_macros.h +0
-0
include/tst_safe_macros.h static inline int safe_dup(const char *file, const int lineno, · line 76
Quoted 5 lines
include/tst_safe_macros.h +2
-0@@ -72,6 +72,9 @@ static inline int safe_dup(const char *file, const int lineno,#define SAFE_GETPWNAM (name) \ safe_getpwnam(__FILE__, __LINE__, NULL, (name)) +#define SAFE_GETGRNAM (name) \ + safe_getgrnam(__FILE__, __LINE__, NULL, (name))
And here.
Quoted 5 lines
include/tst_safe_macros.h +1
-0+#define SAFE_GETRUSAGE (who, usage) \ safe_getrusage(__FILE__, __LINE__, NULL, (who), (usage))
include/tst_safe_macros.h static inline sighandler_t safe_signal(const char *file, const int lineno, · line 405
Quoted 9 lines
include/tst_safe_macros.h +0
-6@@ -397,12 +400,6 @@ static inline sighandler_t safe_signal(const char *file, const int lineno,#define SAFE_SIGNAL (signum, handler) \ safe_signal(__FILE__, __LINE__, (signum), (handler)) -int safe_sigaction (const char *file,const int lineno, -int signum,const struct sigaction *act, -struct sigaction *oldact); -#define SAFE_SIGACTION (signum, act, oldact) \ - safe_sigaction(__FILE__, __LINE__, (signum), (act), (oldact)) -
Removing SAFE_SIGACTION() & safe_sigaction() breaks build. I guess you removed it by accident.
Quoted 16 lines
include/tst_safe_macros.h +0
-0#define SAFE_EXECLP (file, arg, ...) do { \ execlp((file), (arg), ##__VA_ARGS__); \ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \lib/safe_macros.c +1
-0@@ -15,6 +15,7 @@#include <stdlib.h> #include <unistd.h> #include <malloc.h> +#include <grp.h> #include "test.h" #include "safe_macros.h"
lib/safe_macros.c struct passwd *safe_getpwnam(const char *file, const int lineno, · line 131
Quoted 5 lines
lib/safe_macros.c +2
-0@@ -126,6 +127,20 @@ struct passwd *safe_getpwnam(const char *file, const int lineno,return rval; } +struct group *safe_getgrnam (const char *file,const int lineno, +void (*cleanup_fn) (void ),const char *name)
Again, sort it alphabetically please.
Quoted 5 lines
lib/safe_macros.c +5
-0+{ +struct group *rval; + + rval =getgrnam (name); +if (rval ==NULL ) {
lib/safe_macros.c struct passwd *safe_getpwnam(const char *file, const int lineno, · line 146
Quoted 10 lines
lib/safe_macros.c +7
-0+tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: getgrnam(%s) failed" , file, lineno, name); + } + +return rval; +} +int safe_getrusage (const char *file,const int lineno,void (*cleanup_fn) (void ),int who,struct rusage *usage)
Kind regards,
Petr
PATCH 1/2 SAFE_MACROS: Add SAFE_GETGRNAM()
Hi!
Quoted 5 lines
include/old/safe_macros.h line 48
Quoted 2 lines
include/old/safe_macros.h +2
-0+#define SAFE_GETGRNAM (cleanup_fn, name) \ + safe_getgrnam(__FILE__, __LINE__, cleanup_fn, (name))Can you please sort it alphabetically (i.e. put
SAFE_GETGRNAM()beforeSAFE_GETPWNAM())?@Cyril: Do we want to change also
safe_macros.h?
We are not supposed to add anything into oldlib safe macros, the old library is in a maintenance mode, only bugfixes should go there, no new functionality.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 SAFE_MACROS: Add SAFE_GETGRNAM()
In reply to Petr VorelTo Petr
I will write V2 as you suggested,
I am sorry to reply so late.
Kind Regards,
Jinhui
On 2018/03/26 21:22, Petr Vorel Wrote:
Quoted 108 lines
Hi Jinhui,
Quoted 12 lines
Signed-off-by Jinhui Huang<[email protected]>--- include/old/safe_macros.h | 3 +++ include/safe_macros_fn.h | 3 +++ include/tst_safe_macros.h | 9 +++------ lib/safe_macros.c | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-)include/old/safe_macros.h +0
-0include/old/safe_macros.h line 47
Quoted 4 lines
include/old/safe_macros.h +2
-0@@ -44,6 +44,9 @@#define SAFE_GETPWNAM (cleanup_fn, name) \ safe_getpwnam(__FILE__, __LINE__, cleanup_fn, (name)) +#define SAFE_GETGRNAM (cleanup_fn, name) \ + safe_getgrnam(__FILE__, __LINE__, cleanup_fn, (name))Can you please sort it alphabetically (i.e. put
SAFE_GETGRNAM()beforeSAFE_GETPWNAM())?@Cyril: Do we want to change also
safe_macros.h?include/safe_macros_fn.h char* safe_getcwd(const char *file, const int lineno, · line 48
Quoted 12 lines
include/old/safe_macros.h +1
-0+#define SAFE_GETRUSAGE (cleanup_fn, who, usage) \ safe_getrusage(__FILE__, __LINE__, (cleanup_fn), (who), (usage))include/safe_macros_fn.h +2
-0@@ -45,6 +45,9 @@ char* safe_getcwd(const char *file, const int lineno,struct passwd *safe_getpwnam (const char *file,const int lineno,void (*cleanup_fn)(void ),const char *name); +struct group *safe_getgrnam (const char *file,const int lineno, +void (*cleanup_fn)(void ),const char *name);Again, sort it alphabetically please.
include/tst_safe_macros.h static inline int safe_dup(const char *file, const int lineno, · line 75
Quoted 12 lines
include/safe_macros_fn.h +1
-0+int safe_getrusage (const char *file,const int lineno,void (*cleanup_fn)(void ),int who,struct rusage *usage);include/tst_safe_macros.h +2
-0@@ -72,6 +72,9 @@ static inline int safe_dup(const char *file, const int lineno,#define SAFE_GETPWNAM (name) \ safe_getpwnam(__FILE__, __LINE__, NULL, (name)) +#define SAFE_GETGRNAM (name) \ + safe_getgrnam(__FILE__, __LINE__, NULL, (name))And here.
include/tst_safe_macros.h static inline sighandler_t safe_signal(const char *file, const int lineno, · line 404
Quoted 12 lines
include/tst_safe_macros.h +1
-6+#define SAFE_GETRUSAGE (who, usage) \ safe_getrusage(__FILE__, __LINE__, NULL, (who), (usage))@@ -397,12 +400,6 @@ static inline sighandler_t safe_signal(const char *file, const int lineno,#define SAFE_SIGNAL (signum, handler) \ safe_signal(__FILE__, __LINE__, (signum), (handler)) -int safe_sigaction (const char *file,const int lineno, -int signum,const struct sigaction *act, -struct sigaction *oldact); -#define SAFE_SIGACTION (signum, act, oldact) \ - safe_sigaction(__FILE__, __LINE__, (signum), (act), (oldact)) -Removing SAFE_SIGACTION()&
safe_sigaction()breaks build. I guess you removed it by accident.Quoted 15 lines
include/tst_safe_macros.h +0
-0#define SAFE_EXECLP (file, arg, ...) do { \ execlp((file), (arg), ##__VA_ARGS__); \ tst_brk_(__FILE__, __LINE__, TBROK | TERRNO, \lib/safe_macros.c +1
-0@@ -15,6 +15,7 @@#include <stdlib.h> #include <unistd.h> #include <malloc.h> +#include <grp.h> #include "test.h" #include "safe_macros.h" lib/safe_macros.c struct passwd *safe_getpwnam(const char *file, const int lineno, · line 130
Quoted 4 lines
lib/safe_macros.c +2
-0@@ -126,6 +127,20 @@ struct passwd *safe_getpwnam(const char *file, const int lineno,return rval; } +struct group *safe_getgrnam (const char *file,const int lineno, +void (*cleanup_fn) (void ),const char *name)Again, sort it alphabetically please.
Quoted 5 lines
lib/safe_macros.c +5
-0+{ +struct group *rval; + + rval =getgrnam (name); +if (rval ==NULL ) {lib/safe_macros.c struct passwd *safe_getpwnam(const char *file, const int lineno, · line 146
Quoted 10 lines
lib/safe_macros.c +7
-0+tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: getgrnam(%s) failed" , file, lineno, name); + } + +return rval; +} +int safe_getrusage (const char *file,const int lineno,void (*cleanup_fn) (void ),int who,struct rusage *usage)Kind regards,
Petr.
PATCH v2 1/1 SAFE_MACROS: Add SAFE_GETGRNAM()
In reply to Jinhui HuangFrom: Jinhui Huang <[email protected]>
--- include/safe_macros_fn.h | 3 +++ include/tst_safe_macros.h | 3 +++ lib/safe_macros.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+)
include/safe_macros_fn.h +3 -0
@@ -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);
include/tst_safe_macros.h +3 -0
@@ -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))
lib/safe_macros.c +15 -0
@@ -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) {
Signature · 1 line
1.8.3.1
PATCH v2 1/1 SAFE_MACROS: Add SAFE_GETGRNAM()
Hi Jinhui,
Quoted 4 lines
From: Jinhui Huang <[email protected]>
Signed-off-by Jinhui Huang <[email protected]>---
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
safe_macros_fn.h +0 -3
@@ -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);
tst_safe_macros.h +6 -3
@@ -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) \
safe_macros.c +0 -15
@@ -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) {
tst_safe_macros.c +14 -0
@@ -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; +}