xref: /dflybsd-src/lib/libc/sys/procctl.2 (revision 3856b4349e5085541ea478c27f7a5568881d43b9)
1fc3bc286SMatthew Dillon.\"
2fc3bc286SMatthew Dillon.\" Copyright (c) 2014
3fc3bc286SMatthew Dillon.\"	The DragonFly Project.  All rights reserved.
4fc3bc286SMatthew Dillon.\"
5fc3bc286SMatthew Dillon.\" Redistribution and use in source and binary forms, with or without
6fc3bc286SMatthew Dillon.\" modification, are permitted provided that the following conditions
7fc3bc286SMatthew Dillon.\" are met:
8fc3bc286SMatthew Dillon.\"
9fc3bc286SMatthew Dillon.\" 1. Redistributions of source code must retain the above copyright
10fc3bc286SMatthew Dillon.\"    notice, this list of conditions and the following disclaimer.
11fc3bc286SMatthew Dillon.\" 2. Redistributions in binary form must reproduce the above copyright
12fc3bc286SMatthew Dillon.\"    notice, this list of conditions and the following disclaimer in
13fc3bc286SMatthew Dillon.\"    the documentation and/or other materials provided with the
14fc3bc286SMatthew Dillon.\"    distribution.
15fc3bc286SMatthew Dillon.\" 3. Neither the name of The DragonFly Project nor the names of its
16fc3bc286SMatthew Dillon.\"    contributors may be used to endorse or promote products derived
17fc3bc286SMatthew Dillon.\"    from this software without specific, prior written permission.
18fc3bc286SMatthew Dillon.\"
19fc3bc286SMatthew Dillon.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20fc3bc286SMatthew Dillon.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21fc3bc286SMatthew Dillon.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22fc3bc286SMatthew Dillon.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
23fc3bc286SMatthew Dillon.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24fc3bc286SMatthew Dillon.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25fc3bc286SMatthew Dillon.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26fc3bc286SMatthew Dillon.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27fc3bc286SMatthew Dillon.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28fc3bc286SMatthew Dillon.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29fc3bc286SMatthew Dillon.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30fc3bc286SMatthew Dillon.\" SUCH DAMAGE.
31fc3bc286SMatthew Dillon.\"
32a1ebcbc6SSascha Wildner.Dd December 2, 2014
33fc3bc286SMatthew Dillon.Dt PROCCTL 2
34fc3bc286SMatthew Dillon.Os
35fc3bc286SMatthew Dillon.Sh NAME
36fc3bc286SMatthew Dillon.Nm procctl
37acdf1ee6SMatthew Dillon.Nd control reaping of sub-processes and other functions
38fc3bc286SMatthew Dillon.Sh LIBRARY
39fc3bc286SMatthew Dillon.Lb libc
40fc3bc286SMatthew Dillon.Sh SYNOPSIS
41a1ebcbc6SSascha Wildner.In sys/types.h
42fc3bc286SMatthew Dillon.In sys/procctl.h
43fc3bc286SMatthew Dillon.Ft int
44fc3bc286SMatthew Dillon.Fo procctl
45fc3bc286SMatthew Dillon.Fa "idtype_t idtype"
46fc3bc286SMatthew Dillon.Fa "id_t id"
47fc3bc286SMatthew Dillon.Fa "int cmd"
48fc3bc286SMatthew Dillon.Fa "void *data"
49fc3bc286SMatthew Dillon.Fc
50fc3bc286SMatthew Dillon.Sh DESCRIPTION
51fc3bc286SMatthew DillonThe
52fc3bc286SMatthew Dillon.Fn procctl
53acdf1ee6SMatthew Dillonsystem call applies certain process-related control operations to the system.
54acdf1ee6SMatthew DillonThe
55acdf1ee6SMatthew Dillon.Fa idtype
56acdf1ee6SMatthew Dillonargument may be
57acdf1ee6SMatthew Dillon.Dv P_PID
58acdf1ee6SMatthew Dillonor
59acdf1ee6SMatthew Dillon.Dv P_PGID ,
60acdf1ee6SMatthew Dillonand the
61acdf1ee6SMatthew Dillon.Fa id
62acdf1ee6SMatthew Dillonargument is either a process id or a process group id, or 0 indicating
63acdf1ee6SMatthew Dillonthe current process or process group.
64acdf1ee6SMatthew Dillon.Pp
65acdf1ee6SMatthew DillonNote that currently all functions only operate on the current process.
66acdf1ee6SMatthew Dillon.Sh REAPER OPERATION
67acdf1ee6SMatthew DillonThe
68acdf1ee6SMatthew Dillon.Fn procctl
69acdf1ee6SMatthew Dillonsystem call may be used by a process to take-over the reaping task from init
70acdf1ee6SMatthew Dillonfor any forked sub-process, recursively (for all children thereafter) which
71fc3bc286SMatthew Dillonwould otherwise reparent to init.
72fc3bc286SMatthew DillonThis allows a chain of control to be maintained no matter what the
73fc3bc286SMatthew Dillonsub-process does.
74fc3bc286SMatthew Dillon.Pp
75fc3bc286SMatthew DillonAny process may become a reaper for its sub-processes.
76fc3bc286SMatthew DillonThe feature may also be used recursively, or independently, to
77fc3bc286SMatthew Dilloncreate reaping domains or sub-domains.
78fc3bc286SMatthew Dillon.Pp
79fc3bc286SMatthew DillonThis call is typically used by service monitoring programs, jails, or
80fc3bc286SMatthew Dillonchroots to ensure that the underlying services cannot get away from under
81fc3bc286SMatthew Dillonthe monitor.
82fc3bc286SMatthew Dillon.Sh CONTROL OPERATIONS
83fc3bc286SMatthew DillonThe following operations are defined in
84fc3bc286SMatthew Dillon.In sys/procctl.h :
85fc3bc286SMatthew Dillon.Bl -tag -width indent
86fc3bc286SMatthew Dillon.It Dv PROC_REAP_ACQUIRE
87fc3bc286SMatthew DillonBecome a reaper for all sub-processes forked after the call returns.
88fc3bc286SMatthew DillonThe data argument is ignored and can be NULL.
89fc3bc286SMatthew Dillon.It Dv PROC_REAP_RELEASE
90fc3bc286SMatthew DillonRelease reaping duties, reaping returns to normal operation.
91fc3bc286SMatthew DillonThe data argument is ignored and can be NULL.
92fc3bc286SMatthew Dillon.It Dv PROC_REAP_STATUS
93fc3bc286SMatthew DillonRequest status.
94fc3bc286SMatthew DillonThe supplied data structure is loaded with the current reaper status.
95fc3bc286SMatthew DillonThe data argument may be NULL, which can be used to test whether
96a0cfb174SSascha Wildnerthe system call exists or not (assuming you catch
97a0cfb174SSascha Wildner.Er ENOSYS ) .
98fc3bc286SMatthew DillonSee the include file for more information.
99fc3bc286SMatthew Dillon.Pp
100fc3bc286SMatthew DillonCurrent status flags, indicating whether reaping is acquired.
101fc3bc286SMatthew DillonIf reaping is acquired additional data will be returned.
102fc3bc286SMatthew Dillon.Pp
103fc3bc286SMatthew DillonWhen reaping is acquired, the first running pid under the reaper
104fc3bc286SMatthew Dillonis also loaded into the data structure, or -1 if there are none
105fc3bc286SMatthew Dillonrunning.
106fc3bc286SMatthew DillonCallers wishing to destroy all processes under management can
107fc3bc286SMatthew Dillonkill the process in question, waitpid it, and loop until no processes
108fc3bc286SMatthew Dillonremain.
1091ef3b4caSSascha WildnerThis is guaranteed to ultimately irradicate everything that was directly
110fc3bc286SMatthew Dillonor indirectly started under the reaper.
111acdf1ee6SMatthew Dillon.It Dv PROC_PDEATHSIG_CTL
112acdf1ee6SMatthew DillonThe argument is a pointer to an integer specifying the signal that should
113acdf1ee6SMatthew Dillonbe delivered to the current process when its parent process exits.
114acdf1ee6SMatthew DillonA value of 0 cancels any previously set signal.
115acdf1ee6SMatthew Dillon.Pp
116acdf1ee6SMatthew DillonAny previously set signal is automatically canceled in the child process of
117*3856b434SSascha Wildnera
118*3856b434SSascha Wildner.Fn fork
119*3856b434SSascha Wildneror when a suid or sgid program is exec'd.
120acdf1ee6SMatthew Dillon.Pp
121acdf1ee6SMatthew DillonOnly the current process pid or 0 may be specified.  Both have the same effect.
122acdf1ee6SMatthew Dillon.It Dv PROC_PDEATHSIG_STATUS
123acdf1ee6SMatthew DillonThe argument is a pointer to an integer variable which will be filled in
124acdf1ee6SMatthew Dillonwith the current pdeathsig signal, or 0 if the feature is not enabled.
125acdf1ee6SMatthew Dillon.Pp
126acdf1ee6SMatthew DillonOnly the current process pid or 0 may be specified.  Both have the same effect.
127fc3bc286SMatthew Dillon.El
128fc3bc286SMatthew Dillon.Sh RETURN VALUES
12957874d15SSascha Wildner.Rv -std
130fc3bc286SMatthew Dillon.Pp
131fc3bc286SMatthew DillonIf a data structure is supplied, data may be read or written to it
132fc3bc286SMatthew Dillonaccording to the op code.
133fc3bc286SMatthew DillonOnly sufficient data to support the requested operation is read or
134fc3bc286SMatthew Dillonwritten.
135fc3bc286SMatthew Dillon.Sh ERRORS
136fc3bc286SMatthew DillonThe
137fc3bc286SMatthew Dillon.Fn procctl
138fc3bc286SMatthew Dillonfunction will fail when one of the following occurs:
139fc3bc286SMatthew Dillon.Bl -tag -width Er
140fc3bc286SMatthew Dillon.It Bq Er EALREADY
141fc3bc286SMatthew DillonAn attempt to acquire reaping is made but the current
142fc3bc286SMatthew Dillonprocess has already acquired the feature.
143fc3bc286SMatthew Dillon.It Bq Er ENOTCONN
144fc3bc286SMatthew DillonAn attempt to release reaping is made but the current
145fc3bc286SMatthew Dillonprocess has not currently acquired the feature.
146fc3bc286SMatthew Dillon.It Bq Er EINVAL
147fc3bc286SMatthew DillonThe operation is not supported.
148fc3bc286SMatthew Dillon.El
14957874d15SSascha Wildner.\".Sh SEE ALSO
150fc3bc286SMatthew Dillon.Sh HISTORY
151fc3bc286SMatthew DillonThe
152fc3bc286SMatthew Dillon.Fn procctl
153fc3bc286SMatthew Dillonsystem call first appeared in
154fc3bc286SMatthew Dillon.Dx 4.0 .
155fc3bc286SMatthew Dillon.Sh AUTHORS
156fc3bc286SMatthew Dillon.An -nosplit
157fc3bc286SMatthew DillonThe
158fc3bc286SMatthew Dillon.Fn procctl
159fc3bc286SMatthew Dillonsystem call was written by
160fc3bc286SMatthew Dillon.An Matthew Dillon .
161