Skip to content

Commit

Permalink
check for error return from fork()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Paul T Darga authored and Junio C Hamano committed Jun 8, 2006
1 parent fb6a9f9 commit c9bc159
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ int git_connect(int fd[2], char *url, const char *prog)
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
die("unable to create pipe pair for communication");
pid = fork();
if (pid < 0)
die("unable to fork");
if (!pid) {
snprintf(command, sizeof(command), "%s %s", prog,
sq_quote(path));
Expand Down
6 changes: 5 additions & 1 deletion imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ imap_open_store( imap_server_conf_t *srvc )
struct hostent *he;
struct sockaddr_in addr;
int s, a[2], preauth;
pid_t pid;

ctx = xcalloc( sizeof(*ctx), 1 );

Expand All @@ -941,7 +942,10 @@ imap_open_store( imap_server_conf_t *srvc )
exit( 1 );
}

if (fork() == 0) {
pid = fork();
if (pid < 0)
_exit( 127 );
if (!pid) {
if (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1)
_exit( 127 );
close( a[0] );
Expand Down
6 changes: 5 additions & 1 deletion rsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
int sizen;
int of;
int i;
pid_t pid;

if (!strcmp(url, "-")) {
*fd_in = 0;
Expand Down Expand Up @@ -91,7 +92,10 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
return error("Couldn't create socket");

if (!fork()) {
pid = fork();
if (pid < 0)
return error("Couldn't fork");
if (!pid) {
const char *ssh, *ssh_basename;
ssh = getenv("GIT_SSH");
if (!ssh) ssh = "ssh";
Expand Down

0 comments on commit c9bc159

Please sign in to comment.