xref: /minix/lib/libc/gen/posix_spawn_sched.c (revision 0a6a1f1d)
1 /*-
2  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __RCSID("$NetBSD: posix_spawn_sched.c,v 1.2 2014/02/02 14:54:39 martin Exp $");
29 
30 #include "namespace.h"
31 
32 #include <errno.h>
33 #include <fcntl.h>
34 #include <sched.h>
35 #include <signal.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.h>
39 #include <spawn.h>
40 
41 /*
42  * Spawn attributes
43  */
44 
45 int
posix_spawnattr_init(posix_spawnattr_t * ret)46 posix_spawnattr_init(posix_spawnattr_t *ret)
47 {
48 	if (ret == NULL)
49 		return -1;
50 
51 	memset(ret, 0, sizeof(posix_spawnattr_t));
52 	return 0;
53 }
54 
55 int
posix_spawnattr_destroy(posix_spawnattr_t * sa)56 posix_spawnattr_destroy(posix_spawnattr_t *sa)
57 {
58 	if (sa == NULL)
59 		return -1;
60 
61 	return 0;
62 }
63 
64 int
posix_spawnattr_getflags(const posix_spawnattr_t * __restrict sa,short * __restrict flags)65 posix_spawnattr_getflags(const posix_spawnattr_t * __restrict sa,
66     short * __restrict flags)
67 {
68 	*flags = sa->sa_flags;
69 	return 0;
70 }
71 
72 int
posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict sa,pid_t * __restrict pgroup)73 posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict sa,
74     pid_t * __restrict pgroup)
75 {
76 	*pgroup = sa->sa_pgroup;
77 	return 0;
78 }
79 
80 int
posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict sa,struct sched_param * __restrict schedparam)81 posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict sa,
82     struct sched_param * __restrict schedparam)
83 {
84 	*schedparam = sa->sa_schedparam;
85 	return 0;
86 }
87 
88 int
posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict sa,int * __restrict schedpolicy)89 posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict sa,
90     int * __restrict schedpolicy)
91 {
92 	*schedpolicy = sa->sa_schedpolicy;
93 	return 0;
94 }
95 
96 int
posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict sa,sigset_t * __restrict sigdefault)97 posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict sa,
98     sigset_t * __restrict sigdefault)
99 {
100 	*sigdefault = sa->sa_sigdefault;
101 	return 0;
102 }
103 
104 int
posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa,sigset_t * __restrict sigmask)105 posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa,
106     sigset_t * __restrict sigmask)
107 {
108 	*sigmask = sa->sa_sigmask;
109 	return 0;
110 }
111 
112 int
posix_spawnattr_setflags(posix_spawnattr_t * sa,short flags)113 posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags)
114 {
115 	sa->sa_flags = flags;
116 	return 0;
117 }
118 
119 int
posix_spawnattr_setpgroup(posix_spawnattr_t * sa,pid_t pgroup)120 posix_spawnattr_setpgroup(posix_spawnattr_t *sa, pid_t pgroup)
121 {
122 	sa->sa_pgroup = pgroup;
123 	return 0;
124 }
125 
126 int
posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict sa,const struct sched_param * __restrict schedparam)127 posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict sa,
128     const struct sched_param * __restrict schedparam)
129 {
130 	sa->sa_schedparam = *schedparam;
131 	return 0;
132 }
133 
134 int
posix_spawnattr_setschedpolicy(posix_spawnattr_t * sa,int schedpolicy)135 posix_spawnattr_setschedpolicy(posix_spawnattr_t *sa, int schedpolicy)
136 {
137 	sa->sa_schedpolicy = schedpolicy;
138 	return 0;
139 }
140 
141 int
posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict sa,const sigset_t * __restrict sigdefault)142 posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict sa,
143     const sigset_t * __restrict sigdefault)
144 {
145 	sa->sa_sigdefault = *sigdefault;
146 	return 0;
147 }
148 
149 int
posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict sa,const sigset_t * __restrict sigmask)150 posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict sa,
151     const sigset_t * __restrict sigmask)
152 {
153 	sa->sa_sigmask = *sigmask;
154 	return 0;
155 }
156