Skip to content

Commit f1385c0

Browse files
committed
Convert return values to bool in fpm_sockets.c
The return value was always either 0 or -1
1 parent b4328e5 commit f1385c0

File tree

4 files changed

+34
-37
lines changed

4 files changed

+34
-37
lines changed

sapi/fpm/fpm/fpm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
6262
!fpm_env_init_main() ||
6363
!fpm_signals_init_main() ||
6464
!fpm_children_init_main() ||
65-
0 > fpm_sockets_init_main() ||
65+
!fpm_sockets_init_main() ||
6666
0 > fpm_worker_pool_init_main() ||
6767
!fpm_event_init_main()) {
6868

sapi/fpm/fpm/fpm_process_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
338338

339339
/* update status structure for all PMs */
340340
if (wp->listen_address_domain == FPM_AF_INET) {
341-
if (0 > fpm_socket_get_listening_queue(wp->listening_socket, &cur_lq, NULL)) {
341+
if (!fpm_socket_get_listening_queue(wp->listening_socket, &cur_lq, NULL)) {
342342
cur_lq = 0;
343343
#if 0
344344
} else {

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int fpm_sockets_hash_op(int sock, struct sockaddr *sa, char *key, int typ
201201
}
202202
/* }}} */
203203

204-
static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, int socklen) /* {{{ */
204+
static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, socklen_t socklen) /* {{{ */
205205
{
206206
int flags = 1;
207207
int sock;
@@ -219,7 +219,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct
219219
}
220220

221221
if (wp->listen_address_domain == FPM_AF_UNIX) {
222-
if (fpm_socket_unix_test_connect((struct sockaddr_un *)sa, socklen) == 0) {
222+
if (!fpm_socket_unix_test_connect((struct sockaddr_un *)sa, socklen)) {
223223
zlog(ZLOG_ERROR, "Another FPM instance seems to already listen on %s", ((struct sockaddr_un *) sa)->sun_path);
224224
close(sock);
225225
return -1;
@@ -272,7 +272,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct
272272
}
273273
/* }}} */
274274

275-
static int fpm_sockets_get_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, int socklen) /* {{{ */
275+
static int fpm_sockets_get_listening_socket(struct fpm_worker_pool_s *wp, struct sockaddr *sa, socklen_t socklen) /* {{{ */
276276
{
277277
int sock;
278278

@@ -418,7 +418,7 @@ static zend_result fpm_socket_setfib_init(void)
418418
}
419419
#endif
420420

421-
int fpm_sockets_init_main(void)
421+
bool fpm_sockets_init_main(void)
422422
{
423423
unsigned i, lq_len;
424424
struct fpm_worker_pool_s *wp;
@@ -428,12 +428,12 @@ int fpm_sockets_init_main(void)
428428
struct listening_socket_s *ls;
429429

430430
if (0 == fpm_array_init(&sockets_list, sizeof(struct listening_socket_s), 10)) {
431-
return -1;
431+
return false;
432432
}
433433

434434
#ifdef SO_SETFIB
435435
if (fpm_socket_setfib_init() == FAILURE) {
436-
return -1;
436+
return false;
437437
}
438438
#endif
439439

@@ -486,17 +486,17 @@ int fpm_sockets_init_main(void)
486486

487487
case FPM_AF_UNIX :
488488
if (0 > fpm_unix_resolve_socket_permissions(wp)) {
489-
return -1;
489+
return false;
490490
}
491491
wp->listening_socket = fpm_socket_af_unix_listening_socket(wp);
492492
break;
493493
}
494494

495495
if (wp->listening_socket == -1) {
496-
return -1;
496+
return false;
497497
}
498498

499-
if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) {
499+
if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len)) {
500500
fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
501501
}
502502
}
@@ -518,10 +518,7 @@ int fpm_sockets_init_main(void)
518518
}
519519
}
520520

521-
if (!fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_sockets_cleanup, 0)) {
522-
return -1;
523-
}
524-
return 0;
521+
return fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_sockets_cleanup, 0);
525522
}
526523

