1 | Index: privateenv.c |
---|
2 | =================================================================== |
---|
3 | RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/privateenv.c,v |
---|
4 | retrieving revision 1.14 |
---|
5 | diff -u -r1.14 privateenv.c |
---|
6 | --- privateenv.c 26 Jul 2010 22:03:17 -0000 1.14 |
---|
7 | +++ privateenv.c 29 Jul 2010 21:18:00 -0000 |
---|
8 | @@ -115,34 +115,53 @@ |
---|
9 | * while changing any of those (chdir(), chroot()). |
---|
10 | */ |
---|
11 | |
---|
12 | -#ifndef HAVE_USERENV_REFCNT |
---|
13 | rtems_status_code rtems_libio_share_private_env(rtems_id task_id) |
---|
14 | { |
---|
15 | rtems_status_code sc; |
---|
16 | rtems_user_env_t * shared_user_env; |
---|
17 | rtems_id current_task_id; |
---|
18 | |
---|
19 | + /* |
---|
20 | + * get current task id |
---|
21 | + */ |
---|
22 | current_task_id = rtems_task_self(); |
---|
23 | |
---|
24 | - if (rtems_current_user_env->task_id==current_task_id) { |
---|
25 | - /* kill the current user env & task_var*/ |
---|
26 | - rtems_user_env_t *tmp = rtems_current_user_env; |
---|
27 | - sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env); |
---|
28 | - if (sc != RTEMS_SUCCESSFUL) return sc; |
---|
29 | - free_user_env(tmp); |
---|
30 | - } else { |
---|
31 | - sc = rtems_task_variable_get( |
---|
32 | - task_id,(void*)&rtems_current_user_env, (void*)&shared_user_env ); |
---|
33 | + /* |
---|
34 | + * If this was an attempt to share the task with self, |
---|
35 | + * if somebody wanted to do it... Lets tell them, its shared |
---|
36 | + */ |
---|
37 | + |
---|
38 | + if( task_id == current_task_id ) |
---|
39 | + return RTEMS_SUCCESSFUL; |
---|
40 | + /* |
---|
41 | + * Try to get the requested user environment |
---|
42 | + */ |
---|
43 | + sc = rtems_task_variable_get( |
---|
44 | + task_id, |
---|
45 | + (void*)&rtems_current_user_env, |
---|
46 | + (void*)&shared_user_env ); |
---|
47 | + |
---|
48 | + /* |
---|
49 | + * If it was not successful, return the error code |
---|
50 | + */ |
---|
51 | if (sc != RTEMS_SUCCESSFUL) |
---|
52 | - goto bailout; |
---|
53 | - } |
---|
54 | + return sc; |
---|
55 | |
---|
56 | - /* AT THIS POINT, rtems_current_user_env is DANGLING */ |
---|
57 | + /* |
---|
58 | + * If we are here, we have the required environment to be |
---|
59 | + * shared with the current task |
---|
60 | + */ |
---|
61 | + |
---|
62 | + /* |
---|
63 | + * If we have a current environment in place, we need to |
---|
64 | + * free it, since we will be sharing the variable with the |
---|
65 | + * shared_user_env |
---|
66 | + */ |
---|
67 | |
---|
68 | - sc = rtems_task_variable_add( |
---|
69 | - RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env); |
---|
70 | - if (sc != RTEMS_SUCCESSFUL) |
---|
71 | - goto bailout; |
---|
72 | + if (rtems_current_user_env->task_id==current_task_id) { |
---|
73 | + rtems_user_env_t *tmp = rtems_current_user_env; |
---|
74 | + free_user_env( tmp ); |
---|
75 | + } |
---|
76 | |
---|
77 | /* the current_user_env is the same pointer that remote env */ |
---|
78 | rtems_current_user_env = shared_user_env; |
---|
79 | @@ -153,10 +172,4 @@ |
---|
80 | #endif |
---|
81 | |
---|
82 | return RTEMS_SUCCESSFUL; |
---|
83 | - |
---|
84 | -bailout: |
---|
85 | - /* fallback to the global env */ |
---|
86 | - rtems_current_user_env = &rtems_global_user_env; |
---|
87 | - return sc; |
---|
88 | } |
---|
89 | -#endif |
---|