Skip to content

Commit 08189b1

Browse files
committed
Convert return values to bool in fpm_trace.c files
The return value was always either 0 or -1
1 parent fb3330c commit 08189b1

File tree

6 files changed

+65
-64
lines changed

6 files changed

+65
-64
lines changed

sapi/fpm/fpm/fpm_php_trace.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
5252

5353
fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
5454

55-
if (0 > fpm_trace_get_long((long) &SG(request_info).path_translated, &l)) {
55+
if (!fpm_trace_get_long((long) &SG(request_info).path_translated, &l)) {
5656
return false;
5757
}
5858

5959
path_translated = l;
6060

61-
if (0 > fpm_trace_get_strz(buf, buf_size, path_translated)) {
61+
if (!fpm_trace_get_strz(buf, buf_size, path_translated)) {
6262
return false;
6363
}
6464

6565
fprintf(slowlog, "script_filename = %s\n", buf);
6666

67-
if (0 > fpm_trace_get_long((long) &EG(current_execute_data), &l)) {
67+
if (!fpm_trace_get_long((long) &EG(current_execute_data), &l)) {
6868
return false;
6969
}
7070

@@ -77,22 +77,22 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
7777
long prev;
7878
uint32_t lineno = 0;
7979

80-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l)) {
80+
if (!fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l)) {
8181
return false;
8282
}
8383

8484
function = l;
8585

8686
if (valid_ptr(function)) {
87-
if (0 > fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l)) {
87+
if (!fpm_trace_get_long(function + offsetof(zend_function, common.function_name), &l)) {
8888
return false;
8989
}
9090

9191
function_name = l;
9292

9393
if (function_name == 0) {
9494
uint32_t *call_info = (uint32_t *)&l;
95-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, This.u1.type_info), &l)) {
95+
if (!fpm_trace_get_long(execute_data + offsetof(zend_execute_data, This.u1.type_info), &l)) {
9696
return false;
9797
}
9898

@@ -104,7 +104,7 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
104104
ZEND_UNREACHABLE();
105105
}
106106
} else {
107-
if (0 > fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) {
107+
if (!fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) {
108108
return false;
109109
}
110110

@@ -119,7 +119,7 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
119119

120120
*buf = '\0';
121121

122-
if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) {
122+
if (!fpm_trace_get_long(execute_data + offsetof(zend_execute_data, prev_execute_data), &l)) {
123123
return false;
124124
}
125125

@@ -128,7 +128,7 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
128128
while (prev) {
129129
zend_uchar *type;
130130

131-
if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, func), &l)) {
131+
if (!fpm_trace_get_long(prev + offsetof(zend_execute_data, func), &l)) {
132132
return false;
133133
}
134134

@@ -139,30 +139,30 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
139139
}
140140

