Changeset d8a9155 in rtems


Ignore:
Timestamp:
Apr 20, 2001, 9:11:25 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
6de4727f
Parents:
dd74e612
Message:

2001-04-20 Correo Fernando-ruiz <correo@…>

  • include/rtems/libio_.h, libc/chroot.c, libc/privateenv.c: Private environment and chroot() enhancements and fixes. Comments: + privateenv has been modified to let at chroot() to be more

POSIX like Sergei Organov recommended.

+ A task owner lets that rtems_set_private_env() will be

called twice or more times.

+ chroot() can be called without a previous

rtems_set_private_env(); (transpanrently)

+ The second call of rtems_set_private_env() makes a internal

chroot("/") into global imfs_root.

+ chroot() runs like chdir() without a previous chdir("/") with

the global root.

+ The current directory can be in a wrong place like Linux and

many other Unices.

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/include/rtems/libio_.h

    rdd74e612 rd8a9155  
    210210 */
    211211typedef struct {
     212 rtems_id                         task_id;     
    212213 rtems_filesystem_location_info_t current_directory;
    213214 rtems_filesystem_location_info_t root_directory;
     
    230231
    231232rtems_status_code rtems_libio_set_private_env(void);
     233rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
     234       
    232235
    233236
  • c/src/exec/libcsupport/include/rtems/libio_.h

    rdd74e612 rd8a9155  
    210210 */
    211211typedef struct {
     212 rtems_id                         task_id;     
    212213 rtems_filesystem_location_info_t current_directory;
    213214 rtems_filesystem_location_info_t root_directory;
     
    230231
    231232rtems_status_code rtems_libio_set_private_env(void);
     233rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
     234       
    232235
    233236
  • c/src/exec/libcsupport/src/chroot.c

    rdd74e612 rd8a9155  
    3131  rtems_filesystem_location_info_t  loc;
    3232 
    33   if (rtems_current_user_env == &rtems_global_user_env)
     33  /* an automatic call to new private env the first time */
     34  if (rtems_current_user_env == &rtems_global_user_env) {
     35   rtems_libio_set_private_env(); /* try to set a new private env*/
     36   if (rtems_current_user_env == &rtems_global_user_env) /* not ok */
    3437    set_errno_and_return_minus_one( ENOTSUP );
     38  };
    3539
    3640  loc = rtems_filesystem_root;     /* save the value */
    37 
    38   /* if has been already changed */
    39   rtems_filesystem_root = rtems_global_user_env.root_directory;
    4041
    4142  result = chdir(pathname);
     
    4647  rtems_filesystem_root = rtems_filesystem_current;
    4748
    48   result = chdir("/");
    49   if (result) {
    50     rtems_filesystem_root = loc; /* restore the value */
    51     set_errno_and_return_minus_one( errno );
    52   };
    53 
    54   /*XXX : Call this? Sorry but I don't known if it is necesary */
    55   /* The old root.
    56    rtems_filesystem_freenode( &loc );
    57    */
    5849  return 0;
    5950}
  • c/src/exec/libcsupport/src/privateenv.c

    rdd74e612 rd8a9155  
    2424rtems_status_code rtems_libio_set_private_env(void) {
    2525  rtems_status_code sc;
     26  rtems_id          task_id;
    2627
    27   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free);
    28   if (sc != RTEMS_SUCCESSFUL)
    29     return sc;
     28  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
     29  if (sc != RTEMS_SUCCESSFUL) return sc;
    3030
    31   rtems_current_user_env = malloc(sizeof(rtems_user_env_t));
    32   if (!rtems_current_user_env)
    33     return RTEMS_NO_MEMORY;
     31  /* Only for the first time a malloc is necesary */
     32  if (rtems_current_user_env==&rtems_global_user_env) {
     33   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free);
     34   if (sc != RTEMS_SUCCESSFUL) return sc;
     35   rtems_current_user_env = malloc(sizeof(rtems_user_env_t));
     36   if (!rtems_current_user_env)
     37     return RTEMS_NO_MEMORY;
     38  };
    3439
    35   *rtems_current_user_env = rtems_global_user_env;
     40  /* the side effect desired . chroot("/") */
     41  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
     42  rtems_current_user_env->task_id=task_id;         /* mark the local values*/
     43
    3644  return RTEMS_SUCCESSFUL;
    3745}
     46
     47/*
     48 *  Share a same private environment beetween two task:
     49 *   Task_id (remote) and RTEMS_SELF(current).
     50 */
     51
     52rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
     53  rtems_status_code  sc;
     54  rtems_user_env_t * shared_user_env;
     55  rtems_id           current_task_id;
     56
     57  sc=rtems_task_ident(RTEMS_SELF,0,&current_task_id);
     58  if (sc != RTEMS_SUCCESSFUL) return sc;
     59
     60  if (rtems_current_user_env->task_id==current_task_id) {
     61   /* kill the current user env & task_var*/     
     62   free(rtems_current_user_env);         
     63   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
     64   if (sc != RTEMS_SUCCESSFUL) return sc;
     65  };
     66
     67  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
     68                                       (void*)&shared_user_env       );
     69  if (sc != RTEMS_SUCCESSFUL) return sc;
     70
     71  /* don't free(NULL'ed) at the task_delete. It is a shared var... */     
     72  sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,NULL);
     73  if (sc != RTEMS_SUCCESSFUL) return sc;
     74 
     75  /* the current_user_env is the same pointer that remote env */
     76  rtems_current_user_env = shared_user_env;
     77
     78  return RTEMS_SUCCESSFUL;
     79}
  • c/src/lib/ChangeLog

    rdd74e612 rd8a9155  
     12001-04-20  Correo Fernando-ruiz <correo@fernando-ruiz.com>
     2
     3        * include/rtems/libio_.h, libc/chroot.c, libc/privateenv.c:
     4        Private environment and chroot() enhancements and fixes.  Comments:
     5          + privateenv has been modified to let at chroot() to be more
     6            POSIX like Sergei Organov recommended.
     7          + A task owner lets that rtems_set_private_env() will be
     8            called twice or more times.
     9          + chroot() can be called without a previous
     10            rtems_set_private_env(); (transpanrently)
     11          + The second call of rtems_set_private_env() makes a internal
     12            chroot("/") into global imfs_root.
     13          + chroot() runs like chdir() without a previous chdir("/") with
     14            the global root.
     15          + The current directory can be in a wrong place like Linux and
     16            many other Unices.
     17
    1182001-04-16      Joel Sherrill <joel@OARcorp.com>
    219
  • c/src/lib/include/rtems/libio_.h

    rdd74e612 rd8a9155  
    210210 */
    211211typedef struct {
     212 rtems_id                         task_id;     
    212213 rtems_filesystem_location_info_t current_directory;
    213214 rtems_filesystem_location_info_t root_directory;
     
    230231
    231232rtems_status_code rtems_libio_set_private_env(void);
     233rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
     234       
    232235
    233236
  • c/src/lib/libc/chroot.c

    rdd74e612 rd8a9155  
    3131  rtems_filesystem_location_info_t  loc;
    3232 
    33   if (rtems_current_user_env == &rtems_global_user_env)
     33  /* an automatic call to new private env the first time */
     34  if (rtems_current_user_env == &rtems_global_user_env) {
     35   rtems_libio_set_private_env(); /* try to set a new private env*/
     36   if (rtems_current_user_env == &rtems_global_user_env) /* not ok */
    3437    set_errno_and_return_minus_one( ENOTSUP );
     38  };
    3539
    3640  loc = rtems_filesystem_root;     /* save the value */
    37 
    38   /* if has been already changed */
    39   rtems_filesystem_root = rtems_global_user_env.root_directory;
    4041
    4142  result = chdir(pathname);
     
    4647  rtems_filesystem_root = rtems_filesystem_current;
    4748
    48   result = chdir("/");
    49   if (result) {
    50     rtems_filesystem_root = loc; /* restore the value */
    51     set_errno_and_return_minus_one( errno );
    52   };
    53 
    54   /*XXX : Call this? Sorry but I don't known if it is necesary */
    55   /* The old root.
    56    rtems_filesystem_freenode( &loc );
    57    */
    5849  return 0;
    5950}
  • c/src/lib/libc/privateenv.c

    rdd74e612 rd8a9155  
    2424rtems_status_code rtems_libio_set_private_env(void) {
    2525  rtems_status_code sc;
     26  rtems_id          task_id;
    2627
    27   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free);
    28   if (sc != RTEMS_SUCCESSFUL)
    29     return sc;
     28  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
     29  if (sc != RTEMS_SUCCESSFUL) return sc;
    3030
    31   rtems_current_user_env = malloc(sizeof(rtems_user_env_t));
    32   if (!rtems_current_user_env)
    33     return RTEMS_NO_MEMORY;
     31  /* Only for the first time a malloc is necesary */
     32  if (rtems_current_user_env==&rtems_global_user_env) {
     33   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free);
     34   if (sc != RTEMS_SUCCESSFUL) return sc;
     35   rtems_current_user_env = malloc(sizeof(rtems_user_env_t));
     36   if (!rtems_current_user_env)
     37     return RTEMS_NO_MEMORY;
     38  };
    3439
    35   *rtems_current_user_env = rtems_global_user_env;
     40  /* the side effect desired . chroot("/") */
     41  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
     42  rtems_current_user_env->task_id=task_id;         /* mark the local values*/
     43
    3644  return RTEMS_SUCCESSFUL;
    3745}
     46
     47/*
     48 *  Share a same private environment beetween two task:
     49 *   Task_id (remote) and RTEMS_SELF(current).
     50 */
     51
     52rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
     53  rtems_status_code  sc;
     54  rtems_user_env_t * shared_user_env;
     55  rtems_id           current_task_id;
     56
     57  sc=rtems_task_ident(RTEMS_SELF,0,&current_task_id);
     58  if (sc != RTEMS_SUCCESSFUL) return sc;
     59
     60  if (rtems_current_user_env->task_id==current_task_id) {
     61   /* kill the current user env & task_var*/     
     62   free(rtems_current_user_env);         
     63   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
     64   if (sc != RTEMS_SUCCESSFUL) return sc;
     65  };
     66
     67  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
     68                                       (void*)&shared_user_env       );
     69  if (sc != RTEMS_SUCCESSFUL) return sc;
     70
     71  /* don't free(NULL'ed) at the task_delete. It is a shared var... */     
     72  sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,NULL);
     73  if (sc != RTEMS_SUCCESSFUL) return sc;
     74 
     75  /* the current_user_env is the same pointer that remote env */
     76  rtems_current_user_env = shared_user_env;
     77
     78  return RTEMS_SUCCESSFUL;
     79}
  • cpukit/include/rtems/libio_.h

    rdd74e612 rd8a9155  
    210210 */
    211211typedef struct {
     212 rtems_id                         task_id;     
    212213 rtems_filesystem_location_info_t current_directory;
    213214 rtems_filesystem_location_info_t root_directory;
     
    230231
    231232rtems_status_code rtems_libio_set_private_env(void);
     233rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
     234       
    232235
    233236
  • cpukit/libcsupport/include/rtems/libio_.h

    rdd74e612 rd8a9155  
    210210 */
    211211typedef struct {
     212 rtems_id                         task_id;     
    212213 rtems_filesystem_location_info_t current_directory;
    213214 rtems_filesystem_location_info_t root_directory;
     
    230231
    231232rtems_status_code rtems_libio_set_private_env(void);
     233rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
     234       
    232235
    233236
  • cpukit/libcsupport/src/chroot.c

    rdd74e612 rd8a9155  
    3131  rtems_filesystem_location_info_t  loc;
    3232 
    33   if (rtems_current_user_env == &rtems_global_user_env)
     33  /* an automatic call to new private env the first time */
     34  if (rtems_current_user_env == &rtems_global_user_env) {
     35   rtems_libio_set_private_env(); /* try to set a new private env*/
     36   if (rtems_current_user_env == &rtems_global_user_env) /* not ok */
    3437    set_errno_and_return_minus_one( ENOTSUP );
     38  };
    3539
    3640  loc = rtems_filesystem_root;     /* save the value */
    37 
    38   /* if has been already changed */
    39   rtems_filesystem_root = rtems_global_user_env.root_directory;
    4041
    4142  result = chdir(pathname);
     
    4647  rtems_filesystem_root = rtems_filesystem_current;
    4748
    48   result = chdir("/");
    49   if (result) {
    50     rtems_filesystem_root = loc; /* restore the value */
    51     set_errno_and_return_minus_one( errno );
    52   };
    53 
    54   /*XXX : Call this? Sorry but I don't known if it is necesary */
    55   /* The old root.
    56    rtems_filesystem_freenode( &loc );
    57    */
    5849  return 0;
    5950}
  • cpukit/libcsupport/src/privateenv.c

    rdd74e612 rd8a9155  
    2424rtems_status_code rtems_libio_set_private_env(void) {
    2525  rtems_status_code sc;
     26  rtems_id          task_id;
    2627
    27   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free);
    28   if (sc != RTEMS_SUCCESSFUL)
    29     return sc;
     28  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
     29  if (sc != RTEMS_SUCCESSFUL) return sc;
    3030
    31   rtems_current_user_env = malloc(sizeof(rtems_user_env_t));
    32   if (!rtems_current_user_env)
    33     return RTEMS_NO_MEMORY;
     31  /* Only for the first time a malloc is necesary */
     32  if (rtems_current_user_env==&rtems_global_user_env) {
     33   sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free);
     34   if (sc != RTEMS_SUCCESSFUL) return sc;
     35   rtems_current_user_env = malloc(sizeof(rtems_user_env_t));
     36   if (!rtems_current_user_env)
     37     return RTEMS_NO_MEMORY;
     38  };
    3439
    35   *rtems_current_user_env = rtems_global_user_env;
     40  /* the side effect desired . chroot("/") */
     41  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
     42  rtems_current_user_env->task_id=task_id;         /* mark the local values*/
     43
    3644  return RTEMS_SUCCESSFUL;
    3745}
     46
     47/*
     48 *  Share a same private environment beetween two task:
     49 *   Task_id (remote) and RTEMS_SELF(current).
     50 */
     51
     52rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
     53  rtems_status_code  sc;
     54  rtems_user_env_t * shared_user_env;
     55  rtems_id           current_task_id;
     56
     57  sc=rtems_task_ident(RTEMS_SELF,0,&current_task_id);
     58  if (sc != RTEMS_SUCCESSFUL) return sc;
     59
     60  if (rtems_current_user_env->task_id==current_task_id) {
     61   /* kill the current user env & task_var*/     
     62   free(rtems_current_user_env);         
     63   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
     64   if (sc != RTEMS_SUCCESSFUL) return sc;
     65  };
     66
     67  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
     68                                       (void*)&shared_user_env       );
     69  if (sc != RTEMS_SUCCESSFUL) return sc;
     70
     71  /* don't free(NULL'ed) at the task_delete. It is a shared var... */     
     72  sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,NULL);
     73  if (sc != RTEMS_SUCCESSFUL) return sc;
     74 
     75  /* the current_user_env is the same pointer that remote env */
     76  rtems_current_user_env = shared_user_env;
     77
     78  return RTEMS_SUCCESSFUL;
     79}
Note: See TracChangeset for help on using the changeset viewer.