527524
#if HAVE_FPM_LQ
@@ -530,18 +527,18 @@ int fpm_sockets_init_main(void)
530527

531528
#include <netinet/tcp.h>
532529

533-
int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
530+
bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
534531
{
535532
struct tcp_info info;
536533
socklen_t len = sizeof(info);
537534

538535
if (0 > getsockopt(sock, IPPROTO_TCP, TCP_INFO, &info, &len)) {
539536
zlog(ZLOG_SYSERROR, "failed to retrieve TCP_INFO for socket");
540-
return -1;
537+
return false;
541538
}
542539
#if defined(__FreeBSD__) || defined(__NetBSD__)
543540
if (info.__tcpi_sacked == 0) {
544-
return -1;
541+
return false;
545542
}
546543

547544
if (cur_lq) {
@@ -554,7 +551,7 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
554551
#else
555552
/* kernel >= 2.6.24 return non-zero here, that means operation is supported */
556553
if (info.tcpi_sacked == 0) {
557-
return -1;
554+
return false;
558555
}
559556

560557
if (cur_lq) {
@@ -566,21 +563,21 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
566563
}
567564
#endif
568565

569-
return 0;
566+
return true;
570567
}
571568

572569
#elif defined(HAVE_LQ_TCP_CONNECTION_INFO)
573570

574571
#include <netinet/tcp.h>
575572

576-
int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
573+
bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
577574
{
578575
struct tcp_connection_info info;
579576
socklen_t len = sizeof(info);
580577

581578
if (0 > getsockopt(sock, IPPROTO_TCP, TCP_CONNECTION_INFO, &info, &len)) {
582579
zlog(ZLOG_SYSERROR, "failed to retrieve TCP_CONNECTION_INFO for socket");
583-
return -1;
580+
return false;
584581
}
585582

586583
if (cur_lq) {
@@ -591,65 +588,65 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
591588
*max_lq = 0;
592589
}
593590

594-
return 0;
591+
return true;
595592
}
596593
#endif
597594

598595
#ifdef HAVE_LQ_SO_LISTENQ
599596

600-
int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
597+
bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
601598
{
602599
int val;
603600
socklen_t len = sizeof(val);
604601

605602
if (cur_lq) {
606603
if (0 > getsockopt(sock, SOL_SOCKET, SO_LISTENQLEN, &val, &len)) {
607-
return -1;
604+
return false;
608605
}
609606

610607
*cur_lq = val;
611608
}
612609

613610
if (max_lq) {
614611
if (0 > getsockopt(sock, SOL_SOCKET, SO_LISTENQLIMIT, &val, &len)) {
615-
return -1;
612+
return false;
616613
}
617614

618615
*max_lq = val;
619616
}
620617

621-
return 0;
618+
return true;
622619
}
623620

624621
#endif
625622

626623
#else
627624

628-
int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
625+
bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
629626
{
630-
return -1;
627+
return false;
631628
}
632629

633630
#endif
634631

635-
int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */
632+
bool fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */
636633
{
637634
int fd;
638635

639636
if (!sock || sock->sun_family != AF_UNIX) {
640-
return -1;
637+
return false;
641638
}
642639

643640
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
644-
return -1;
641+
return false;
645642
}
646643

647644
if (connect(fd, (struct sockaddr *)sock, socklen) == -1) {
648645
close(fd);
649-
return -1;
646+
return false;
650647
}
651648

652649
close(fd);
653-
return 0;
650+
return true;
654651
}
655652
/* }}} */

sapi/fpm/fpm/fpm_sockets.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#define FPM_ENV_SOCKET_SET_SIZE 128
2828

2929
enum fpm_address_domain fpm_sockets_domain_from_address(char *addr);
30-
int fpm_sockets_init_main(void);
31-
int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq);
32-
int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen);
30+
bool fpm_sockets_init_main(void);
31+
bool fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq);
32+
bool fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen);
3333

3434

3535
static inline int fd_set_blocked(int fd, int blocked) /* {{{ */

0 commit comments

Comments
 (0)