PHP extension "sockets" build error (could not compile)
Description
Short description
PHP extension sockets is not compiled due to compilation errors.
Reproduced in Docker containers and on a standalone Debian host.
With Docker CE, PHP official images:
- php:8.0.15-fpm-bullseye
- php:8.1.2-fpm-buster
# docker run -it --rm php:8.0.15-fpm-bullseye bash
~# docker-php-source extract
~# docker-php-ext-install -j"$(nproc)" sockets
/usr/src/php/ext/sockets/sendrecvmsg.c: In function 'init_ancillary_registry':
/usr/src/php/ext/sockets/sendrecvmsg.c:128:19: error: invalid application of 'sizeof' to incomplete type 'struct cmsgcred'
128 | PUT_ENTRY(sizeof(struct cmsgcred), 0, 0, from_zval_write_ucred,
| ^~~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:99:17: note: in definition of macro 'PUT_ENTRY'
99 | entry.size = sizev; \
| ^~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:129:36: error: 'SCM_CREDS' undeclared (first use in this function)
129 | to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
| ^~~~~~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:105:19: note: in definition of macro 'PUT_ENTRY'
105 | key.cmsg_type = type; \
| ^~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:129:36: note: each undeclared identifier is reported only once for each function it appears in
129 | to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
| ^~~~~~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:105:19: note: in definition of macro 'PUT_ENTRY'
105 | key.cmsg_type = type; \
| ^~~~
make: *** [Makefile:216: sendrecvmsg.lo] Error 1
make: *** Waiting for unfinished jobs....
The difference of the file /usr/src/php/ext/sockets/sendrecvmsg.c against the same file in previous PHP versions (8.0.14 and 8.1.1):
8c8
< | https://www.php.net/license/3_01.txt |
---
> | http://www.php.net/license/3_01.txt |
123a124
> #ifdef ANC_CREDS_UCRED
125a127,130
> #else
> PUT_ENTRY(sizeof(struct cmsgcred), 0, 0, from_zval_write_ucred,
> to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
> #endif
438a444
> #ifdef SCM_CREDENTIALS
439a446,448
> #else
> REGISTER_LONG_CONSTANT("SCM_CREDS", SCM_CREDS, CONST_CS | CONST_PERSISTENT);
> #endif
Temporary workaround:
I could not find struct cmsgcred definition in various sockets.h files, so I have inserted the following line at the start of the file /usr/src/php/ext/sockets/sendrecvmsg.c:
#define ANC_CREDS_UCRED 1
After that change, the sockets extension was compiled successfully.
Of course, this hack cannot be a correct fix. Please provide more acceptable workaround and fix this issue. Let me know if you have any questions.
Thanks.
-- Eduard
PHP Version
8.0.15, 8.1.2
Operating System
Debian 10, Debian 11
I can confirm that I have the same issue. Impossible to compile sockets extension on PHP 8.1.2.
This is a duplicate of #7978; the bug has already been fixed.
I confirm: the patch https://github.com/php/php-src/pull/7981/files fixes the issue:
# docker run -it --rm php:8.0.15-fpm-bullseye bash
~# docker-php-source extract
~# patch /usr/src/php/ext/sockets/config.m4 -i- <<EOF
@@ -67,6 +67,9 @@
AC_CACHE_CHECK([if ancillary credentials uses ucred],[ac_cv_ucred],
[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
#include <sys/socket.h>
]], [[struct ucred u = {.gid = 0};]])],
[ac_cv_ucred=yes], [ac_cv_ucred=no])
EOF
~# docker-php-ext-install -j"$(nproc)" sockets
....
Build complete.
Thanks.
This issue is still reproducing. I'm trying to use it inside docker container, I use official image php:8.0 and I install sockets through docker-php-ext-install sockets and has the same issue
We do not provide the official Docker images, so we cannot fix anything in this regard.
@vandal-kherson this is adressed here, including workaround https://github.com/docker-library/php/issues/1245
We do not provide the official Docker images, so we cannot fix anything in this regard.
Thank you for fixing the issue. :-) Who provides the official docker images? Just by curiosity. 😅
@CViniciusSDias They're official from Docker. https://docs.docker.com/docker-hub/official_images/