Debian Codegraph @

m4/posix_spawn.m4

raw
1 # posix_spawn.m4
2 # serial 25
3 dnl Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl Tests whether the entire posix_spawn facility is available.
10 AC_DEFUN([gl_POSIX_SPAWN],
11 [
12 AC_REQUIRE([gl_POSIX_SPAWN_BODY])
13 ])
14
15 AC_DEFUN([gl_POSIX_SPAWN_BODY],
16 [
17 AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
18 AC_REQUIRE([gl_HAVE_POSIX_SPAWN])
19 dnl Assume that when the main function exists, all the others,
20 dnl except posix_spawnattr_{get,set}sched*, are available as well.
21 dnl AC_CHECK_FUNCS_ONCE([posix_spawnp])
22 dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_init])
23 dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addclose])
24 dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_adddup2])
25 dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addopen])
26 dnl AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_destroy])
27 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_init])
28 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getflags])
29 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setflags])
30 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getpgroup])
31 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setpgroup])
32 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getsigdefault])
33 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigdefault])
34 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getsigmask])
35 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigmask])
36 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_destroy])
37 AC_CHECK_DECLS([posix_spawn], , , [[#include <spawn.h>]])
38 if test $ac_cv_func_posix_spawn = yes; then
39 m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR],
40 [dnl Module 'posix_spawn_file_actions_addchdir' is present.
41 gl_CHECK_FUNCS_ANDROID([posix_spawn_file_actions_addchdir_np],
42 [[#include <spawn.h>]])
43 if test $ac_cv_func_posix_spawn_file_actions_addchdir_np = no; then
44 dnl In order to implement the posix_spawn_file_actions_addchdir
45 dnl function, we need to replace the entire posix_spawn facility.
46 REPLACE_POSIX_SPAWN=1
47 fi
48 ])
49 m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR],
50 [dnl Module 'posix_spawn_file_actions_addfchdir' is present.
51 gl_CHECK_FUNCS_ANDROID([posix_spawn_file_actions_addfchdir_np],
52 [[#include <spawn.h>]])
53 if test $ac_cv_func_posix_spawn_file_actions_addfchdir_np = no; then
54 dnl In order to implement the posix_spawn_file_actions_addfchdir
55 dnl function, we need to replace the entire posix_spawn facility.
56 REPLACE_POSIX_SPAWN=1
57 fi
58 ])
59 if test $REPLACE_POSIX_SPAWN = 0; then
60 gl_POSIX_SPAWN_WORKS
61 case "$gl_cv_func_posix_spawn_works" in
62 *yes) ;;
63 *) REPLACE_POSIX_SPAWN=1 ;;
64 esac
65 fi
66 if test $REPLACE_POSIX_SPAWN = 0; then
67 gl_POSIX_SPAWN_SECURE
68 case "$gl_cv_func_posix_spawn_secure_exec" in
69 *yes) ;;
70 *) REPLACE_POSIX_SPAWN=1 ;;
71 esac
72 case "$gl_cv_func_posix_spawnp_secure_exec" in
73 *yes) ;;
74 *) REPLACE_POSIX_SPAWN=1 ;;
75 esac
76 fi
77 if test $REPLACE_POSIX_SPAWN = 0; then
78 dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDULER
79 dnl evaluates to nonzero.
80 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedpolicy])
81 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedpolicy])
82 AC_CACHE_CHECK([whether posix_spawnattr_setschedpolicy is supported],
83 [gl_cv_func_spawnattr_setschedpolicy],
84 [AC_EGREP_CPP([POSIX scheduling supported], [
85 #include <spawn.h>
86 #if POSIX_SPAWN_SETSCHEDULER
87 POSIX scheduling supported
88 #endif
89 ],
90 [gl_cv_func_spawnattr_setschedpolicy=yes],
91 [gl_cv_func_spawnattr_setschedpolicy=no])
92 ])
93 dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDPARAM
94 dnl evaluates to nonzero.
95 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedparam])
96 dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedparam])
97 AC_CACHE_CHECK([whether posix_spawnattr_setschedparam is supported],
98 [gl_cv_func_spawnattr_setschedparam],
99 [AC_EGREP_CPP([POSIX scheduling supported], [
100 #include <spawn.h>
101 #if POSIX_SPAWN_SETSCHEDPARAM
102 POSIX scheduling supported
103 #endif
104 ],
105 [gl_cv_func_spawnattr_setschedparam=yes],
106 [gl_cv_func_spawnattr_setschedparam=no])
107 ])
108 fi
109 else
110 dnl The system does not have the main function. Therefore we have to
111 dnl provide our own implementation. This implies to define our own
112 dnl posix_spawn_file_actions_t and posix_spawnattr_t types.
113 if test $ac_cv_have_decl_posix_spawn = yes; then
114 dnl The system declares posix_spawn() already. This declaration uses
115 dnl the original posix_spawn_file_actions_t and posix_spawnattr_t types.
116 dnl But we need a declaration with our own posix_spawn_file_actions_t and
117 dnl posix_spawnattr_t types.
118 REPLACE_POSIX_SPAWN=1
119 fi
120 fi
121 if test $ac_cv_func_posix_spawn != yes || test $REPLACE_POSIX_SPAWN = 1; then
122 AC_DEFINE([REPLACE_POSIX_SPAWN], [1],
123 [Define if gnulib uses its own posix_spawn and posix_spawnp functions.])
124 fi
125 ])
126
127 dnl Test whether posix_spawn actually works.
128 dnl posix_spawn on AIX 5.3..6.1 has two bugs:
129 dnl 1) When it fails to execute the program, the child process exits with
130 dnl exit() rather than _exit(), which causes the stdio buffers to be
131 dnl flushed. Reported by Rainer Tammer.
132 dnl 2) The posix_spawn_file_actions_addopen function does not support file
133 dnl names that contain a '*'.
134 dnl posix_spawn on AIX 5.3..6.1 has also a third bug: It does not work
135 dnl when POSIX threads are used. But we don't test against this bug here.
136 AC_DEFUN([gl_POSIX_SPAWN_WORKS],
137 [
138 AC_REQUIRE([AC_PROG_CC])
139 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
140 AC_CACHE_CHECK([whether posix_spawn works], [gl_cv_func_posix_spawn_works],
141 [if test $cross_compiling = no; then
142 AC_LINK_IFELSE([AC_LANG_SOURCE([[
143 #include <errno.h>
144 #include <fcntl.h>
145 #include <signal.h>
146 #include <spawn.h>
147 #include <stdbool.h>
148 #include <stdio.h>
149 #include <stdlib.h>
150 #include <string.h>
151 #include <unistd.h>
152 #include <sys/types.h>
153 #include <sys/wait.h>
154 ]GL_MDA_DEFINES[
155
156 extern char **environ;
157
158 #ifndef STDIN_FILENO
159 # define STDIN_FILENO 0
160 #endif
161 #ifndef STDOUT_FILENO
162 # define STDOUT_FILENO 1
163 #endif
164 #ifndef STDERR_FILENO
165 # define STDERR_FILENO 2
166 #endif
167
168 #ifndef WTERMSIG
169 # define WTERMSIG(x) ((x) & 0x7f)
170 #endif
171 #ifndef WIFEXITED
172 # define WIFEXITED(x) (WTERMSIG (x) == 0)
173 #endif
174 #ifndef WEXITSTATUS
175 # define WEXITSTATUS(x) (((x) >> 8) & 0xff)
176 #endif
177
178 #define CHILD_PROGRAM_FILENAME "/non/exist/ent"
179
180 static int
181 fd_safer (int fd)
182 {
183 if (0 <= fd && fd <= 2)
184 {
185 int f = fd_safer (dup (fd));
186 int e = errno;
187 close (fd);
188 errno = e;
189 fd = f;
190 }
191
192 return fd;
193 }
194
195 int
196 main ()
197 {
198 char *argv[2] = { CHILD_PROGRAM_FILENAME, NULL };
199 int ofd[2];
200 sigset_t blocked_signals;
201 sigset_t fatal_signal_set;
202 posix_spawn_file_actions_t actions;
203 bool actions_allocated;
204 posix_spawnattr_t attrs;
205 bool attrs_allocated;
206 int err;
207 pid_t child;
208 int status;
209 int exitstatus;
210
211 setvbuf (stdout, NULL, _IOFBF, 0);
212 puts ("This should be seen only once.");
213 if (pipe (ofd) < 0 || (ofd[1] = fd_safer (ofd[1])) < 0)
214 {
215 perror ("cannot create pipe");
216 exit (1);
217 }
218 sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
219 sigemptyset (&fatal_signal_set);
220 sigaddset (&fatal_signal_set, SIGINT);
221 sigaddset (&fatal_signal_set, SIGTERM);
222 sigaddset (&fatal_signal_set, SIGHUP);
223 sigaddset (&fatal_signal_set, SIGPIPE);
224 sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
225 actions_allocated = false;
226 attrs_allocated = false;
227 if ((err = posix_spawn_file_actions_init (&actions)) != 0
228 || (actions_allocated = true,
229 (err = posix_spawn_file_actions_adddup2 (&actions, ofd[0], STDIN_FILENO)) != 0
230 || (err = posix_spawn_file_actions_addclose (&actions, ofd[0])) != 0
231 || (err = posix_spawn_file_actions_addclose (&actions, ofd[1])) != 0
232 || (err = posix_spawnattr_init (&attrs)) != 0
233 || (attrs_allocated = true,
234 (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
235 || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
236 || (err = posix_spawnp (&child, CHILD_PROGRAM_FILENAME, &actions, &attrs, argv, environ)) != 0))
237 {
238 if (actions_allocated)
239 posix_spawn_file_actions_destroy (&actions);
240 if (attrs_allocated)
241 posix_spawnattr_destroy (&attrs);
242 sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
243 if (err == ENOENT)
244 return 0;
245 else
246 {
247 errno = err;
248 perror ("subprocess failed");
249 exit (1);
250 }
251 }
252 posix_spawn_file_actions_destroy (&actions);
253 posix_spawnattr_destroy (&attrs);
254 sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
255 close (ofd[0]);
256 close (ofd[1]);
257 status = 0;
258 while (waitpid (child, &status, 0) != child)
259 ;
260 if (!WIFEXITED (status))
261 {
262 fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status);
263 exit (1);
264 }
265 exitstatus = WEXITSTATUS (status);
266 if (exitstatus != 127)
267 {
268 fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
269 exit (1);
270 }
271 return 0;
272 }
273 ]])],
274 [if test -s conftest$ac_exeext \
275 && ./conftest$ac_exeext > conftest.out \
276 && echo 'This should be seen only once.' > conftest.ok \
277 && cmp conftest.out conftest.ok >/dev/null 2>&1; then
278 gl_cv_func_posix_spawn_works=yes
279 else
280 gl_cv_func_posix_spawn_works=no
281 fi],
282 [gl_cv_func_posix_spawn_works=no])
283 if test $gl_cv_func_posix_spawn_works = yes; then
284 AC_RUN_IFELSE([AC_LANG_SOURCE([[
285 /* Test whether posix_spawn_file_actions_addopen supports filename arguments
286 that contain special characters such as '*'. */
287
288 #include <errno.h>
289 #include <fcntl.h>
290 #include <signal.h>
291 #include <spawn.h>
292 #include <stdbool.h>
293 #include <stdio.h>
294 #include <string.h>
295 #include <unistd.h>
296 #include <sys/types.h>
297 #include <sys/wait.h>
298 ]GL_MDA_DEFINES[
299
300 extern char **environ;
301
302 #ifndef STDIN_FILENO
303 # define STDIN_FILENO 0
304 #endif
305 #ifndef STDOUT_FILENO
306 # define STDOUT_FILENO 1
307 #endif
308 #ifndef STDERR_FILENO
309 # define STDERR_FILENO 2
310 #endif
311
312 #ifndef WTERMSIG
313 # define WTERMSIG(x) ((x) & 0x7f)
314 #endif
315 #ifndef WIFEXITED
316 # define WIFEXITED(x) (WTERMSIG (x) == 0)
317 #endif
318 #ifndef WEXITSTATUS
319 # define WEXITSTATUS(x) (((x) >> 8) & 0xff)
320 #endif
321
322 #define CHILD_PROGRAM_FILENAME "conftest"
323 #define DATA_FILENAME "conftest%=*#?"
324
325 static int
326 parent_main (void)
327 {
328 FILE *fp;
329 char *argv[3] = { CHILD_PROGRAM_FILENAME, "-child", NULL };
330 posix_spawn_file_actions_t actions;
331 bool actions_allocated;
332 int err;
333 pid_t child;
334 int status;
335 int exitstatus;
336
337 /* Create a data file with specific contents. */
338 fp = fopen (DATA_FILENAME, "wb");
339 if (fp == NULL)
340 {
341 perror ("cannot create data file");
342 return 1;
343 }
344 fwrite ("Halle Potta", 1, 11, fp);
345 if (fflush (fp) || fclose (fp))
346 {
347 perror ("cannot prepare data file");
348 return 2;
349 }
350
351 /* Avoid reading from our stdin, as it could block. */
352 freopen ("/dev/null", "rb", stdin);
353
354 /* Test whether posix_spawn_file_actions_addopen with this file name
355 actually works, but spawning a child that reads from this file. */
356 actions_allocated = false;
357 if ((err = posix_spawn_file_actions_init (&actions)) != 0
358 || (actions_allocated = true,
359 (err = posix_spawn_file_actions_addopen (&actions, STDIN_FILENO, DATA_FILENAME, O_RDONLY, 0600)) != 0
360 || (err = posix_spawn (&child, CHILD_PROGRAM_FILENAME, &actions, NULL, argv, environ)) != 0))
361 {
362 if (actions_allocated)
363 posix_spawn_file_actions_destroy (&actions);
364 errno = err;
365 perror ("subprocess failed");
366 return 3;
367 }
368 posix_spawn_file_actions_destroy (&actions);
369 status = 0;
370 while (waitpid (child, &status, 0) != child)
371 ;
372 if (!WIFEXITED (status))
373 {
374 fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status);
375 return 4;
376 }
377 exitstatus = WEXITSTATUS (status);
378 if (exitstatus != 0)
379 {
380 fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
381 return 5;
382 }
383 return 0;
384 }
385
386 static int
387 child_main (void)
388 {
389 char buf[1024];
390
391 /* See if reading from STDIN_FILENO yields the expected contents. */
392 if (fread (buf, 1, sizeof (buf), stdin) == 11
393 && memcmp (buf, "Halle Potta", 11) == 0)
394 return 0;
395 else
396 return 8;
397 }
398
399 static void
400 cleanup_then_die (int sig)
401 {
402 /* Clean up data file. */
403 unlink (DATA_FILENAME);
404
405 /* Re-raise the signal and die from it. */
406 signal (sig, SIG_DFL);
407 raise (sig);
408 }
409
410 int
411 main (int argc, char *argv[])
412 {
413 int exitstatus;
414
415 if (!(argc > 1 && strcmp (argv[1], "-child") == 0))
416 {
417 /* This is the parent process. */
418 signal (SIGINT, cleanup_then_die);
419 signal (SIGTERM, cleanup_then_die);
420 #ifdef SIGHUP
421 signal (SIGHUP, cleanup_then_die);
422 #endif
423
424 exitstatus = parent_main ();
425 }
426 else
427 {
428 /* This is the child process. */
429
430 exitstatus = child_main ();
431 }
432 unlink (DATA_FILENAME);
433 return exitstatus;
434 }
435 ]])],
436 [],
437 [gl_cv_func_posix_spawn_works=no])
438 fi
439 else
440 case "$host_os" in
441 aix*) gl_cv_func_posix_spawn_works="guessing no";;
442 *) gl_cv_func_posix_spawn_works="guessing yes";;
443 esac
444 fi
445 ])
446 ])
447
448 dnl Test whether posix_spawn and posix_spawnp are secure.
449 AC_DEFUN([gl_POSIX_SPAWN_SECURE],
450 [
451 AC_REQUIRE([AC_PROG_CC])
452 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
453 dnl On many platforms, posix_spawn or posix_spawnp allow executing a
454 dnl script without a '#!' marker as a shell script. This is unsecure.
455 AC_CACHE_CHECK([whether posix_spawn rejects scripts without shebang],
456 [gl_cv_func_posix_spawn_secure_exec],
457 [echo ':' > conftest.scr
458 chmod a+x conftest.scr
459 AC_RUN_IFELSE([AC_LANG_SOURCE([[
460 #include <errno.h>
461 #include <spawn.h>
462 #include <stddef.h>
463 #include <sys/types.h>
464 #include <sys/wait.h>
465 int
466 main ()
467 {
468 const char *prog_path = "./conftest.scr";
469 const char *prog_argv[2] = { prog_path, NULL };
470 const char *environment[2] = { "PATH=.", NULL };
471 pid_t child;
472 int status;
473 int err = posix_spawn (&child, prog_path, NULL, NULL,
474 (char **) prog_argv, (char **) environment);
475 if (err == ENOEXEC)
476 return 0;
477 if (err != 0)
478 return 1;
479 status = 0;
480 while (waitpid (child, &status, 0) != child)
481 ;
482 if (!WIFEXITED (status))
483 return 2;
484 if (WEXITSTATUS (status) != 127)
485 return 3;
486 return 0;
487 }
488 ]])],
489 [gl_cv_func_posix_spawn_secure_exec=yes],
490 [gl_cv_func_posix_spawn_secure_exec=no],
491 [case "$host_os" in
492 # Guess no on GNU/Hurd.
493 gnu*)
494 gl_cv_func_posix_spawn_secure_exec="guessing no" ;;
495 # Guess yes on all other platforms.
496 *)
497 gl_cv_func_posix_spawn_secure_exec="guessing yes" ;;
498 esac
499 ])
500 rm -f conftest.scr
501 ])
502 AC_CACHE_CHECK([whether posix_spawnp rejects scripts without shebang],
503 [gl_cv_func_posix_spawnp_secure_exec],
504 [echo ':' > conftest.scr
505 chmod a+x conftest.scr
506 AC_RUN_IFELSE([AC_LANG_SOURCE([[
507 #include <errno.h>
508 #include <spawn.h>
509 #include <stddef.h>
510 #include <sys/types.h>
511 #include <sys/wait.h>
512 int
513 main ()
514 {
515 const char *prog_path = "./conftest.scr";
516 const char *prog_argv[2] = { prog_path, NULL };
517 const char *environment[2] = { "PATH=.", NULL };
518 pid_t child;
519 int status;
520 int err = posix_spawnp (&child, prog_path, NULL, NULL,
521 (char **) prog_argv, (char **) environment);
522 if (err == ENOEXEC)
523 return 0;
524 if (err != 0)
525 return 1;
526 status = 0;
527 while (waitpid (child, &status, 0) != child)
528 ;
529 if (!WIFEXITED (status))
530 return 2;
531 if (WEXITSTATUS (status) != 127)
532 return 3;
533 return 0;
534 }
535 ]])],
536 [gl_cv_func_posix_spawnp_secure_exec=yes],
537 [gl_cv_func_posix_spawnp_secure_exec=no],
538 [case "$host_os" in
539 # Guess yes on glibc systems (glibc >= 2.15 actually) except GNU/Hurd,
540 # musl libc, NetBSD.
541 *-gnu* | *-musl* | midipix* | netbsd*)
542 gl_cv_func_posix_spawnp_secure_exec="guessing yes" ;;
543 # Guess no on GNU/Hurd, macOS, FreeBSD, OpenBSD, AIX, Solaris, Cygwin.
544 gnu* | darwin* | freebsd* | dragonfly* | midnightbsd* | openbsd* | \
545 aix* | solaris* | cygwin*)
546 gl_cv_func_posix_spawnp_secure_exec="guessing no" ;;
547 # If we don't know, obey --enable-cross-guesses.
548 *)
549 gl_cv_func_posix_spawnp_secure_exec="$gl_cross_guess_normal" ;;
550 esac
551 ])
552 rm -f conftest.scr
553 ])
554 ])
555
556 # Prerequisites of lib/spawni.c.
557 AC_DEFUN([gl_PREREQ_POSIX_SPAWN_INTERNAL],
558 [
559 AC_CHECK_HEADERS([paths.h])
560 AC_CHECK_FUNCS([confstr sched_setparam sched_setscheduler setegid seteuid vfork])
561 ])
562
563 AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE],
564 [
565 AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
566 AC_REQUIRE([AC_PROG_CC])
567 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
568 gl_POSIX_SPAWN
569 if test $REPLACE_POSIX_SPAWN = 1; then
570 REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=1
571 else
572 dnl On musl libc, posix_spawn_file_actions_addclose succeeds even if the fd
573 dnl argument is negative.
574 AC_CACHE_CHECK([whether posix_spawn_file_actions_addclose works],
575 [gl_cv_func_posix_spawn_file_actions_addclose_works],
576 [AC_RUN_IFELSE(
577 [AC_LANG_SOURCE([[
578 #include <spawn.h>
579 int main ()
580 {
581 posix_spawn_file_actions_t actions;
582 if (posix_spawn_file_actions_init (&actions) != 0)
583 return 1;
584 if (posix_spawn_file_actions_addclose (&actions, -5) == 0)
585 return 2;
586 return 0;
587 }]])],
588 [gl_cv_func_posix_spawn_file_actions_addclose_works=yes],
589 [gl_cv_func_posix_spawn_file_actions_addclose_works=no],
590 [# Guess no on musl libc and Solaris, yes otherwise.
591 case "$host_os" in
592 *-musl* | midipix*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
593 solaris*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
594 # Guess no on native Windows.
595 mingw* | windows*) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing no" ;;
596 *) gl_cv_func_posix_spawn_file_actions_addclose_works="guessing yes" ;;
597 esac
598 ])
599 ])
600 case "$gl_cv_func_posix_spawn_file_actions_addclose_works" in
601 *yes) ;;
602 *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=1 ;;
603 esac
604 fi
605 ])
606
607 AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2],
608 [
609 AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
610 AC_REQUIRE([AC_PROG_CC])
611 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
612 gl_POSIX_SPAWN
613 if test $REPLACE_POSIX_SPAWN = 1; then
614 REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=1
615 else
616 dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_adddup2
617 dnl succeeds even if the fd argument is out of range.
618 AC_CACHE_CHECK([whether posix_spawn_file_actions_adddup2 works],
619 [gl_cv_func_posix_spawn_file_actions_adddup2_works],
620 [AC_RUN_IFELSE(
621 [AC_LANG_SOURCE([[
622 #include <spawn.h>
623 int main ()
624 {
625 posix_spawn_file_actions_t actions;
626 if (posix_spawn_file_actions_init (&actions) != 0)
627 return 1;
628 if (posix_spawn_file_actions_adddup2 (&actions, 10000000, 2) == 0)
629 return 2;
630 return 0;
631 }]])],
632 [gl_cv_func_posix_spawn_file_actions_adddup2_works=yes],
633 [gl_cv_func_posix_spawn_file_actions_adddup2_works=no],
634 [# Guess no on musl libc and Solaris, yes otherwise.
635 case "$host_os" in
636 *-musl* | midipix*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no";;
637 solaris*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no";;
638 # Guess no on native Windows.
639 mingw* | windows*) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing no" ;;
640 *) gl_cv_func_posix_spawn_file_actions_adddup2_works="guessing yes";;
641 esac
642 ])
643 ])
644 case "$gl_cv_func_posix_spawn_file_actions_adddup2_works" in
645 *yes) ;;
646 *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=1 ;;
647 esac
648 fi
649 ])
650
651 AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN],
652 [
653 AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
654 AC_REQUIRE([AC_PROG_CC])
655 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
656 gl_POSIX_SPAWN
657 if test $REPLACE_POSIX_SPAWN = 1; then
658 REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=1
659 else
660 dnl On musl libc and Solaris 11.0, posix_spawn_file_actions_addopen
661 dnl succeeds even if the fd argument is out of range.
662 AC_CACHE_CHECK([whether posix_spawn_file_actions_addopen works],
663 [gl_cv_func_posix_spawn_file_actions_addopen_works],
664 [AC_RUN_IFELSE(
665 [AC_LANG_SOURCE([[
666 #include <spawn.h>
667 #include <fcntl.h>
668 int main ()
669 {
670 posix_spawn_file_actions_t actions;
671 if (posix_spawn_file_actions_init (&actions) != 0)
672 return 1;
673 if (posix_spawn_file_actions_addopen (&actions, 10000000, "foo", 0, O_RDONLY)
674 == 0)
675 return 2;
676 return 0;
677 }]])],
678 [gl_cv_func_posix_spawn_file_actions_addopen_works=yes],
679 [gl_cv_func_posix_spawn_file_actions_addopen_works=no],
680 [# Guess no on musl libc and Solaris, yes otherwise.
681 case "$host_os" in
682 *-musl* | midipix*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no";;
683 solaris*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no";;
684 # Guess no on native Windows.
685 mingw* | windows*) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing no" ;;
686 *) gl_cv_func_posix_spawn_file_actions_addopen_works="guessing yes";;
687 esac
688 ])
689 ])
690 case "$gl_cv_func_posix_spawn_file_actions_addopen_works" in
691 *yes) ;;
692 *) REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=1 ;;
693 esac
694 fi
695 ])