source: rtems-docs/posix_users/process_environment.rst @ 9aafb39

4.115
Last change on this file since 9aafb39 was 36def91, checked in by Joel Sherrill <joel@…>, on 10/28/16 at 00:47:07

rtems-docs: Fix many unnecessary back slashes

  • Property mode set to 100644
File size: 15.9 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2002.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7Process Environment Manager
8###########################
9
10Introduction
11============
12
13The process environment manager is responsible for providing the functions
14related to user and group Id management.
15
16The directives provided by the process environment manager are:
17
18- getpid_ - Get Process ID
19
20- getppid_ - Get Parent Process ID
21
22- getuid_ - Get User ID
23
24- geteuid_ - Get Effective User ID
25
26- getgid_ - Get Real Group ID
27
28- getegid_ - Get Effective Group ID
29
30- setuid_ - Set User ID
31
32- setgid_ - Set Group ID
33
34- getgroups_ - Get Supplementary Group IDs
35
36- getlogin_ - Get User Name
37
38- getlogin_r_ - Reentrant Get User Name
39
40- getpgrp_ - Get Process Group ID
41
42- setsid_ - Create Session and Set Process Group ID
43
44- setpgid_ - Set Process Group ID for Job Control
45
46- uname_ - Get System Name
47
48- times_ - Get Process Times
49
50- getenv_ - Get Environment Variables
51
52- setenv_ - Set Environment Variables
53
54- ctermid_ - Generate Terminal Pathname
55
56- ttyname_ - Determine Terminal Device Name
57
58- ttyname_r_ - Reentrant Determine Terminal Device Name
59
60- isatty_ - Determine if File Descriptor is Terminal
61
62- sysconf_ - Get Configurable System Variables
63
64Background
65==========
66
67Users and Groups
68----------------
69
70RTEMS provides a single process, multi-threaded execution environment.  In this
71light, the notion of user and group is somewhat without meaning.  But RTEMS
72does provide services to provide a synthetic version of user and group.  By
73default, a single user and group is associated with the application.  Thus
74unless special actions are taken, every thread in the application shares the
75same user and group Id.  The initial rationale for providing user and group Id
76functionality in RTEMS was for the filesystem infrastructure to implement file
77permission checks.  The effective user/group Id capability has since been used
78to implement permissions checking by the ``ftpd`` server.
79
80In addition to the "real" user and group Ids, a process may have an effective
81user/group Id.  This allows a process to function using a more limited
82permission set for certain operations.
83
84User and Group Names
85--------------------
86
87POSIX considers user and group Ids to be a unique integer that may be
88associated with a name.  This is usually accomplished via a file named
89:file:`/etc/passwd` for user Id mapping and :file:`/etc/groups` for group Id
90mapping.  Again, although RTEMS is effectively a single process and thus single
91user system, it provides limited support for user and group names.  When
92configured with an appropriate filesystem, RTEMS will access the appropriate
93files to map user and group Ids to names.
94
95If these files do not exist, then RTEMS will synthesize a minimal version so
96this family of services return without error.  It is important to remember that
97a design goal of the RTEMS POSIX services is to provide useable and meaningful
98results even though a full process model is not available.
99
100Environment Variables
101---------------------
102
103POSIX allows for variables in the run-time environment.  These are name/value
104pairs that make be dynamically set and obtained by programs.  In a full POSIX
105environment with command line shell and multiple processes, environment
106variables may be set in one process - such as the shell - and inherited by
107child processes.  In RTEMS, there is only one process and thus only one set of
108environment variables across all processes.
109
110Operations
111==========
112
113Accessing User and Group Ids
114----------------------------
115
116The user Id associated with the current thread may be obtain using the
117``getuid()`` service.  Similarly, the group Id may be obtained using the
118``getgid()`` service.
119
120Accessing Environment Variables
121-------------------------------
122
123The value associated with an environment variable may be obtained using the
124``getenv()`` service and set using the ``putenv()`` service.
125
126Directives
127==========
128
129This section details the process environment manager's directives.  A
130subsection is dedicated to each of this manager's directives and describes the
131calling sequence, related constants, usage, and status codes.
132
133.. _getpid:
134
135getpid - Get Process ID
136-----------------------
137.. index:: getpid
138.. index:: get process id
139
140**CALLING SEQUENCE:**
141
142.. code-block:: c
143
144    int getpid( void );
145
146**STATUS CODES:**
147
148The process Id is returned.
149
150**DESCRIPTION:**
151
152This service returns the process Id.
153
154**NOTES:**
155
156NONE
157
158.. _getppid:
159
160getppid - Get Parent Process ID
161-------------------------------
162.. index:: getppid
163.. index:: get parent process id
164
165**CALLING SEQUENCE:**
166
167.. code-block:: c
168
169    int getppid( void );
170
171**STATUS CODES:**
172
173The parent process Id is returned.
174
175**DESCRIPTION:**
176
177This service returns the parent process Id.
178
179**NOTES:**
180
181NONE
182
183.. _getuid:
184
185getuid - Get User ID
186--------------------
187.. index:: getuid
188.. index:: get user id
189
190**CALLING SEQUENCE:**
191
192.. code-block:: c
193
194    int getuid( void );
195
196**STATUS CODES:**
197
198The effective user Id is returned.
199
200**DESCRIPTION:**
201
202This service returns the effective user Id.
203
204**NOTES:**
205
206NONE
207
208.. _geteuid:
209
210geteuid - Get Effective User ID
211-------------------------------
212.. index:: geteuid
213.. index:: get effective user id
214
215**CALLING SEQUENCE:**
216
217.. code-block:: c
218
219    int geteuid( void );
220
221**STATUS CODES:**
222
223The effective group Id is returned.
224
225**DESCRIPTION:**
226
227This service returns the effective group Id.
228
229**NOTES:**
230
231NONE
232
233.. _getgid:
234
235getgid - Get Real Group ID
236--------------------------
237.. index:: getgid
238.. index:: get real group id
239
240**CALLING SEQUENCE:**
241
242.. code-block:: c
243
244    int getgid( void );
245
246**STATUS CODES:**
247
248The group Id is returned.
249
250**DESCRIPTION:**
251
252This service returns the group Id.
253
254**NOTES:**
255
256NONE
257
258.. _getegid:
259
260getegid - Get Effective Group ID
261--------------------------------
262.. index:: getegid
263.. index:: get effective group id
264
265**CALLING SEQUENCE:**
266
267.. code-block:: c
268
269    int getegid( void );
270
271**STATUS CODES:**
272
273The effective group Id is returned.
274
275**DESCRIPTION:**
276
277This service returns the effective group Id.
278
279**NOTES:**
280
281NONE
282
283.. _setuid:
284
285setuid - Set User ID
286--------------------
287.. index:: setuid
288.. index:: set user id
289
290**CALLING SEQUENCE:**
291
292.. code-block:: c
293
294    int setuid(
295        uid_t uid
296    );
297
298**STATUS CODES:**
299
300This service returns 0.
301
302**DESCRIPTION:**
303
304This service sets the user Id to ``uid``.
305
306**NOTES:**
307
308NONE
309
310.. _setgid:
311
312setgid - Set Group ID
313---------------------
314.. index:: setgid
315.. index:: set group id
316
317**CALLING SEQUENCE:**
318
319.. code-block:: c
320
321    int setgid(
322        gid_t  gid
323    );
324
325**STATUS CODES:**
326
327This service returns 0.
328
329**DESCRIPTION:**
330
331This service sets the group Id to ``gid``.
332
333**NOTES:**
334
335NONE
336
337.. _getgroups:
338
339getgroups - Get Supplementary Group IDs
340---------------------------------------
341.. index:: getgroups
342.. index:: get supplementary group ids
343
344**CALLING SEQUENCE:**
345
346.. code-block:: c
347
348    int getgroups(
349        int    gidsetsize,
350        gid_t  grouplist[]
351    );
352
353**STATUS CODES:**
354
355NA
356
357**DESCRIPTION:**
358
359This service is not implemented as RTEMS has no notion of supplemental groups.
360
361**NOTES:**
362
363If supported, this routine would only be allowed for the super-user.
364
365.. _getlogin:
366
367getlogin - Get User Name
368------------------------
369.. index:: getlogin
370.. index:: get user name
371
372**CALLING SEQUENCE:**
373
374.. code-block:: c
375
376    char *getlogin( void );
377
378**STATUS CODES:**
379
380Returns a pointer to a string containing the name of the current user.
381
382**DESCRIPTION:**
383
384This routine returns the name of the current user.
385
386**NOTES:**
387
388This routine is not reentrant and subsequent calls to ``getlogin()`` will
389overwrite the same buffer.
390
391.. _getlogin_r:
392
393getlogin_r - Reentrant Get User Name
394------------------------------------
395.. index:: getlogin_r
396.. index:: reentrant get user name
397.. index:: get user name, reentrant
398
399**CALLING SEQUENCE:**
400
401.. code-block:: c
402
403    int getlogin_r(
404        char   *name,
405        size_t  namesize
406    );
407
408**STATUS CODES:**
409
410.. list-table::
411 :class: rtems-table
412
413 * - ``EINVAL``
414   - The arguments were invalid.
415
416**DESCRIPTION:**
417
418This is a reentrant version of the ``getlogin()`` service.  The caller
419specified their own buffer, ``name``, as well as the length of this buffer,
420``namesize``.
421
422**NOTES:**
423
424NONE
425
426.. _getpgrp:
427
428getpgrp - Get Process Group ID
429------------------------------
430.. index:: getpgrp
431.. index:: get process group id
432
433**CALLING SEQUENCE:**
434
435.. code-block:: c
436
437    pid_t getpgrp( void );
438
439**STATUS CODES:**
440
441The procress group Id is returned.
442
443**DESCRIPTION:**
444
445This service returns the current progress group Id.
446
447**NOTES:**
448
449This routine is implemented in a somewhat meaningful way for RTEMS but is truly
450not functional.
451
452.. _setsid:
453
454setsid - Create Session and Set Process Group ID
455------------------------------------------------
456.. index:: setsid
457.. index:: create session and set process group id
458
459**CALLING SEQUENCE:**
460
461.. code-block:: c
462
463    pid_t setsid( void );
464
465**STATUS CODES:**
466
467.. list-table::
468 :class: rtems-table
469
470 * - ``EPERM``
471   - The application does not have permission to create a process group.
472
473**DESCRIPTION:**
474
475This routine always returns ``EPERM`` as RTEMS has no way to create new
476processes and thus no way to create a new process group.
477
478**NOTES:**
479
480NONE
481
482.. _setpgid:
483
484setpgid - Set Process Group ID for Job Control
485----------------------------------------------
486.. index:: setpgid
487.. index:: set process group id for job control
488
489**CALLING SEQUENCE:**
490
491.. code-block:: c
492
493    int setpgid(
494        pid_t pid,
495        pid_t pgid
496    );
497
498**STATUS CODES:**
499
500.. list-table::
501 :class: rtems-table
502
503 * - ``ENOSYS``
504   - The routine is not implemented.
505
506**DESCRIPTION:**
507
508This service is not implemented for RTEMS as process groups are not supported.
509
510**NOTES:**
511
512NONE
513
514.. _uname:
515
516uname - Get System Name
517-----------------------
518.. index:: uname
519.. index:: get system name
520
521**CALLING SEQUENCE:**
522
523.. code-block:: c
524
525    int uname(
526        struct utsname *name
527    );
528
529**STATUS CODES:**
530
531.. list-table::
532 :class: rtems-table
533
534 * - ``EPERM``
535   - The provided structure pointer is invalid.
536
537**DESCRIPTION:**
538
539This service returns system information to the caller.  It does this by filling
540in the ``struct utsname`` format structure for the caller.
541
542**NOTES:**
543
544The information provided includes the operating system (RTEMS in all
545configurations), the node number, the release as the RTEMS version, and the CPU
546family and model.  The CPU model name will indicate the multilib executive
547variant being used.
548
549.. _times:
550
551times - Get process times
552-------------------------
553.. index:: times
554.. index:: get process times
555
556**CALLING SEQUENCE:**
557
558.. code-block:: c
559
560    #include <sys/time.h>
561    clock_t times(
562        struct tms *ptms
563    );
564
565**STATUS CODES:**
566
567This routine returns the number of clock ticks that have elapsed since the
568system was initialized (e.g. the application was started).
569
570**DESCRIPTION:**
571
572``times`` stores the current process times in ``ptms``.  The format of ``struct
573tms`` is as defined in ``<sys/times.h>``.  RTEMS fills in the field
574``tms_utime`` with the number of ticks that the calling thread has executed and
575the field ``tms_stime`` with the number of clock ticks since system boot (also
576returned).  All other fields in the ``ptms`` are left zero.
577
578**NOTES:**
579
580RTEMS has no way to distinguish between user and system time so this routine
581returns the most meaningful information possible.
582
583.. _getenv:
584
585getenv - Get Environment Variables
586----------------------------------
587.. index:: getenv
588.. index:: get environment variables
589
590**CALLING SEQUENCE:**
591
592.. code-block:: c
593
594    char *getenv(
595        const char *name
596    );
597
598**STATUS CODES:**
599
600.. list-table::
601 :class: rtems-table
602
603 * - ``NULL``
604   - when no match
605 * - `pointer to value`
606   - when successful
607
608**DESCRIPTION:**
609
610This service searches the set of environment variables for a string that
611matches the specified ``name``.  If found, it returns the associated value.
612
613**NOTES:**
614
615The environment list consists of name value pairs that are of the form ``name =
616value``.
617
618.. _setenv:
619
620setenv - Set Environment Variables
621----------------------------------
622.. index:: setenv
623.. index:: set environment variables
624
625**CALLING SEQUENCE:**
626
627.. code-block:: c
628
629    int setenv(
630        const char *name,
631        const char *value,
632        int overwrite
633    );
634
635**STATUS CODES:**
636
637Returns 0 if successful and -1 otherwise.
638
639**DESCRIPTION:**
640
641This service adds the variable ``name`` to the environment with ``value``.  If
642``name`` is not already exist, then it is created.  If ``name`` exists and
643``overwrite`` is zero, then the previous value is not overwritten.
644
645**NOTES:**
646
647NONE
648
649.. _ctermid:
650
651ctermid - Generate Terminal Pathname
652------------------------------------
653.. index:: ctermid
654.. index:: generate terminal pathname
655
656**CALLING SEQUENCE:**
657
658.. code-block:: c
659
660    char *ctermid(
661        char *s
662    );
663
664**STATUS CODES:**
665
666Returns a pointer to a string indicating the pathname for the controlling
667terminal.
668
669**DESCRIPTION:**
670
671This service returns the name of the terminal device associated with this
672process.  If ``s`` is NULL, then a pointer to a static buffer is returned.
673Otherwise, ``s`` is assumed to have a buffer of sufficient size to contain the
674name of the controlling terminal.
675
676**NOTES:**
677
678By default on RTEMS systems, the controlling terminal is :file:`/dev/console`.
679Again this implementation is of limited meaning, but it provides true and
680useful results which should be sufficient to ease porting applications from a
681full POSIX implementation to the reduced profile supported by RTEMS.
682
683.. _ttyname:
684
685ttyname - Determine Terminal Device Name
686----------------------------------------
687.. index:: ttyname
688.. index:: determine terminal device name
689
690**CALLING SEQUENCE:**
691
692.. code-block:: c
693
694    char *ttyname(
695        int fd
696    );
697
698**STATUS CODES:**
699
700Pointer to a string containing the terminal device name or ``NULL`` is returned
701on any error.
702
703**DESCRIPTION:**
704
705This service returns a pointer to the pathname of the terminal device that is
706open on the file descriptor ``fd``.  If ``fd`` is not a valid descriptor for a
707terminal device, then NULL is returned.
708
709**NOTES:**
710
711This routine uses a static buffer.
712
713.. _ttyname_r:
714
715ttyname_r - Reentrant Determine Terminal Device Name
716----------------------------------------------------
717.. index:: ttyname_r
718.. index:: reentrant determine terminal device name
719
720**CALLING SEQUENCE:**
721
722.. code-block:: c
723
724    int ttyname_r(
725        int   fd,
726        char *name,
727        int   namesize
728    );
729
730**STATUS CODES:**
731
732This routine returns -1 and sets ``errno`` as follows:
733
734.. list-table::
735 :class: rtems-table
736
737 * - ``EBADF``
738   - If not a valid descriptor for a terminal device.
739 * - ``EINVAL``
740   - If ``name`` is ``NULL`` or ``namesize`` are insufficient.
741
742**DESCRIPTION:**
743
744This service the pathname of the terminal device that is open on the file
745descriptor ``fd``.
746
747**NOTES:**
748
749NONE
750
751.. _isatty:
752
753isatty - Determine if File Descriptor is Terminal
754-------------------------------------------------
755.. index:: isatty
756.. index:: determine if file descriptor is terminal
757
758**CALLING SEQUENCE:**
759
760.. code-block:: c
761
762    int isatty(
763        int fd
764    );
765
766**STATUS CODES:**
767
768Returns 1 if ``fd`` is a terminal device and 0 otherwise.
769
770**DESCRIPTION:**
771
772This service returns 1 if ``fd`` is an open file descriptor connected to a
773terminal and 0 otherwise.
774
775**NOTES:**
776
777.. _sysconf:
778
779sysconf - Get Configurable System Variables
780-------------------------------------------
781.. index:: sysconf
782.. index:: get configurable system variables
783
784**CALLING SEQUENCE:**
785
786.. code-block:: c
787
788    long sysconf(
789        int name
790    );
791
792**STATUS CODES:**
793
794The value returned is the actual value of the system resource.  If the
795requested configuration name is a feature flag, then 1 is returned if the
796available and 0 if it is not.  On any other error condition, -1 is returned.
797
798**DESCRIPTION:**
799
800This service is the mechanism by which an application determines values for
801system limits or options at runtime.
802
803**NOTES:**
804
805Much of the information that may be obtained via ``sysconf`` has equivalent
806macros in ``unistd.h``.  However, those macros reflect conservative limits
807which may have been altered by application configuration.
Note: See TracBrowser for help on using the repository browser.