fix gcc 7 warnings in pipe routines
This commit is contained in:
parent
8a945194af
commit
47e4bfae57
@ -37,21 +37,20 @@ int rc_pipe_command(char *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0)
|
if (pid > 0) {
|
||||||
return -1;
|
|
||||||
else if (pid > 0) {
|
|
||||||
/* parent */
|
/* parent */
|
||||||
close(pfd[0]);
|
close(pfd[pipe_read_end]);
|
||||||
return pfd[pipe_write_end];
|
return pfd[pipe_write_end];
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
/* child */
|
/* child */
|
||||||
close(pfd[pipe_write_end]);
|
close(pfd[pipe_write_end]);
|
||||||
if (pfd[0] != STDIN_FILENO) {
|
if (pfd[pipe_read_end] != STDIN_FILENO) {
|
||||||
if (dup2(pfd[0], STDIN_FILENO) < 0)
|
if (dup2(pfd[pipe_read_end], STDIN_FILENO) < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
close(pfd[0]);
|
close(pfd[pipe_read_end]);
|
||||||
}
|
}
|
||||||
execl("/bin/sh", "sh", "-c", cmd, NULL);
|
execl("/bin/sh", "sh", "-c", cmd, NULL);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user