[php-src] Issue #7986: PHP extension "sockets" build error (could not compile)

From: Date: Sat, 22 Jan 2022 09:33:10 +0000
Subject: [php-src] Issue #7986: PHP extension "sockets" build error (could not compile)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239203@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7986
Author: eduard-haritonov

### 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.1

### Operating System

Debian 10, Debian 11


Thread (1 message)

  • eduard-haritonov
« previous php.bugs (#239203) next »