spawn.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Definitions for POSIX spawn interface.
  2. Copyright (C) 2000-2020 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SPAWN_H
  16. #define _SPAWN_H 1
  17. #include <features.h>
  18. #include <sched.h>
  19. #include <sys/types.h>
  20. #include <bits/types/sigset_t.h>
  21. /* Data structure to contain attributes for thread creation. */
  22. typedef struct
  23. {
  24. short int __flags;
  25. pid_t __pgrp;
  26. sigset_t __sd;
  27. sigset_t __ss;
  28. struct sched_param __sp;
  29. int __policy;
  30. int __pad[16];
  31. } posix_spawnattr_t;
  32. /* Data structure to contain information about the actions to be
  33. performed in the new process with respect to file descriptors. */
  34. typedef struct
  35. {
  36. int __allocated;
  37. int __used;
  38. struct __spawn_action *__actions;
  39. int __pad[16];
  40. } posix_spawn_file_actions_t;
  41. /* Flags to be set in the `posix_spawnattr_t'. */
  42. #define POSIX_SPAWN_RESETIDS 0x01
  43. #define POSIX_SPAWN_SETPGROUP 0x02
  44. #define POSIX_SPAWN_SETSIGDEF 0x04
  45. #define POSIX_SPAWN_SETSIGMASK 0x08
  46. #define POSIX_SPAWN_SETSCHEDPARAM 0x10
  47. #define POSIX_SPAWN_SETSCHEDULER 0x20
  48. #ifdef __USE_GNU
  49. # define POSIX_SPAWN_USEVFORK 0x40
  50. # define POSIX_SPAWN_SETSID 0x80
  51. #endif
  52. __BEGIN_DECLS
  53. /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
  54. Before running the process perform the actions described in FILE-ACTIONS.
  55. This function is a possible cancellation point and therefore not
  56. marked with __THROW. */
  57. extern int posix_spawn (pid_t *__restrict __pid,
  58. const char *__restrict __path,
  59. const posix_spawn_file_actions_t *__restrict
  60. __file_actions,
  61. const posix_spawnattr_t *__restrict __attrp,
  62. char *const __argv[__restrict_arr],
  63. char *const __envp[__restrict_arr])
  64. __nonnull ((2, 5));
  65. /* Similar to `posix_spawn' but search for FILE in the PATH.
  66. This function is a possible cancellation point and therefore not
  67. marked with __THROW. */
  68. extern int posix_spawnp (pid_t *__pid, const char *__file,
  69. const posix_spawn_file_actions_t *__file_actions,
  70. const posix_spawnattr_t *__attrp,
  71. char *const __argv[], char *const __envp[])
  72. __nonnull ((2, 5));
  73. /* Initialize data structure with attributes for `spawn' to default values. */
  74. extern int posix_spawnattr_init (posix_spawnattr_t *__attr)
  75. __THROW __nonnull ((1));
  76. /* Free resources associated with ATTR. */
  77. extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr)
  78. __THROW __nonnull ((1));
  79. /* Store signal mask for signals with default handling from ATTR in
  80. SIGDEFAULT. */
  81. extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *
  82. __restrict __attr,
  83. sigset_t *__restrict __sigdefault)
  84. __THROW __nonnull ((1, 2));
  85. /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
  86. extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *__restrict __attr,
  87. const sigset_t *__restrict
  88. __sigdefault)
  89. __THROW __nonnull ((1, 2));
  90. /* Store signal mask for the new process from ATTR in SIGMASK. */
  91. extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *__restrict
  92. __attr,
  93. sigset_t *__restrict __sigmask)
  94. __THROW __nonnull ((1, 2));
  95. /* Set signal mask for the new process in ATTR to SIGMASK. */
  96. extern int posix_spawnattr_setsigmask (posix_spawnattr_t *__restrict __attr,
  97. const sigset_t *__restrict __sigmask)
  98. __THROW __nonnull ((1, 2));
  99. /* Get flag word from the attribute structure. */
  100. extern int posix_spawnattr_getflags (const posix_spawnattr_t *__restrict
  101. __attr,
  102. short int *__restrict __flags)
  103. __THROW __nonnull ((1, 2));
  104. /* Store flags in the attribute structure. */
  105. extern int posix_spawnattr_setflags (posix_spawnattr_t *_attr,
  106. short int __flags)
  107. __THROW __nonnull ((1));
  108. /* Get process group ID from the attribute structure. */
  109. extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *__restrict
  110. __attr, pid_t *__restrict __pgroup)
  111. __THROW __nonnull ((1, 2));
  112. /* Store process group ID in the attribute structure. */
  113. extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
  114. pid_t __pgroup)
  115. __THROW __nonnull ((1));
  116. /* Get scheduling policy from the attribute structure. */
  117. extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *
  118. __restrict __attr,
  119. int *__restrict __schedpolicy)
  120. __THROW __nonnull ((1, 2));
  121. /* Store scheduling policy in the attribute structure. */
  122. extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
  123. int __schedpolicy)
  124. __THROW __nonnull ((1));
  125. /* Get scheduling parameters from the attribute structure. */
  126. extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *
  127. __restrict __attr,
  128. struct sched_param *__restrict
  129. __schedparam)
  130. __THROW __nonnull ((1, 2));
  131. /* Store scheduling parameters in the attribute structure. */
  132. extern int posix_spawnattr_setschedparam (posix_spawnattr_t *__restrict __attr,
  133. const struct sched_param *
  134. __restrict __schedparam)
  135. __THROW __nonnull ((1, 2));
  136. /* Initialize data structure for file attribute for `spawn' call. */
  137. extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *
  138. __file_actions)
  139. __THROW __nonnull ((1));
  140. /* Free resources associated with FILE-ACTIONS. */
  141. extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *
  142. __file_actions)
  143. __THROW __nonnull ((1));
  144. /* Add an action to FILE-ACTIONS which tells the implementation to call
  145. `open' for the given file during the `spawn' call. */
  146. extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *
  147. __restrict __file_actions,
  148. int __fd,
  149. const char *__restrict __path,
  150. int __oflag, mode_t __mode)
  151. __THROW __nonnull ((1, 3));
  152. /* Add an action to FILE-ACTIONS which tells the implementation to call
  153. `close' for the given file descriptor during the `spawn' call. */
  154. extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *
  155. __file_actions, int __fd)
  156. __THROW __nonnull ((1));
  157. /* Add an action to FILE-ACTIONS which tells the implementation to call
  158. `dup2' for the given file descriptors during the `spawn' call. */
  159. extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
  160. __file_actions,
  161. int __fd, int __newfd)
  162. __THROW __nonnull ((1));
  163. #ifdef __USE_GNU
  164. /* Add an action changing the directory to PATH during spawn. This
  165. affects the subsequent file actions. */
  166. extern int posix_spawn_file_actions_addchdir_np (posix_spawn_file_actions_t *
  167. __restrict __actions,
  168. const char *__restrict __path)
  169. __THROW __nonnull ((1, 2));
  170. /* Add an action changing the directory to FD during spawn. This
  171. affects the subsequent file actions. FD is not duplicated and must
  172. be open when the file action is executed. */
  173. extern int posix_spawn_file_actions_addfchdir_np (posix_spawn_file_actions_t *,
  174. int __fd)
  175. __THROW __nonnull ((1));
  176. #endif
  177. __END_DECLS
  178. #endif /* spawn.h */