xref: /dflybsd-src/lib/libc/sys/procctl.2 (revision acdf1ee6e01f6d399479bd25d28f8f57ff8a3ad8)
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
37*acdf1ee6SMatthew 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
53*acdf1ee6SMatthew Dillonsystem call applies certain process-related control operations to the system.
54*acdf1ee6SMatthew DillonThe
55*acdf1ee6SMatthew Dillon.Fa idtype
56*acdf1ee6SMatthew Dillonargument may be
57*acdf1ee6SMatthew Dillon.Dv P_PID
58*acdf1ee6SMatthew Dillonor
59*acdf1ee6SMatthew Dillon.Dv P_PGID ,
60*acdf1ee6SMatthew Dillonand the
61*acdf1ee6SMatthew Dillon.Fa id
62*acdf1ee6SMatthew Dillonargument is either a process id or a process group id, or 0 indicating
63*acdf1ee6SMatthew Dillonthe current process or process group.
64*acdf1ee6SMatthew Dillon.Pp
65*acdf1ee6SMatthew DillonNote that currently all functions only operate on the current process.
66*acdf1ee6SMatthew Dillon.Sh REAPER OPERATION
67*acdf1ee6SMatthew DillonThe
68*acdf1ee6SMatthew Dillon.Fn procctl
69*acdf1ee6SMatthew Dillonsystem call may be used by a process to take-over the reaping task from init
70*acdf1ee6SMatthew 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.
111*acdf1ee6SMatthew Dillon.It Dv PROC_PDEATHSIG_CTL
112*acdf1ee6SMatthew DillonThe argument is a pointer to an integer specifying the signal that should
113*acdf1ee6SMatthew Dillonbe delivered to the current process when its parent process exits.
114*acdf1ee6SMatthew DillonA value of 0 cancels any previously set signal.
115*acdf1ee6SMatthew Dillon.Pp
116*acdf1ee6SMatthew DillonAny previously set signal is automatically canceled in the child process of
117*acdf1ee6SMatthew Dillona fork() or when a suid or sgid program is exec'd.
118*acdf1ee6SMatthew Dillon.Pp
119*acdf1ee6SMatthew DillonOnly the current process pid or 0 may be specified.  Both have the same effect.
120*acdf1ee6SMatthew Dillon.It Dv PROC_PDEATHSIG_STATUS
121*acdf1ee6SMatthew DillonThe argument is a pointer to an integer variable which will be filled in
122*acdf1ee6SMatthew Dillonwith the current pdeathsig signal, or 0 if the feature is not enabled.
123*acdf1ee6SMatthew Dillon.Pp
124*acdf1ee6SMatthew DillonOnly the current process pid or 0 may be specified.  Both have the same effect.
125fc3bc286SMatthew Dillon.El
126fc3bc286SMatthew Dillon.Sh RETURN VALUES
12757874d15SSascha Wildner.Rv -std
128fc3bc286SMatthew Dillon.Pp
129fc3bc286SMatthew DillonIf a data structure is supplied, data may be read or written to it
130fc3bc286SMatthew Dillonaccording to the op code.
131fc3bc286SMatthew DillonOnly sufficient data to support the requested operation is read or
132fc3bc286SMatthew Dillonwritten.
133fc3bc286SMatthew Dillon.Sh ERRORS
134fc3bc286SMatthew DillonThe
135fc3bc286SMatthew Dillon.Fn procctl
136fc3bc286SMatthew Dillonfunction will fail when one of the following occurs:
137fc3bc286SMatthew Dillon.Bl -tag -width Er
138fc3bc286SMatthew Dillon.It Bq Er EALREADY
139fc3bc286SMatthew DillonAn attempt to acquire reaping is made but the current
140fc3bc286SMatthew Dillonprocess has already acquired the feature.
141fc3bc286SMatthew Dillon.It Bq Er ENOTCONN
142fc3bc286SMatthew DillonAn attempt to release reaping is made but the current
143fc3bc286SMatthew Dillonprocess has not currently acquired the feature.
144fc3bc286SMatthew Dillon.It Bq Er EINVAL
145fc3bc286SMatthew DillonThe operation is not supported.
146fc3bc286SMatthew Dillon.El
14757874d15SSascha Wildner.\".Sh SEE ALSO
148fc3bc286SMatthew Dillon.Sh HISTORY
149fc3bc286SMatthew DillonThe
150fc3bc286SMatthew Dillon.Fn procctl
151fc3bc286SMatthew Dillonsystem call first appeared in
152fc3bc286SMatthew Dillon.Dx 4.0 .
153fc3bc286SMatthew Dillon.Sh AUTHORS
154fc3bc286SMatthew Dillon.An -nosplit
155fc3bc286SMatthew DillonThe
156fc3bc286SMatthew Dillon.Fn procctl
157fc3bc286SMatthew Dillonsystem call was written by
158fc3bc286SMatthew Dillon.An Matthew Dillon .
159