Skip to content

Commit 88e00aa

Browse files
authored
Merge pull request #1919 from Explorer09/fdpair-init
pipe() & fork() code quality improvements
2 parents 47aeb0a + 63018ac commit 88e00aa

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

OpenFilesScreen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
100100
pdata->cols[getIndexForType('o')] = 8;
101101
pdata->cols[getIndexForType('i')] = 8;
102102

103-
int fdpair[2] = {0, 0};
104-
if (pipe(fdpair) == -1) {
103+
int fdpair[2] = {-1, -1};
104+
if (pipe(fdpair) < 0) {
105105
pdata->error = 1;
106106
return pdata;
107107
}
108108

109109
pid_t child = fork();
110-
if (child == -1) {
110+
if (child < 0) {
111111
close(fdpair[1]);
112112
close(fdpair[0]);
113113
pdata->error = 1;

TraceScreen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ static void TraceScreen_draw(InfoScreen* this) {
6767
}
6868

6969
bool TraceScreen_forkTracer(TraceScreen* this) {
70-
int fdpair[2] = {0, 0};
70+
int fdpair[2] = {-1, -1};
7171

72-
if (pipe(fdpair) == -1)
72+
if (pipe(fdpair) < 0)
7373
return false;
7474

7575
if (fcntl(fdpair[0], F_SETFL, O_NONBLOCK) < 0)
@@ -79,7 +79,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
7979
goto err;
8080

8181
pid_t child = fork();
82-
if (child == -1)
82+
if (child < 0)
8383
goto err;
8484

8585
if (child == 0) {

linux/OpenRCMeter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void updateViaExec(bool user) {
4848
if (Settings_isReadonly())
4949
return;
5050

51-
int fdpair[2];
51+
int fdpair[2] = {-1, -1};
5252
if (pipe(fdpair) < 0)
5353
return;
5454

linux/SystemdMeter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static void updateViaExec(bool user) {
217217
if (Settings_isReadonly())
218218
return;
219219

220-
int fdpair[2];
220+
int fdpair[2] = {-1, -1};
221221
if (pipe(fdpair) < 0)
222222
return;
223223

0 commit comments

Comments
 (0)