Changeset f6161c72 in rtems


Ignore:
Timestamp:
01/03/03 18:14:09 (21 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
883129a
Parents:
36799d4
Message:

2003-01-03 Till Straumann <strauman@…>

  • ChangeLog?, base_fs.c, getpwent.c, privateenv.c Per PR303, Fix violation of node_access copy syemantics
Location:
cpukit/libcsupport/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/base_fs.c

    r36799d4 rf6161c72  
    5050  rtems_filesystem_mount_table_entry_t *entry;
    5151  rtems_filesystem_mount_table_t       *mt;
     52  rtems_filesystem_location_info_t              loc;
    5253 
    5354  /*
     
    7677
    7778  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   */
    78100  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   */
    80111
    81112
  • cpukit/libcsupport/src/getpwent.c

    r36799d4 rf6161c72  
    186186  FILE *fp;
    187187  int match;
    188   rtems_user_env_t * aux=rtems_current_user_env; /* save */
    189188
    190189  init_etc_passwd_group();
    191   rtems_current_user_env=&rtems_global_user_env; /* set root */
    192190
    193191  if ((fp = fopen("/etc/passwd", "r")) == NULL) {
    194192    errno = EINVAL;
    195     rtems_current_user_env=aux; /* restore */
    196193    return -1;
    197194  }
     
    200197      errno = EINVAL;
    201198      fclose(fp);
    202       rtems_current_user_env=aux; /* restore */
    203199      return -1;
    204200    }
     
    212208      fclose(fp);
    213209      *result = pwd;
    214       rtems_current_user_env=aux; /* restore */
    215210      return 0;
    216211    }
     
    218213  fclose(fp);
    219214  errno = EINVAL;
    220   rtems_current_user_env=aux; /* restore */
    221215  return -1;
    222216}
     
    277271void setpwent(void)
    278272{
    279   rtems_user_env_t * aux=rtems_current_user_env; /* save */
    280273  init_etc_passwd_group();
    281   rtems_current_user_env=&rtems_global_user_env; /* set root */
    282274
    283275  if (passwd_fp != NULL)
    284276    fclose(passwd_fp);
    285277  passwd_fp = fopen("/etc/passwd", "r");
    286   rtems_current_user_env=aux; /* restore */
    287278}
    288279
     
    354345  FILE *fp;
    355346  int match;
    356   rtems_user_env_t * aux=rtems_current_user_env; /* save */
    357347
    358348  init_etc_passwd_group();
    359   rtems_current_user_env=&rtems_global_user_env; /* set root */
    360349
    361350  if ((fp = fopen("/etc/group", "r")) == NULL) {
    362351    errno = EINVAL;
    363     rtems_current_user_env=aux; /* restore */
    364352    return -1;
    365353  }
     
    368356      errno = EINVAL;
    369357      fclose(fp);
    370       rtems_current_user_env=aux; /* restore */
    371358      return -1;
    372359    }
     
    380367      fclose(fp);
    381368      *result = grp;
    382       rtems_current_user_env=aux; /* restore */
    383369      return 0;
    384370    }
     
    386372  fclose(fp);
    387373  errno = EINVAL;
    388   rtems_current_user_env=aux; /* restore */
    389374  return -1;
    390375}
     
    445430void setgrent(void)
    446431{
    447   rtems_user_env_t * aux=rtems_current_user_env; /* save */
    448432  init_etc_passwd_group();
    449   rtems_current_user_env=&rtems_global_user_env; /* set root */
    450433
    451434  if (group_fp != NULL)
    452435    fclose(group_fp);
    453436  group_fp = fopen("/etc/group", "r");
    454   rtems_current_user_env=aux; /* restore */
    455437}
    456438
  • cpukit/libcsupport/src/privateenv.c

    r36799d4 rf6161c72  
    2424#include <rtems/libio_.h>
    2525
     26extern 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 */
     36static void
     37free_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
    2650rtems_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;
    2954
    3055  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
     
    3257
    3358  /* 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)
    3962     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;
    4077  };
    4178
    42   /* the side effect desired . chroot("/") */
    4379  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
    4480  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;
    4595
    4696  return RTEMS_SUCCESSFUL;
     
    52102 */
    53103
     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
    54119rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
    55120  rtems_status_code  sc;
     
    62127  if (rtems_current_user_env->task_id==current_task_id) {
    63128   /* kill the current user env & task_var*/     
    64    free(rtems_current_user_env);         
     129        rtems_user_env_t        *tmp = rtems_current_user_env;
    65130   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
    66131   if (sc != RTEMS_SUCCESSFUL) return sc;
     132   free_user_env(tmp);   
    67133  };
     134
     135  /* AT THIS POINT, rtems_current_user_env is DANGLING */
    68136
    69137  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
    70138                                       (void*)&shared_user_env       );
    71   if (sc != RTEMS_SUCCESSFUL) return sc;
     139  if (sc != RTEMS_SUCCESSFUL)
     140    goto bailout;
    72141
    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;
    76145 
    77146  /* the current_user_env is the same pointer that remote env */
    78147  rtems_current_user_env = shared_user_env;
    79148
     149  /* increase the reference count */
     150#ifdef HAVE_USERENV_REFCNT
     151  rtems_current_user_env->refcnt++;
     152#endif
     153
    80154  return RTEMS_SUCCESSFUL;
     155
     156bailout:
     157  /* fallback to the global env */
     158  rtems_current_user_env = &rtems_global_user_env;
     159  return sc;
    81160}
     161#endif
Note: See TracChangeset for help on using the changeset viewer.