aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPhilipp Stephani2020-12-25 11:33:02 +0100
committerPhilipp Stephani2020-12-25 11:54:02 +0100
commit3ba34141da77a24c251ee6530f3f72a366fe556e (patch)
tree66b28a4a122d20ca29548c8894fba2c6fa4645f3 /lib
parent42d58264db165d265cba68d6dbebc53a50738355 (diff)
downloademacs-3ba34141da77a24c251ee6530f3f72a366fe556e.tar.gz
emacs-3ba34141da77a24c251ee6530f3f72a366fe556e.zip
Import posix_spawn from Gnulib.
posix_spawn is less error-prone than vfork + exec, and can make use of system-specific optimizations like `clone' on Linux. Import Gnulib replacement so that we can use recent additions like `posix_spawn_file_actions_addchdir'. The only manual change are to admin/merge-gnulib and .gitignore. All other changes are due to rerunning merge-gnulib. * admin/merge-gnulib (GNULIB_MODULES): Add posix_spawn-related modules. * .gitignore: Add new generated files.
Diffstat (limited to 'lib')
-rw-r--r--lib/gnulib.mk.in302
-rw-r--r--lib/sched.in.h99
-rw-r--r--lib/spawn.c34
-rw-r--r--lib/spawn.in.h974
-rw-r--r--lib/spawn_faction_addchdir.c70
-rw-r--r--lib/spawn_faction_adddup2.c70
-rw-r--r--lib/spawn_faction_destroy.c61
-rw-r--r--lib/spawn_faction_init.c56
-rw-r--r--lib/spawn_int.h72
-rw-r--r--lib/spawnattr_destroy.c28
-rw-r--r--lib/spawnattr_init.c33
-rw-r--r--lib/spawnattr_setdefault.c33
-rw-r--r--lib/spawnattr_setflags.c45
-rw-r--r--lib/spawnattr_setpgroup.c32
-rw-r--r--lib/spawnattr_setsigmask.c33
-rw-r--r--lib/spawni.c349
-rw-r--r--lib/strchrnul.c142
-rw-r--r--lib/strchrnul.valgrind28
18 files changed, 2461 insertions, 0 deletions
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index a37f9278a31..209c7eef299 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -130,6 +130,17 @@
130# nstrftime \ 130# nstrftime \
131# pathmax \ 131# pathmax \
132# pipe2 \ 132# pipe2 \
133# posix_spawn \
134# posix_spawn_file_actions_addchdir \
135# posix_spawn_file_actions_adddup2 \
136# posix_spawn_file_actions_destroy \
137# posix_spawn_file_actions_init \
138# posix_spawnattr_destroy \
139# posix_spawnattr_init \
140# posix_spawnattr_setflags \
141# posix_spawnattr_setpgroup \
142# posix_spawnattr_setsigdefault \
143# posix_spawnattr_setsigmask \
133# pselect \ 144# pselect \
134# pthread_sigmask \ 145# pthread_sigmask \
135# qcopy-acl \ 146# qcopy-acl \
@@ -393,6 +404,29 @@ GNULIB_PIPE2 = @GNULIB_PIPE2@
393GNULIB_POPEN = @GNULIB_POPEN@ 404GNULIB_POPEN = @GNULIB_POPEN@
394GNULIB_POSIX_MEMALIGN = @GNULIB_POSIX_MEMALIGN@ 405GNULIB_POSIX_MEMALIGN = @GNULIB_POSIX_MEMALIGN@
395GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@ 406GNULIB_POSIX_OPENPT = @GNULIB_POSIX_OPENPT@
407GNULIB_POSIX_SPAWN = @GNULIB_POSIX_SPAWN@
408GNULIB_POSIX_SPAWNATTR_DESTROY = @GNULIB_POSIX_SPAWNATTR_DESTROY@
409GNULIB_POSIX_SPAWNATTR_GETFLAGS = @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
410GNULIB_POSIX_SPAWNATTR_GETPGROUP = @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
411GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM = @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
412GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY = @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
413GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT = @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
414GNULIB_POSIX_SPAWNATTR_GETSIGMASK = @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
415GNULIB_POSIX_SPAWNATTR_INIT = @GNULIB_POSIX_SPAWNATTR_INIT@
416GNULIB_POSIX_SPAWNATTR_SETFLAGS = @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
417GNULIB_POSIX_SPAWNATTR_SETPGROUP = @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
418GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM = @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
419GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY = @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
420GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT = @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
421GNULIB_POSIX_SPAWNATTR_SETSIGMASK = @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
422GNULIB_POSIX_SPAWNP = @GNULIB_POSIX_SPAWNP@
423GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
424GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
425GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
426GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@
427GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
428GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
429GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT = @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
396GNULIB_PREAD = @GNULIB_PREAD@ 430GNULIB_PREAD = @GNULIB_PREAD@
397GNULIB_PRINTF = @GNULIB_PRINTF@ 431GNULIB_PRINTF = @GNULIB_PRINTF@
398GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@ 432GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@
@@ -425,6 +459,7 @@ GNULIB_RMDIR = @GNULIB_RMDIR@
425GNULIB_RPMATCH = @GNULIB_RPMATCH@ 459GNULIB_RPMATCH = @GNULIB_RPMATCH@
426GNULIB_SCANDIR = @GNULIB_SCANDIR@ 460GNULIB_SCANDIR = @GNULIB_SCANDIR@
427GNULIB_SCANF = @GNULIB_SCANF@ 461GNULIB_SCANF = @GNULIB_SCANF@
462GNULIB_SCHED_YIELD = @GNULIB_SCHED_YIELD@
428GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@ 463GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@
429GNULIB_SELECT = @GNULIB_SELECT@ 464GNULIB_SELECT = @GNULIB_SELECT@
430GNULIB_SETENV = @GNULIB_SETENV@ 465GNULIB_SETENV = @GNULIB_SETENV@
@@ -634,6 +669,11 @@ HAVE_POPEN = @HAVE_POPEN@
634HAVE_POSIX_MEMALIGN = @HAVE_POSIX_MEMALIGN@ 669HAVE_POSIX_MEMALIGN = @HAVE_POSIX_MEMALIGN@
635HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@ 670HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@
636HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@ 671HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@
672HAVE_POSIX_SPAWN = @HAVE_POSIX_SPAWN@
673HAVE_POSIX_SPAWNATTR_T = @HAVE_POSIX_SPAWNATTR_T@
674HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
675HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@
676HAVE_POSIX_SPAWN_FILE_ACTIONS_T = @HAVE_POSIX_SPAWN_FILE_ACTIONS_T@
637HAVE_PREAD = @HAVE_PREAD@ 677HAVE_PREAD = @HAVE_PREAD@
638HAVE_PSELECT = @HAVE_PSELECT@ 678HAVE_PSELECT = @HAVE_PSELECT@
639HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@ 679HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@
@@ -655,6 +695,8 @@ HAVE_RENAMEAT = @HAVE_RENAMEAT@
655HAVE_REWINDDIR = @HAVE_REWINDDIR@ 695HAVE_REWINDDIR = @HAVE_REWINDDIR@
656HAVE_RPMATCH = @HAVE_RPMATCH@ 696HAVE_RPMATCH = @HAVE_RPMATCH@
657HAVE_SCANDIR = @HAVE_SCANDIR@ 697HAVE_SCANDIR = @HAVE_SCANDIR@
698HAVE_SCHED_H = @HAVE_SCHED_H@
699HAVE_SCHED_YIELD = @HAVE_SCHED_YIELD@
658HAVE_SECURE_GETENV = @HAVE_SECURE_GETENV@ 700HAVE_SECURE_GETENV = @HAVE_SECURE_GETENV@
659HAVE_SETENV = @HAVE_SETENV@ 701HAVE_SETENV = @HAVE_SETENV@
660HAVE_SETHOSTNAME = @HAVE_SETHOSTNAME@ 702HAVE_SETHOSTNAME = @HAVE_SETHOSTNAME@
@@ -669,6 +711,7 @@ HAVE_SIGNED_WCHAR_T = @HAVE_SIGNED_WCHAR_T@
669HAVE_SIGNED_WINT_T = @HAVE_SIGNED_WINT_T@ 711HAVE_SIGNED_WINT_T = @HAVE_SIGNED_WINT_T@
670HAVE_SIGSET_T = @HAVE_SIGSET_T@ 712HAVE_SIGSET_T = @HAVE_SIGSET_T@
671HAVE_SLEEP = @HAVE_SLEEP@ 713HAVE_SLEEP = @HAVE_SLEEP@
714HAVE_SPAWN_H = @HAVE_SPAWN_H@
672HAVE_STDINT_H = @HAVE_STDINT_H@ 715HAVE_STDINT_H = @HAVE_STDINT_H@
673HAVE_STPCPY = @HAVE_STPCPY@ 716HAVE_STPCPY = @HAVE_STPCPY@
674HAVE_STPNCPY = @HAVE_STPNCPY@ 717HAVE_STPNCPY = @HAVE_STPNCPY@
@@ -683,6 +726,7 @@ HAVE_STRTOLD = @HAVE_STRTOLD@
683HAVE_STRTOLL = @HAVE_STRTOLL@ 726HAVE_STRTOLL = @HAVE_STRTOLL@
684HAVE_STRTOULL = @HAVE_STRTOULL@ 727HAVE_STRTOULL = @HAVE_STRTOULL@
685HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@ 728HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@
729HAVE_STRUCT_SCHED_PARAM = @HAVE_STRUCT_SCHED_PARAM@
686HAVE_STRUCT_SIGACTION_SA_SIGACTION = @HAVE_STRUCT_SIGACTION_SA_SIGACTION@ 730HAVE_STRUCT_SIGACTION_SA_SIGACTION = @HAVE_STRUCT_SIGACTION_SA_SIGACTION@
687HAVE_STRUCT_TIMEVAL = @HAVE_STRUCT_TIMEVAL@ 731HAVE_STRUCT_TIMEVAL = @HAVE_STRUCT_TIMEVAL@
688HAVE_STRVERSCMP = @HAVE_STRVERSCMP@ 732HAVE_STRVERSCMP = @HAVE_STRVERSCMP@
@@ -782,6 +826,7 @@ LIB_EACCESS = @LIB_EACCESS@
782LIB_EXECINFO = @LIB_EXECINFO@ 826LIB_EXECINFO = @LIB_EXECINFO@
783LIB_GETRANDOM = @LIB_GETRANDOM@ 827LIB_GETRANDOM = @LIB_GETRANDOM@
784LIB_MATH = @LIB_MATH@ 828LIB_MATH = @LIB_MATH@
829LIB_POSIX_SPAWN = @LIB_POSIX_SPAWN@
785LIB_PTHREAD = @LIB_PTHREAD@ 830LIB_PTHREAD = @LIB_PTHREAD@
786LIB_PTHREAD_SIGMASK = @LIB_PTHREAD_SIGMASK@ 831LIB_PTHREAD_SIGMASK = @LIB_PTHREAD_SIGMASK@
787LIB_TIMER_TIME = @LIB_TIMER_TIME@ 832LIB_TIMER_TIME = @LIB_TIMER_TIME@
@@ -805,7 +850,9 @@ NEXT_AS_FIRST_DIRECTIVE_FCNTL_H = @NEXT_AS_FIRST_DIRECTIVE_FCNTL_H@
805NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@ 850NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@
806NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@ 851NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@
807NEXT_AS_FIRST_DIRECTIVE_LIMITS_H = @NEXT_AS_FIRST_DIRECTIVE_LIMITS_H@ 852NEXT_AS_FIRST_DIRECTIVE_LIMITS_H = @NEXT_AS_FIRST_DIRECTIVE_LIMITS_H@
853NEXT_AS_FIRST_DIRECTIVE_SCHED_H = @NEXT_AS_FIRST_DIRECTIVE_SCHED_H@
808NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H = @NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H@ 854NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H = @NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H@
855NEXT_AS_FIRST_DIRECTIVE_SPAWN_H = @NEXT_AS_FIRST_DIRECTIVE_SPAWN_H@
809NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@ 856NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@
810NEXT_AS_FIRST_DIRECTIVE_STDINT_H = @NEXT_AS_FIRST_DIRECTIVE_STDINT_H@ 857NEXT_AS_FIRST_DIRECTIVE_STDINT_H = @NEXT_AS_FIRST_DIRECTIVE_STDINT_H@
811NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@ 858NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
@@ -824,7 +871,9 @@ NEXT_FCNTL_H = @NEXT_FCNTL_H@
824NEXT_GETOPT_H = @NEXT_GETOPT_H@ 871NEXT_GETOPT_H = @NEXT_GETOPT_H@
825NEXT_INTTYPES_H = @NEXT_INTTYPES_H@ 872NEXT_INTTYPES_H = @NEXT_INTTYPES_H@
826NEXT_LIMITS_H = @NEXT_LIMITS_H@ 873NEXT_LIMITS_H = @NEXT_LIMITS_H@
874NEXT_SCHED_H = @NEXT_SCHED_H@
827NEXT_SIGNAL_H = @NEXT_SIGNAL_H@ 875NEXT_SIGNAL_H = @NEXT_SIGNAL_H@
876NEXT_SPAWN_H = @NEXT_SPAWN_H@
828NEXT_STDDEF_H = @NEXT_STDDEF_H@ 877NEXT_STDDEF_H = @NEXT_STDDEF_H@
829NEXT_STDINT_H = @NEXT_STDINT_H@ 878NEXT_STDINT_H = @NEXT_STDINT_H@
830NEXT_STDIO_H = @NEXT_STDIO_H@ 879NEXT_STDIO_H = @NEXT_STDIO_H@
@@ -946,6 +995,12 @@ REPLACE_OPENDIR = @REPLACE_OPENDIR@
946REPLACE_PERROR = @REPLACE_PERROR@ 995REPLACE_PERROR = @REPLACE_PERROR@
947REPLACE_POPEN = @REPLACE_POPEN@ 996REPLACE_POPEN = @REPLACE_POPEN@
948REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@ 997REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@
998REPLACE_POSIX_SPAWN = @REPLACE_POSIX_SPAWN@
999REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
1000REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
1001REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
1002REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@
1003REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
949REPLACE_PREAD = @REPLACE_PREAD@ 1004REPLACE_PREAD = @REPLACE_PREAD@
950REPLACE_PRINTF = @REPLACE_PRINTF@ 1005REPLACE_PRINTF = @REPLACE_PRINTF@
951REPLACE_PSELECT = @REPLACE_PSELECT@ 1006REPLACE_PSELECT = @REPLACE_PSELECT@
@@ -967,6 +1022,7 @@ REPLACE_REMOVE = @REPLACE_REMOVE@
967REPLACE_RENAME = @REPLACE_RENAME@ 1022REPLACE_RENAME = @REPLACE_RENAME@
968REPLACE_RENAMEAT = @REPLACE_RENAMEAT@ 1023REPLACE_RENAMEAT = @REPLACE_RENAMEAT@
969REPLACE_RMDIR = @REPLACE_RMDIR@ 1024REPLACE_RMDIR = @REPLACE_RMDIR@
1025REPLACE_SCHED_YIELD = @REPLACE_SCHED_YIELD@
970REPLACE_SELECT = @REPLACE_SELECT@ 1026REPLACE_SELECT = @REPLACE_SELECT@
971REPLACE_SETENV = @REPLACE_SETENV@ 1027REPLACE_SETENV = @REPLACE_SETENV@
972REPLACE_SETSTATE = @REPLACE_SETSTATE@ 1028REPLACE_SETSTATE = @REPLACE_SETSTATE@
@@ -1108,11 +1164,13 @@ gamegroup = @gamegroup@
1108gameuser = @gameuser@ 1164gameuser = @gameuser@
1109gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7 = @gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7@ 1165gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7 = @gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7@
1110gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b = @gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b@ 1166gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b = @gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b@
1167gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7 = @gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7@
1111gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31 = @gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31@ 1168gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31 = @gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31@
1112gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c = @gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c@ 1169gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c = @gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c@
1113gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec = @gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec@ 1170gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec = @gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec@
1114gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 = @gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1@ 1171gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1 = @gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1@
1115gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@ 1172gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36 = @gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36@
1173gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70 = @gl_GNULIB_ENABLED_cdeb0f2aaf9d280baa6526bfa1b07f70@
1116gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@ 1174gl_GNULIB_ENABLED_cloexec = @gl_GNULIB_ENABLED_cloexec@
1117gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@ 1175gl_GNULIB_ENABLED_dirfd = @gl_GNULIB_ENABLED_dirfd@
1118gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955 = @gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955@ 1176gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955 = @gl_GNULIB_ENABLED_ef07dc4b3077c11ea9cef586db4e5955@
@@ -1124,6 +1182,7 @@ gl_GNULIB_ENABLED_lchmod = @gl_GNULIB_ENABLED_lchmod@
1124gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@ 1182gl_GNULIB_ENABLED_open = @gl_GNULIB_ENABLED_open@
1125gl_GNULIB_ENABLED_rawmemchr = @gl_GNULIB_ENABLED_rawmemchr@ 1183gl_GNULIB_ENABLED_rawmemchr = @gl_GNULIB_ENABLED_rawmemchr@
1126gl_GNULIB_ENABLED_scratch_buffer = @gl_GNULIB_ENABLED_scratch_buffer@ 1184gl_GNULIB_ENABLED_scratch_buffer = @gl_GNULIB_ENABLED_scratch_buffer@
1185gl_GNULIB_ENABLED_strchrnul = @gl_GNULIB_ENABLED_strchrnul@
1127gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@ 1186gl_GNULIB_ENABLED_strtoll = @gl_GNULIB_ENABLED_strtoll@
1128gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@ 1187gl_GNULIB_ENABLED_utimens = @gl_GNULIB_ENABLED_utimens@
1129gl_LIBOBJS = @gl_LIBOBJS@ 1188gl_LIBOBJS = @gl_LIBOBJS@
@@ -2270,6 +2329,140 @@ libgnu_a_SOURCES += pipe2.c
2270endif 2329endif
2271## end gnulib module pipe2 2330## end gnulib module pipe2
2272 2331
2332## begin gnulib module posix_spawn
2333ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn))
2334
2335
2336EXTRA_DIST += spawn.c
2337
2338EXTRA_libgnu_a_SOURCES += spawn.c
2339
2340endif
2341## end gnulib module posix_spawn
2342
2343## begin gnulib module posix_spawn-internal
2344ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn-internal))
2345
2346ifneq (,$(gl_GNULIB_ENABLED_332607f759618fb73dfc3076748afea7))
2347
2348endif
2349EXTRA_DIST += spawn_int.h spawni.c
2350
2351EXTRA_libgnu_a_SOURCES += spawni.c
2352
2353endif
2354## end gnulib module posix_spawn-internal
2355
2356## begin gnulib module posix_spawn_file_actions_addchdir
2357ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_addchdir))
2358
2359
2360EXTRA_DIST += spawn_faction_addchdir.c spawn_int.h
2361
2362EXTRA_libgnu_a_SOURCES += spawn_faction_addchdir.c
2363
2364endif
2365## end gnulib module posix_spawn_file_actions_addchdir
2366
2367## begin gnulib module posix_spawn_file_actions_adddup2
2368ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_adddup2))
2369
2370
2371EXTRA_DIST += spawn_faction_adddup2.c spawn_int.h
2372
2373EXTRA_libgnu_a_SOURCES += spawn_faction_adddup2.c
2374
2375endif
2376## end gnulib module posix_spawn_file_actions_adddup2
2377
2378## begin gnulib module posix_spawn_file_actions_destroy
2379ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_destroy))
2380
2381
2382EXTRA_DIST += spawn_faction_destroy.c
2383
2384EXTRA_libgnu_a_SOURCES += spawn_faction_destroy.c
2385
2386endif
2387## end gnulib module posix_spawn_file_actions_destroy
2388
2389## begin gnulib module posix_spawn_file_actions_init
2390ifeq (,$(OMIT_GNULIB_MODULE_posix_spawn_file_actions_init))
2391
2392
2393EXTRA_DIST += spawn_faction_init.c spawn_int.h
2394
2395EXTRA_libgnu_a_SOURCES += spawn_faction_init.c
2396
2397endif
2398## end gnulib module posix_spawn_file_actions_init
2399
2400## begin gnulib module posix_spawnattr_destroy
2401ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_destroy))
2402
2403
2404EXTRA_DIST += spawnattr_destroy.c
2405
2406EXTRA_libgnu_a_SOURCES += spawnattr_destroy.c
2407
2408endif
2409## end gnulib module posix_spawnattr_destroy
2410
2411## begin gnulib module posix_spawnattr_init
2412ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_init))
2413
2414
2415EXTRA_DIST += spawnattr_init.c
2416
2417EXTRA_libgnu_a_SOURCES += spawnattr_init.c
2418
2419endif
2420## end gnulib module posix_spawnattr_init
2421
2422## begin gnulib module posix_spawnattr_setflags
2423ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setflags))
2424
2425
2426EXTRA_DIST += spawnattr_setflags.c
2427
2428EXTRA_libgnu_a_SOURCES += spawnattr_setflags.c
2429
2430endif
2431## end gnulib module posix_spawnattr_setflags
2432
2433## begin gnulib module posix_spawnattr_setpgroup
2434ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setpgroup))
2435
2436
2437EXTRA_DIST += spawnattr_setpgroup.c
2438
2439EXTRA_libgnu_a_SOURCES += spawnattr_setpgroup.c
2440
2441endif
2442## end gnulib module posix_spawnattr_setpgroup
2443
2444## begin gnulib module posix_spawnattr_setsigdefault
2445ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setsigdefault))
2446
2447
2448EXTRA_DIST += spawnattr_setdefault.c
2449
2450EXTRA_libgnu_a_SOURCES += spawnattr_setdefault.c
2451
2452endif
2453## end gnulib module posix_spawnattr_setsigdefault
2454
2455## begin gnulib module posix_spawnattr_setsigmask
2456ifeq (,$(OMIT_GNULIB_MODULE_posix_spawnattr_setsigmask))
2457
2458
2459EXTRA_DIST += spawnattr_setsigmask.c
2460
2461EXTRA_libgnu_a_SOURCES += spawnattr_setsigmask.c
2462
2463endif
2464## end gnulib module posix_spawnattr_setsigmask
2465
2273## begin gnulib module pselect 2466## begin gnulib module pselect
2274ifeq (,$(OMIT_GNULIB_MODULE_pselect)) 2467ifeq (,$(OMIT_GNULIB_MODULE_pselect))
2275 2468
@@ -2357,6 +2550,39 @@ EXTRA_DIST += root-uid.h
2357endif 2550endif
2358## end gnulib module root-uid 2551## end gnulib module root-uid
2359 2552
2553## begin gnulib module sched
2554ifeq (,$(OMIT_GNULIB_MODULE_sched))
2555
2556BUILT_SOURCES += sched.h
2557
2558# We need the following in order to create a replacement for <sched.h> when
2559# the system doesn't have one.
2560sched.h: sched.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
2561 $(AM_V_GEN)rm -f $@-t $@ && \
2562 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
2563 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
2564 -e 's|@''HAVE_SCHED_H''@|$(HAVE_SCHED_H)|g' \
2565 -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \
2566 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
2567 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2568 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2569 -e 's|@''NEXT_SCHED_H''@|$(NEXT_SCHED_H)|g' \
2570 -e 's|@''HAVE_STRUCT_SCHED_PARAM''@|$(HAVE_STRUCT_SCHED_PARAM)|g' \
2571 -e 's/@''GNULIB_SCHED_YIELD''@/$(GNULIB_SCHED_YIELD)/g' \
2572 -e 's|@''HAVE_SCHED_YIELD''@|$(HAVE_SCHED_YIELD)|g' \
2573 -e 's|@''REPLACE_SCHED_YIELD''@|$(REPLACE_SCHED_YIELD)|g' \
2574 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2575 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2576 < $(srcdir)/sched.in.h; \
2577 } > $@-t && \
2578 mv $@-t $@
2579MOSTLYCLEANFILES += sched.h sched.h-t
2580
2581EXTRA_DIST += sched.in.h
2582
2583endif
2584## end gnulib module sched
2585
2360## begin gnulib module scratch_buffer 2586## begin gnulib module scratch_buffer
2361ifeq (,$(OMIT_GNULIB_MODULE_scratch_buffer)) 2587ifeq (,$(OMIT_GNULIB_MODULE_scratch_buffer))
2362 2588
@@ -2491,6 +2717,69 @@ EXTRA_DIST += warn-on-use.h
2491endif 2717endif
2492## end gnulib module snippet/warn-on-use 2718## end gnulib module snippet/warn-on-use
2493 2719
2720## begin gnulib module spawn
2721ifeq (,$(OMIT_GNULIB_MODULE_spawn))
2722
2723BUILT_SOURCES += spawn.h
2724
2725# We need the following in order to create a replacement for <spawn.h> when
2726# the system doesn't have one.
2727spawn.h: spawn.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
2728 $(AM_V_GEN)rm -f $@-t $@ && \
2729 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
2730 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
2731 -e 's|@''HAVE_SPAWN_H''@|$(HAVE_SPAWN_H)|g' \
2732 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
2733 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2734 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2735 -e 's|@''NEXT_SPAWN_H''@|$(NEXT_SPAWN_H)|g' \
2736 -e 's/@''GNULIB_POSIX_SPAWN''@/$(GNULIB_POSIX_SPAWN)/g' \
2737 -e 's/@''GNULIB_POSIX_SPAWNP''@/$(GNULIB_POSIX_SPAWNP)/g' \
2738 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT)/g' \
2739 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)/g' \
2740 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)/g' \
2741 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)/g' \
2742 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)/g' \
2743 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)/g' \
2744 -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY)/g' \
2745 -e 's/@''GNULIB_POSIX_SPAWNATTR_INIT''@/$(GNULIB_POSIX_SPAWNATTR_INIT)/g' \
2746 -e 's/@''GNULIB_POSIX_SPAWNATTR_GETFLAGS''@/$(GNULIB_POSIX_SPAWNATTR_GETFLAGS)/g' \
2747 -e 's/@''GNULIB_POSIX_SPAWNATTR_SETFLAGS''@/$(GNULIB_POSIX_SPAWNATTR_SETFLAGS)/g' \
2748 -e 's/@''GNULIB_POSIX_SPAWNATTR_GETPGROUP''@/$(GNULIB_POSIX_SPAWNATTR_GETPGROUP)/g' \
2749 -e 's/@''GNULIB_POSIX_SPAWNATTR_SETPGROUP''@/$(GNULIB_POSIX_SPAWNATTR_SETPGROUP)/g' \
2750 -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM''@/$(GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM)/g' \
2751 -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM''@/$(GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM)/g' \
2752 -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY''@/$(GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY)/g' \
2753 -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY''@/$(GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY)/g' \
2754 -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT''@/$(GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT)/g' \
2755 -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT''@/$(GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT)/g' \
2756 -e 's/@''GNULIB_POSIX_SPAWNATTR_GETSIGMASK''@/$(GNULIB_POSIX_SPAWNATTR_GETSIGMASK)/g' \
2757 -e 's/@''GNULIB_POSIX_SPAWNATTR_SETSIGMASK''@/$(GNULIB_POSIX_SPAWNATTR_SETSIGMASK)/g' \
2758 -e 's/@''GNULIB_POSIX_SPAWNATTR_DESTROY''@/$(GNULIB_POSIX_SPAWNATTR_DESTROY)/g' \
2759 -e 's|@''HAVE_POSIX_SPAWN''@|$(HAVE_POSIX_SPAWN)|g' \
2760 -e 's|@''HAVE_POSIX_SPAWNATTR_T''@|$(HAVE_POSIX_SPAWNATTR_T)|g' \
2761 -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_T''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_T)|g' \
2762 -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \
2763 -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)|g' \
2764 -e 's|@''REPLACE_POSIX_SPAWN''@|$(REPLACE_POSIX_SPAWN)|g' \
2765 -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \
2766 -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)|g' \
2767 -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)|g' \
2768 -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR)|g' \
2769 -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)|g' \
2770 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2771 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
2772 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2773 < $(srcdir)/spawn.in.h; \
2774 } > $@-t && \
2775 mv $@-t $@
2776MOSTLYCLEANFILES += spawn.h spawn.h-t
2777
2778EXTRA_DIST += spawn.in.h
2779
2780endif
2781## end gnulib module spawn
2782
2494## begin gnulib module stat-time 2783## begin gnulib module stat-time
2495ifeq (,$(OMIT_GNULIB_MODULE_stat-time)) 2784ifeq (,$(OMIT_GNULIB_MODULE_stat-time))
2496 2785
@@ -2885,6 +3174,19 @@ EXTRA_libgnu_a_SOURCES += stpcpy.c
2885endif 3174endif
2886## end gnulib module stpcpy 3175## end gnulib module stpcpy
2887 3176
3177## begin gnulib module strchrnul
3178ifeq (,$(OMIT_GNULIB_MODULE_strchrnul))
3179
3180ifneq (,$(gl_GNULIB_ENABLED_strchrnul))
3181
3182endif
3183EXTRA_DIST += strchrnul.c strchrnul.valgrind
3184
3185EXTRA_libgnu_a_SOURCES += strchrnul.c
3186
3187endif
3188## end gnulib module strchrnul
3189
2888## begin gnulib module string 3190## begin gnulib module string
2889ifeq (,$(OMIT_GNULIB_MODULE_string)) 3191ifeq (,$(OMIT_GNULIB_MODULE_string))
2890 3192
diff --git a/lib/sched.in.h b/lib/sched.in.h
new file mode 100644
index 00000000000..4ee9defe82b
--- /dev/null
+++ b/lib/sched.in.h
@@ -0,0 +1,99 @@
1/* A GNU-like <sched.h>.
2 Copyright (C) 2008-2020 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#ifndef _@GUARD_PREFIX@_SCHED_H
18
19#if __GNUC__ >= 3
20@PRAGMA_SYSTEM_HEADER@
21#endif
22@PRAGMA_COLUMNS@
23
24/* The include_next requires a split double-inclusion guard. */
25#if @HAVE_SCHED_H@
26# if @HAVE_SYS_CDEFS_H@
27# include <sys/cdefs.h>
28# endif
29# @INCLUDE_NEXT@ @NEXT_SCHED_H@
30#endif
31
32#ifndef _@GUARD_PREFIX@_SCHED_H
33#define _@GUARD_PREFIX@_SCHED_H
34
35/* Get pid_t.
36 This is needed on glibc 2.11 (see
37 glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=13198>)
38 and Mac OS X 10.5. */
39#include <sys/types.h>
40
41#ifdef __KLIBC__
42/* On OS/2 kLIBC, struct sched_param is in spawn.h. */
43# include <spawn.h>
44#endif
45
46#ifdef __VMS
47/* On OpenVMS, struct sched_param is in <pthread.h>. */
48# include <pthread.h>
49#endif
50
51/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
52
53/* The definition of _GL_WARN_ON_USE is copied here. */
54
55#if !@HAVE_STRUCT_SCHED_PARAM@
56
57# if !GNULIB_defined_struct_sched_param
58struct sched_param
59{
60 int sched_priority;
61};
62# define GNULIB_defined_struct_sched_param 1
63# endif
64
65#endif
66
67#if !(defined SCHED_FIFO && defined SCHED_RR && defined SCHED_OTHER)
68# define SCHED_FIFO 1
69# define SCHED_RR 2
70# define SCHED_OTHER 0
71#endif
72
73#if @GNULIB_SCHED_YIELD@
74# if @REPLACE_SCHED_YIELD@
75# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
76# undef sched_yield
77# define sched_yield rpl_sched_yield
78# endif
79_GL_FUNCDECL_RPL (sched_yield, int, (void));
80_GL_CXXALIAS_RPL (sched_yield, int, (void));
81# else
82# if !@HAVE_SCHED_YIELD@
83_GL_FUNCDECL_SYS (sched_yield, int, (void));
84# endif
85_GL_CXXALIAS_SYS (sched_yield, int, (void));
86# endif
87# if __GLIBC__ >= 2
88_GL_CXXALIASWARN (sched_yield);
89# endif
90#elif defined GNULIB_POSIXCHECK
91# undef sched_yield
92# if HAVE_RAW_DECL_SCHED_YIELD
93_GL_WARN_ON_USE (sched_yield, "sched_yield is not portable - "
94 "use gnulib module sched_yield for portability");
95# endif
96#endif
97
98#endif /* _@GUARD_PREFIX@_SCHED_H */
99#endif /* _@GUARD_PREFIX@_SCHED_H */
diff --git a/lib/spawn.c b/lib/spawn.c
new file mode 100644
index 00000000000..b658453a10f
--- /dev/null
+++ b/lib/spawn.c
@@ -0,0 +1,34 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include "spawn_int.h"
23
24/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
25 Before running the process perform the actions described in FILE-ACTIONS. */
26int
27posix_spawn (pid_t *pid, const char *path,
28 const posix_spawn_file_actions_t *file_actions,
29 const posix_spawnattr_t *attrp, char *const argv[],
30 char *const envp[])
31{
32 return __spawni (pid, path, file_actions, attrp,
33 (const char * const *) argv, (const char * const *) envp, 0);
34}
diff --git a/lib/spawn.in.h b/lib/spawn.in.h
new file mode 100644
index 00000000000..537fac7dbc5
--- /dev/null
+++ b/lib/spawn.in.h
@@ -0,0 +1,974 @@
1/* Definitions for POSIX spawn interface.
2 Copyright (C) 2000, 2003-2004, 2008-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#ifndef _@GUARD_PREFIX@_SPAWN_H
19
20#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@
22#endif
23@PRAGMA_COLUMNS@
24
25/* The include_next requires a split double-inclusion guard. */
26#if @HAVE_SPAWN_H@
27# @INCLUDE_NEXT@ @NEXT_SPAWN_H@
28#endif
29
30#ifndef _@GUARD_PREFIX@_SPAWN_H
31#define _@GUARD_PREFIX@_SPAWN_H
32
33/* Get definitions of 'struct sched_param' and 'sigset_t'.
34 But avoid namespace pollution on glibc systems. */
35#if !(defined __GLIBC__ && !defined __UCLIBC__)
36# include <sched.h>
37# include <signal.h>
38#endif
39
40#include <sys/types.h>
41
42#ifndef __THROW
43# define __THROW
44#endif
45
46/* For plain 'restrict', use glibc's __restrict if defined.
47 Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have
48 "restrict", and "configure" may have defined "restrict".
49 Other compilers use __restrict, __restrict__, and _Restrict, and
50 'configure' might #define 'restrict' to those words, so pick a
51 different name. */
52#ifndef _Restrict_
53# if defined __restrict \
54 || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
55 || __clang_major__ >= 3
56# define _Restrict_ __restrict
57# elif 199901L <= __STDC_VERSION__ || defined restrict
58# define _Restrict_ restrict
59# else
60# define _Restrict_
61# endif
62#endif
63/* For the ISO C99 syntax
64 array_name[restrict]
65 use glibc's __restrict_arr if available.
66 Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode).
67 Other ISO C99 compilers support it as well. */
68#ifndef _Restrict_arr_
69# ifdef __restrict_arr
70# define _Restrict_arr_ __restrict_arr
71# elif ((199901L <= __STDC_VERSION__ \
72 || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
73 || __clang_major__ >= 3) \
74 && !defined __cplusplus)
75# define _Restrict_arr_ _Restrict_
76# else
77# define _Restrict_arr_
78# endif
79#endif
80
81/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
82
83/* The definition of _GL_ARG_NONNULL is copied here. */
84
85/* The definition of _GL_WARN_ON_USE is copied here. */
86
87
88/* Data structure to contain attributes for thread creation. */
89#if @REPLACE_POSIX_SPAWN@ || (@HAVE_POSIX_SPAWNATTR_T@ && !@HAVE_POSIX_SPAWN@)
90# define posix_spawnattr_t rpl_posix_spawnattr_t
91#endif
92#if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWNATTR_T@ || !@HAVE_POSIX_SPAWN@
93# if !GNULIB_defined_posix_spawnattr_t
94typedef struct
95{
96 short int _flags;
97 pid_t _pgrp;
98 sigset_t _sd;
99 sigset_t _ss;
100 struct sched_param _sp;
101 int _policy;
102 int __pad[16];
103} posix_spawnattr_t;
104# define GNULIB_defined_posix_spawnattr_t 1
105# endif
106#endif
107
108
109/* Data structure to contain information about the actions to be
110 performed in the new process with respect to file descriptors. */
111#if @REPLACE_POSIX_SPAWN@ || (@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ && !@HAVE_POSIX_SPAWN@)
112# define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
113#endif
114#if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@ || !@HAVE_POSIX_SPAWN@
115# if !GNULIB_defined_posix_spawn_file_actions_t
116typedef struct
117{
118 int _allocated;
119 int _used;
120 struct __spawn_action *_actions;
121 int __pad[16];
122} posix_spawn_file_actions_t;
123# define GNULIB_defined_posix_spawn_file_actions_t 1
124# endif
125#endif
126
127
128/* Flags to be set in the 'posix_spawnattr_t'. */
129#if @HAVE_POSIX_SPAWN@
130/* Use the values from the system, but provide the missing ones. */
131# ifndef POSIX_SPAWN_SETSCHEDPARAM
132# define POSIX_SPAWN_SETSCHEDPARAM 0
133# endif
134# ifndef POSIX_SPAWN_SETSCHEDULER
135# define POSIX_SPAWN_SETSCHEDULER 0
136# endif
137#else
138# if @REPLACE_POSIX_SPAWN@
139/* Use the values from the system, for better compatibility. */
140/* But this implementation does not support AIX extensions. */
141# undef POSIX_SPAWN_FORK_HANDLERS
142# else
143# define POSIX_SPAWN_RESETIDS 0x01
144# define POSIX_SPAWN_SETPGROUP 0x02
145# define POSIX_SPAWN_SETSIGDEF 0x04
146# define POSIX_SPAWN_SETSIGMASK 0x08
147# define POSIX_SPAWN_SETSCHEDPARAM 0x10
148# define POSIX_SPAWN_SETSCHEDULER 0x20
149# endif
150#endif
151/* A GNU extension. Use the next free bit position. */
152#ifndef POSIX_SPAWN_USEVFORK
153# define POSIX_SPAWN_USEVFORK \
154 ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \
155 | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \
156 | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \
157 | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \
158 | POSIX_SPAWN_SETSCHEDPARAM \
159 | (POSIX_SPAWN_SETSCHEDPARAM > 0 ? POSIX_SPAWN_SETSCHEDPARAM - 1 : 0) \
160 | POSIX_SPAWN_SETSCHEDULER \
161 | (POSIX_SPAWN_SETSCHEDULER > 0 ? POSIX_SPAWN_SETSCHEDULER - 1 : 0)) \
162 + 1)
163#endif
164#if !GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap
165typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
166 [(((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
167 | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
168 | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
169 & POSIX_SPAWN_USEVFORK)
170 == 0)
171 ? 1 : -1];
172# define GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap 1
173#endif
174
175
176#if @GNULIB_POSIX_SPAWN@
177/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
178 Before running the process perform the actions described in FILE-ACTIONS.
179
180 This function is a possible cancellation points and therefore not
181 marked with __THROW. */
182# if @REPLACE_POSIX_SPAWN@
183# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
184# define posix_spawn rpl_posix_spawn
185# endif
186_GL_FUNCDECL_RPL (posix_spawn, int,
187 (pid_t *_Restrict_ __pid,
188 const char *_Restrict_ __path,
189 const posix_spawn_file_actions_t *_Restrict_ __file_actions,
190 const posix_spawnattr_t *_Restrict_ __attrp,
191 char *const argv[_Restrict_arr_],
192 char *const envp[_Restrict_arr_])
193 _GL_ARG_NONNULL ((2, 5, 6)));
194_GL_CXXALIAS_RPL (posix_spawn, int,
195 (pid_t *_Restrict_ __pid,
196 const char *_Restrict_ __path,
197 const posix_spawn_file_actions_t *_Restrict_ __file_actions,
198 const posix_spawnattr_t *_Restrict_ __attrp,
199 char *const argv[_Restrict_arr_],
200 char *const envp[_Restrict_arr_]));
201# else
202# if !@HAVE_POSIX_SPAWN@
203_GL_FUNCDECL_SYS (posix_spawn, int,
204 (pid_t *_Restrict_ __pid,
205 const char *_Restrict_ __path,
206 const posix_spawn_file_actions_t *_Restrict_ __file_actions,
207 const posix_spawnattr_t *_Restrict_ __attrp,
208 char *const argv[_Restrict_arr_],
209 char *const envp[_Restrict_arr_])
210 _GL_ARG_NONNULL ((2, 5, 6)));
211# endif
212_GL_CXXALIAS_SYS (posix_spawn, int,
213 (pid_t *_Restrict_ __pid,
214 const char *_Restrict_ __path,
215 const posix_spawn_file_actions_t *_Restrict_ __file_actions,
216 const posix_spawnattr_t *_Restrict_ __attrp,
217 char *const argv[_Restrict_arr_],
218 char *const envp[_Restrict_arr_]));
219# endif
220_GL_CXXALIASWARN (posix_spawn);
221#elif defined GNULIB_POSIXCHECK
222# undef posix_spawn
223# if HAVE_RAW_DECL_POSIX_SPAWN
224_GL_WARN_ON_USE (posix_spawn, "posix_spawn is unportable - "
225 "use gnulib module posix_spawn for portability");
226# endif
227#endif
228
229#if @GNULIB_POSIX_SPAWNP@
230/* Similar to 'posix_spawn' but search for FILE in the PATH.
231
232 This function is a possible cancellation points and therefore not
233 marked with __THROW. */
234# if @REPLACE_POSIX_SPAWN@
235# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
236# define posix_spawnp rpl_posix_spawnp
237# endif
238_GL_FUNCDECL_RPL (posix_spawnp, int,
239 (pid_t *__pid, const char *__file,
240 const posix_spawn_file_actions_t *__file_actions,
241 const posix_spawnattr_t *__attrp,
242 char *const argv[], char *const envp[])
243 _GL_ARG_NONNULL ((2, 5, 6)));
244_GL_CXXALIAS_RPL (posix_spawnp, int,
245 (pid_t *__pid, const char *__file,
246 const posix_spawn_file_actions_t *__file_actions,
247 const posix_spawnattr_t *__attrp,
248 char *const argv[], char *const envp[]));
249# else
250# if !@HAVE_POSIX_SPAWN@
251_GL_FUNCDECL_SYS (posix_spawnp, int,
252 (pid_t *__pid, const char *__file,
253 const posix_spawn_file_actions_t *__file_actions,
254 const posix_spawnattr_t *__attrp,
255 char *const argv[], char *const envp[])
256 _GL_ARG_NONNULL ((2, 5, 6)));
257# endif
258_GL_CXXALIAS_SYS (posix_spawnp, int,
259 (pid_t *__pid, const char *__file,
260 const posix_spawn_file_actions_t *__file_actions,
261 const posix_spawnattr_t *__attrp,
262 char *const argv[], char *const envp[]));
263# endif
264_GL_CXXALIASWARN (posix_spawnp);
265#elif defined GNULIB_POSIXCHECK
266# undef posix_spawnp
267# if HAVE_RAW_DECL_POSIX_SPAWNP
268_GL_WARN_ON_USE (posix_spawnp, "posix_spawnp is unportable - "
269 "use gnulib module posix_spawnp for portability");
270# endif
271#endif
272
273
274#if @GNULIB_POSIX_SPAWNATTR_INIT@
275/* Initialize data structure with attributes for 'spawn' to default values. */
276# if @REPLACE_POSIX_SPAWN@
277# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
278# define posix_spawnattr_init rpl_posix_spawnattr_init
279# endif
280_GL_FUNCDECL_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)
281 __THROW _GL_ARG_NONNULL ((1)));
282_GL_CXXALIAS_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr));
283# else
284# if !@HAVE_POSIX_SPAWN@
285_GL_FUNCDECL_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)
286 __THROW _GL_ARG_NONNULL ((1)));
287# endif
288_GL_CXXALIAS_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr));
289# endif
290_GL_CXXALIASWARN (posix_spawnattr_init);
291#elif defined GNULIB_POSIXCHECK
292# undef posix_spawnattr_init
293# if HAVE_RAW_DECL_POSIX_SPAWNATTR_INIT
294_GL_WARN_ON_USE (posix_spawnattr_init, "posix_spawnattr_init is unportable - "
295 "use gnulib module posix_spawnattr_init for portability");
296# endif
297#endif
298
299#if @GNULIB_POSIX_SPAWNATTR_DESTROY@
300/* Free resources associated with ATTR. */
301# if @REPLACE_POSIX_SPAWN@
302# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
303# define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
304# endif
305_GL_FUNCDECL_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)
306 __THROW _GL_ARG_NONNULL ((1)));
307_GL_CXXALIAS_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr));
308# else
309# if !@HAVE_POSIX_SPAWN@
310_GL_FUNCDECL_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)
311 __THROW _GL_ARG_NONNULL ((1)));
312# endif
313_GL_CXXALIAS_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr));
314# endif
315_GL_CXXALIASWARN (posix_spawnattr_destroy);
316#elif defined GNULIB_POSIXCHECK
317# undef posix_spawnattr_destroy
318# if HAVE_RAW_DECL_POSIX_SPAWNATTR_DESTROY
319_GL_WARN_ON_USE (posix_spawnattr_destroy,
320 "posix_spawnattr_destroy is unportable - "
321 "use gnulib module posix_spawnattr_destroy for portability");
322# endif
323#endif
324
325#if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
326/* Store signal mask for signals with default handling from ATTR in
327 SIGDEFAULT. */
328# if @REPLACE_POSIX_SPAWN@
329# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
330# define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
331# endif
332_GL_FUNCDECL_RPL (posix_spawnattr_getsigdefault, int,
333 (const posix_spawnattr_t *_Restrict_ __attr,
334 sigset_t *_Restrict_ __sigdefault)
335 __THROW _GL_ARG_NONNULL ((1, 2)));
336_GL_CXXALIAS_RPL (posix_spawnattr_getsigdefault, int,
337 (const posix_spawnattr_t *_Restrict_ __attr,
338 sigset_t *_Restrict_ __sigdefault));
339# else
340# if !@HAVE_POSIX_SPAWN@
341_GL_FUNCDECL_SYS (posix_spawnattr_getsigdefault, int,
342 (const posix_spawnattr_t *_Restrict_ __attr,
343 sigset_t *_Restrict_ __sigdefault)
344 __THROW _GL_ARG_NONNULL ((1, 2)));
345# endif
346_GL_CXXALIAS_SYS (posix_spawnattr_getsigdefault, int,
347 (const posix_spawnattr_t *_Restrict_ __attr,
348 sigset_t *_Restrict_ __sigdefault));
349# endif
350_GL_CXXALIASWARN (posix_spawnattr_getsigdefault);
351#elif defined GNULIB_POSIXCHECK
352# undef posix_spawnattr_getsigdefault
353# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGDEFAULT
354_GL_WARN_ON_USE (posix_spawnattr_getsigdefault,
355 "posix_spawnattr_getsigdefault is unportable - "
356 "use gnulib module posix_spawnattr_getsigdefault for portability");
357# endif
358#endif
359
360#if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
361/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
362# if @REPLACE_POSIX_SPAWN@
363# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
364# define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
365# endif
366_GL_FUNCDECL_RPL (posix_spawnattr_setsigdefault, int,
367 (posix_spawnattr_t *_Restrict_ __attr,
368 const sigset_t *_Restrict_ __sigdefault)
369 __THROW _GL_ARG_NONNULL ((1, 2)));
370_GL_CXXALIAS_RPL (posix_spawnattr_setsigdefault, int,
371 (posix_spawnattr_t *_Restrict_ __attr,
372 const sigset_t *_Restrict_ __sigdefault));
373# else
374# if !@HAVE_POSIX_SPAWN@
375_GL_FUNCDECL_SYS (posix_spawnattr_setsigdefault, int,
376 (posix_spawnattr_t *_Restrict_ __attr,
377 const sigset_t *_Restrict_ __sigdefault)
378 __THROW _GL_ARG_NONNULL ((1, 2)));
379# endif
380_GL_CXXALIAS_SYS (posix_spawnattr_setsigdefault, int,
381 (posix_spawnattr_t *_Restrict_ __attr,
382 const sigset_t *_Restrict_ __sigdefault));
383# endif
384_GL_CXXALIASWARN (posix_spawnattr_setsigdefault);
385#elif defined GNULIB_POSIXCHECK
386# undef posix_spawnattr_setsigdefault
387# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGDEFAULT
388_GL_WARN_ON_USE (posix_spawnattr_setsigdefault,
389 "posix_spawnattr_setsigdefault is unportable - "
390 "use gnulib module posix_spawnattr_setsigdefault for portability");
391# endif
392#endif
393
394#if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
395/* Store signal mask for the new process from ATTR in SIGMASK. */
396# if @REPLACE_POSIX_SPAWN@
397# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
398# define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
399# endif
400_GL_FUNCDECL_RPL (posix_spawnattr_getsigmask, int,
401 (const posix_spawnattr_t *_Restrict_ __attr,
402 sigset_t *_Restrict_ __sigmask)
403 __THROW _GL_ARG_NONNULL ((1, 2)));
404_GL_CXXALIAS_RPL (posix_spawnattr_getsigmask, int,
405 (const posix_spawnattr_t *_Restrict_ __attr,
406 sigset_t *_Restrict_ __sigmask));
407# else
408# if !@HAVE_POSIX_SPAWN@
409_GL_FUNCDECL_SYS (posix_spawnattr_getsigmask, int,
410 (const posix_spawnattr_t *_Restrict_ __attr,
411 sigset_t *_Restrict_ __sigmask)
412 __THROW _GL_ARG_NONNULL ((1, 2)));
413# endif
414_GL_CXXALIAS_SYS (posix_spawnattr_getsigmask, int,
415 (const posix_spawnattr_t *_Restrict_ __attr,
416 sigset_t *_Restrict_ __sigmask));
417# endif
418_GL_CXXALIASWARN (posix_spawnattr_getsigmask);
419#elif defined GNULIB_POSIXCHECK
420# undef posix_spawnattr_getsigmask
421# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGMASK
422_GL_WARN_ON_USE (posix_spawnattr_getsigmask,
423 "posix_spawnattr_getsigmask is unportable - "
424 "use gnulib module posix_spawnattr_getsigmask for portability");
425# endif
426#endif
427
428#if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
429/* Set signal mask for the new process in ATTR to SIGMASK. */
430# if @REPLACE_POSIX_SPAWN@
431# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
432# define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
433# endif
434_GL_FUNCDECL_RPL (posix_spawnattr_setsigmask, int,
435 (posix_spawnattr_t *_Restrict_ __attr,
436 const sigset_t *_Restrict_ __sigmask)
437 __THROW _GL_ARG_NONNULL ((1, 2)));
438_GL_CXXALIAS_RPL (posix_spawnattr_setsigmask, int,
439 (posix_spawnattr_t *_Restrict_ __attr,
440 const sigset_t *_Restrict_ __sigmask));
441# else
442# if !@HAVE_POSIX_SPAWN@
443_GL_FUNCDECL_SYS (posix_spawnattr_setsigmask, int,
444 (posix_spawnattr_t *_Restrict_ __attr,
445 const sigset_t *_Restrict_ __sigmask)
446 __THROW _GL_ARG_NONNULL ((1, 2)));
447# endif
448_GL_CXXALIAS_SYS (posix_spawnattr_setsigmask, int,
449 (posix_spawnattr_t *_Restrict_ __attr,
450 const sigset_t *_Restrict_ __sigmask));
451# endif
452_GL_CXXALIASWARN (posix_spawnattr_setsigmask);
453#elif defined GNULIB_POSIXCHECK
454# undef posix_spawnattr_setsigmask
455# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGMASK
456_GL_WARN_ON_USE (posix_spawnattr_setsigmask,
457 "posix_spawnattr_setsigmask is unportable - "
458 "use gnulib module posix_spawnattr_setsigmask for portability");
459# endif
460#endif
461
462#if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
463/* Get flag word from the attribute structure. */
464# if @REPLACE_POSIX_SPAWN@
465# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
466# define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
467# endif
468_GL_FUNCDECL_RPL (posix_spawnattr_getflags, int,
469 (const posix_spawnattr_t *_Restrict_ __attr,
470 short int *_Restrict_ __flags)
471 __THROW _GL_ARG_NONNULL ((1, 2)));
472_GL_CXXALIAS_RPL (posix_spawnattr_getflags, int,
473 (const posix_spawnattr_t *_Restrict_ __attr,
474 short int *_Restrict_ __flags));
475# else
476# if !@HAVE_POSIX_SPAWN@
477_GL_FUNCDECL_SYS (posix_spawnattr_getflags, int,
478 (const posix_spawnattr_t *_Restrict_ __attr,
479 short int *_Restrict_ __flags)
480 __THROW _GL_ARG_NONNULL ((1, 2)));
481# endif
482_GL_CXXALIAS_SYS (posix_spawnattr_getflags, int,
483 (const posix_spawnattr_t *_Restrict_ __attr,
484 short int *_Restrict_ __flags));
485# endif
486_GL_CXXALIASWARN (posix_spawnattr_getflags);
487#elif defined GNULIB_POSIXCHECK
488# undef posix_spawnattr_getflags
489# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETFLAGS
490_GL_WARN_ON_USE (posix_spawnattr_getflags,
491 "posix_spawnattr_getflags is unportable - "
492 "use gnulib module posix_spawnattr_getflags for portability");
493# endif
494#endif
495
496#if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
497/* Store flags in the attribute structure. */
498# if @REPLACE_POSIX_SPAWN@
499# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
500# define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
501# endif
502_GL_FUNCDECL_RPL (posix_spawnattr_setflags, int,
503 (posix_spawnattr_t *__attr, short int __flags)
504 __THROW _GL_ARG_NONNULL ((1)));
505_GL_CXXALIAS_RPL (posix_spawnattr_setflags, int,
506 (posix_spawnattr_t *__attr, short int __flags));
507# else
508# if !@HAVE_POSIX_SPAWN@
509_GL_FUNCDECL_SYS (posix_spawnattr_setflags, int,
510 (posix_spawnattr_t *__attr, short int __flags)
511 __THROW _GL_ARG_NONNULL ((1)));
512# endif
513_GL_CXXALIAS_SYS (posix_spawnattr_setflags, int,
514 (posix_spawnattr_t *__attr, short int __flags));
515# endif
516_GL_CXXALIASWARN (posix_spawnattr_setflags);
517#elif defined GNULIB_POSIXCHECK
518# undef posix_spawnattr_setflags
519# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETFLAGS
520_GL_WARN_ON_USE (posix_spawnattr_setflags,
521 "posix_spawnattr_setflags is unportable - "
522 "use gnulib module posix_spawnattr_setflags for portability");
523# endif
524#endif
525
526#if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
527/* Get process group ID from the attribute structure. */
528# if @REPLACE_POSIX_SPAWN@
529# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
530# define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
531# endif
532_GL_FUNCDECL_RPL (posix_spawnattr_getpgroup, int,
533 (const posix_spawnattr_t *_Restrict_ __attr,
534 pid_t *_Restrict_ __pgroup)
535 __THROW _GL_ARG_NONNULL ((1, 2)));
536_GL_CXXALIAS_RPL (posix_spawnattr_getpgroup, int,
537 (const posix_spawnattr_t *_Restrict_ __attr,
538 pid_t *_Restrict_ __pgroup));
539# else
540# if !@HAVE_POSIX_SPAWN@
541_GL_FUNCDECL_SYS (posix_spawnattr_getpgroup, int,
542 (const posix_spawnattr_t *_Restrict_ __attr,
543 pid_t *_Restrict_ __pgroup)
544 __THROW _GL_ARG_NONNULL ((1, 2)));
545# endif
546_GL_CXXALIAS_SYS (posix_spawnattr_getpgroup, int,
547 (const posix_spawnattr_t *_Restrict_ __attr,
548 pid_t *_Restrict_ __pgroup));
549# endif
550_GL_CXXALIASWARN (posix_spawnattr_getpgroup);
551#elif defined GNULIB_POSIXCHECK
552# undef posix_spawnattr_getpgroup
553# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETPGROUP
554_GL_WARN_ON_USE (posix_spawnattr_getpgroup,
555 "posix_spawnattr_getpgroup is unportable - "
556 "use gnulib module posix_spawnattr_getpgroup for portability");
557# endif
558#endif
559
560#if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
561/* Store process group ID in the attribute structure. */
562# if @REPLACE_POSIX_SPAWN@
563# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
564# define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
565# endif
566_GL_FUNCDECL_RPL (posix_spawnattr_setpgroup, int,
567 (posix_spawnattr_t *__attr, pid_t __pgroup)
568 __THROW _GL_ARG_NONNULL ((1)));
569_GL_CXXALIAS_RPL (posix_spawnattr_setpgroup, int,
570 (posix_spawnattr_t *__attr, pid_t __pgroup));
571# else
572# if !@HAVE_POSIX_SPAWN@
573_GL_FUNCDECL_SYS (posix_spawnattr_setpgroup, int,
574 (posix_spawnattr_t *__attr, pid_t __pgroup)
575 __THROW _GL_ARG_NONNULL ((1)));
576# endif
577_GL_CXXALIAS_SYS (posix_spawnattr_setpgroup, int,
578 (posix_spawnattr_t *__attr, pid_t __pgroup));
579# endif
580_GL_CXXALIASWARN (posix_spawnattr_setpgroup);
581#elif defined GNULIB_POSIXCHECK
582# undef posix_spawnattr_setpgroup
583# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETPGROUP
584_GL_WARN_ON_USE (posix_spawnattr_setpgroup,
585 "posix_spawnattr_setpgroup is unportable - "
586 "use gnulib module posix_spawnattr_setpgroup for portability");
587# endif
588#endif
589
590#if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
591/* Get scheduling policy from the attribute structure. */
592# if @REPLACE_POSIX_SPAWN@
593# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
594# define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
595# endif
596_GL_FUNCDECL_RPL (posix_spawnattr_getschedpolicy, int,
597 (const posix_spawnattr_t *_Restrict_ __attr,
598 int *_Restrict_ __schedpolicy)
599 __THROW _GL_ARG_NONNULL ((1, 2)));
600_GL_CXXALIAS_RPL (posix_spawnattr_getschedpolicy, int,
601 (const posix_spawnattr_t *_Restrict_ __attr,
602 int *_Restrict_ __schedpolicy));
603# else
604# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDULER == 0
605_GL_FUNCDECL_SYS (posix_spawnattr_getschedpolicy, int,
606 (const posix_spawnattr_t *_Restrict_ __attr,
607 int *_Restrict_ __schedpolicy)
608 __THROW _GL_ARG_NONNULL ((1, 2)));
609# endif
610_GL_CXXALIAS_SYS (posix_spawnattr_getschedpolicy, int,
611 (const posix_spawnattr_t *_Restrict_ __attr,
612 int *_Restrict_ __schedpolicy));
613# endif
614# if __GLIBC__ >= 2
615_GL_CXXALIASWARN (posix_spawnattr_getschedpolicy);
616# endif
617#elif defined GNULIB_POSIXCHECK
618# undef posix_spawnattr_getschedpolicy
619# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPOLICY
620_GL_WARN_ON_USE (posix_spawnattr_getschedpolicy,
621 "posix_spawnattr_getschedpolicy is unportable - "
622 "use gnulib module posix_spawnattr_getschedpolicy for portability");
623# endif
624#endif
625
626#if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
627/* Store scheduling policy in the attribute structure. */
628# if @REPLACE_POSIX_SPAWN@
629# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
630# define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
631# endif
632_GL_FUNCDECL_RPL (posix_spawnattr_setschedpolicy, int,
633 (posix_spawnattr_t *__attr, int __schedpolicy)
634 __THROW _GL_ARG_NONNULL ((1)));
635_GL_CXXALIAS_RPL (posix_spawnattr_setschedpolicy, int,
636 (posix_spawnattr_t *__attr, int __schedpolicy));
637# else
638# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDULER == 0
639_GL_FUNCDECL_SYS (posix_spawnattr_setschedpolicy, int,
640 (posix_spawnattr_t *__attr, int __schedpolicy)
641 __THROW _GL_ARG_NONNULL ((1)));
642# endif
643_GL_CXXALIAS_SYS (posix_spawnattr_setschedpolicy, int,
644 (posix_spawnattr_t *__attr, int __schedpolicy));
645# endif
646# if __GLIBC__ >= 2
647_GL_CXXALIASWARN (posix_spawnattr_setschedpolicy);
648# endif
649#elif defined GNULIB_POSIXCHECK
650# undef posix_spawnattr_setschedpolicy
651# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPOLICY
652_GL_WARN_ON_USE (posix_spawnattr_setschedpolicy,
653 "posix_spawnattr_setschedpolicy is unportable - "
654 "use gnulib module posix_spawnattr_setschedpolicy for portability");
655# endif
656#endif
657
658#if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
659/* Get scheduling parameters from the attribute structure. */
660# if @REPLACE_POSIX_SPAWN@
661# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
662# define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
663# endif
664_GL_FUNCDECL_RPL (posix_spawnattr_getschedparam, int,
665 (const posix_spawnattr_t *_Restrict_ __attr,
666 struct sched_param *_Restrict_ __schedparam)
667 __THROW _GL_ARG_NONNULL ((1, 2)));
668_GL_CXXALIAS_RPL (posix_spawnattr_getschedparam, int,
669 (const posix_spawnattr_t *_Restrict_ __attr,
670 struct sched_param *_Restrict_ __schedparam));
671# else
672# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDPARAM == 0
673_GL_FUNCDECL_SYS (posix_spawnattr_getschedparam, int,
674 (const posix_spawnattr_t *_Restrict_ __attr,
675 struct sched_param *_Restrict_ __schedparam)
676 __THROW _GL_ARG_NONNULL ((1, 2)));
677# endif
678_GL_CXXALIAS_SYS (posix_spawnattr_getschedparam, int,
679 (const posix_spawnattr_t *_Restrict_ __attr,
680 struct sched_param *_Restrict_ __schedparam));
681# endif
682# if __GLIBC__ >= 2
683_GL_CXXALIASWARN (posix_spawnattr_getschedparam);
684# endif
685#elif defined GNULIB_POSIXCHECK
686# undef posix_spawnattr_getschedparam
687# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPARAM
688_GL_WARN_ON_USE (posix_spawnattr_getschedparam,
689 "posix_spawnattr_getschedparam is unportable - "
690 "use gnulib module posix_spawnattr_getschedparam for portability");
691# endif
692#endif
693
694#if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
695/* Store scheduling parameters in the attribute structure. */
696# if @REPLACE_POSIX_SPAWN@
697# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
698# define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
699# endif
700_GL_FUNCDECL_RPL (posix_spawnattr_setschedparam, int,
701 (posix_spawnattr_t *_Restrict_ __attr,
702 const struct sched_param *_Restrict_ __schedparam)
703 __THROW _GL_ARG_NONNULL ((1, 2)));
704_GL_CXXALIAS_RPL (posix_spawnattr_setschedparam, int,
705 (posix_spawnattr_t *_Restrict_ __attr,
706 const struct sched_param *_Restrict_ __schedparam));
707# else
708# if !@HAVE_POSIX_SPAWN@ || POSIX_SPAWN_SETSCHEDPARAM == 0
709_GL_FUNCDECL_SYS (posix_spawnattr_setschedparam, int,
710 (posix_spawnattr_t *_Restrict_ __attr,
711 const struct sched_param *_Restrict_ __schedparam)
712 __THROW _GL_ARG_NONNULL ((1, 2)));
713# endif
714_GL_CXXALIAS_SYS (posix_spawnattr_setschedparam, int,
715 (posix_spawnattr_t *_Restrict_ __attr,
716 const struct sched_param *_Restrict_ __schedparam));
717# endif
718# if __GLIBC__ >= 2
719_GL_CXXALIASWARN (posix_spawnattr_setschedparam);
720# endif
721#elif defined GNULIB_POSIXCHECK
722# undef posix_spawnattr_setschedparam
723# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPARAM
724_GL_WARN_ON_USE (posix_spawnattr_setschedparam,
725 "posix_spawnattr_setschedparam is unportable - "
726 "use gnulib module posix_spawnattr_setschedparam for portability");
727# endif
728#endif
729
730
731#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
732/* Initialize data structure for file attribute for 'spawn' call. */
733# if @REPLACE_POSIX_SPAWN@
734# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
735# define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
736# endif
737_GL_FUNCDECL_RPL (posix_spawn_file_actions_init, int,
738 (posix_spawn_file_actions_t *__file_actions)
739 __THROW _GL_ARG_NONNULL ((1)));
740_GL_CXXALIAS_RPL (posix_spawn_file_actions_init, int,
741 (posix_spawn_file_actions_t *__file_actions));
742# else
743# if !@HAVE_POSIX_SPAWN@
744_GL_FUNCDECL_SYS (posix_spawn_file_actions_init, int,
745 (posix_spawn_file_actions_t *__file_actions)
746 __THROW _GL_ARG_NONNULL ((1)));
747# endif
748_GL_CXXALIAS_SYS (posix_spawn_file_actions_init, int,
749 (posix_spawn_file_actions_t *__file_actions));
750# endif
751_GL_CXXALIASWARN (posix_spawn_file_actions_init);
752#elif defined GNULIB_POSIXCHECK
753# undef posix_spawn_file_actions_init
754# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_INIT
755_GL_WARN_ON_USE (posix_spawn_file_actions_init,
756 "posix_spawn_file_actions_init is unportable - "
757 "use gnulib module posix_spawn_file_actions_init for portability");
758# endif
759#endif
760
761#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
762/* Free resources associated with FILE-ACTIONS. */
763# if @REPLACE_POSIX_SPAWN@
764# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
765# define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
766# endif
767_GL_FUNCDECL_RPL (posix_spawn_file_actions_destroy, int,
768 (posix_spawn_file_actions_t *__file_actions)
769 __THROW _GL_ARG_NONNULL ((1)));
770_GL_CXXALIAS_RPL (posix_spawn_file_actions_destroy, int,
771 (posix_spawn_file_actions_t *__file_actions));
772# else
773# if !@HAVE_POSIX_SPAWN@
774_GL_FUNCDECL_SYS (posix_spawn_file_actions_destroy, int,
775 (posix_spawn_file_actions_t *__file_actions)
776 __THROW _GL_ARG_NONNULL ((1)));
777# endif
778_GL_CXXALIAS_SYS (posix_spawn_file_actions_destroy, int,
779 (posix_spawn_file_actions_t *__file_actions));
780# endif
781_GL_CXXALIASWARN (posix_spawn_file_actions_destroy);
782#elif defined GNULIB_POSIXCHECK
783# undef posix_spawn_file_actions_destroy
784# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_DESTROY
785_GL_WARN_ON_USE (posix_spawn_file_actions_destroy,
786 "posix_spawn_file_actions_destroy is unportable - "
787 "use gnulib module posix_spawn_file_actions_destroy for portability");
788# endif
789#endif
790
791#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
792/* Add an action to FILE-ACTIONS which tells the implementation to call
793 'open' for the given file during the 'spawn' call. */
794# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
795# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
796# define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
797# endif
798_GL_FUNCDECL_RPL (posix_spawn_file_actions_addopen, int,
799 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
800 int __fd,
801 const char *_Restrict_ __path, int __oflag, mode_t __mode)
802 __THROW _GL_ARG_NONNULL ((1, 3)));
803_GL_CXXALIAS_RPL (posix_spawn_file_actions_addopen, int,
804 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
805 int __fd,
806 const char *_Restrict_ __path, int __oflag, mode_t __mode));
807# else
808# if !@HAVE_POSIX_SPAWN@
809_GL_FUNCDECL_SYS (posix_spawn_file_actions_addopen, int,
810 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
811 int __fd,
812 const char *_Restrict_ __path, int __oflag, mode_t __mode)
813 __THROW _GL_ARG_NONNULL ((1, 3)));
814# endif
815_GL_CXXALIAS_SYS (posix_spawn_file_actions_addopen, int,
816 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
817 int __fd,
818 const char *_Restrict_ __path, int __oflag, mode_t __mode));
819# endif
820# if __GLIBC__ >= 2
821_GL_CXXALIASWARN (posix_spawn_file_actions_addopen);
822# endif
823#elif defined GNULIB_POSIXCHECK
824# undef posix_spawn_file_actions_addopen
825# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN
826_GL_WARN_ON_USE (posix_spawn_file_actions_addopen,
827 "posix_spawn_file_actions_addopen is unportable - "
828 "use gnulib module posix_spawn_file_actions_addopen for portability");
829# endif
830#endif
831
832#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
833/* Add an action to FILE-ACTIONS which tells the implementation to call
834 'close' for the given file descriptor during the 'spawn' call. */
835# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
836# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
837# define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
838# endif
839_GL_FUNCDECL_RPL (posix_spawn_file_actions_addclose, int,
840 (posix_spawn_file_actions_t *__file_actions, int __fd)
841 __THROW _GL_ARG_NONNULL ((1)));
842_GL_CXXALIAS_RPL (posix_spawn_file_actions_addclose, int,
843 (posix_spawn_file_actions_t *__file_actions, int __fd));
844# else
845# if !@HAVE_POSIX_SPAWN@
846_GL_FUNCDECL_SYS (posix_spawn_file_actions_addclose, int,
847 (posix_spawn_file_actions_t *__file_actions, int __fd)
848 __THROW _GL_ARG_NONNULL ((1)));
849# endif
850_GL_CXXALIAS_SYS (posix_spawn_file_actions_addclose, int,
851 (posix_spawn_file_actions_t *__file_actions, int __fd));
852# endif
853# if __GLIBC__ >= 2
854_GL_CXXALIASWARN (posix_spawn_file_actions_addclose);
855# endif
856#elif defined GNULIB_POSIXCHECK
857# undef posix_spawn_file_actions_addclose
858# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE
859_GL_WARN_ON_USE (posix_spawn_file_actions_addclose,
860 "posix_spawn_file_actions_addclose is unportable - "
861 "use gnulib module posix_spawn_file_actions_addclose for portability");
862# endif
863#endif
864
865#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
866/* Add an action to FILE-ACTIONS which tells the implementation to call
867 'dup2' for the given file descriptors during the 'spawn' call. */
868# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
869# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
870# define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
871# endif
872_GL_FUNCDECL_RPL (posix_spawn_file_actions_adddup2, int,
873 (posix_spawn_file_actions_t *__file_actions,
874 int __fd, int __newfd)
875 __THROW _GL_ARG_NONNULL ((1)));
876_GL_CXXALIAS_RPL (posix_spawn_file_actions_adddup2, int,
877 (posix_spawn_file_actions_t *__file_actions,
878 int __fd, int __newfd));
879# else
880# if !@HAVE_POSIX_SPAWN@
881_GL_FUNCDECL_SYS (posix_spawn_file_actions_adddup2, int,
882 (posix_spawn_file_actions_t *__file_actions,
883 int __fd, int __newfd)
884 __THROW _GL_ARG_NONNULL ((1)));
885# endif
886_GL_CXXALIAS_SYS (posix_spawn_file_actions_adddup2, int,
887 (posix_spawn_file_actions_t *__file_actions,
888 int __fd, int __newfd));
889# endif
890# if __GLIBC__ >= 2
891_GL_CXXALIASWARN (posix_spawn_file_actions_adddup2);
892# endif
893#elif defined GNULIB_POSIXCHECK
894# undef posix_spawn_file_actions_adddup2
895# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
896_GL_WARN_ON_USE (posix_spawn_file_actions_adddup2,
897 "posix_spawn_file_actions_adddup2 is unportable - "
898 "use gnulib module posix_spawn_file_actions_adddup2 for portability");
899# endif
900#endif
901
902#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
903/* Add an action to FILE-ACTIONS which tells the implementation to call
904 'chdir' to the given directory during the 'spawn' call. */
905# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
906# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
907# define posix_spawn_file_actions_addchdir rpl_posix_spawn_file_actions_addchdir
908# endif
909_GL_FUNCDECL_RPL (posix_spawn_file_actions_addchdir, int,
910 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
911 const char *_Restrict_ __path)
912 __THROW _GL_ARG_NONNULL ((1, 2)));
913_GL_CXXALIAS_RPL (posix_spawn_file_actions_addchdir, int,
914 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
915 const char *_Restrict_ __path));
916# else
917# if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
918_GL_FUNCDECL_SYS (posix_spawn_file_actions_addchdir, int,
919 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
920 const char *_Restrict_ __path)
921 __THROW _GL_ARG_NONNULL ((1, 2)));
922# endif
923_GL_CXXALIAS_SYS (posix_spawn_file_actions_addchdir, int,
924 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
925 const char *_Restrict_ __path));
926# endif
927_GL_CXXALIASWARN (posix_spawn_file_actions_addchdir);
928#elif defined GNULIB_POSIXCHECK
929# undef posix_spawn_file_actions_addchdir
930# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
931_GL_WARN_ON_USE (posix_spawn_file_actions_addchdir,
932 "posix_spawn_file_actions_addchdir is unportable - "
933 "use gnulib module posix_spawn_file_actions_addchdir for portability");
934# endif
935#endif
936
937#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@
938/* Add an action to FILE-ACTIONS which tells the implementation to call
939 'fchdir' to the given directory during the 'spawn' call. */
940# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@
941# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
942# define posix_spawn_file_actions_addfchdir rpl_posix_spawn_file_actions_addfchdir
943# endif
944_GL_FUNCDECL_RPL (posix_spawn_file_actions_addfchdir, int,
945 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
946 int __fd)
947 __THROW _GL_ARG_NONNULL ((1)));
948_GL_CXXALIAS_RPL (posix_spawn_file_actions_addfchdir, int,
949 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
950 int __fd));
951# else
952# if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR@
953_GL_FUNCDECL_SYS (posix_spawn_file_actions_addfchdir, int,
954 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
955 int __fd)
956 __THROW _GL_ARG_NONNULL ((1)));
957# endif
958_GL_CXXALIAS_SYS (posix_spawn_file_actions_addfchdir, int,
959 (posix_spawn_file_actions_t *_Restrict_ __file_actions,
960 int __fd));
961# endif
962_GL_CXXALIASWARN (posix_spawn_file_actions_addfchdir);
963#elif defined GNULIB_POSIXCHECK
964# undef posix_spawn_file_actions_addfchdir
965# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR
966_GL_WARN_ON_USE (posix_spawn_file_actions_addfchdir,
967 "posix_spawn_file_actions_addfchdir is unportable - "
968 "use gnulib module posix_spawn_file_actions_addfchdir for portability");
969# endif
970#endif
971
972
973#endif /* _@GUARD_PREFIX@_SPAWN_H */
974#endif /* _@GUARD_PREFIX@_SPAWN_H */
diff --git a/lib/spawn_faction_addchdir.c b/lib/spawn_faction_addchdir.c
new file mode 100644
index 00000000000..8fb6cb0f7d2
--- /dev/null
+++ b/lib/spawn_faction_addchdir.c
@@ -0,0 +1,70 @@
1/* Copyright (C) 2018-2020 Free Software Foundation, Inc.
2
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3 of the License, or
6 (at your option) any later version.
7
8 This program 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
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <https://www.gnu.org/licenses/>. */
15
16#include <config.h>
17
18/* Specification. */
19#include <spawn.h>
20
21#include <errno.h>
22#include <stdlib.h>
23#include <string.h>
24
25#if REPLACE_POSIX_SPAWN
26# include "spawn_int.h"
27#endif
28
29/* Add an action to FILE-ACTIONS which tells the implementation to call
30 'chdir' to the given directory during the 'spawn' call. */
31int
32posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t *file_actions,
33 const char *path)
34#undef posix_spawn_file_actions_addchdir
35{
36#if !REPLACE_POSIX_SPAWN
37 return posix_spawn_file_actions_addchdir_np (file_actions, path);
38#else
39 {
40 /* Copy PATH, because the caller may free it before calling posix_spawn()
41 or posix_spawnp(). */
42 char *path_copy = strdup (path);
43 if (path_copy == NULL)
44 return ENOMEM;
45
46 /* Allocate more memory if needed. */
47 if (file_actions->_used == file_actions->_allocated
48 && __posix_spawn_file_actions_realloc (file_actions) != 0)
49 {
50 /* This can only mean we ran out of memory. */
51 free (path_copy);
52 return ENOMEM;
53 }
54
55 {
56 struct __spawn_action *rec;
57
58 /* Add the new value. */
59 rec = &file_actions->_actions[file_actions->_used];
60 rec->tag = spawn_do_chdir;
61 rec->action.chdir_action.path = path_copy;
62
63 /* Account for the new entry. */
64 ++file_actions->_used;
65
66 return 0;
67 }
68 }
69#endif
70}
diff --git a/lib/spawn_faction_adddup2.c b/lib/spawn_faction_adddup2.c
new file mode 100644
index 00000000000..c00b0b49668
--- /dev/null
+++ b/lib/spawn_faction_adddup2.c
@@ -0,0 +1,70 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <errno.h>
23#include <unistd.h>
24
25#if !_LIBC
26# define __sysconf(open_max) getdtablesize ()
27#endif
28
29#if REPLACE_POSIX_SPAWN
30# include "spawn_int.h"
31#endif
32
33/* Add an action to FILE-ACTIONS which tells the implementation to call
34 'dup2' for the given file descriptors during the 'spawn' call. */
35int
36posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions,
37 int fd, int newfd)
38#undef posix_spawn_file_actions_adddup2
39{
40 int maxfd = __sysconf (_SC_OPEN_MAX);
41
42 /* Test for the validity of the file descriptor. */
43 if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd)
44 return EBADF;
45
46#if !REPLACE_POSIX_SPAWN
47 return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd);
48#else
49 /* Allocate more memory if needed. */
50 if (file_actions->_used == file_actions->_allocated
51 && __posix_spawn_file_actions_realloc (file_actions) != 0)
52 /* This can only mean we ran out of memory. */
53 return ENOMEM;
54
55 {
56 struct __spawn_action *rec;
57
58 /* Add the new value. */
59 rec = &file_actions->_actions[file_actions->_used];
60 rec->tag = spawn_do_dup2;
61 rec->action.dup2_action.fd = fd;
62 rec->action.dup2_action.newfd = newfd;
63
64 /* Account for the new entry. */
65 ++file_actions->_used;
66
67 return 0;
68 }
69#endif
70}
diff --git a/lib/spawn_faction_destroy.c b/lib/spawn_faction_destroy.c
new file mode 100644
index 00000000000..e9985f4a0d4
--- /dev/null
+++ b/lib/spawn_faction_destroy.c
@@ -0,0 +1,61 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <stdlib.h>
23
24#if REPLACE_POSIX_SPAWN
25# include "spawn_int.h"
26#endif
27
28/* Initialize data structure for file attribute for 'spawn' call. */
29int
30posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions)
31#undef posix_spawn_file_actions_destroy
32{
33#if !REPLACE_POSIX_SPAWN
34 return posix_spawn_file_actions_destroy (file_actions);
35#else
36 int i;
37
38 /* Free the paths in the open actions. */
39 for (i = 0; i < file_actions->_used; ++i)
40 {
41 struct __spawn_action *sa = &file_actions->_actions[i];
42 switch (sa->tag)
43 {
44 case spawn_do_open:
45 free (sa->action.open_action.path);
46 break;
47 case spawn_do_chdir:
48 free (sa->action.chdir_action.path);
49 break;
50 default:
51 /* No cleanup required. */
52 break;
53 }
54 }
55
56 /* Free the array of actions. */
57 free (file_actions->_actions);
58
59 return 0;
60#endif
61}
diff --git a/lib/spawn_faction_init.c b/lib/spawn_faction_init.c
new file mode 100644
index 00000000000..135605fb8c6
--- /dev/null
+++ b/lib/spawn_faction_init.c
@@ -0,0 +1,56 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <errno.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "spawn_int.h"
27
28
29/* Function used to increase the size of the allocated array. This
30 function is called from the 'add'-functions. */
31int
32__posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions)
33{
34 int newalloc = file_actions->_allocated + 8;
35 void *newmem = realloc (file_actions->_actions,
36 newalloc * sizeof (struct __spawn_action));
37
38 if (newmem == NULL)
39 /* Not enough memory. */
40 return ENOMEM;
41
42 file_actions->_actions = (struct __spawn_action *) newmem;
43 file_actions->_allocated = newalloc;
44
45 return 0;
46}
47
48
49/* Initialize data structure for file attribute for 'spawn' call. */
50int
51posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions)
52{
53 /* Simply clear all the elements. */
54 memset (file_actions, '\0', sizeof (*file_actions));
55 return 0;
56}
diff --git a/lib/spawn_int.h b/lib/spawn_int.h
new file mode 100644
index 00000000000..60a94ddd55a
--- /dev/null
+++ b/lib/spawn_int.h
@@ -0,0 +1,72 @@
1/* Copyright (C) 2000, 2008-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <sys/types.h>
18
19/* Data structure to contain the action information. */
20struct __spawn_action
21{
22 enum
23 {
24 spawn_do_close,
25 spawn_do_dup2,
26 spawn_do_open,
27 spawn_do_chdir,
28 spawn_do_fchdir
29 } tag;
30
31 union
32 {
33 struct
34 {
35 int fd;
36 } close_action;
37 struct
38 {
39 int fd;
40 int newfd;
41 } dup2_action;
42 struct
43 {
44 int fd;
45 char *path;
46 int oflag;
47 mode_t mode;
48 } open_action;
49 struct
50 {
51 char *path;
52 } chdir_action;
53 struct
54 {
55 int fd;
56 } fchdir_action;
57 } action;
58};
59
60#if !_LIBC
61# define __posix_spawn_file_actions_realloc gl_posix_spawn_file_actions_realloc
62#endif
63extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *
64 file_actions);
65
66#if !_LIBC
67# define __spawni gl_posix_spawn_internal
68#endif
69extern int __spawni (pid_t *pid, const char *path,
70 const posix_spawn_file_actions_t *file_actions,
71 const posix_spawnattr_t *attrp, const char *const argv[],
72 const char *const envp[], int use_path);
diff --git a/lib/spawnattr_destroy.c b/lib/spawnattr_destroy.c
new file mode 100644
index 00000000000..22a7d5a61a2
--- /dev/null
+++ b/lib/spawnattr_destroy.c
@@ -0,0 +1,28 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22/* Initialize data structure for file attribute for 'spawn' call. */
23int
24posix_spawnattr_destroy (posix_spawnattr_t *attr)
25{
26 /* Nothing to do in the moment. */
27 return 0;
28}
diff --git a/lib/spawnattr_init.c b/lib/spawnattr_init.c
new file mode 100644
index 00000000000..99674488f81
--- /dev/null
+++ b/lib/spawnattr_init.c
@@ -0,0 +1,33 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <string.h>
23
24/* Initialize data structure for file attribute for 'spawn' call. */
25int
26posix_spawnattr_init (posix_spawnattr_t *attr)
27{
28 /* All elements have to be initialized to the default values which
29 is generally zero. */
30 memset (attr, '\0', sizeof (*attr));
31
32 return 0;
33}
diff --git a/lib/spawnattr_setdefault.c b/lib/spawnattr_setdefault.c
new file mode 100644
index 00000000000..01c29e94847
--- /dev/null
+++ b/lib/spawnattr_setdefault.c
@@ -0,0 +1,33 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <string.h>
23
24/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
25int
26posix_spawnattr_setsigdefault (posix_spawnattr_t *attr,
27 const sigset_t *sigdefault)
28{
29 /* Copy the sigset_t data to the user buffer. */
30 memcpy (&attr->_sd, sigdefault, sizeof (sigset_t));
31
32 return 0;
33}
diff --git a/lib/spawnattr_setflags.c b/lib/spawnattr_setflags.c
new file mode 100644
index 00000000000..084d5bcea4c
--- /dev/null
+++ b/lib/spawnattr_setflags.c
@@ -0,0 +1,45 @@
1/* Copyright (C) 2000, 2004, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <errno.h>
23#include <string.h>
24
25#define ALL_FLAGS (POSIX_SPAWN_RESETIDS \
26 | POSIX_SPAWN_SETPGROUP \
27 | POSIX_SPAWN_SETSIGDEF \
28 | POSIX_SPAWN_SETSIGMASK \
29 | POSIX_SPAWN_SETSCHEDPARAM \
30 | POSIX_SPAWN_SETSCHEDULER \
31 | POSIX_SPAWN_USEVFORK)
32
33/* Store flags in the attribute structure. */
34int
35posix_spawnattr_setflags (posix_spawnattr_t *attr, short int flags)
36{
37 /* Check no invalid bits are set. */
38 if (flags & ~ALL_FLAGS)
39 return EINVAL;
40
41 /* Store the flag word. */
42 attr->_flags = flags;
43
44 return 0;
45}
diff --git a/lib/spawnattr_setpgroup.c b/lib/spawnattr_setpgroup.c
new file mode 100644
index 00000000000..479457ad23e
--- /dev/null
+++ b/lib/spawnattr_setpgroup.c
@@ -0,0 +1,32 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <string.h>
23
24/* Store process group ID in the attribute structure. */
25int
26posix_spawnattr_setpgroup (posix_spawnattr_t *attr, pid_t pgroup)
27{
28 /* Store the process group ID. */
29 attr->_pgrp = pgroup;
30
31 return 0;
32}
diff --git a/lib/spawnattr_setsigmask.c b/lib/spawnattr_setsigmask.c
new file mode 100644
index 00000000000..9b6f9ece38e
--- /dev/null
+++ b/lib/spawnattr_setsigmask.c
@@ -0,0 +1,33 @@
1/* Copyright (C) 2000, 2009-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <spawn.h>
21
22#include <string.h>
23
24/* Set signal mask for the new process in ATTR to SIGMASK. */
25int
26posix_spawnattr_setsigmask (posix_spawnattr_t *attr,
27 const sigset_t *sigmask)
28{
29 /* Copy the sigset_t data to the user buffer. */
30 memcpy (&attr->_ss, sigmask, sizeof (sigset_t));
31
32 return 0;
33}
diff --git a/lib/spawni.c b/lib/spawni.c
new file mode 100644
index 00000000000..182d13ff24c
--- /dev/null
+++ b/lib/spawni.c
@@ -0,0 +1,349 @@
1/* Guts of POSIX spawn interface. Generic POSIX.1 version.
2 Copyright (C) 2000-2006, 2008-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18#include <config.h>
19
20/* Specification. */
21#include <spawn.h>
22#include "spawn_int.h"
23
24#include <alloca.h>
25#include <errno.h>
26
27#include <fcntl.h>
28#ifndef O_LARGEFILE
29# define O_LARGEFILE 0
30#endif
31
32#if _LIBC || HAVE_PATHS_H
33# include <paths.h>
34#else
35# define _PATH_BSHELL BOURNE_SHELL
36#endif
37
38#include <signal.h>
39#include <stdlib.h>
40#include <string.h>
41#include <unistd.h>
42
43#if _LIBC
44# include <not-cancel.h>
45#else
46# define close_not_cancel close
47# define open_not_cancel open
48#endif
49
50#if _LIBC
51# include <local-setxid.h>
52#else
53# if !HAVE_SETEUID
54# define seteuid(id) setresuid (-1, id, -1)
55# endif
56# if !HAVE_SETEGID
57# define setegid(id) setresgid (-1, id, -1)
58# endif
59# define local_seteuid(id) seteuid (id)
60# define local_setegid(id) setegid (id)
61#endif
62
63#if _LIBC
64# define alloca __alloca
65# define execve __execve
66# define dup2 __dup2
67# define fork __fork
68# define getgid __getgid
69# define getuid __getuid
70# define sched_setparam __sched_setparam
71# define sched_setscheduler __sched_setscheduler
72# define setpgid __setpgid
73# define sigaction __sigaction
74# define sigismember __sigismember
75# define sigprocmask __sigprocmask
76# define strchrnul __strchrnul
77# define vfork __vfork
78#endif
79
80
81/* The Unix standard contains a long explanation of the way to signal
82 an error after the fork() was successful. Since no new wait status
83 was wanted there is no way to signal an error using one of the
84 available methods. The committee chose to signal an error by a
85 normal program exit with the exit code 127. */
86#define SPAWN_ERROR 127
87
88
89#if defined _WIN32 && ! defined __CYGWIN__
90
91/* Native Windows API. */
92int
93__spawni (pid_t *pid, const char *file,
94 const posix_spawn_file_actions_t *file_actions,
95 const posix_spawnattr_t *attrp, const char *const argv[],
96 const char *const envp[], int use_path)
97{
98 /* Not yet implemented. */
99 return ENOSYS;
100}
101
102#else
103
104
105/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
106 Before running the process perform the actions described in FILE-ACTIONS. */
107int
108__spawni (pid_t *pid, const char *file,
109 const posix_spawn_file_actions_t *file_actions,
110 const posix_spawnattr_t *attrp, const char *const argv[],
111 const char *const envp[], int use_path)
112{
113 pid_t new_pid;
114 char *path, *p, *name;
115 size_t len;
116 size_t pathlen;
117
118 /* Do this once. */
119 short int flags = attrp == NULL ? 0 : attrp->_flags;
120
121 /* Avoid gcc warning
122 "variable 'flags' might be clobbered by 'longjmp' or 'vfork'" */
123 (void) &flags;
124
125 /* Generate the new process. */
126#if HAVE_VFORK
127 if ((flags & POSIX_SPAWN_USEVFORK) != 0
128 /* If no major work is done, allow using vfork. Note that we
129 might perform the path searching. But this would be done by
130 a call to execvp(), too, and such a call must be OK according
131 to POSIX. */
132 || ((flags & (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF
133 | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER
134 | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0
135 && file_actions == NULL))
136 new_pid = vfork ();
137 else
138#endif
139 new_pid = fork ();
140
141 if (new_pid != 0)
142 {
143 if (new_pid < 0)
144 return errno;
145
146 /* The call was successful. Store the PID if necessary. */
147 if (pid != NULL)
148 *pid = new_pid;
149
150 return 0;
151 }
152
153 /* Set signal mask. */
154 if ((flags & POSIX_SPAWN_SETSIGMASK) != 0
155 && sigprocmask (SIG_SETMASK, &attrp->_ss, NULL) != 0)
156 _exit (SPAWN_ERROR);
157
158 /* Set signal default action. */
159 if ((flags & POSIX_SPAWN_SETSIGDEF) != 0)
160 {
161 /* We have to iterate over all signals. This could possibly be
162 done better but it requires system specific solutions since
163 the sigset_t data type can be very different on different
164 architectures. */
165 int sig;
166 struct sigaction sa;
167
168 memset (&sa, '\0', sizeof (sa));
169 sa.sa_handler = SIG_DFL;
170
171 for (sig = 1; sig <= NSIG; ++sig)
172 if (sigismember (&attrp->_sd, sig) != 0
173 && sigaction (sig, &sa, NULL) != 0)
174 _exit (SPAWN_ERROR);
175
176 }
177
178#if (_LIBC ? defined _POSIX_PRIORITY_SCHEDULING : HAVE_SCHED_SETPARAM && HAVE_SCHED_SETSCHEDULER)
179 /* Set the scheduling algorithm and parameters. */
180 if ((flags & (POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER))
181 == POSIX_SPAWN_SETSCHEDPARAM)
182 {
183 if (sched_setparam (0, &attrp->_sp) == -1)
184 _exit (SPAWN_ERROR);
185 }
186 else if ((flags & POSIX_SPAWN_SETSCHEDULER) != 0)
187 {
188 if (sched_setscheduler (0, attrp->_policy,
189 (flags & POSIX_SPAWN_SETSCHEDPARAM) != 0
190 ? &attrp->_sp : NULL) == -1)
191 _exit (SPAWN_ERROR);
192 }
193#endif
194
195 /* Set the process group ID. */
196 if ((flags & POSIX_SPAWN_SETPGROUP) != 0
197 && setpgid (0, attrp->_pgrp) != 0)
198 _exit (SPAWN_ERROR);
199
200 /* Set the effective user and group IDs. */
201 if ((flags & POSIX_SPAWN_RESETIDS) != 0
202 && (local_seteuid (getuid ()) != 0
203 || local_setegid (getgid ()) != 0))
204 _exit (SPAWN_ERROR);
205
206 /* Execute the file actions. */
207 if (file_actions != NULL)
208 {
209 int cnt;
210
211 for (cnt = 0; cnt < file_actions->_used; ++cnt)
212 {
213 struct __spawn_action *action = &file_actions->_actions[cnt];
214
215 switch (action->tag)
216 {
217 case spawn_do_close:
218 if (close_not_cancel (action->action.close_action.fd) != 0)
219 /* Signal the error. */
220 _exit (SPAWN_ERROR);
221 break;
222
223 case spawn_do_open:
224 {
225 int new_fd = open_not_cancel (action->action.open_action.path,
226 action->action.open_action.oflag
227 | O_LARGEFILE,
228 action->action.open_action.mode);
229
230 if (new_fd == -1)
231 /* The 'open' call failed. */
232 _exit (SPAWN_ERROR);
233
234 /* Make sure the desired file descriptor is used. */
235 if (new_fd != action->action.open_action.fd)
236 {
237 if (dup2 (new_fd, action->action.open_action.fd)
238 != action->action.open_action.fd)
239 /* The 'dup2' call failed. */
240 _exit (SPAWN_ERROR);
241
242 if (close_not_cancel (new_fd) != 0)
243 /* The 'close' call failed. */
244 _exit (SPAWN_ERROR);
245 }
246 }
247 break;
248
249 case spawn_do_dup2:
250 if (dup2 (action->action.dup2_action.fd,
251 action->action.dup2_action.newfd)
252 != action->action.dup2_action.newfd)
253 /* The 'dup2' call failed. */
254 _exit (SPAWN_ERROR);
255 break;
256
257 case spawn_do_chdir:
258 if (chdir (action->action.chdir_action.path) < 0)
259 /* The 'chdir' call failed. */
260 _exit (SPAWN_ERROR);
261 break;
262
263 case spawn_do_fchdir:
264 if (fchdir (action->action.fchdir_action.fd) < 0)
265 /* The 'fchdir' call failed. */
266 _exit (SPAWN_ERROR);
267 break;
268 }
269 }
270 }
271
272 if (! use_path || strchr (file, '/') != NULL)
273 {
274 /* The FILE parameter is actually a path. */
275 execve (file, (char * const *) argv, (char * const *) envp);
276
277 /* Oh, oh. 'execve' returns. This is bad. */
278 _exit (SPAWN_ERROR);
279 }
280
281 /* We have to search for FILE on the path. */
282 path = getenv ("PATH");
283 if (path == NULL)
284 {
285#if HAVE_CONFSTR
286 /* There is no 'PATH' in the environment.
287 The default search path is the current directory
288 followed by the path 'confstr' returns for '_CS_PATH'. */
289 len = confstr (_CS_PATH, (char *) NULL, 0);
290 path = (char *) alloca (1 + len);
291 path[0] = ':';
292 (void) confstr (_CS_PATH, path + 1, len);
293#else
294 /* Pretend that the PATH contains only the current directory. */
295 path = "";
296#endif
297 }
298
299 len = strlen (file) + 1;
300 pathlen = strlen (path);
301 name = alloca (pathlen + len + 1);
302 /* Copy the file name at the top. */
303 name = (char *) memcpy (name + pathlen + 1, file, len);
304 /* And add the slash. */
305 *--name = '/';
306
307 p = path;
308 do
309 {
310 char *startp;
311
312 path = p;
313 p = strchrnul (path, ':');
314
315 if (p == path)
316 /* Two adjacent colons, or a colon at the beginning or the end
317 of 'PATH' means to search the current directory. */
318 startp = name + 1;
319 else
320 startp = (char *) memcpy (name - (p - path), path, p - path);
321
322 /* Try to execute this name. If it works, execv will not return. */
323 execve (startp, (char * const *) argv, (char * const *) envp);
324
325 switch (errno)
326 {
327 case EACCES:
328 case ENOENT:
329 case ESTALE:
330 case ENOTDIR:
331 /* Those errors indicate the file is missing or not executable
332 by us, in which case we want to just try the next path
333 directory. */
334 break;
335
336 default:
337 /* Some other error means we found an executable file, but
338 something went wrong executing it; return the error to our
339 caller. */
340 _exit (SPAWN_ERROR);
341 }
342 }
343 while (*p++ != '\0');
344
345 /* Return with an error. */
346 _exit (SPAWN_ERROR);
347}
348
349#endif
diff --git a/lib/strchrnul.c b/lib/strchrnul.c
new file mode 100644
index 00000000000..858d66fab18
--- /dev/null
+++ b/lib/strchrnul.c
@@ -0,0 +1,142 @@
1/* Searching in a string.
2 Copyright (C) 2003, 2007-2020 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19/* Specification. */
20#include <string.h>
21
22/* Find the first occurrence of C in S or the final NUL byte. */
23char *
24strchrnul (const char *s, int c_in)
25{
26 /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
27 long instead of a 64-bit uintmax_t tends to give better
28 performance. On 64-bit hardware, unsigned long is generally 64
29 bits already. Change this typedef to experiment with
30 performance. */
31 typedef unsigned long int longword;
32
33 const unsigned char *char_ptr;
34 const longword *longword_ptr;
35 longword repeated_one;
36 longword repeated_c;
37 unsigned char c;
38
39 c = (unsigned char) c_in;
40 if (!c)
41 return rawmemchr (s, 0);
42
43 /* Handle the first few bytes by reading one byte at a time.
44 Do this until CHAR_PTR is aligned on a longword boundary. */
45 for (char_ptr = (const unsigned char *) s;
46 (size_t) char_ptr % sizeof (longword) != 0;
47 ++char_ptr)
48 if (!*char_ptr || *char_ptr == c)
49 return (char *) char_ptr;
50
51 longword_ptr = (const longword *) char_ptr;
52
53 /* All these elucidatory comments refer to 4-byte longwords,
54 but the theory applies equally well to any size longwords. */
55
56 /* Compute auxiliary longword values:
57 repeated_one is a value which has a 1 in every byte.
58 repeated_c has c in every byte. */
59 repeated_one = 0x01010101;
60 repeated_c = c | (c << 8);
61 repeated_c |= repeated_c << 16;
62 if (0xffffffffU < (longword) -1)
63 {
64 repeated_one |= repeated_one << 31 << 1;
65 repeated_c |= repeated_c << 31 << 1;
66 if (8 < sizeof (longword))
67 {
68 size_t i;
69
70 for (i = 64; i < sizeof (longword) * 8; i *= 2)
71 {
72 repeated_one |= repeated_one << i;
73 repeated_c |= repeated_c << i;
74 }
75 }
76 }
77
78 /* Instead of the traditional loop which tests each byte, we will
79 test a longword at a time. The tricky part is testing if *any of
80 the four* bytes in the longword in question are equal to NUL or
81 c. We first use an xor with repeated_c. This reduces the task
82 to testing whether *any of the four* bytes in longword1 or
83 longword2 is zero.
84
85 Let's consider longword1. We compute tmp =
86 ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
87 That is, we perform the following operations:
88 1. Subtract repeated_one.
89 2. & ~longword1.
90 3. & a mask consisting of 0x80 in every byte.
91 Consider what happens in each byte:
92 - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
93 and step 3 transforms it into 0x80. A carry can also be propagated
94 to more significant bytes.
95 - If a byte of longword1 is nonzero, let its lowest 1 bit be at
96 position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
97 the byte ends in a single bit of value 0 and k bits of value 1.
98 After step 2, the result is just k bits of value 1: 2^k - 1. After
99 step 3, the result is 0. And no carry is produced.
100 So, if longword1 has only non-zero bytes, tmp is zero.
101 Whereas if longword1 has a zero byte, call j the position of the least
102 significant zero byte. Then the result has a zero at positions 0, ...,
103 j-1 and a 0x80 at position j. We cannot predict the result at the more
104 significant bytes (positions j+1..3), but it does not matter since we
105 already have a non-zero bit at position 8*j+7.
106
107 The test whether any byte in longword1 or longword2 is zero is equivalent
108 to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine
109 this into a single test, whether (tmp1 | tmp2) is nonzero.
110
111 This test can read more than one byte beyond the end of a string,
112 depending on where the terminating NUL is encountered. However,
113 this is considered safe since the initialization phase ensured
114 that the read will be aligned, therefore, the read will not cross
115 page boundaries and will not cause a fault. */
116
117 while (1)
118 {
119 longword longword1 = *longword_ptr ^ repeated_c;
120 longword longword2 = *longword_ptr;
121
122 if (((((longword1 - repeated_one) & ~longword1)
123 | ((longword2 - repeated_one) & ~longword2))
124 & (repeated_one << 7)) != 0)
125 break;
126 longword_ptr++;
127 }
128
129 char_ptr = (const unsigned char *) longword_ptr;
130
131 /* At this point, we know that one of the sizeof (longword) bytes
132 starting at char_ptr is == 0 or == c. On little-endian machines,
133 we could determine the first such byte without any further memory
134 accesses, just by looking at the tmp result from the last loop
135 iteration. But this does not work on big-endian machines.
136 Choose code that works in both cases. */
137
138 char_ptr = (unsigned char *) longword_ptr;
139 while (*char_ptr && (*char_ptr != c))
140 char_ptr++;
141 return (char *) char_ptr;
142}
diff --git a/lib/strchrnul.valgrind b/lib/strchrnul.valgrind
new file mode 100644
index 00000000000..a85608a7c76
--- /dev/null
+++ b/lib/strchrnul.valgrind
@@ -0,0 +1,28 @@
1# Suppress a valgrind message about use of uninitialized memory in strchrnul().
2
3# Copyright (C) 2008-2020 Free Software Foundation, Inc.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18# This use is OK because it provides only a speedup.
19{
20 strchrnul-value4
21 Memcheck:Value4
22 fun:strchrnul
23}
24{
25 strchrnul-value8
26 Memcheck:Value8
27 fun:strchrnul
28}