[ofa-general] [PATCH 1/1][v2.0] dat: cleanup error handling with static registry parsing of dat.conf

Davis, Arlin R arlin.r.davis at intel.com
Tue Apr 29 19:45:30 PDT 2008


change asserts to return codes, add log messages, and
report errors via open instead of asserts during dat
library load.

Signed-off by: Arlin Davis ardavis at ichips.intel.com
---
 dat/udat/linux/dat_osd.c  |    2 +-
 dat/udat/udat_sr_parser.c |  382
+++++++++++++++++----------------------------
 2 files changed, 144 insertions(+), 240 deletions(-)

diff --git a/dat/udat/linux/dat_osd.c b/dat/udat/linux/dat_osd.c
index fa76c12..7305168 100644
--- a/dat/udat/linux/dat_osd.c
+++ b/dat/udat/linux/dat_osd.c
@@ -76,7 +76,7 @@ typedef enum
  *                                                                   *
  *********************************************************************/
 
-static DAT_OS_DBG_TYPE_VAL 	g_dbg_type = 0;
+static DAT_OS_DBG_TYPE_VAL 	g_dbg_type = DAT_OS_DBG_TYPE_ERROR;
 static DAT_OS_DBG_DEST 		g_dbg_dest =
DAT_OS_DBG_DEST_STDOUT;
 
 
diff --git a/dat/udat/udat_sr_parser.c b/dat/udat/udat_sr_parser.c
index 5761e3b..904acff 100644
--- a/dat/udat/udat_sr_parser.c
+++ b/dat/udat/udat_sr_parser.c
@@ -297,7 +297,7 @@ dat_sr_load (void)
     sr_file = dat_os_fopen (sr_path);
     if ( sr_file == NULL )
     {
-	return DAT_INTERNAL_ERROR;
+	goto bail;
     }
 
     for (;;)
@@ -312,17 +312,22 @@ dat_sr_load (void)
 	}
 	else
 	{
-	    dat_os_assert (!"unable to parse static registry file");
-	    break;
+            goto cleanup;
 	}
     }
 
-    if ( 0 != dat_os_fclose (sr_file) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
+    if (0 != dat_os_fclose (sr_file))
+	goto bail;
 
     return DAT_SUCCESS;
+
+cleanup:
+    dat_os_fclose(sr_file);	
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     "ERROR: unable to parse static registry file,
dat.conf\n");
+    return DAT_INTERNAL_ERROR;
+
 }
 
 
@@ -574,33 +579,22 @@ dat_sr_parse_ia_name (
     DAT_SR_CONF_ENTRY 	*entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
 
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	entry->ia_name = token.value;
-
-	status = DAT_SUCCESS;
-    }
-
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
-
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
+    if (DAT_SR_TOKEN_STRING != token.type) {
+	dat_sr_put_token (file, &token);
+	goto bail;
     }
+    entry->ia_name = token.value;
+    return DAT_SUCCESS;
 
-    return status;
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " ia_name, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -614,39 +608,26 @@ dat_sr_parse_api (
     DAT_SR_CONF_ENTRY 	*entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
-
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else if ( DAT_SUCCESS != dat_sr_convert_api (
-		  token.value, &entry->api_version) )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	dat_os_free (token.value,
-		    (sizeof (char) * dat_os_strlen (token.value)) + 1);
 
-	status = DAT_SUCCESS;
-    }
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
+    if (DAT_SR_TOKEN_STRING != token.type)
+	goto cleanup;
 
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
-    }
+    if (DAT_SUCCESS != dat_sr_convert_api(token.value,
&entry->api_version))
+	goto cleanup;
+    
+    dat_os_free(token.value, (sizeof(char) *
dat_os_strlen(token.value))+1);
+    return DAT_SUCCESS;
 
-    return status;
+cleanup:
+    dat_sr_put_token (file, &token);
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " api_ver, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -660,39 +641,27 @@ dat_sr_parse_thread_safety (
     DAT_SR_CONF_ENTRY 	*entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
-
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else if ( DAT_SUCCESS != dat_sr_convert_thread_safety (
-		  token.value, &entry->is_thread_safe) )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	dat_os_free (token.value,
-		    (sizeof (char) * dat_os_strlen (token.value)) + 1);
 
-	status = DAT_SUCCESS;
-    }
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
+    if (DAT_SR_TOKEN_STRING != token.type)
+	goto cleanup;
 
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
-    }
+    if (DAT_SUCCESS != dat_sr_convert_thread_safety(
+			token.value, &entry->is_thread_safe))
+	goto cleanup;
+    
+    dat_os_free(token.value, (sizeof(char) *
dat_os_strlen(token.value))+1);
+    return DAT_SUCCESS;
 
-    return status;
+cleanup:
+    dat_sr_put_token (file, &token);
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " thread_safety, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -706,39 +675,26 @@ dat_sr_parse_default (
     DAT_SR_CONF_ENTRY 	*entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
-
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else if ( DAT_SUCCESS != dat_sr_convert_default (
-		  token.value, &entry->is_default) )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	dat_os_free (token.value,
-		    (sizeof (char) * dat_os_strlen (token.value)) + 1);
 
-	status = DAT_SUCCESS;
-    }
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
+    if (DAT_SR_TOKEN_STRING != token.type)
+	goto cleanup;
 
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
-    }
+    if (DAT_SUCCESS != dat_sr_convert_default(token.value,
&entry->is_default))
+	goto cleanup;
+    
+    dat_os_free(token.value, (sizeof(char) *
dat_os_strlen(token.value))+1);
+    return DAT_SUCCESS;
 
