diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-07-15 21:31:10 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-07-15 21:31:10 +0000 |
commit | e77a193482dac30202bb13d911c4df5c94669ce6 (patch) | |
tree | 72f1c39c940f8a20a2a62308e8d4d08b5fa3ff84 /cpukit/libcsupport/src/privateenv.c | |
parent | 2010-07-15 Sebastian Huber <Sebastian.Huber@embedded-brains.de> (diff) | |
download | rtems-e77a193482dac30202bb13d911c4df5c94669ce6.tar.bz2 |
2010-07-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/src/privateenv.c: Fix bug.
Diffstat (limited to 'cpukit/libcsupport/src/privateenv.c')
-rw-r--r-- | cpukit/libcsupport/src/privateenv.c | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index 3d31cf55e2..b46f8e000b 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -3,7 +3,7 @@ * * Submitted by: fernando.ruiz@ctv.es (correo@fernando-ruiz.com) * - * COPYRIGHT (c) 1989-2000. + * COPYRIGHT (c) 1989-2010. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -17,7 +17,7 @@ #include "config.h" #endif -#include <stdlib.h> /* free */ +#include <stdlib.h> /* free */ #include <rtems.h> #include <rtems/chain.h> @@ -33,28 +33,29 @@ free_user_env(void *venv) { rtems_user_env_t *env = (rtems_user_env_t*) venv ; - if (env != &rtems_global_user_env + if (env != &rtems_global_user_env #ifdef HAVE_USERENV_REFCNT - && --env->refcnt <= 0 + && --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) { - rtems_status_code sc; - rtems_id task_id; - rtems_filesystem_location_info_t loc; +rtems_status_code rtems_libio_set_private_env(void) +{ + rtems_status_code sc; + rtems_id task_id; + rtems_filesystem_location_info_t loc; sc=rtems_task_ident(RTEMS_SELF,0,&task_id); if (sc != RTEMS_SUCCESSFUL) return sc; /* Only for the first time a malloc is necesary */ if (rtems_current_user_env==&rtems_global_user_env) { - rtems_user_env_t *tmp = malloc(sizeof(rtems_user_env_t)); + rtems_user_env_t *tmp = malloc(sizeof(rtems_user_env_t)); if (!tmp) return RTEMS_NO_MEMORY; @@ -62,16 +63,20 @@ rtems_status_code rtems_libio_set_private_env(void) { tmp->refcnt = 1; #endif - sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,(void(*)(void *))free_user_env); + 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 - */ + /* 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*/ @@ -111,7 +116,8 @@ rtems_status_code rtems_libio_set_private_env(void) { */ #ifndef HAVE_USERENV_REFCNT -rtems_status_code rtems_libio_share_private_env(rtems_id task_id) { +rtems_status_code rtems_libio_share_private_env(rtems_id task_id) +{ rtems_status_code sc; rtems_user_env_t * shared_user_env; rtems_id current_task_id; @@ -121,20 +127,21 @@ rtems_status_code rtems_libio_share_private_env(rtems_id task_id) { if (rtems_current_user_env->task_id==current_task_id) { /* kill the current user env & task_var*/ - rtems_user_env_t *tmp = rtems_current_user_env; + rtems_user_env_t *tmp = rtems_current_user_env; sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env); if (sc != RTEMS_SUCCESSFUL) return sc; free_user_env(tmp); - }; + } else { + sc = rtems_task_variable_get( + task_id,(void*)&rtems_current_user_env, (void*)&shared_user_env ); + if (sc != RTEMS_SUCCESSFUL) + goto bailout; + } /* AT THIS POINT, rtems_current_user_env is DANGLING */ - sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env, - (void*)&shared_user_env ); - if (sc != RTEMS_SUCCESSFUL) - goto bailout; - - sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env); + sc = rtems_task_variable_add( + RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env); if (sc != RTEMS_SUCCESSFUL) goto bailout; |