chiark / gitweb /
New "shutdown" builtin service for terminating uservd. setenv emulation using putenv...
[userv.git] / spec.html / ch-envir.html
1 <html><head>
2 <title>User service daemon and client specification - Execution environment of the service program</title>
3 <link rev=made href="mailto:ian@davenant.greenend.org.uk">
4 </head><body>
5 <h1>
6 User service daemon and client specification - chapter 3<br>
7 Execution environment of the service program
8 </h1>
9
10 The daemon which is handling the service user side of things will read
11 configuration files to decide what to do.  If it decides to allow the
12 service to be provided it will fork a subprocess to execute the
13 service.<P>
14
15 The service will have no controlling terminal, but it will be a
16 process group leader.<P>
17
18 If the client is killed or times out or a file or descriptor being
19 read or written by the client process gets an error then the service
20 will be disconnected from the client.  The client will return an exit
21 status of 255 and some the service's pipes may be closed at the other
22 end.  The service will become a child of <kbd>init</kbd>.  The service may
23 well not notice the disconnection, though writing to a pipe after this
24 may produce a <kbd>SIGPIPE</kbd> and the facility exists to have a
25 <kbd>SIGHUP</kbd> sent to the service on disconnection.
26 <hr>
27 <h2><A name="s3.1">
28 3.1 File descriptors
29 </A></h2>
30
31 The service program's standard filedescriptors, and possibly other
32 file descriptors, will be connected to pipes or to
33 <kbd>/dev/null</kbd>.  The <kbd>userv</kbd> client/daemon pair will arrange
34 that data is copied between the files or file descriptors specified to
35 to the client by the caller and these these pipes.<P>
36
37 Pipes which may be written to will be closed if a write error occurs
38 on the corresponding client-side file or descriptor, which may result
39 in a <kbd>SIGPIPE</kbd> in the service program; pipes open for reading
40 will get <kbd>EOF</kbd> if the client-side file descriptor gets <kbd>EOF</kbd>
41 or an error.<P>
42
43 If the service closes one of its reading file descriptors the writing
44 end of the corresponding pipe will generate a <kbd>SIGPIPE</kbd> when
45 attempts are made by the client/daemon pair to write to it.  This will
46 not be considered an error; rather, the relevant pipe will be
47 discarded and the corresponding file or file descriptor held by the
48 client will be closed.<P>
49
50 Likewise, if one of the file descriptors held by the client for
51 writing by the service is a pipe whose other end is closed by the
52 caller then the client/daemon pair will see an error when trying to
53 copy data provided by the service.  This too will not be considered an
54 error; rather, the pipe correspondong to that descriptor will be
55 closed and any further writes will cause the service to get a
56 <kbd>SIGPIPE</kbd>.<P>
57
58 Note that not all write errors or broken pipes on file descriptors may
59 be visible to the service, since buffered data may be discarded by the
60 operating system and there will be a finite interval between the error
61 happening and the service being disconnected from the client or the
62 next write causing a <kbd>SIGPIPE</kbd>.<P>
63
64 Read errors on file descriptors (and disconnection) will only be
65 visible to the service and distinguishable from normal end of file if
66 <kbd>disconnect-hup</kbd> is in effect.<P>
67
68 Read and write errors (other than broken pipes, as described above)
69 will always be visible to the caller; they are system errors, and will
70 therefore cause the client to print an error message to stderr and
71 return with an exit status of 255.<P>
72
73 If the main service program process exits while it still has running
74 children any file descriptors held by those children can remain open,
75 depending on the use of <code>wait</code>, <code>nowait</code> or <code>close</code> for the
76 relevant file descriptor in the client's arguments.  By default
77 writing filedescriptors remain open and the client will wait for them
78 to be closed at the service end, and reading file descriptors are
79 closed immediately.  These leftover child processes will not get a any
80 <kbd>SIGHUP</kbd> even if a read or write error occurs or the client
81 disconnects before then.
82 <hr>
83 <h2><A name="s3.2">
84 3.2 Environment
85 </A></h2>
86
87 The service will have some information in environment variables:
88 <dl compact>
89 <dt><code>USERV_USER</code><dd>The login name of the calling user.  If the <kbd>LOGNAME</kbd> variable is
90 set (or, if that is unset, if the <kbd>USER</kbd> variable is set) in the
91 environment passed to the client by the caller then the password entry
92 for that login name will be looked up; if that password entry's uid is
93 the same as that of the calling process then that login name will be
94 used, otherwise (or if neither <kbd>LOGNAME</kbd> nor <kbd>USER</kbd> is set)
95 the calling process's uid will be looked up to determine their login
96 name (and if this lookup fails then the service will not be invoked).
97 <dt><code>USERV_UID</code><dd>The uid of the calling process.
98 <dt><code>USERV_GID</code><dd>The gid and supplementary group list of the calling process: first the
99 group in gid and then those in the supplementary group list, in
100 decimal, separated by spaces.
101 <dt><code>USERV_GROUP</code><dd>The group names of the calling process, listed in the same way as the
102 ids are in <kbd>USERV_GID</kbd>.  If no name can be found for any of the
103 calling process's group(s) then the service will not be invoked.
104 <dt><code>USERV_CWD</code><dd>The client's current working directory name (this directory may not be
105 accessible to the service).  If it could not be determined or the
106 <kbd>--hidecwd</kbd> flag was used then this variable will be set to an
107 empty string (this is not considered an error).
108 <dt><code>USERV_SERVICE</code><dd>The service name requested by the caller.
109 <dt><code>USERV_U_</code><var>name</var><code></code><dd>The value supplied to the client by the caller using -D<var>name</var>.
110 </dl>
111
112
113 <kbd>HOME</kbd>, <kbd>PATH</kbd>, <kbd>SHELL</kbd>, <kbd>LOGNAME</kbd> and <kbd>USER</kbd>
114 will be set appropriately (according to the details of the service
115 user).
116
117 <hr>
118 User service daemon and client specification
119 - <A href="index.html#copyright"><kbd>userv</kbd> is Copyright 1996-1999 Ian Jackson.</A>
120 <br>
121 <A href="index.html#toc">Contents</A>; <A href="index.html#abstract">abstract</A>; <A href="ch-config.html">next</A>; <A href="ch-client.html">back</A>.
122 <br>
123 <address>0.62<br>
124 Ian Jackson <A href="mailto:ian@davenant.greenend.org.uk">ian@davenant.greenend.org.uk</A></address>
125 </body></html>