| 1 | /* $NetBSD: spawn.h,v 1.5 2014/09/05 05:46:54 matt Exp $ */ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (c) 2008 Ed Schouten <ed@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 }; |
| 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 | } fae_data; |
| 69 | } posix_spawn_file_actions_entry_t; |
| 70 | |
| 71 | struct posix_spawn_file_actions { |
| 72 | unsigned int size; /* size of fae array */ |
| 73 | unsigned int len; /* how many slots are used */ |
| 74 | posix_spawn_file_actions_entry_t *fae; |
| 75 | }; |
| 76 | |
| 77 | typedef struct posix_spawnattr posix_spawnattr_t; |
| 78 | typedef struct posix_spawn_file_actions posix_spawn_file_actions_t; |
| 79 | |
| 80 | #define POSIX_SPAWN_RESETIDS 0x01 |
| 81 | #define POSIX_SPAWN_SETPGROUP 0x02 |
| 82 | #define POSIX_SPAWN_SETSCHEDPARAM 0x04 |
| 83 | #define POSIX_SPAWN_SETSCHEDULER 0x08 |
| 84 | #define POSIX_SPAWN_SETSIGDEF 0x10 |
| 85 | #define POSIX_SPAWN_SETSIGMASK 0x20 |
| 86 | |
| 87 | #ifdef _NETBSD_SOURCE |
| 88 | /* |
| 89 | * With this flag set, the kernel part of posix_spawn will not try to |
| 90 | * maximize parallelism, but instead the parent will wait for the child |
| 91 | * process to complete all file/scheduler actions and report back errors |
| 92 | * from that via the return value of the posix_spawn syscall. This is |
| 93 | * usefull for testing, as it can verify the generated error codes and |
| 94 | * match to the supposedly triggered failures. |
| 95 | * In general, the kernel will return from the posix_spawn syscall as |
| 96 | * early as possible, as soon as creating the new process is known to |
| 97 | * work. Errors might either be reported back via the return value in |
| 98 | * the parent, or (less explicit) by an error exit of the child |
| 99 | * process. Our test cases deal with both behaviours in the general |
| 100 | * case, but request the POSIX_SPAWN_RETURNERROR for some tests. |
| 101 | */ |
| 102 | #define POSIX_SPAWN_RETURNERROR 0x40 |
| 103 | #endif |
| 104 | |
| 105 | #endif /* !_SYS_SPAWN_H_ */ |
| 106 | |