119f52532Smartin /*-
219f52532Smartin * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
319f52532Smartin * All rights reserved.
419f52532Smartin *
519f52532Smartin * Redistribution and use in source and binary forms, with or without
619f52532Smartin * modification, are permitted provided that the following conditions
719f52532Smartin * are met:
819f52532Smartin * 1. Redistributions of source code must retain the above copyright
919f52532Smartin * notice, this list of conditions and the following disclaimer.
1019f52532Smartin * 2. Redistributions in binary form must reproduce the above copyright
1119f52532Smartin * notice, this list of conditions and the following disclaimer in the
1219f52532Smartin * documentation and/or other materials provided with the distribution.
1319f52532Smartin *
1419f52532Smartin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1519f52532Smartin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1619f52532Smartin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1719f52532Smartin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1819f52532Smartin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1919f52532Smartin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2019f52532Smartin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2119f52532Smartin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2219f52532Smartin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2319f52532Smartin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2419f52532Smartin * SUCH DAMAGE.
2519f52532Smartin */
2619f52532Smartin
2719f52532Smartin #include <sys/cdefs.h>
28*b450cd5bSmartin __RCSID("$NetBSD: posix_spawn_sched.c,v 1.2 2014/02/02 14:54:39 martin Exp $");
2919f52532Smartin
3019f52532Smartin #include "namespace.h"
3119f52532Smartin
3219f52532Smartin #include <errno.h>
3319f52532Smartin #include <fcntl.h>
3419f52532Smartin #include <sched.h>
3519f52532Smartin #include <signal.h>
3619f52532Smartin #include <stdlib.h>
3719f52532Smartin #include <string.h>
3819f52532Smartin #include <unistd.h>
3919f52532Smartin #include <spawn.h>
4019f52532Smartin
4119f52532Smartin /*
4219f52532Smartin * Spawn attributes
4319f52532Smartin */
4419f52532Smartin
4519f52532Smartin int
posix_spawnattr_init(posix_spawnattr_t * ret)4619f52532Smartin posix_spawnattr_init(posix_spawnattr_t *ret)
4719f52532Smartin {
4819f52532Smartin if (ret == NULL)
4919f52532Smartin return -1;
5019f52532Smartin
5119f52532Smartin memset(ret, 0, sizeof(posix_spawnattr_t));
52*b450cd5bSmartin return 0;
5319f52532Smartin }
5419f52532Smartin
5519f52532Smartin int
posix_spawnattr_destroy(posix_spawnattr_t * sa)5619f52532Smartin posix_spawnattr_destroy(posix_spawnattr_t *sa)
5719f52532Smartin {
5819f52532Smartin if (sa == NULL)
5919f52532Smartin return -1;
6019f52532Smartin
61*b450cd5bSmartin return 0;
6219f52532Smartin }
6319f52532Smartin
6419f52532Smartin int
posix_spawnattr_getflags(const posix_spawnattr_t * __restrict sa,short * __restrict flags)6519f52532Smartin posix_spawnattr_getflags(const posix_spawnattr_t * __restrict sa,
6619f52532Smartin short * __restrict flags)
6719f52532Smartin {
6819f52532Smartin *flags = sa->sa_flags;
69*b450cd5bSmartin return 0;
7019f52532Smartin }
7119f52532Smartin
7219f52532Smartin int
posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict sa,pid_t * __restrict pgroup)7319f52532Smartin posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict sa,
7419f52532Smartin pid_t * __restrict pgroup)
7519f52532Smartin {
7619f52532Smartin *pgroup = sa->sa_pgroup;
77*b450cd5bSmartin return 0;
7819f52532Smartin }
7919f52532Smartin
8019f52532Smartin int
posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict sa,struct sched_param * __restrict schedparam)8119f52532Smartin posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict sa,
8219f52532Smartin struct sched_param * __restrict schedparam)
8319f52532Smartin {
8419f52532Smartin *schedparam = sa->sa_schedparam;
85*b450cd5bSmartin return 0;
8619f52532Smartin }
8719f52532Smartin
8819f52532Smartin int
posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict sa,int * __restrict schedpolicy)8919f52532Smartin posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict sa,
9019f52532Smartin int * __restrict schedpolicy)
9119f52532Smartin {
9219f52532Smartin *schedpolicy = sa->sa_schedpolicy;
93*b450cd5bSmartin return 0;
9419f52532Smartin }
9519f52532Smartin
9619f52532Smartin int
posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict sa,sigset_t * __restrict sigdefault)9719f52532Smartin posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict sa,
9819f52532Smartin sigset_t * __restrict sigdefault)
9919f52532Smartin {
10019f52532Smartin *sigdefault = sa->sa_sigdefault;
101*b450cd5bSmartin return 0;
10219f52532Smartin }
10319f52532Smartin
10419f52532Smartin int
posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa,sigset_t * __restrict sigmask)10519f52532Smartin posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa,
10619f52532Smartin sigset_t * __restrict sigmask)
10719f52532Smartin {
10819f52532Smartin *sigmask = sa->sa_sigmask;
109*b450cd5bSmartin return 0;
11019f52532Smartin }
11119f52532Smartin
11219f52532Smartin int
posix_spawnattr_setflags(posix_spawnattr_t * sa,short flags)11319f52532Smartin posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags)
11419f52532Smartin {
11519f52532Smartin sa->sa_flags = flags;
116*b450cd5bSmartin return 0;
11719f52532Smartin }
11819f52532Smartin
11919f52532Smartin int
posix_spawnattr_setpgroup(posix_spawnattr_t * sa,pid_t pgroup)12019f52532Smartin posix_spawnattr_setpgroup(posix_spawnattr_t *sa, pid_t pgroup)
12119f52532Smartin {
12219f52532Smartin sa->sa_pgroup = pgroup;
123*b450cd5bSmartin return 0;
12419f52532Smartin }
12519f52532Smartin
12619f52532Smartin int
posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict sa,const struct sched_param * __restrict schedparam)12719f52532Smartin posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict sa,
12819f52532Smartin const struct sched_param * __restrict schedparam)
12919f52532Smartin {
13019f52532Smartin sa->sa_schedparam = *schedparam;
131*b450cd5bSmartin return 0;
13219f52532Smartin }
13319f52532Smartin
13419f52532Smartin int
posix_spawnattr_setschedpolicy(posix_spawnattr_t * sa,int schedpolicy)13519f52532Smartin posix_spawnattr_setschedpolicy(posix_spawnattr_t *sa, int schedpolicy)
13619f52532Smartin {
13719f52532Smartin sa->sa_schedpolicy = schedpolicy;
138*b450cd5bSmartin return 0;
13919f52532Smartin }
14019f52532Smartin
14119f52532Smartin int
posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict sa,const sigset_t * __restrict sigdefault)14219f52532Smartin posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict sa,
14319f52532Smartin const sigset_t * __restrict sigdefault)
14419f52532Smartin {
14519f52532Smartin sa->sa_sigdefault = *sigdefault;
146*b450cd5bSmartin return 0;
14719f52532Smartin }
14819f52532Smartin
14919f52532Smartin int
posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict sa,const sigset_t * __restrict sigmask)15019f52532Smartin posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict sa,
15119f52532Smartin const sigset_t * __restrict sigmask)
15219f52532Smartin {
15319f52532Smartin sa->sa_sigmask = *sigmask;
154*b450cd5bSmartin return 0;
15519f52532Smartin }
156