infiniband-diags: Fix saquery error reporting
PATCH 1/1 infiniband-diags: Fix saquery error reporting
The sa_query function can fail in 2 ways
1) the system calls can fail
2) the SA returns a failure result
The first case was not being handled properly. In addition ensure the program returns a proper errno value as an exit code regardless of the failure mode.
Signed-off-by Ira Weiny <[email protected]>
--- src/ibdiag_common.c | 4 ++-- src/saquery.c | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-)
src/ibdiag_common.c +2 -2
@@ -561,7 +561,7 @@ int sa_query(bind_handle_t h, uint8_t method,IBWARN ("umad_send failed: attr %u: %s\n" , attr,strerror (errno));free (umad); -return (IB_ERROR ); +return (-ret); } recv_mad:
@@ -574,7 +574,7 @@ recv_mad:IBWARN ("umad_recv failed: attr 0x%x: %s\n" , attr,strerror (errno));free (umad); -return (IB_ERROR ); +return (-ret); }if ((ret =umad_status (umad)))
src/saquery.c +4 -5
@@ -732,7 +732,7 @@ static int get_any_records(bind_handle_t h,int ret =sa_query (h,IB_MAD_METHOD_GET_TABLE , attr_id, attr_mod,cl_ntoh64 (comp_mask), sm_key, attr, result);if (ret) { -fprintf (stderr,"Query SA failed: %s\n" ,ib_get_err_str (ret)); +fprintf (stderr,"Query SA failed: %s\n" ,strerror (ret));return ret; }
@@ -822,7 +822,7 @@ static uint16_t get_lid(bind_handle_t h, const char *name)if (!name)return 0 ;if (isalpha (name[0 ])) { -if (get_lid_from_name (h, name, &rc_lid) !=IB_SUCCESS ) { +if (get_lid_from_name (h, name, &rc_lid) !=0 ) {fprintf (stderr,"Failed to find lid for \"%s\"\n" , name);exit (EINVAL ); }
@@ -946,8 +946,7 @@ static int get_print_class_port_info(bind_handle_t h)int ret =sa_query (h,IB_MAD_METHOD_GET ,CLASS_PORT_INFO ,0 ,0 ,0 ,NULL , &result);if (ret) { -fprintf (stderr,"ERROR: Query SA failed: %s\n" , -ib_get_err_str (ret)); +fprintf (stderr,"ERROR: Query SA failed: %s\n" ,strerror (ret));return ret; }if (result.status !=IB_SA_MAD_STATUS_SUCCESS ) {
@@ -1719,7 +1718,7 @@ int main(int argc, char **argv) || !q->handler) {fprintf (stderr,"Unknown query type %d\n" ,ntohs (query_type)); - status =IB_UNKNOWN_ERROR ; + status =EINVAL ; } else status = q->handler (q, h, ¶ms, argc, argv);break ;
Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html