source: rtems/cpukit/include/rtems/userenv.h @ ba74ebde

5
Last change on this file since ba74ebde was ba74ebde, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 14, 2020 at 6:09:56 PM

libio: Add POSIX user environment pointer to TCB

The IO library used a POSIX key to store an optional POSIX user
environment pointer. This pulled in the POSIX keys support in every
application configuration. Add a user environment pointer to the thread
control block (TCB) instead. Applications which do not need the POSIX
user environment will just get an overhead of one pointer per thread.

Close #3882.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup LibIOEnv
5 * @brief User Environment Support
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Modifications to support reference counting in the file system are
13 *  Copyright (c) 2012 embedded brains GmbH.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#ifndef _RTEMS_USERENV_H
21#define _RTEMS_USERENV_H
22
23/*
24 * According to IEEE Std 1003.1-2001,
25 * limits.h is supposed to provide _POSIX_LOGIN_NAME_MAX
26 * XXX: We do not rely on this.
27 */
28#include <sys/param.h>
29#include <limits.h>
30
31#include <rtems.h>
32#include <rtems/fs.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * @defgroup LibIOEnv User Environment
40 *
41 * @ingroup LibIO
42 *
43 * @brief Provides a POSIX like user environment for tasks.
44 */
45/**@{**/
46
47#ifndef LOGIN_NAME_MAX
48  #ifdef _POSIX_LOGIN_NAME_MAX
49    #define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
50  #else
51    /* Fallback */
52    #define LOGIN_NAME_MAX 9
53  #endif
54#endif
55
56typedef struct rtems_user_env_t rtems_user_env_t;
57
58/**
59 * @brief User environment.
60 */
61struct rtems_user_env_t {
62  /**
63   * @brief The anchor directory for relative paths.
64   */
65  rtems_filesystem_global_location_t *current_directory;
66
67  /**
68   * @brief The anchor directory for absolute paths.
69   */
70  rtems_filesystem_global_location_t *root_directory;
71
72  /**
73   * @brief The file mode creation mask.
74   */
75  mode_t umask;
76
77  /**
78   * @brief The real user ID.
79   */
80  uid_t uid;
81
82  /**
83   * @brief The real group ID.
84   */
85  gid_t gid;
86
87  /**
88   * @brief The effective user ID.
89   */
90  uid_t euid;
91
92  /**
93   * @brief The effective group ID.
94   */
95  gid_t egid;
96
97  /**
98   * @brief The login buffer.
99   */
100  char login_buffer[LOGIN_NAME_MAX];
101
102  /**
103   * @brief The process group ID.
104   */
105  pid_t pgrp;
106
107  /**
108   * @brief The count of supplementary group IDs.
109   */
110  size_t ngroups;
111
112  /**
113   * @brief The list of supplementary group IDs.
114   */
115  gid_t groups[NGROUPS];
116};
117
118extern rtems_user_env_t rtems_global_user_env;
119
120/**
121 * @brief Fetch the pointer to the current user environment.
122 *
123 * If the task has a private user environment the pointer to it will be
124 * returned. Otherwise the pointer to rtems_global_user_env will be returned.
125 */
126rtems_user_env_t * rtems_current_user_env_get(void);
127
128#define rtems_current_user_env rtems_current_user_env_get()
129
130#define rtems_filesystem_current     (rtems_current_user_env->current_directory)
131#define rtems_filesystem_root        (rtems_current_user_env->root_directory)
132#define rtems_filesystem_umask       (rtems_current_user_env->umask)
133
134#define _POSIX_types_Uid             (rtems_current_user_env->uid)
135#define _POSIX_types_Gid             (rtems_current_user_env->gid)
136#define _POSIX_types_Euid            (rtems_current_user_env->euid)
137#define _POSIX_types_Egid            (rtems_current_user_env->egid)
138#define _POSIX_types_Getlogin_buffer (rtems_current_user_env->login_buffer)
139
140/**
141 * @brief Creates a private environment.
142 *
143 * If the task has already a private environment nothing will be changed.  This
144 * function must be called from normal thread context and may block on a mutex.
145 * Thread dispatching is disabled to protect some critical sections.
146 *
147 * The private environment internally uses a POSIX key. The key is added to the
148 * configuration implicitly. But for each thread that uses a private environment
149 * a key value pair has to be configured by the application. If only the global
150 * environment is used there is no need to configure a key value pair.
151 *
152 * @retval RTEMS_SUCCESSFUL Successful operation.
153 * @retval RTEMS_NO_MEMORY Not enough memory.
154 * @retval RTEMS_UNSATISFIED Cloning of the current environment failed.
155 * @retval RTEMS_TOO_MANY Cannot register the private environment.
156 */
157rtems_status_code rtems_libio_set_private_env(void);
158
159/**
160 * @brief Use the global environment.
161 *
162 * A private environment will be released.  This function may be called from
163 * every thread context.  Thread dispatching is disabled to protect the
164 * critical sections.
165 */
166void rtems_libio_use_global_env(void);
167
168/**
169 * @brief Gets the supplementary group IDs using the current user ID and
170 * updates the table of supplementary group IDs in the current user
171 * environment.
172 *
173 * In case of an error, the count of supplementary group IDs is set to zero.
174 */
175void rtems_current_user_env_getgroups(void);
176
177/** @} */
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif
184/* end of include file */
Note: See TracBrowser for help on using the repository browser.