source: rtems/cpukit/libcsupport/src/privateenv.c @ d8a9155

4.104.114.84.95
Last change on this file since d8a9155 was d8a9155, checked in by Joel Sherrill <joel.sherrill@…>, on 04/20/01 at 21:11:25

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.

  • Property mode set to 100644
File size: 2.4 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 <rtems.h>
21#include <rtems/libio.h>
22#include <rtems/libio_.h>
23
24rtems_status_code rtems_libio_set_private_env(void) {
25  rtems_status_code sc;
26  rtems_id          task_id;
27
28  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
29  if (sc != RTEMS_SUCCESSFUL) return sc;
30
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  };
39
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
44  return RTEMS_SUCCESSFUL;
45}
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 TracBrowser for help on using the repository browser.