spawn.h 8.8 KB

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