source: rtems-docs/posix_users/process_environment.rst @ fa70fd2

4.115
Last change on this file since fa70fd2 was fa70fd2, checked in by Chris Johns <chrisj@…>, on 02/26/16 at 07:22:07

POSIX User clean up.

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