From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci common/executils.cpp modules/log/L ...
Date: 20 Sep 2007 05:39:04 -0000 [thread overview]
Message-ID: <20070920053904.11823.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-09-20 05:39:04
Modified files:
ricci/common : executils.cpp
ricci/modules/log: LogParser.cpp
Log message:
Ensure that malloc/new/whatever is not called between fork() and execv() in a function that can be called from a thread.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/executils.cpp.diff?cvsroot=cluster&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/log/LogParser.cpp.diff?cvsroot=cluster&r1=1.12&r2=1.13
--- conga/ricci/common/executils.cpp 2007/09/18 21:01:00 1.11
+++ conga/ricci/common/executils.cpp 2007/09/20 05:39:03 1.12
@@ -52,17 +52,42 @@
int _stdout_pipe[2];
int _stderr_pipe[2];
- if (pipe(_stdout_pipe) == -1)
+ /*
+ ** Prepare argv before forking in case we were called from a thread.
+ */
+ unsigned int size = args.size() + 2;
+ char **argv = (char **) malloc(sizeof(char *) * size);
+ if (argv == NULL)
+ return 3;
+
+ try {
+ argv[0] = (char *) path.c_str();
+ for (unsigned int i = 0 ; i < args.size() ; i++)
+ argv[i + 1] = (char *) args[i].c_str();
+ argv[size - 1] = NULL;
+ } catch (...) {
+ free(argv);
+ return 3;
+ }
+
+ if (pipe(_stdout_pipe) == -1) {
+ free(argv);
return 2;
+ }
if (pipe(_stderr_pipe) == -1) {
+ free(argv);
close_fd(_stdout_pipe[0]);
close_fd(_stdout_pipe[1]);
return 2;
}
+ setenv("LANG", "C", 1);
+ setenv("LC_ALL", "C", 1);
+
int pid = fork();
if (pid == -1) {
+ free(argv);
close_fd(_stdout_pipe[0]);
close_fd(_stdout_pipe[1]);
close_fd(_stderr_pipe[0]);
@@ -70,9 +95,6 @@
return 3;
}
- unsigned int time_beg = time_mil();
- unsigned int time_to_kill = time_beg + timeout;
-
if (pid == 0) {
/* child */
@@ -97,7 +119,7 @@
close_fd(devnull);
// close open fds
- for (unsigned int i = 3; i < __FD_SETSIZE ; i++)
+ for (unsigned int i = 3 ; i < __FD_SETSIZE ; i++)
close_fd(i);
// restore signals
@@ -108,27 +130,18 @@
sigfillset(&set);
sigprocmask(SIG_UNBLOCK, &set, NULL);
- setenv("LANG", "C", 1);
- setenv("LC_ALL", "C", 1);
-
- /* exec */
- try {
- unsigned int size = args.size() + 2;
- char **argv = new char*[size];
-
- argv[0] = (char *) path.c_str();
- for (unsigned int i = 0 ; i < args.size() ; i++)
- argv[i + 1] = (char *) args[i].c_str();
- argv[size - 1] = NULL;
- execv(path.c_str(), argv);
- } catch ( ... ) {}
+ execv(path.c_str(), argv);
_exit(1);
}
/* parent */
+ unsigned int time_beg = time_mil();
+ unsigned int time_to_kill = time_beg + timeout;
+ bool out_closed = false, err_closed = false;
+
+ free(argv);
close_fd(_stdout_pipe[1]);
close_fd(_stderr_pipe[1]);
- bool out_closed = false, err_closed = false;
while (true) {
// kill child if timeout elapsed
@@ -183,12 +196,12 @@
if (poll_info.fd == _stderr_pipe[0])
read_data(poll_info, err_closed, err);
}
- } // while (true)
+ }
// command
- String comm(path);
- for (unsigned int i = 0 ; i < args.size() ; i++)
- comm += " " + args[i];
+ //String comm(path);
+ //for (unsigned int i = 0 ; i < args.size() ; i++)
+ // comm += " " + args[i];
// get status
int ret;
--- conga/ricci/modules/log/LogParser.cpp 2007/09/18 21:01:00 1.12
+++ conga/ricci/modules/log/LogParser.cpp 2007/09/20 05:39:03 1.13
@@ -437,12 +437,8 @@
log.getline(buff, sizeof(buff));
LogEntry e(buff);
- /*
- ** Since the log entries' times ascend chronologically, we
- ** can bail if we hit an entry that's older than the max age.
- */
if (e.age > age)
- break;
+ continue;
if (req_tags.empty())
ret.insert(e);
reply other threads:[~2007-09-20 5:39 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=20070920053904.11823.qmail@sourceware.org \
--to=rmccabe@sourceware.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.