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

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

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