1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
|
/**
* D header file for spawn.h.
*
* Copyright: Copyright (C) 2018 by The D Language Foundation, All Rights Reserved
* Authors: Petar Kirov
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/druntime/blob/master/src/core/sys/posix/spawn.d, _spawn.d)
* Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
*/
module core.sys.posix.spawn;
/*
Based on the following system headers:
Glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/spawn.h;hb=HEAD
Bionic libc: https://android.googlesource.com/platform/bionic.git/+/master/libc/include/spawn.h
Musl libc: https://git.musl-libc.org/cgit/musl/tree/include/spawn.h
uClibc: https://git.uclibc.org/uClibc/tree/include/spawn.h
Darwin XNU:
https://opensource.apple.com/source/xnu/xnu-4570.71.2/libsyscall/wrappers/spawn/spawn.h.auto.html
https://opensource.apple.com/source/xnu/xnu-4570.71.2/bsd/sys/spawn.h.auto.html
https://github.com/opensource-apple/xnu (GitHub mirror)
FreeBSD: https://github.com/freebsd/freebsd/blob/master/include/spawn.h
NetBSD: https://github.com/NetBSD/src/blob/trunk/sys/sys/spawn.h
OpenBSD: https://github.com/openbsd/src/blob/master/include/spawn.h
DragonFlyBSD: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/include/spawn.h
Solaris: https://github.com/illumos/illumos-gate/blob/master/usr/src/head/spawn.h
*/
version (OSX) // macOS and iOS only as this API is prohibited on WatchOS and TVOS
version = Darwin;
else version (iOS)
version = Darwin;
version (Posix):
public import core.sys.posix.sys.types : mode_t, pid_t;
public import core.sys.posix.signal : sigset_t;
public import core.sys.posix.sched : sched_param;
extern(C):
@nogc:
nothrow:
@system:
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t*, int);
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t*, int, int);
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t*, int, const char*, int, mode_t);
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t*);
int posix_spawn_file_actions_init(posix_spawn_file_actions_t*);
int posix_spawnattr_destroy(posix_spawnattr_t*);
int posix_spawnattr_getflags(const posix_spawnattr_t*, short*);
int posix_spawnattr_getpgroup(const posix_spawnattr_t*, pid_t*);
version (Darwin)
{ } // Not supported
else
{
int posix_spawnattr_getschedparam(const posix_spawnattr_t*, sched_param*);
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t*, int*);
int posix_spawnattr_setschedparam(posix_spawnattr_t*, const sched_param*);
int posix_spawnattr_setschedpolicy(posix_spawnattr_t*, int);
}
int posix_spawnattr_getsigdefault(const posix_spawnattr_t*, sigset_t*);
int posix_spawnattr_getsigmask(const posix_spawnattr_t*, sigset_t*);
int posix_spawnattr_init(posix_spawnattr_t*);
int posix_spawnattr_setflags(posix_spawnattr_t*, short);
int posix_spawnattr_setpgroup(posix_spawnattr_t*, pid_t);
int posix_spawnattr_setsigdefault(posix_spawnattr_t*, const sigset_t*);
int posix_spawnattr_setsigmask(posix_spawnattr_t*, const sigset_t*);
int posix_spawn(pid_t*pid, const char* path,
const posix_spawn_file_actions_t* file_actions,
const posix_spawnattr_t* attrp,
const char** argv, const char** envp);
int posix_spawnp(pid_t* pid, const char* file,
const posix_spawn_file_actions_t* file_actions,
const posix_spawnattr_t* attrp,
const char** argv, const char** envp);
version (linux)
{
version (CRuntime_Glibc)
{
// Source: https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/spawn.h;hb=HEAD
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSIGDEF = 0x04,
POSIX_SPAWN_SETSIGMASK = 0x08,
POSIX_SPAWN_SETSCHEDPARAM = 0x10,
POSIX_SPAWN_SETSCHEDULER = 0x20
}
import core.sys.posix.config : _GNU_SOURCE;
static if (_GNU_SOURCE)
{
enum
{
POSIX_SPAWN_USEVFORK = 0x40,
POSIX_SPAWN_SETSID = 0x80
}
}
struct posix_spawnattr_t
{
short __flags;
pid_t __pgrp;
sigset_t __sd;
sigset_t __ss;
sched_param __sp;
int __policy;
int[16] __pad;
}
struct __spawn_action;
struct posix_spawn_file_actions_t
{
int __allocated;
int __used;
__spawn_action* __actions;
int[16] __pad;
}
}
else version (CRuntime_Bionic)
{
// Source: https://android.googlesource.com/platform/bionic.git/+/master/libc/include/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 1,
POSIX_SPAWN_SETPGROUP = 2,
POSIX_SPAWN_SETSIGDEF = 4,
POSIX_SPAWN_SETSIGMASK = 8,
POSIX_SPAWN_SETSCHEDPARAM = 16,
POSIX_SPAWN_SETSCHEDULER = 32
}
import core.sys.posix.config : _GNU_SOURCE;
static if (_GNU_SOURCE)
{
enum
{
POSIX_SPAWN_USEVFORK = 64,
POSIX_SPAWN_SETSID = 128
}
}
alias posix_spawnattr_t = __posix_spawnattr*;
alias posix_spawn_file_actions_t = __posix_spawn_file_actions*;
struct __posix_spawnattr;
struct __posix_spawn_file_actions;
}
else version (CRuntime_Musl)
{
// Source: https://git.musl-libc.org/cgit/musl/tree/include/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 1,
POSIX_SPAWN_SETPGROUP = 2,
POSIX_SPAWN_SETSIGDEF = 4,
POSIX_SPAWN_SETSIGMASK = 8,
POSIX_SPAWN_SETSCHEDPARAM = 16,
POSIX_SPAWN_SETSCHEDULER = 32,
POSIX_SPAWN_USEVFORK = 64,
POSIX_SPAWN_SETSID = 128
}
struct posix_spawnattr_t
{
int __flags;
pid_t __pgrp;
sigset_t __def, __mask;
int __prio, __pol;
void* __fn;
char[64 - (void*).sizeof] __pad = void;
}
struct posix_spawn_file_actions_t
{
int[2] __pad0;
void* __actions;
int[16] __pad;
}
}
else version (CRuntime_UClibc)
{
// Source: https://git.uclibc.org/uClibc/tree/include/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSIGDEF = 0x04,
POSIX_SPAWN_SETSIGMASK = 0x08,
POSIX_SPAWN_SETSCHEDPARAM = 0x10,
POSIX_SPAWN_SETSCHEDULER = 0x20
}
import core.sys.posix.config : _GNU_SOURCE;
static if (_GNU_SOURCE)
{
enum
{
POSIX_SPAWN_USEVFORK = 0x40,
}
}
struct posix_spawnattr_t
{
short __flags;
pid_t __pgrp;
sigset_t __sd;
sigset_t __ss;
sched_param __sp;
int __policy;
int[16] __pad;
}
struct __spawn_action;
struct posix_spawn_file_actions_t
{
int __allocated;
int __used;
__spawn_action* __actions;
int[16] __pad;
}
}
else
static assert(0, "Unsupported Linux libc");
}
else version (Darwin)
{
// Sources:
// https://opensource.apple.com/source/xnu/xnu-4570.71.2/libsyscall/wrappers/spawn/spawn.h.auto.html
// https://opensource.apple.com/source/xnu/xnu-4570.71.2/bsd/sys/spawn.h.auto.html
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSIGDEF = 0x04,
POSIX_SPAWN_SETSIGMASK = 0x08,
// POSIX_SPAWN_SETSCHEDPARAM = 0x10, // not supported
// POSIX_SPAWN_SETSCHEDULER = 0x20, // ditto
POSIX_SPAWN_SETEXEC = 0x40,
POSIX_SPAWN_START_SUSPENDED = 0x80,
POSIX_SPAWN_CLOEXEC_DEFAULT = 0x4000
}
alias posix_spawnattr_t = void*;
alias posix_spawn_file_actions_t = void*;
}
else version (FreeBSD)
{
// Source: https://github.com/freebsd/freebsd/blob/master/include/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSCHEDPARAM = 0x04,
POSIX_SPAWN_SETSCHEDULER = 0x08,
POSIX_SPAWN_SETSIGDEF = 0x10,
POSIX_SPAWN_SETSIGMASK = 0x20
}
alias posix_spawnattr_t = void*;
alias posix_spawn_file_actions_t = void*;
}
else version (NetBSD)
{
// Source: https://github.com/NetBSD/src/blob/trunk/sys/sys/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSCHEDPARAM = 0x04,
POSIX_SPAWN_SETSCHEDULER = 0x08,
POSIX_SPAWN_SETSIGDEF = 0x10,
POSIX_SPAWN_SETSIGMASK = 0x20,
POSIX_SPAWN_RETURNERROR = 0x40 // NetBSD specific
}
struct posix_spawnattr
{
short sa_flags;
pid_t sa_pgroup;
sched_param sa_schedparam;
int sa_schedpolicy;
sigset_t sa_sigdefault;
sigset_t sa_sigmask;
}
struct posix_spawn_file_actions_entry_t;
struct posix_spawn_file_actions
{
uint size;
uint len;
posix_spawn_file_actions_entry_t* fae;
}
alias posix_spawnattr_t = posix_spawnattr;
alias posix_spawn_file_actions_t = posix_spawn_file_actions;
}
else version (OpenBSD)
{
// Source: https://github.com/openbsd/src/blob/master/include/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSCHEDPARAM = 0x04,
POSIX_SPAWN_SETSCHEDULER = 0x08,
POSIX_SPAWN_SETSIGDEF = 0x10,
POSIX_SPAWN_SETSIGMASK = 0x20
}
alias posix_spawnattr_t = __posix_spawnattr*;
alias posix_spawn_file_actions_t = __posix_spawn_file_actions*;
struct __posix_spawnattr;
struct __posix_spawn_file_actions;
}
else version (DragonFlyBSD)
{
// Source: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/include/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSCHEDPARAM = 0x04,
POSIX_SPAWN_SETSCHEDULER = 0x08,
POSIX_SPAWN_SETSIGDEF = 0x10,
POSIX_SPAWN_SETSIGMASK = 0x20
}
alias posix_spawnattr_t = __posix_spawnattr*;
alias posix_spawn_file_actions_t = __posix_spawn_file_actions*;
struct __posix_spawnattr;
struct __posix_spawn_file_actions;
}
else version (Solaris)
{
// Source: https://github.com/illumos/illumos-gate/blob/master/usr/src/head/spawn.h
enum
{
POSIX_SPAWN_RESETIDS = 0x01,
POSIX_SPAWN_SETPGROUP = 0x02,
POSIX_SPAWN_SETSIGDEF = 0x04,
POSIX_SPAWN_SETSIGMASK = 0x08,
POSIX_SPAWN_SETSCHEDPARAM = 0x10,
POSIX_SPAWN_SETSCHEDULER = 0x20,
}
version (none)
{
// Non-portable Solaris extensions.
enum
{
POSIX_SPAWN_SETSIGIGN_NP = 0x0800,
POSIX_SPAWN_NOSIGCHLD_NP = 0x1000,
POSIX_SPAWN_WAITPID_NP = 0x2000,
POSIX_SPAWN_NOEXECERR_NP = 0x4000,
}
}
struct posix_spawnattr_t
{
void* __spawn_attrp;
}
struct posix_spawn_file_actions_t
{
void* __file_attrp;
}
version (none)
{
// Non-portable Solaris extensions.
alias boolean_t = int;
int posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t* file_actions,
int lowfiledes);
int posix_spawn_pipe_np(pid_t* pidp, int* fdp, const char* cmd, boolean_t write,
posix_spawn_file_actions_t* fact,
posix_spawnattr_t* attr);
int posix_spawnattr_getsigignore_np(const posix_spawnattr_t* attr, sigset_t* sigignore);
int posix_spawnattr_setsigignore_np(posix_spawnattr_t* attr, const sigset_t* sigignore);
}
}
else
static assert(0, "Unsupported OS");
|