141141
type = (zend_uchar *)&l;
142-
if (0 > fpm_trace_get_long(function + offsetof(zend_function, type), &l)) {
142+
if (!fpm_trace_get_long(function + offsetof(zend_function, type), &l)) {
143143
return false;
144144
}
145145

146146
if (ZEND_USER_CODE(*type)) {
147-
if (0 > fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l)) {
147+
if (!fpm_trace_get_long(function + offsetof(zend_op_array, filename), &l)) {
148148
return false;
149149
}
150150

151151
file_name = l;
152152

153-
if (0 > fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) {
153+
if (!fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) {
154154
return false;
155155
}
156156

157-
if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l)) {
157+
if (!fpm_trace_get_long(prev + offsetof(zend_execute_data, opline), &l)) {
158158
return false;
159159
}
160160

161161
if (valid_ptr(l)) {
162162
long opline = l;
163163
uint32_t *lu = (uint32_t *) &l;
164164

165-
if (0 > fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) {
165+
if (!fpm_trace_get_long(opline + offsetof(struct _zend_op, lineno), &l)) {
166166
return false;
167167
}
168168

@@ -171,7 +171,7 @@ static bool fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{
171171
break;
172172
}
173173

174-
if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l)) {
174+
if (!fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l)) {
175175
return false;
176176
}
177177

@@ -203,15 +203,15 @@ void fpm_php_trace(struct fpm_child_s *child) /* {{{ */
203203
goto done0;
204204
}
205205

206-
if (0 > fpm_trace_ready(child->pid)) {
206+
if (!fpm_trace_ready(child->pid)) {
207207
goto done1;
208208
}
209209

210210
if (!fpm_php_trace_dump(child, slowlog)) {
211211
fprintf(slowlog, "+++ dump failed\n");
212212
}
213213

214-
if (0 > fpm_trace_close(child->pid)) {
214+
if (!fpm_trace_close(child->pid)) {
215215
goto done1;
216216
}
217217

sapi/fpm/fpm/fpm_trace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "fpm_trace.h"
88

9-
int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */
9+
bool fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */
1010
{
1111
int i;
1212
long l = addr;
@@ -15,8 +15,8 @@ int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */
1515
i = l % SIZEOF_LONG;
1616
l -= i;
1717
for (addr = l; ; addr += SIZEOF_LONG) {
18-
if (0 > fpm_trace_get_long(addr, &l)) {
19-
return -1;
18+
if (!fpm_trace_get_long(addr, &l)) {
19+
return false;
2020
}
2121
for ( ; i < SIZEOF_LONG; i++) {
2222
--sz;
@@ -25,7 +25,7 @@ int fpm_trace_get_strz(char *buf, size_t sz, long addr) /* {{{ */
2525
continue;
2626
}
2727
*buf = '\0';
28-
return 0;
28+
return true;
2929
}
3030
i = 0;
3131
}

sapi/fpm/fpm/fpm_trace.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#ifndef FPM_TRACE_H
44
#define FPM_TRACE_H 1
55

6+
#include <stdbool.h>
67
#include <unistd.h>
78

8-
int fpm_trace_signal(pid_t pid);
9-
int fpm_trace_ready(pid_t pid);
10-
int fpm_trace_close(pid_t pid);
11-
int fpm_trace_get_long(long addr, long *data);
12-
int fpm_trace_get_strz(char *buf, size_t sz, long addr);
9+
bool fpm_trace_signal(pid_t pid);
10+
bool fpm_trace_ready(pid_t pid);
11+
bool fpm_trace_close(pid_t pid);
12+
bool fpm_trace_get_long(long addr, long *data);
13+
bool fpm_trace_get_strz(char *buf, size_t sz, long addr);
1314

1415
#endif

sapi/fpm/fpm/fpm_trace_mach.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ static void fpm_mach_vm_deallocate(void)
2828
}
2929
}
3030

31-
static int fpm_mach_vm_read_page(vm_offset_t page) /* {{{ */
31+
static bool fpm_mach_vm_read_page(vm_offset_t page) /* {{{ */
3232
{
3333
kern_return_t kr;
3434

3535
kr = mach_vm_read(target, page, fpm_pagesize, &local_page, &local_size);
3636
if (kr != KERN_SUCCESS) {
3737
zlog(ZLOG_ERROR, "failed to read vm page: mach_vm_read(): %s (%d)", mach_error_string(kr), kr);
38-
return -1;
38+
return false;
3939
}
40-
return 0;
40+
return true;
4141
}
4242
/* }}} */
4343

44-
int fpm_trace_signal(pid_t pid) /* {{{ */
44+
bool fpm_trace_signal(pid_t pid) /* {{{ */
4545
{
4646
if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) {
4747
zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid);
48-
return -1;
48+
return false;
4949
}
50-
return 0;
50+
return true;
5151
}
5252
/* }}} */
5353

54-
int fpm_trace_ready(pid_t pid) /* {{{ */
54+
bool fpm_trace_ready(pid_t pid) /* {{{ */
5555
{
5656
kern_return_t kr;
5757

@@ -63,32 +63,32 @@ int fpm_trace_ready(pid_t pid) /* {{{ */
6363
msg = " It seems that master process does not have enough privileges to trace processes.";
6464
}
6565
zlog(ZLOG_ERROR, "task_for_pid() failed: %s (%d)%s", mach_error_string(kr), kr, msg);
66-
return -1;
66+
return false;
6767
}
68-
return 0;
68+
return true;
6969
}
7070
/* }}} */
7171

72-
int fpm_trace_close(pid_t pid) /* {{{ */
72+
bool fpm_trace_close(pid_t pid) /* {{{ */
7373
{
7474
fpm_mach_vm_deallocate();
7575
target = 0;
76-
return 0;
76+
return true;
7777
}
7878
/* }}} */
7979

