spawn.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #ifndef _SPAWN_H_
  29. #define _SPAWN_H_
  30. #include <sys/cdefs.h>
  31. #include <sys/_types.h>
  32. #include <sys/_sigset.h>
  33. #ifndef _MODE_T_DECLARED
  34. typedef __mode_t mode_t;
  35. #define _MODE_T_DECLARED
  36. #endif
  37. #ifndef _PID_T_DECLARED
  38. typedef __pid_t pid_t;
  39. #define _PID_T_DECLARED
  40. #endif
  41. #ifndef _SIGSET_T_DECLARED
  42. #define _SIGSET_T_DECLARED
  43. typedef __sigset_t sigset_t;
  44. #endif
  45. struct sched_param;
  46. typedef struct __posix_spawnattr *posix_spawnattr_t;
  47. typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t;
  48. #define POSIX_SPAWN_RESETIDS 0x01
  49. #define POSIX_SPAWN_SETPGROUP 0x02
  50. #define POSIX_SPAWN_SETSCHEDPARAM 0x04
  51. #define POSIX_SPAWN_SETSCHEDULER 0x08
  52. #define POSIX_SPAWN_SETSIGDEF 0x10
  53. #define POSIX_SPAWN_SETSIGMASK 0x20
  54. #define POSIX_SPAWN_DISABLE_ASLR_NP 0x40
  55. __BEGIN_DECLS
  56. /*
  57. * Spawn routines
  58. *
  59. * XXX both arrays should be __restrict, but this does not work when GCC
  60. * is invoked with -std=c99.
  61. */
  62. int posix_spawn(pid_t * __restrict, const char * __restrict,
  63. const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
  64. char * const [], char * const []);
  65. int posix_spawnp(pid_t * __restrict, const char * __restrict,
  66. const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
  67. char * const [], char * const []);
  68. /*
  69. * File descriptor actions
  70. */
  71. int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
  72. int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
  73. int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict,
  74. int, const char * __restrict, int, mode_t);
  75. int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int);
  76. int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int);
  77. #if __BSD_VISIBLE
  78. int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *
  79. __restrict, const char * __restrict);
  80. int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
  81. int);
  82. int posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *,
  83. int);
  84. #endif
  85. /*
  86. * Spawn attributes
  87. */
  88. int posix_spawnattr_init(posix_spawnattr_t *);
  89. int posix_spawnattr_destroy(posix_spawnattr_t *);
  90. int posix_spawnattr_getflags(const posix_spawnattr_t * __restrict,
  91. short * __restrict);
  92. int posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict,
  93. pid_t * __restrict);
  94. int posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict,
  95. struct sched_param * __restrict);
  96. int posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict,
  97. int * __restrict);
  98. int posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict,
  99. sigset_t * __restrict);
  100. int posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict,
  101. sigset_t * __restrict sigmask);
  102. int posix_spawnattr_setflags(posix_spawnattr_t *, short);
  103. int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t);
  104. int posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict,
  105. const struct sched_param * __restrict);
  106. int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
  107. int posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict,
  108. const sigset_t * __restrict);
  109. int posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict,
  110. const sigset_t * __restrict);
  111. __END_DECLS
  112. #endif /* !_SPAWN_H_ */