spawn.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* Definitions for POSIX spawn interface.
  2. Copyright (C) 2000-2016 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. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SPAWN_H
  16. #define _SPAWN_H 1
  17. #include <features.h>
  18. #include <sched.h>
  19. #define __need_sigset_t
  20. #include <signal.h>
  21. #include <sys/types.h>
  22. /* Data structure to contain attributes for thread creation. */
  23. typedef struct
  24. {
  25. short int __flags;
  26. pid_t __pgrp;
  27. sigset_t __sd;
  28. sigset_t __ss;
  29. struct sched_param __sp;
  30. int __policy;
  31. int __pad[16];
  32. } posix_spawnattr_t;
  33. /* Data structure to contain information about the actions to be
  34. performed in the new process with respect to file descriptors. */
  35. typedef struct
  36. {
  37. int __allocated;
  38. int __used;
  39. struct __spawn_action *__actions;
  40. int __pad[16];
  41. } posix_spawn_file_actions_t;
  42. /* Flags to be set in the `posix_spawnattr_t'. */
  43. #define POSIX_SPAWN_RESETIDS 0x01
  44. #define POSIX_SPAWN_SETPGROUP 0x02
  45. #define POSIX_SPAWN_SETSIGDEF 0x04
  46. #define POSIX_SPAWN_SETSIGMASK 0x08
  47. #define POSIX_SPAWN_SETSCHEDPARAM 0x10
  48. #define POSIX_SPAWN_SETSCHEDULER 0x20
  49. #ifdef __USE_GNU
  50. # define POSIX_SPAWN_USEVFORK 0x40
  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. /* Similar to `posix_spawn' but search for FILE in the PATH.
  65. This function is a possible cancellation point and therefore not
  66. marked with __THROW. */
  67. extern int posix_spawnp (pid_t *__pid, const char *__file,
  68. const posix_spawn_file_actions_t *__file_actions,
  69. const posix_spawnattr_t *__attrp,
  70. char *const __argv[], char *const __envp[]);
  71. /* Initialize data structure with attributes for `spawn' to default values. */
  72. extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW;
  73. /* Free resources associated with ATTR. */
  74. extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW;
  75. /* Store signal mask for signals with default handling from ATTR in
  76. SIGDEFAULT. */
  77. extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *
  78. __restrict __attr,
  79. sigset_t *__restrict __sigdefault)
  80. __THROW;
  81. /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
  82. extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *__restrict __attr,
  83. const sigset_t *__restrict
  84. __sigdefault)
  85. __THROW;
  86. /* Store signal mask for the new process from ATTR in SIGMASK. */
  87. extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *__restrict
  88. __attr,
  89. sigset_t *__restrict __sigmask) __THROW;
  90. /* Set signal mask for the new process in ATTR to SIGMASK. */
  91. extern int posix_spawnattr_setsigmask (posix_spawnattr_t *__restrict __attr,
  92. const sigset_t *__restrict __sigmask)
  93. __THROW;
  94. /* Get flag word from the attribute structure. */
  95. extern int posix_spawnattr_getflags (const posix_spawnattr_t *__restrict
  96. __attr,
  97. short int *__restrict __flags) __THROW;
  98. /* Store flags in the attribute structure. */
  99. extern int posix_spawnattr_setflags (posix_spawnattr_t *_attr,
  100. short int __flags) __THROW;
  101. /* Get process group ID from the attribute structure. */
  102. extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *__restrict
  103. __attr, pid_t *__restrict __pgroup)
  104. __THROW;
  105. /* Store process group ID in the attribute structure. */
  106. extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
  107. pid_t __pgroup) __THROW;
  108. /* Get scheduling policy from the attribute structure. */
  109. extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *
  110. __restrict __attr,
  111. int *__restrict __schedpolicy)
  112. __THROW;
  113. /* Store scheduling policy in the attribute structure. */
  114. extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
  115. int __schedpolicy) __THROW;
  116. /* Get scheduling parameters from the attribute structure. */
  117. extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *
  118. __restrict __attr,
  119. struct sched_param *__restrict
  120. __schedparam) __THROW;
  121. /* Store scheduling parameters in the attribute structure. */
  122. extern int posix_spawnattr_setschedparam (posix_spawnattr_t *__restrict __attr,
  123. const struct sched_param *
  124. __restrict __schedparam) __THROW;
  125. /* Initialize data structure for file attribute for `spawn' call. */
  126. extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *
  127. __file_actions) __THROW;
  128. /* Free resources associated with FILE-ACTIONS. */
  129. extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *
  130. __file_actions) __THROW;
  131. /* Add an action to FILE-ACTIONS which tells the implementation to call
  132. `open' for the given file during the `spawn' call. */
  133. extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *
  134. __restrict __file_actions,
  135. int __fd,
  136. const char *__restrict __path,
  137. int __oflag, mode_t __mode)
  138. __THROW;
  139. /* Add an action to FILE-ACTIONS which tells the implementation to call
  140. `close' for the given file descriptor during the `spawn' call. */
  141. extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *
  142. __file_actions, int __fd)
  143. __THROW;
  144. /* Add an action to FILE-ACTIONS which tells the implementation to call
  145. `dup2' for the given file descriptors during the `spawn' call. */
  146. extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
  147. __file_actions,
  148. int __fd, int __newfd) __THROW;
  149. __END_DECLS
  150. #endif /* spawn.h */