Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: spawn.h,v 1.7 2021/11/07 13:47:49 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2008 Ed Schouten <ed (at) FreeBSD.org>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  * $FreeBSD: src/include/spawn.h,v 1.3.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $
     29  */
     30 
     31 #ifndef _SYS_SPAWN_H_
     32 #define _SYS_SPAWN_H_
     33 
     34 #include <sys/cdefs.h>
     35 #include <sys/featuretest.h>
     36 #include <sys/types.h>
     37 #include <sys/sigtypes.h>
     38 #include <sys/signal.h>
     39 #include <sys/sched.h>
     40 
     41 struct posix_spawnattr {
     42 	short			sa_flags;
     43 	pid_t			sa_pgroup;
     44 	struct sched_param	sa_schedparam;
     45 	int			sa_schedpolicy;
     46 	sigset_t		sa_sigdefault;
     47 	sigset_t		sa_sigmask;
     48 };
     49 
     50 enum fae_action { FAE_OPEN, FAE_DUP2, FAE_CLOSE, FAE_CHDIR, FAE_FCHDIR };
     51 typedef struct posix_spawn_file_actions_entry {
     52 	enum fae_action fae_action;
     53 
     54 	int fae_fildes;
     55 	union {
     56 		struct {
     57 			char *path;
     58 #define fae_path	fae_data.open.path
     59 			int oflag;
     60 #define fae_oflag	fae_data.open.oflag
     61 			mode_t mode;
     62 #define fae_mode	fae_data.open.mode
     63 		} open;
     64 		struct {
     65 			int newfildes;
     66 #define fae_newfildes	fae_data.dup2.newfildes
     67 		} dup2;
     68 		struct {
     69 			char *path;
     70 #define fae_chdir_path	fae_data.chdir.path
     71 		} chdir;
     72 	} fae_data;
     73 } posix_spawn_file_actions_entry_t;
     74 
     75 struct posix_spawn_file_actions {
     76 	unsigned int size;	/* size of fae array */
     77 	unsigned int len;	/* how many slots are used */
     78 	posix_spawn_file_actions_entry_t *fae;
     79 };
     80 
     81 typedef struct posix_spawnattr		posix_spawnattr_t;
     82 typedef struct posix_spawn_file_actions	posix_spawn_file_actions_t;
     83 
     84 #define POSIX_SPAWN_RESETIDS		0x01
     85 #define POSIX_SPAWN_SETPGROUP		0x02
     86 #define POSIX_SPAWN_SETSCHEDPARAM	0x04
     87 #define POSIX_SPAWN_SETSCHEDULER	0x08
     88 #define POSIX_SPAWN_SETSIGDEF		0x10
     89 #define POSIX_SPAWN_SETSIGMASK		0x20
     90 
     91 #ifdef _NETBSD_SOURCE
     92 /*
     93  * With this flag set, the kernel part of posix_spawn will not try to
     94  * maximize parallelism, but instead the parent will wait for the child
     95  * process to complete all file/scheduler actions and report back errors
     96  * from that via the return value of the posix_spawn syscall. This is
     97  * useful for testing, as it can verify the generated error codes and
     98  * match to the supposedly triggered failures.
     99  * In general, the kernel will return from the posix_spawn syscall as
    100  * early as possible, as soon as creating the new process is known to
    101  * work. Errors might either be reported back via the return value in
    102  * the parent, or (less explicit) by an error exit of the child
    103  * process. Our test cases deal with both behaviours in the general
    104  * case, but request the POSIX_SPAWN_RETURNERROR for some tests.
    105  */
    106 #define POSIX_SPAWN_RETURNERROR		0x40
    107 #endif
    108 
    109 #endif /* !_SYS_SPAWN_H_ */
    110