spawn.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2020, Nico Weber <thakis@chromium.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. /* posix_spawn and friends
  7. *
  8. * values from POSIX standard unix specification
  9. *
  10. * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/spawn.h.html
  11. */
  12. #pragma once
  13. #include <sched.h>
  14. #include <signal.h>
  15. #include <sys/cdefs.h>
  16. #include <sys/types.h>
  17. __BEGIN_DECLS
  18. enum {
  19. POSIX_SPAWN_RESETIDS = 1 << 0,
  20. POSIX_SPAWN_SETPGROUP = 1 << 1,
  21. POSIX_SPAWN_SETSCHEDPARAM = 1 << 2,
  22. POSIX_SPAWN_SETSCHEDULER = 1 << 3,
  23. POSIX_SPAWN_SETSIGDEF = 1 << 4,
  24. POSIX_SPAWN_SETSIGMASK = 1 << 5,
  25. POSIX_SPAWN_SETSID = 1 << 6,
  26. };
  27. #define POSIX_SPAWN_SETSID POSIX_SPAWN_SETSID
  28. struct posix_spawn_file_actions_state;
  29. typedef struct {
  30. struct posix_spawn_file_actions_state* state;
  31. } posix_spawn_file_actions_t;
  32. typedef struct {
  33. short flags;
  34. pid_t pgroup;
  35. struct sched_param schedparam;
  36. int schedpolicy;
  37. sigset_t sigdefault;
  38. sigset_t sigmask;
  39. } posix_spawnattr_t;
  40. int posix_spawn(pid_t*, char const*, posix_spawn_file_actions_t const*, posix_spawnattr_t const*, char* const argv[], char* const envp[]);
  41. int posix_spawnp(pid_t*, char const*, posix_spawn_file_actions_t const*, posix_spawnattr_t const*, char* const argv[], char* const envp[]);
  42. int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t*, char const*);
  43. int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t*, int);
  44. int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t*, int);
  45. int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t*, int old_fd, int new_fd);
  46. int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t*, int fd, char const*, int flags, mode_t);
  47. int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t*);
  48. int posix_spawn_file_actions_init(posix_spawn_file_actions_t*);
  49. int posix_spawnattr_destroy(posix_spawnattr_t*);
  50. int posix_spawnattr_getflags(posix_spawnattr_t const*, short*);
  51. int posix_spawnattr_getpgroup(posix_spawnattr_t const*, pid_t*);
  52. int posix_spawnattr_getschedparam(posix_spawnattr_t const*, struct sched_param*);
  53. int posix_spawnattr_getschedpolicy(posix_spawnattr_t const*, int*);
  54. int posix_spawnattr_getsigdefault(posix_spawnattr_t const*, sigset_t*);
  55. int posix_spawnattr_getsigmask(posix_spawnattr_t const*, sigset_t*);
  56. int posix_spawnattr_init(posix_spawnattr_t*);
  57. int posix_spawnattr_setflags(posix_spawnattr_t*, short);
  58. int posix_spawnattr_setpgroup(posix_spawnattr_t*, pid_t);
  59. int posix_spawnattr_setschedparam(posix_spawnattr_t*, const struct sched_param*);
  60. int posix_spawnattr_setschedpolicy(posix_spawnattr_t*, int);
  61. int posix_spawnattr_setsigdefault(posix_spawnattr_t*, sigset_t const*);
  62. int posix_spawnattr_setsigmask(posix_spawnattr_t*, sigset_t const*);
  63. __END_DECLS