Suppress bogus [-Wlogical-op] warning from GCC

See GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602
which emits the warning for (errno == EWOULDBLOCK || errno == EAGAIN)
which is the correct way of handling errors as the value of EWOULDBLOCK
and EAGAIN is implementation defined.

Therefore introduce a new macro function PHP_IS_TRANSIENT_ERROR()
which handles the case when EWOULDBLOCK and EAGAIN are identical.

Thanks to @twose for the idea.
This commit is contained in:
George Peter Banyard 2020-09-23 23:46:58 +01:00
parent f211f1586f
commit 150ebfdf77
5 changed files with 15 additions and 10 deletions

View file

@ -1045,11 +1045,7 @@ PHP_FUNCTION(socket_read)
if (retval == -1) {
/* if the socket is in non-blocking mode and there's no data to read,
don't output any error, as this is a normal situation, and not an error */
if (errno == EAGAIN
#ifdef EWOULDBLOCK
|| errno == EWOULDBLOCK
#endif
) {
if (PHP_IS_TRANSIENT_ERROR(errno)) {
php_sock->error = errno;
SOCKETS_G(last_error) = errno;
} else {

View file

@ -49,6 +49,13 @@
# define EWOULDBLOCK EAGAIN
#endif
/* This is a work around for GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 */
#if EAGAIN != EWOULDBLOCK
# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
#else
# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN)
#endif
#ifdef PHP_WIN32
#define php_socket_errno() WSAGetLastError()
#else

View file

@ -351,7 +351,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
ssize_t bytes_written = write(data->fd, buf, count);
#endif
if (bytes_written < 0) {
if (errno == EWOULDBLOCK || errno == EAGAIN) {
if (PHP_IS_TRANSIENT_ERROR(errno)) {
return 0;
}
if (errno == EINTR) {
@ -420,7 +420,7 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
}
if (ret < 0) {
if (errno == EWOULDBLOCK || errno == EAGAIN) {
if (PHP_IS_TRANSIENT_ERROR(errno)) {
/* Not an error. */
ret = 0;
} else if (errno == EINTR) {

View file

@ -75,7 +75,8 @@ retry:
if (didwrite <= 0) {
char *estr;
int err = php_socket_errno();
if (err == EWOULDBLOCK || err == EAGAIN) {
if (PHP_IS_TRANSIENT_ERROR(err)) {
if (sock->is_blocked) {
int retval;
@ -166,7 +167,7 @@ static ssize_t php_sockop_read(php_stream *stream, char *buf, size_t count)
err = php_socket_errno();
if (nr_bytes < 0) {
if (err == EAGAIN || err == EWOULDBLOCK) {
if (PHP_IS_TRANSIENT_ERROR(err)) {
nr_bytes = 0;
} else {
stream->eof = 1;

View file

@ -10,6 +10,7 @@
#include <errno.h>
#include "php_syslog.h"
#include "php_network.h"
#include "fpm.h"
#include "fpm_children.h"
@ -166,7 +167,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
stdio_read:
in_buf = read(fd, buf, max_buf_size - 1);
if (in_buf <= 0) { /* no data */
if (in_buf == 0 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
if (in_buf == 0 || !PHP_IS_TRANSIENT_ERROR(errno)) {
/* pipe is closed or error */
read_fail = (in_buf < 0) ? in_buf : 1;
}