Changeset f6161c72 in rtems
- Timestamp:
- 01/03/03 18:14:09 (21 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 883129a
- Parents:
- 36799d4
- Location:
- cpukit/libcsupport/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libcsupport/src/base_fs.c
r36799d4 rf6161c72 50 50 rtems_filesystem_mount_table_entry_t *entry; 51 51 rtems_filesystem_mount_table_t *mt; 52 rtems_filesystem_location_info_t loc; 52 53 53 54 /* … … 76 77 77 78 rtems_filesystem_link_counts = 0; 79 80 /* setup the 'current' and 'root' directories 81 * 82 * NOTE: cloning the pathlocs is not strictly 83 * necessary. Since we implicitely let 84 * all threads that don't call 85 * libio_set_private_env() share the same 86 * (initial) 'root' and 'current' locs, 87 * we (also implicitely) assume that the 88 * root filesystem doesn't care about 89 * reference counts. 90 * I just inserted the code snippet below 91 * to remind everybody of the fact by 92 * making it more explicit... 93 * Ideally, every thread would have to 94 * call either share_private_env() or 95 * set_private_env() - but then: that's 96 * gonna hit performance. 97 * 98 * Till Straumann, 10/25/2002 99 */ 78 100 rtems_filesystem_root = entry->mt_fs_root; 79 rtems_filesystem_current = rtems_filesystem_root; 101 /* Clone the root pathloc */ 102 rtems_filesystem_evaluate_path("/", 0, &loc, 0); 103 rtems_filesystem_root = loc; 104 /* One more clone for the current node */ 105 rtems_filesystem_evaluate_path("/", 0, &loc, 0); 106 rtems_filesystem_current = loc; 107 108 /* Note: the global_env's refcnt doesn't matter 109 * as the global env is never released 110 */ 80 111 81 112 -
cpukit/libcsupport/src/getpwent.c
r36799d4 rf6161c72 186 186 FILE *fp; 187 187 int match; 188 rtems_user_env_t * aux=rtems_current_user_env; /* save */189 188 190 189 init_etc_passwd_group(); 191 rtems_current_user_env=&rtems_global_user_env; /* set root */192 190 193 191 if ((fp = fopen("/etc/passwd", "r")) == NULL) { 194 192 errno = EINVAL; 195 rtems_current_user_env=aux; /* restore */196 193 return -1; 197 194 } … … 200 197 errno = EINVAL; 201 198 fclose(fp); 202 rtems_current_user_env=aux; /* restore */203 199 return -1; 204 200 } … … 212 208 fclose(fp); 213 209 *result = pwd; 214 rtems_current_user_env=aux; /* restore */215 210 return 0; 216 211 } … … 218 213 fclose(fp); 219 214 errno = EINVAL; 220 rtems_current_user_env=aux; /* restore */221 215 return -1; 222 216 } … … 277 271 void setpwent(void) 278 272 { 279 rtems_user_env_t * aux=rtems_current_user_env; /* save */280 273 init_etc_passwd_group(); 281 rtems_current_user_env=&rtems_global_user_env; /* set root */282 274 283 275 if (passwd_fp != NULL) 284 276 fclose(passwd_fp); 285 277 passwd_fp = fopen("/etc/passwd", "r"); 286 rtems_current_user_env=aux; /* restore */287 278 } 288 279 … … 354 345 FILE *fp; 355 346 int match; 356 rtems_user_env_t * aux=rtems_current_user_env; /* save */357 347 358 348 init_etc_passwd_group(); 359 rtems_current_user_env=&rtems_global_user_env; /* set root */360 349 361 350 if ((fp = fopen("/etc/group", "r")) == NULL) { 362 351 errno = EINVAL; 363 rtems_current_user_env=aux; /* restore */364 352 return -1; 365 353 } … … 368 356 errno = EINVAL; 369 357 fclose(fp); 370 rtems_current_user_env=aux; /* restore */371 358 return -1; 372 359 } … … 380 367 fclose(fp); 381 368 *result = grp; 382 rtems_current_user_env=aux; /* restore */383 369 return 0; 384 370 } … … 386 372 fclose(fp); 387 373 errno = EINVAL; 388 rtems_current_user_env=aux; /* restore */389 374 return -1; 390 375 } … … 445 430 void setgrent(void) 446 431 { 447 rtems_user_env_t * aux=rtems_current_user_env; /* save */448 432 init_etc_passwd_group(); 449 rtems_current_user_env=&rtems_global_user_env; /* set root */450 433 451 434 if (group_fp != NULL) 452 435 fclose(group_fp); 453 436 group_fp = fopen("/etc/group", "r"); 454 rtems_current_user_env=aux; /* restore */455 437 } 456 438 -
cpukit/libcsupport/src/privateenv.c
r36799d4 rf6161c72 24 24 #include <rtems/libio_.h> 25 25 26 extern Chain_Control rtems_filesystem_mount_table_control; 27 28 #define THE_ROOT_FS_LOC \ 29 (((rtems_filesystem_mount_table_entry_t*)\ 30 rtems_filesystem_mount_table_control.first)->mt_fs_root) 31 32 /* cleanup a user environment 33 * NOTE: this must be called with 34 * thread dispatching disabled! 35 */ 36 static void 37 free_user_env(rtems_user_env_t *env) 38 { 39 if (env != &rtems_global_user_env 40 #ifdef HAVE_USERENV_REFCNT 41 && --env->refcnt <= 0 42 #endif 43 ) { 44 rtems_filesystem_freenode( &env->current_directory); 45 rtems_filesystem_freenode( &env->root_directory); 46 free(env); 47 } 48 } 49 26 50 rtems_status_code rtems_libio_set_private_env(void) { 27 rtems_status_code sc; 28 rtems_id task_id; 51 rtems_status_code sc; 52 rtems_id task_id; 53 rtems_filesystem_location_info_t loc; 29 54 30 55 sc=rtems_task_ident(RTEMS_SELF,0,&task_id); … … 32 57 33 58 /* Only for the first time a malloc is necesary */ 34 if (rtems_current_user_env==&rtems_global_user_env) { 35 sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free); 36 if (sc != RTEMS_SUCCESSFUL) return sc; 37 rtems_current_user_env = malloc(sizeof(rtems_user_env_t)); 38 if (!rtems_current_user_env) 59 if (rtems_current_user_env==&rtems_global_user_env) { 60 rtems_user_env_t *tmp = malloc(sizeof(rtems_user_env_t)); 61 if (!tmp) 39 62 return RTEMS_NO_MEMORY; 63 64 #ifdef HAVE_USERENV_REFCNT 65 tmp->refcnt = 1; 66 #endif 67 68 sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env); 69 if (sc != RTEMS_SUCCESSFUL) { 70 /* don't use free_user_env because the pathlocs are 71 * not initialized yet 72 */ 73 free(tmp); 74 return sc; 75 } 76 rtems_current_user_env = tmp; 40 77 }; 41 78 42 /* the side effect desired . chroot("/") */43 79 *rtems_current_user_env = rtems_global_user_env; /* get the global values*/ 44 80 rtems_current_user_env->task_id=task_id; /* mark the local values*/ 81 82 /* get a clean root */ 83 rtems_filesystem_root = THE_ROOT_FS_LOC; 84 85 /* Clone the pathlocs. In contrast to most other 86 * code we must _not_ free the original locs because 87 * what we are trying to do here is forking off 88 * clones. 89 */ 90 91 rtems_filesystem_evaluate_path("/", 0, &loc, 0); 92 rtems_filesystem_root = loc; 93 rtems_filesystem_evaluate_path("/", 0, &loc, 0); 94 rtems_filesystem_current = loc; 45 95 46 96 return RTEMS_SUCCESSFUL; … … 52 102 */ 53 103 104 /* NOTE: 105 * 106 * THIS CODE HAS NO PROTECTION IMPLEMENTED 107 * 108 * Tasks who wish to share their environments must 109 * 110 * a) assert that no participants are concurrently 111 * executing 112 * libio_share_private_env() and/or libio_set_private_env() 113 * 114 * b) mutex access to rtems_filesystem_current, rtems_filesytem_root 115 * while changing any of those (chdir(), chroot()). 116 */ 117 118 #ifndef HAVE_USERENV_REFCNT 54 119 rtems_status_code rtems_libio_share_private_env(rtems_id task_id) { 55 120 rtems_status_code sc; … … 62 127 if (rtems_current_user_env->task_id==current_task_id) { 63 128 /* kill the current user env & task_var*/ 64 free(rtems_current_user_env); 129 rtems_user_env_t *tmp = rtems_current_user_env; 65 130 sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env); 66 131 if (sc != RTEMS_SUCCESSFUL) return sc; 132 free_user_env(tmp); 67 133 }; 134 135 /* AT THIS POINT, rtems_current_user_env is DANGLING */ 68 136 69 137 sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env, 70 138 (void*)&shared_user_env ); 71 if (sc != RTEMS_SUCCESSFUL) return sc; 139 if (sc != RTEMS_SUCCESSFUL) 140 goto bailout; 72 141 73 /* don't free(NULL'ed) at the task_delete. It is a shared var... */74 sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,NULL);75 if (sc != RTEMS_SUCCESSFUL) return sc;142 sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env); 143 if (sc != RTEMS_SUCCESSFUL) 144 goto bailout; 76 145 77 146 /* the current_user_env is the same pointer that remote env */ 78 147 rtems_current_user_env = shared_user_env; 79 148 149 /* increase the reference count */ 150 #ifdef HAVE_USERENV_REFCNT 151 rtems_current_user_env->refcnt++; 152 #endif 153 80 154 return RTEMS_SUCCESSFUL; 155 156 bailout: 157 /* fallback to the global env */ 158 rtems_current_user_env = &rtems_global_user_env; 159 return sc; 81 160 } 161 #endif
Note: See TracChangeset
for help on using the changeset viewer.