-    return status;
+cleanup:
+    dat_sr_put_token (file, &token);
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " default section, file offset=%ld\n",
ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -752,33 +708,22 @@ dat_sr_parse_lib_path (
     DAT_SR_CONF_ENTRY 	*entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
 
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	entry->lib_path = token.value;
-
-	status = DAT_SUCCESS;
-    }
-
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
+    if (DAT_SUCCESS != dat_sr_get_token(file, &token))
+	goto bail;
 
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
+    if (DAT_SR_TOKEN_STRING != token.type) {
+ 	dat_sr_put_token (file, &token);
+	goto bail;
     }
+    entry->lib_path = token.value;
+    return DAT_SUCCESS;
 
-    return status;
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " lib_path, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
/***********************************************************************
@@ -791,42 +736,29 @@ dat_sr_parse_provider_version (
     DAT_SR_CONF_ENTRY 	*entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
 
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else if ( DAT_SUCCESS != dat_sr_convert_provider_version (
-		  token.value, &entry->provider_version) )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	dat_os_free (token.value,
-		    (sizeof (char) * dat_os_strlen (token.value)) + 1);
-
-	status = DAT_SUCCESS;
-    }
+    if (DAT_SR_TOKEN_STRING != token.type)
+	goto cleanup;
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
-
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
-    }
+    if (DAT_SUCCESS != dat_sr_convert_provider_version(
+			token.value, &entry->provider_version))
+	goto cleanup;
+    
+    dat_os_free(token.value, (sizeof(char) *
dat_os_strlen(token.value))+1);
+    return DAT_SUCCESS;
 
-    return status;
+cleanup:
+    dat_sr_put_token (file, &token);
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " provider_ver, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
-
 
/***********************************************************************
  * Function: dat_sr_parse_ia_params
 
***********************************************************************/
@@ -837,33 +769,23 @@ dat_sr_parse_ia_params (
     DAT_SR_CONF_ENTRY *entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
 
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	entry->ia_params = token.value;
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-	status = DAT_SUCCESS;
+    if (DAT_SR_TOKEN_STRING != token.type) {
+	dat_sr_put_token (file, &token);
+	goto bail;
     }
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
-
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
-    }
+    entry->ia_params = token.value;
+    return DAT_SUCCESS;
 
-    return status;
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " ia_params, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -877,33 +799,23 @@ dat_sr_parse_platform_params (
     DAT_SR_CONF_ENTRY *entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
 
-    if ( DAT_SR_TOKEN_STRING != token.type )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	entry->platform_params = token.value;
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-	status = DAT_SUCCESS;
+    if (DAT_SR_TOKEN_STRING != token.type) {
+	dat_sr_put_token (file, &token);
+	goto bail;
     }
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
-
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
-    }
+    entry->platform_params = token.value;
+    return DAT_SUCCESS;
 
-    return status;
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " platform_params, file offset=%ld\n",
ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -917,32 +829,23 @@ dat_sr_parse_eoe (
     DAT_SR_CONF_ENTRY *entry)
 {
     DAT_SR_TOKEN 	token;
-    DAT_RETURN 		status;
-
-    if ( DAT_SUCCESS != dat_sr_get_token (file, &token) )
-    {
-	return DAT_INTERNAL_ERROR;
-    }
-
-    if ( (DAT_SR_TOKEN_EOF != token.type) &&
-	 (DAT_SR_TOKEN_EOR != token.type) )
-    {
-	status = DAT_INTERNAL_ERROR;
-    }
-    else
-    {
-	status = DAT_SUCCESS;
-    }
 
-    if ( DAT_SUCCESS != status )
-    {
-	DAT_RETURN 	status_success;
+    if (DAT_SUCCESS != dat_sr_get_token (file, &token))
+	goto bail;
 
-	status_success = dat_sr_put_token (file, &token);
-	dat_os_assert ( DAT_SUCCESS == status_success);
+    if ((DAT_SR_TOKEN_EOF != token.type) &&
+	(DAT_SR_TOKEN_EOR != token.type)) {
+	dat_sr_put_token (file, &token);
+	goto bail;
     }
+    
+    return DAT_SUCCESS;
 
-    return status;
+bail:
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+		     " ERR: corrupt dat.conf entry field:"
+		     " EOR, EOF, file offset=%ld\n", ftell(file));
+    return DAT_INTERNAL_ERROR;
 }
 
 
@@ -958,7 +861,8 @@ dat_sr_convert_api (
     int i;
     int minor_i;
 
-    dat_os_assert ( 0 < dat_os_strlen (str) );
+    if (dat_os_strlen(str) <= 0)
+	return DAT_INTERNAL_ERROR;
 
     if ( 'u' == str[0] )
     {
@@ -1082,8 +986,8 @@ dat_sr_convert_provider_version (
     int 		i;
     int 		decimal_i;
 
-    dat_os_assert ( 0 < dat_os_strlen (str) );
-    dat_os_assert ( NULL == provider_version->id );
+    if ((dat_os_strlen(str) <= 0) || (NULL != provider_version->id))
+	return DAT_INTERNAL_ERROR;
 
     status = DAT_SUCCESS;
 
-- 
1.5.2.5




More information about the general mailing list