From 3e5014891f79e72c02ba50df354bc068c2001611 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 8 Sep 2010 07:31:28 +0000 Subject: 2010-09-08 Sebastian Huber PR 1698/cpukit * libcsupport/src/privateenv.c: Check return values of rtems_filesystem_evaluate_path(). --- cpukit/libcsupport/src/privateenv.c | 87 ++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 40 deletions(-) (limited to 'cpukit/libcsupport/src/privateenv.c') diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index 75d9dc0182..89137200b7 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -21,16 +21,8 @@ #include #include -#include #include -#if defined(RTEMS_DEBUG) - #define CHECK_STATUS(_x) assert((_x) == ) - #include -#else - #define CHECK_STATUS(_x) _x -#endif - /* cleanup a user environment * NOTE: this must be called with * thread dispatching disabled! @@ -53,11 +45,20 @@ free_user_env(void *venv) rtems_status_code rtems_libio_set_private_env(void) { - rtems_status_code sc; - rtems_id task_id; - rtems_filesystem_location_info_t loc; + rtems_status_code sc = RTEMS_SUCCESSFUL; + rtems_id task_id = rtems_task_self(); + rtems_filesystem_location_info_t root_loc; + rtems_filesystem_location_info_t current_loc; + rtems_user_env_t *new_env = NULL; + int rv = 0; + + rv = rtems_filesystem_evaluate_path("/", 1, 0, &root_loc, 0); + if (rv != 0) + goto error_0; - task_id = rtems_task_self(); + rv = rtems_filesystem_evaluate_path("/", 1, 0, ¤t_loc, 0); + if (rv != 0) + goto error_1; /* * Malloc is necessary whenever the current task does not @@ -72,14 +73,16 @@ rtems_status_code rtems_libio_set_private_env(void) * if( rtems_current_user_env->task_id != task_id ) { */ - if (rtems_current_user_env==&rtems_global_user_env || - rtems_current_user_env->task_id != task_id ) { - rtems_user_env_t *tmp = malloc(sizeof(rtems_user_env_t)); - if (!tmp) - return RTEMS_NO_MEMORY; + if ( + rtems_current_user_env == &rtems_global_user_env + || rtems_current_user_env->task_id != task_id + ) { + new_env = malloc(sizeof(rtems_user_env_t)); + if (new_env == NULL) + goto error_2; #ifdef HAVE_USERENV_REFCNT - tmp->refcnt = 1; + new_env->refcnt = 1; #endif sc = rtems_task_variable_add( @@ -87,35 +90,39 @@ rtems_status_code rtems_libio_set_private_env(void) (void*)&rtems_current_user_env, (void(*)(void *))free_user_env ); - if (sc != RTEMS_SUCCESSFUL) { - /* don't use free_user_env because the pathlocs are - * not initialized yet - */ - free(tmp); - return sc; - } - rtems_current_user_env = tmp; + if (sc != RTEMS_SUCCESSFUL) + goto error_3; + + rtems_current_user_env = new_env; } - *rtems_current_user_env = rtems_global_user_env; /* get the global values*/ - rtems_current_user_env->task_id=task_id; /* mark the local values*/ + /* Inherit the global values */ + *rtems_current_user_env = rtems_global_user_env; - /* Clone the pathlocs. In contrast to most other code we must _not_ - * free the original locs because what we are trying to do here is forking - * off clones. The reason is a pathloc can be allocated by the file system - * and needs to be freed when deleting the environment. - * - * NOTE: Evaluation should always work so only check status when debug - * is enabled. + rtems_current_user_env->task_id = task_id; + + /* + * Clone the pathlocs. In contrast to most other code we must _not_ free the + * original locs because what we are trying to do here is forking off clones. + * The reason is a pathloc can be allocated by the file system and needs to + * be freed when deleting the environment. */ + rtems_filesystem_root = root_loc; + rtems_filesystem_current = current_loc; + + return RTEMS_SUCCESSFUL; - CHECK_STATUS( rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0) ); - rtems_filesystem_root = loc; +error_3: + free(new_env); - CHECK_STATUS( rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0) ); - rtems_filesystem_current = loc; +error_2: + rtems_filesystem_freenode(¤t_loc); - return RTEMS_SUCCESSFUL; +error_1: + rtems_filesystem_freenode(&root_loc); + +error_0: + return RTEMS_NO_MEMORY; } /* -- cgit v1.2.3