source: rtems/cpukit/libcsupport/src/privateenv.c @ 8860f103

4.104.114.84.9
Last change on this file since 8860f103 was 8860f103, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 20, 2003 at 10:09:50 PM

Patch against RTEMS-ss-20030128
Author: Till Straumann <strauman@…>

2003/2/11

This patch addresses the following issues:
2003-02-20 Till Straumann <strauman@…>

PR 349/bsps

  • src/mount.c, src/privateenv.c:
    • mount() bugfix: allocated 'loc' node must be released if

mount fails due to missing node_type_h

  • silence compiler warning about improper pointer type

Index: cpukit/libcsupport/src/mount.c
===================================================================
RCS file: /afs/slac/g/spear/cvsrep/rtems/src-20030128/cpukit/libcsupport/src/mount.c,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 mount.c
* cpukit/libcsupport/src/mount.c 29 Jan 2003 22:57:19 -0000 1.1.1.2
--- cpukit/libcsupport/src/mount.c 7 Feb 2003 20:47:49 -0000
*
* 142,147
--- 142,149 ----

mount_point, RTEMS_LIBIO_PERMS_RWX, &loc, TRUE ) == -1 )

goto cleanup_and_bail;

+ loc_to_free = &loc;
+

/*

  • Test for node_type_h */

*
* 155,161

  • Test to see if it is a directory */
  • loc_to_free = &loc;

if ( loc.ops->node_type_h( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {

errno = ENOTDIR;
goto cleanup_and_bail;

--- 157,162 ----
Index: cpukit/libcsupport/src/privateenv.c
===================================================================
RCS file: /afs/slac/g/spear/cvsrep/rtems/src-20030128/cpukit/libcsupport/src/privateenv.c,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 privateenv.c
* cpukit/libcsupport/src/privateenv.c 29 Jan 2003 22:57:20 -0000 1.1.1.3
--- cpukit/libcsupport/src/privateenv.c 30 Jan 2003 18:01:40 -0000
*
* 65,71

tmp->refcnt = 1;

#endif

! sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env);

if (sc != RTEMS_SUCCESSFUL) {

/* don't use free_user_env because the pathlocs are

  • not initialized yet

--- 65,71 ----

tmp->refcnt = 1;

#endif

! 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
  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 *  Instantatiate a private user environment for the calling thread.
3 *
4 *  Submitted by: fernando.ruiz@ctv.es (correo@fernando-ruiz.com)
5 *
6 *  COPYRIGHT (c) 1989-2000.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <stdlib.h>     /* free */
21
22#include <rtems.h>
23#include <rtems/libio.h>
24#include <rtems/libio_.h>
25
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
50rtems_status_code rtems_libio_set_private_env(void) {
51  rtems_status_code                                     sc;
52  rtems_id                                              task_id;
53  rtems_filesystem_location_info_t              loc;
54
55  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
56  if (sc != RTEMS_SUCCESSFUL) return sc;
57
58  /* Only for the first time a malloc is necesary */
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)
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,(void(*)(void *))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;
77  }; 
78
79  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
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;
95
96  return RTEMS_SUCCESSFUL;
97}
98
99/*
100 *  Share a same private environment beetween two task:
101 *   Task_id (remote) and RTEMS_SELF(current).
102 */
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
119rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
120  rtems_status_code  sc;
121  rtems_user_env_t * shared_user_env;
122  rtems_id           current_task_id;
123
124  sc=rtems_task_ident(RTEMS_SELF,0,&current_task_id);
125  if (sc != RTEMS_SUCCESSFUL) return sc;
126
127  if (rtems_current_user_env->task_id==current_task_id) {
128   /* kill the current user env & task_var*/     
129        rtems_user_env_t        *tmp = rtems_current_user_env;
130   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
131   if (sc != RTEMS_SUCCESSFUL) return sc;
132   free_user_env(tmp);   
133  };
134
135  /* AT THIS POINT, rtems_current_user_env is DANGLING */
136
137  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
138                                       (void*)&shared_user_env       );
139  if (sc != RTEMS_SUCCESSFUL)
140    goto bailout;
141
142  sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_user_env,free_user_env);
143  if (sc != RTEMS_SUCCESSFUL)
144    goto bailout;
145 
146  /* the current_user_env is the same pointer that remote env */
147  rtems_current_user_env = shared_user_env;
148
149  /* increase the reference count */
150#ifdef HAVE_USERENV_REFCNT
151  rtems_current_user_env->refcnt++;
152#endif
153
154  return RTEMS_SUCCESSFUL;
155
156bailout:
157  /* fallback to the global env */
158  rtems_current_user_env = &rtems_global_user_env;
159  return sc;
160}
161#endif
Note: See TracBrowser for help on using the repository browser.