80-
int fpm_trace_get_long(long addr, long *data) /* {{{ */
80+
bool fpm_trace_get_long(long addr, long *data) /* {{{ */
8181
{
8282
size_t offset = ((uintptr_t) (addr) % fpm_pagesize);
8383
vm_offset_t base = (uintptr_t) (addr) - offset;
8484

8585
if (base != target_page_base) {
8686
fpm_mach_vm_deallocate();
87-
if (0 > fpm_mach_vm_read_page(base)) {
88-
return -1;
87+
if (!fpm_mach_vm_read_page(base)) {
88+
return false;
8989
}
9090
}
9191
*data = * (long *) (local_page + offset);
92-
return 0;
92+
return true;
9393
}
9494
/* }}} */

sapi/fpm/fpm/fpm_trace_pread.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,44 @@
1919

2020
static int mem_file = -1;
2121

22-
int fpm_trace_signal(pid_t pid) /* {{{ */
22+
bool fpm_trace_signal(pid_t pid) /* {{{ */
2323
{
2424
if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) {
2525
zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid);
26-
return -1;
26+
return false;
2727
}
28-
return 0;
28+
return true;
2929
}
3030
/* }}} */
3131

32-
int fpm_trace_ready(pid_t pid) /* {{{ */
32+
bool fpm_trace_ready(pid_t pid) /* {{{ */
3333
{
3434
char buf[128];
3535

3636
sprintf(buf, "/proc/%d/" PROC_MEM_FILE, (int) pid);
3737
mem_file = open(buf, O_RDONLY);
3838
if (0 > mem_file) {
3939
zlog(ZLOG_SYSERROR, "failed to open %s", buf);
40-
return -1;
40+
return false;
4141
}
42-
return 0;
42+
return true;
4343
}
4444
/* }}} */
4545

46-
int fpm_trace_close(pid_t pid) /* {{{ */
46+
bool fpm_trace_close(pid_t pid) /* {{{ */
4747
{
4848
close(mem_file);
4949
mem_file = -1;
50-
return 0;
50+
return true;
5151
}
5252
/* }}} */
5353

54-
int fpm_trace_get_long(long addr, long *data) /* {{{ */
54+
bool fpm_trace_get_long(long addr, long *data) /* {{{ */
5555
{
5656
if (sizeof(*data) != pread(mem_file, (void *) data, sizeof(*data), (uintptr_t) addr)) {
5757
zlog(ZLOG_SYSERROR, "pread() failed");
58-
return -1;
58+
return false;
5959
}
60-
return 0;
60+
return true;
6161
}
6262
/* }}} */

sapi/fpm/fpm/fpm_trace_ptrace.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@
2424

2525
static pid_t traced_pid;
2626

27-
int fpm_trace_signal(pid_t pid) /* {{{ */
27+
bool fpm_trace_signal(pid_t pid) /* {{{ */
2828
{
2929
if (0 > ptrace(PTRACE_ATTACH, pid, 0, 0)) {
3030
zlog(ZLOG_SYSERROR, "failed to ptrace(ATTACH) child %d", pid);
31-
return -1;
31+
return false;
3232
}
33-
return 0;
33+
return true;
3434
}
3535
/* }}} */
3636

37-
int fpm_trace_ready(pid_t pid) /* {{{ */
37+
bool fpm_trace_ready(pid_t pid) /* {{{ */
3838
{
3939
traced_pid = pid;
40-
return 0;
40+
return true;
4141
}
4242
/* }}} */
4343

44-
int fpm_trace_close(pid_t pid) /* {{{ */
44+
bool fpm_trace_close(pid_t pid) /* {{{ */
4545
{
4646
if (0 > ptrace(PTRACE_DETACH, pid, (void *) 1, 0)) {
4747
zlog(ZLOG_SYSERROR, "failed to ptrace(DETACH) child %d", pid);
48-
return -1;
48+
return false;
4949
}
5050
traced_pid = 0;
51-
return 0;
51+
return true;
5252
}
5353
/* }}} */
5454

55-
int fpm_trace_get_long(long addr, long *data) /* {{{ */
55+
bool fpm_trace_get_long(long addr, long *data) /* {{{ */
5656
{
5757
#ifdef PT_IO
5858
struct ptrace_io_desc ptio = {
@@ -64,16 +64,16 @@ int fpm_trace_get_long(long addr, long *data) /* {{{ */
6464

6565
if (0 > ptrace(PT_IO, traced_pid, (void *) &ptio, 0)) {
6666
zlog(ZLOG_SYSERROR, "failed to ptrace(PT_IO) pid %d", traced_pid);
67-
return -1;
67+
return false;
6868
}
6969
#else
7070
errno = 0;
7171
*data = ptrace(PTRACE_PEEKDATA, traced_pid, (void *) addr, 0);
7272
if (errno) {
7373
zlog(ZLOG_SYSERROR, "failed to ptrace(PEEKDATA) pid %d", traced_pid);
74-
return -1;
74+
return false;
7575
}
7676
#endif
77-
return 0;
77+
return true;
7878
}
7979
/* }}} */

0 commit comments

Comments
 (0)