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