source: rtems/c/src/exec/libcsupport/src/privateenv.c @ d3ba9b35

4.104.114.84.95
Last change on this file since d3ba9b35 was d3ba9b35, checked in by Joel Sherrill <joel.sherrill@…>, on 01/06/02 at 20:11:37

2002-02-05 Ralf Corsepius <corsepiu@…>

  • libc/Makefile.am: Add MULTISUBDIR support.
  • libc/fcntl.c: Add #include <stdarg.h>.
  • libc/privateenv.c: Add #include <stdlib.h>.
  • 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 <stdlib.h>     /* free */
21
22#include <rtems.h>
23#include <rtems/libio.h>
24#include <rtems/libio_.h>
25
26rtems_status_code rtems_libio_set_private_env(void) {
27  rtems_status_code sc;
28  rtems_id          task_id;
29
30  sc=rtems_task_ident(RTEMS_SELF,0,&task_id);
31  if (sc != RTEMS_SUCCESSFUL) return sc;
32
33  /* 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)
39     return RTEMS_NO_MEMORY;
40  };
41
42  /* the side effect desired . chroot("/") */
43  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
44  rtems_current_user_env->task_id=task_id;         /* mark the local values*/
45
46  return RTEMS_SUCCESSFUL;
47}
48
49/*
50 *  Share a same private environment beetween two task:
51 *   Task_id (remote) and RTEMS_SELF(current).
52 */
53
54rtems_status_code rtems_libio_share_private_env(rtems_id task_id) {
55  rtems_status_code  sc;
56  rtems_user_env_t * shared_user_env;
57  rtems_id           current_task_id;
58
59  sc=rtems_task_ident(RTEMS_SELF,0,&current_task_id);
60  if (sc != RTEMS_SUCCESSFUL) return sc;
61
62  if (rtems_current_user_env->task_id==current_task_id) {
63   /* kill the current user env & task_var*/     
64   free(rtems_current_user_env);         
65   sc = rtems_task_variable_delete(RTEMS_SELF,(void*)&rtems_current_user_env);
66   if (sc != RTEMS_SUCCESSFUL) return sc;
67  };
68
69  sc = rtems_task_variable_get(task_id,(void*)&rtems_current_user_env,
70                                       (void*)&shared_user_env       );
71  if (sc != RTEMS_SUCCESSFUL) return sc;
72
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;
76 
77  /* the current_user_env is the same pointer that remote env */
78  rtems_current_user_env = shared_user_env;
79
80  return RTEMS_SUCCESSFUL;
81}
Note: See TracBrowser for help on using the repository browser.