From: Paul T Darga <pdarga@umich.edu>
To: git@vger.kernel.org
Subject: [PATCH] check for error return from fork()
Date: Thu, 8 Jun 2006 14:14:47 -0400 [thread overview]
Message-ID: <20060608181446.GA32089@umich.edu> (raw)
Trivial fixup for fork() callsites which do not check for errors.
Signed-off-by: Paul T Darga <pdarga@umich.edu>
---
connect.c | 2 ++
imap-send.c | 6 +++++-
rsh.c | 6 +++++-
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/connect.c b/connect.c
index eca94f7..52d709e 100644
--- a/connect.c
+++ b/connect.c
@@ -657,6 +657,8 @@ int git_connect(int fd[2], char *url, co
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));
diff --git a/imap-send.c b/imap-send.c
index 52e2400..285ad29 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -924,6 +924,7 @@ imap_open_store( imap_server_conf_t *srv
struct hostent *he;
struct sockaddr_in addr;
int s, a[2], preauth;
+ pid_t pid;
ctx = xcalloc( sizeof(*ctx), 1 );
@@ -941,7 +942,10 @@ imap_open_store( imap_server_conf_t *srv
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] );
diff --git a/rsh.c b/rsh.c
index d665269..07166ad 100644
--- a/rsh.c
+++ b/rsh.c
@@ -48,6 +48,7 @@ int setup_connection(int *fd_in, int *fd
int sizen;
int of;
int i;
+ pid_t pid;
if (!strcmp(url, "-")) {
*fd_in = 0;
@@ -91,7 +92,10 @@ int setup_connection(int *fd_in, int *fd
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";
--
1.4.0.rc2
--
Paul T. Darga - pdarga@umich.edu - http://www.eecs.umich.edu/~pdarga/
"When I gave food to the poor, they called me a saint. When I asked
why the poor were hungry, they called me a communist."
-- Dom Helder Camara, Brazilian Bishop, Nobel Peace Prize nominee
reply other threads:[~2006-06-08 18:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060608181446.GA32089@umich.edu \
--to=pdarga@umich.edu \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).