1.\" Copyright (c) 2018 Mariusz Zaborski <oshogbo@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd November 15, 2021
26.Dt LIBCASPER 3
27.Os
28.Sh NAME
29.Nm CREATE_SERVICE
30.Nd "casper service declaration macro"
31.Sh LIBRARY
32.Lb libcasper
33.Sh SYNOPSIS
34.In sys/nv.h
35.In libcasper.h
36.In libcasper_service.h
37.Bd -literal
38typedef int service_limit_func_t(const nvlist_t *, const nvlist_t *);
39
40typedef int service_command_func_t(const char *, const nvlist_t *, nvlist_t *,
41    nvlist_t *);
42
43.Ed
44.Fn CREATE_SERVICE "name" "limit_func" "command_func" "flags"
45.Sh DESCRIPTION
46The
47.Nm CREATE_SERVICE
48macro is used to create a new casper service.
49The
50.Fa name
51is a string containing the service name, which will be used in the
52.Xr cap_service_open 3 ,
53function to identify it.
54.Pp
55The
56.Fa limit_func
57is a function of type
58.Li service_limit_func_t
59where the first argument of the function contains an
60.Xr nvlist 9 ,
61old service limits and
62the second argument contains the new limits.
63If the service was not limited then the old limits will be set to
64.Dv NULL .
65This function must not allow the extension of service limits.
66The
67.Fa command_func
68is a function of type
69.Li service_command_func_t
70where the first argument is the name of the command that should be executed.
71The first
72.Xr nvlist 9
73contains the current limits and the second contains an
74.Xr nvlist 9
75with the current request.
76The last argument contains a return value
77.Xr nvlist 9
78which contains the response from casper.
79.Pp
80The
81.Fa flags
82argument defines the limits of the service.
83The supported flags are:
84.Bl -ohang -offset indent
85.It CASPER_SERVICE_STDIO
86The casper service has access to the stdio descriptors from the process it was
87spawned from.
88.It CASPER_SERVICE_FD
89The casper service has access to all of the descriptors,
90besides the stdio descriptors,
91from the process it was spawned from.
92.It CASPER_SERVICE_NO_UNIQ_LIMITS
93The whole casper communication is using an
94.Xr nvlist 9
95with the
96.Dv NV_FLAG_NO_UNIQUE
97flag.
98.El
99.Sh SEE ALSO
100.Xr cap_enter 2 ,
101.Xr libcasper 3 ,
102.Xr capsicum 4 ,
103.Xr nv 9
104.Sh HISTORY
105The
106.Nm libcasper
107library first appeared in
108.Fx 10.3 .
109.Sh AUTHORS
110The
111.Nm libcasper
112library was implemented by
113.An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
114under sponsorship from the FreeBSD Foundation.
115The
116.Nm libcasper
117new architecture was implemented by
118.An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org
119.
120