Skip to content

Commit c3a1214

Browse files
authored
ext/standard: Use posix_spawn_file_actions_addchdir when available (php#21553)
posix_spawn_file_actions_addchdir is part of POSIX now, so some OSes (macOS at least) have started to deprecated the _np variant. Some support both names (Solaris, NetBSD), others don't yet (FreeBSD). Use the non-np variant when possible to avoid the deprecation warning on macOS and other platforms in the future. Fixes phpGH-21552
1 parent 358d9c5 commit c3a1214

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

ext/standard/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ dnl
328328

329329
PHP_CHECK_FUNC(res_search, resolv, socket)
330330

331-
AC_CHECK_FUNCS([posix_spawn_file_actions_addchdir_np elf_aux_info])
331+
AC_CHECK_FUNCS([posix_spawn_file_actions_addchdir posix_spawn_file_actions_addchdir_np elf_aux_info])
332332

333333
dnl
334334
dnl Obsolete check for strptime() declaration. The strptime, where available,

ext/standard/proc_open.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <fcntl.h>
3636
#endif
3737

38-
#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP
38+
#if defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP) || defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)
3939
/* Only defined on glibc >= 2.29, FreeBSD CURRENT, musl >= 1.1.24,
4040
* MacOS Catalina or later..
4141
* It should be possible to modify this so it is also
@@ -45,6 +45,13 @@
4545
*/
4646
#include <spawn.h>
4747
#define USE_POSIX_SPAWN
48+
49+
/* The non-_np variant is in macOS 26 (and _np deprecated) */
50+
#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
51+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir
52+
#else
53+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir_np
54+
#endif
4855
#endif
4956

5057
/* This symbol is defined in ext/standard/config.m4.
@@ -1394,9 +1401,9 @@ PHP_FUNCTION(proc_open)
13941401
}
13951402

13961403
if (cwd) {
1397-
r = posix_spawn_file_actions_addchdir_np(&factions, cwd);
1404+
r = POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR(&factions, cwd);
13981405
if (r != 0) {
1399-
php_error_docref(NULL, E_WARNING, "posix_spawn_file_actions_addchdir_np() failed: %s", strerror(r));
1406+
php_error_docref(NULL, E_WARNING, ZEND_TOSTR(POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR) "() failed: %s", strerror(r));
14001407
}
14011408
}
14021409

0 commit comments

Comments
 (0)