check for error return from fork()
Trivial fixup for fork() callsites which do not check for errors. Signed-off-by: Paul T Darga <pdarga@umich.edu> Signed-off-by: Junio C Hamano <junkio@cox.net>
Paul T Darga committed
Jun 8, 2006 at 14:14 UTC
c9bc159d7f41e2916830b05529c1ce06a81d975f
3 files changed
+12
-2
connect.c
+2
@@ -657,6 +657,8 @@ int git_connect(int fd[2], char *url, const char *prog)
657
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
658
die("unable to create pipe pair for communication");
659
pid = fork();
660
+ if (pid < 0)
661
+ die("unable to fork");
662
if (!pid) {
663
snprintf(command, sizeof(command), "%s %s", prog,
664
sq_quote(path));
imap-send.c
+5
-1
@@ -924,6 +924,7 @@ imap_open_store( imap_server_conf_t *srvc )
924
struct hostent *he;
925
struct sockaddr_in addr;
926
int s, a[2], preauth;
927
+ pid_t pid;
928
929
ctx = xcalloc( sizeof(*ctx), 1 );
930
@@ -941,7 +942,10 @@ imap_open_store( imap_server_conf_t *srvc )
942
exit( 1 );
943
}
944
944
- if (fork() == 0) {
945
+ pid = fork();
946
+ if (pid < 0)
947
+ _exit( 127 );
948
+ if (!pid) {
949
if (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1)
950
_exit( 127 );
951
close( a[0] );
rsh.c
+5
-1
@@ -48,6 +48,7 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
48
int sizen;
49
int of;
50
int i;
51
+ pid_t pid;
52
53
if (!strcmp(url, "-")) {
54
*fd_in = 0;
@@ -91,7 +92,10 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
92
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
93
return error("Couldn't create socket");
94
94
- if (!fork()) {
95
+ pid = fork();
96
+ if (pid < 0)
97
+ return error("Couldn't fork");
98
+ if (!pid) {
99
const char *ssh, *ssh_basename;
100
ssh = getenv("GIT_SSH");
101
if (!ssh) ssh = "ssh";