From a006af315337965825a1e4e251ccf70069d06796 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Sun, 29 Aug 2010 19:49:52 +0000 Subject: 2010-08-29 Joel Sherrill * libcsupport/src/privateenv.c: Add macro to test status when RTEMS_DEBUG is enabled. Note than evaluation of root directory should always work. --- cpukit/libcsupport/src/privateenv.c | 86 +++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 38 deletions(-) (limited to 'cpukit/libcsupport/src/privateenv.c') diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index c584dc773a..75d9dc0182 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -24,6 +24,13 @@ #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! @@ -33,15 +40,15 @@ free_user_env(void *venv) { rtems_user_env_t *env = (rtems_user_env_t*) venv ; - if (env != &rtems_global_user_env -#ifdef HAVE_USERENV_REFCNT - && --env->refcnt <= 0 -#endif + if (env != &rtems_global_user_env + #ifdef HAVE_USERENV_REFCNT + && --env->refcnt <= 0 + #endif ) { - rtems_filesystem_freenode( &env->current_directory); - rtems_filesystem_freenode( &env->root_directory); - free(env); - } + rtems_filesystem_freenode( &env->current_directory); + rtems_filesystem_freenode( &env->root_directory); + free(env); + } } rtems_status_code rtems_libio_set_private_env(void) @@ -67,50 +74,53 @@ rtems_status_code rtems_libio_set_private_env(void) 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; - -#ifdef HAVE_USERENV_REFCNT - tmp->refcnt = 1; -#endif - - sc = rtems_task_variable_add( - RTEMS_SELF, - (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; + rtems_user_env_t *tmp = malloc(sizeof(rtems_user_env_t)); + if (!tmp) + return RTEMS_NO_MEMORY; + + #ifdef HAVE_USERENV_REFCNT + tmp->refcnt = 1; + #endif + + sc = rtems_task_variable_add( + RTEMS_SELF, + (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; } *rtems_current_user_env = rtems_global_user_env; /* get the global values*/ rtems_current_user_env->task_id=task_id; /* mark the local values*/ - /* 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. + /* 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_filesystem_evaluate_path("/", 1, 0, &loc, 0); + CHECK_STATUS( rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0) ); rtems_filesystem_root = loc; - rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); + + CHECK_STATUS( rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0) ); rtems_filesystem_current = loc; return RTEMS_SUCCESSFUL; } /* - * Share a same private environment beetween two task: - * Task_id (remote) and RTEMS_SELF(current). + * Share the same private environment between two tasks: + * Task_id (remote) and RTEMS_SELF(current). */ /* NOTE: -- cgit v1.2.3