nfsidmap: fix error reporting for nfs4_* family of functions
Subsystems (2)
PATCH 1/1 nfsidmap: fix error reporting for nfs4_* family of functions
Errors were logged with xlog_err function relying on errno, but these functions don't set it.
Fix the problem by introducing xlog_err_code which accepts error code.
Signed-off-by Mateusz Guzik <[email protected]>
--- support/include/xlog.h | 1 + support/nfs/xlog.c | 12 ++++++++++++ utils/nfsidmap/nfsidmap.c | 11 ++++++----- 3 files changed, 19 insertions(+), 5 deletions(-)
support/include/xlog.h +1 -0
@@ -45,6 +45,7 @@ int xlog_enabled(int fac);void xlog (int fac,const char *fmt, ...);void xlog_warn (const char *fmt, ...);void xlog_err (const char *fmt, ...); +void xlog_err_code (int error,const char *fmt, ...);void xlog_backend (int fac,const char *fmt,va_list args);#endif /* XLOG_H */
support/nfs/xlog.c +12 -0
@@ -27,6 +27,7 @@#include <stdio.h> #include <stdarg.h> #include <syslog.h> +#include <errno.h> #include "nfslib.h" #undef VERBOSE_PRINTF
@@ -220,3 +221,14 @@ xlog_err(const char* fmt, ...)xlog_backend (L_FATAL , fmt, args);va_end (args); } + +void +xlog_err_code (int error,const char *fmt, ...) +{ +va_list args; + + errno = -error; +va_start (args, fmt); +xlog_backend (L_FATAL , fmt, args); +va_end (args); +}
utils/nfsidmap/nfsidmap.c +6 -5
@@ -54,7 +54,7 @@ int id_lookup(char *name_at_domain, key_serial_t key, int type)sprintf (id,"%u" , gid); }if (rc <0 ) -xlog_err ("id_lookup: %s: failed: %m" , +xlog_err_code (rc,"id_lookup: %s: failed: %m" , (type ==USER ?"nfs4_owner_to_uid" :"nfs4_group_owner_to_gid" ));if (rc ==0 ) {
@@ -95,8 +95,9 @@ int name_lookup(char *id, key_serial_t key, int type) rc =nfs4_get_default_domain (NULL , domain,NFS4_MAX_DOMAIN_LEN );if (rc !=0 ) { +xlog_err_code (rc, +"name_lookup: nfs4_get_default_domain failed: %m" ); rc =-1 ; -xlog_err ("name_lookup: nfs4_get_default_domain failed: %m" ); goto out; }
@@ -108,7 +109,7 @@ int name_lookup(char *id, key_serial_t key, int type) rc =nfs4_gid_to_name (gid, domain, name,IDMAP_NAMESZ ); }if (rc <0 ) -xlog_err ("name_lookup: %s: failed: %m" , +xlog_err_code (rc,"name_lookup: %s: failed: %m" , (type ==USER ?"nfs4_uid_to_name" :"nfs4_gid_to_name" ));if (rc ==0 ) {
@@ -272,8 +273,8 @@ int main(int argc, char **argv) } } -if (nfs4_init_name_mapping (PATH_IDMAPDCONF )) { -xlog_err ("Unable to create name to user id mappings." ); +if (rc =nfs4_init_name_mapping (PATH_IDMAPDCONF )) { +xlog_err_code (rc,"Unable to create name to user id mappings." );return 1 ; }if (!verbose)
Signature · 1 line
1.8.3.1
Quoted 6 lines · Mateusz Guzik
Errors were logged with
xlog_errfunction relying on errno, but these functions don't set it.Fix the problem by introducing
xlog_err_codewhich accepts error code.Signed-off-by Mateusz Guzik <[email protected]>
Committed...
steved.
Quoted 90 lines
--- support/include/xlog.h | 1 + support/nfs/xlog.c | 12 ++++++++++++ utils/nfsidmap/nfsidmap.c | 11 ++++++----- 3 files changed, 19 insertions(+), 5 deletions(-)support/include/xlog.h +1
-0@@ -45,6 +45,7 @@ int xlog_enabled(int fac);void xlog (int fac,const char *fmt, ...);void xlog_warn (const char *fmt, ...);void xlog_err (const char *fmt, ...); +void xlog_err_code (int error,const char *fmt, ...);void xlog_backend (int fac,const char *fmt,va_list args);#endif /* XLOG_H */ support/nfs/xlog.c +12
-0@@ -27,6 +27,7 @@#include <stdio.h> #include <stdarg.h> #include <syslog.h> +#include <errno.h> #include "nfslib.h" #undef VERBOSE_PRINTF@@ -220,3 +221,14 @@ xlog_err(const char* fmt, ...)xlog_backend (L_FATAL , fmt, args);va_end (args); } + +void +xlog_err_code (int error,const char *fmt, ...) +{ +va_list args; + + errno = -error; +va_start (args, fmt); +xlog_backend (L_FATAL , fmt, args); +va_end (args); +}utils/nfsidmap/nfsidmap.c +6
-5@@ -54,7 +54,7 @@ int id_lookup(char *name_at_domain, key_serial_t key, int type)sprintf (id,"%u" , gid); }if (rc <0 ) -xlog_err ("id_lookup: %s: failed: %m" , +xlog_err_code (rc,"id_lookup: %s: failed: %m" , (type ==USER ?"nfs4_owner_to_uid" :"nfs4_group_owner_to_gid" ));if (rc ==0 ) {@@ -95,8 +95,9 @@ int name_lookup(char *id, key_serial_t key, int type) rc =nfs4_get_default_domain (NULL , domain,NFS4_MAX_DOMAIN_LEN );if (rc !=0 ) { +xlog_err_code (rc, +"name_lookup: nfs4_get_default_domain failed: %m" ); rc =-1 ; -xlog_err ("name_lookup: nfs4_get_default_domain failed: %m" ); goto out; }@@ -108,7 +109,7 @@ int name_lookup(char *id, key_serial_t key, int type) rc =nfs4_gid_to_name (gid, domain, name,IDMAP_NAMESZ ); }if (rc <0 ) -xlog_err ("name_lookup: %s: failed: %m" , +xlog_err_code (rc,"name_lookup: %s: failed: %m" , (type ==USER ?"nfs4_uid_to_name" :"nfs4_gid_to_name" ));if (rc ==0 ) {@@ -272,8 +273,8 @@ int main(int argc, char **argv) } } -if (nfs4_init_name_mapping (PATH_IDMAPDCONF )) { -xlog_err ("Unable to create name to user id mappings." ); +if (rc =nfs4_init_name_mapping (PATH_IDMAPDCONF )) { +xlog_err_code (rc,"Unable to create name to user id mappings." );return 1 ; }if (!verbose)