{"thread":{"id":"4440","subject":"[PATCH] check for error return from fork()","startedAt":"2006-06-08T18:14:47Z","lastAt":"2006-06-08T18:14:47Z","messageCount":1,"participants":["Paul T Darga"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"21444","messageId":"20060608181446.GA32089@umich.edu","threadId":"4440","inReplyTo":null,"subject":"[PATCH] check for error return from fork()","fromName":"Paul T Darga","fromEmail":"pdarga@umich.edu","sentAt":"2006-06-08T18:14:47Z","receivedAt":"2006-06-08T18:14:47Z","isPatch":true,"sender":{"key":"pdarga@umich.edu","avatar":null},"body":"Trivial fixup for fork() callsites which do not check for errors.\n\nSigned-off-by: Paul T Darga <pdarga@umich.edu>\n---\n connect.c   |    2 ++\n imap-send.c |    6 +++++-\n rsh.c       |    6 +++++-\n 3 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex eca94f7..52d709e 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -657,6 +657,8 @@ int git_connect(int fd[2], char *url, co\n \tif (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)\n \t\tdie(\"unable to create pipe pair for communication\");\n \tpid = fork();\n+\tif (pid < 0)\n+\t\tdie(\"unable to fork\");\n \tif (!pid) {\n \t\tsnprintf(command, sizeof(command), \"%s %s\", prog,\n \t\t\t sq_quote(path));\ndiff --git a/imap-send.c b/imap-send.c\nindex 52e2400..285ad29 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -924,6 +924,7 @@ imap_open_store( imap_server_conf_t *srv\n \tstruct hostent *he;\n \tstruct sockaddr_in addr;\n \tint s, a[2], preauth;\n+\tpid_t pid;\n \n \tctx = xcalloc( sizeof(*ctx), 1 );\n \n@@ -941,7 +942,10 @@ imap_open_store( imap_server_conf_t *srv\n \t\t\texit( 1 );\n \t\t}\n \n-\t\tif (fork() == 0) {\n+\t\tpid = fork();\n+\t\tif (pid < 0)\n+\t\t\t_exit( 127 );\n+\t\tif (!pid) {\n \t\t\tif (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1)\n \t\t\t\t_exit( 127 );\n \t\t\tclose( a[0] );\ndiff --git a/rsh.c b/rsh.c\nindex d665269..07166ad 100644\n--- a/rsh.c\n+++ b/rsh.c\n@@ -48,6 +48,7 @@ int setup_connection(int *fd_in, int *fd\n \tint sizen;\n \tint of;\n \tint i;\n+\tpid_t pid;\n \n \tif (!strcmp(url, \"-\")) {\n \t\t*fd_in = 0;\n@@ -91,7 +92,10 @@ int setup_connection(int *fd_in, int *fd\n \tif (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))\n \t\treturn error(\"Couldn't create socket\");\n \n-\tif (!fork()) {\n+\tpid = fork();\n+\tif (pid < 0)\n+\t\treturn error(\"Couldn't fork\");\n+\tif (!pid) {\n \t\tconst char *ssh, *ssh_basename;\n \t\tssh = getenv(\"GIT_SSH\");\n \t\tif (!ssh) ssh = \"ssh\";\n-- \n1.4.0.rc2\n\n\n-- \nPaul T. Darga - pdarga@umich.edu - http://www.eecs.umich.edu/~pdarga/\n\"When I gave food to the poor, they called me a saint. When I asked\nwhy the poor were hungry, they called me a communist.\"\n    -- Dom Helder Camara, Brazilian Bishop, Nobel Peace Prize nominee\n"}]}