Chromium Code Reviews

Unified Diff: utils.cc

Issue 6114002: AU: Function to trigger crash reporter. (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils.cc
diff --git a/utils.cc b/utils.cc
index 359b6b8866a6fee79b5f242f91d4ea4720ce2d17..fdfe82cafc52a11d00d2fcfaa21e3b60b186551a 100644
--- a/utils.cc
+++ b/utils.cc
@@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -501,6 +502,32 @@ bool Reboot() {
return true;
}
+namespace {
+// Do the actual trigger. We do it as a main-loop callback to (try to) get a
+// consistent stack trace.
+gboolean TriggerCrashReporterUpload(void* unused) {
+ pid_t pid = fork();
+ if (pid < 0) {
petkov 2011/01/07 17:39:34 Maybe just CHECK(pid >= 0) and no comment to reduc
adlr 2011/01/07 21:13:42 Done.
+ // fork() failed. Something is very wrong.
+ CHECK(false) << "fork failed";
+ }
+ if (pid == 0) {
+ // We are the child. Crash.
+ abort(); // never returns
+ }
+ // We are the parent. Wait for child to terminate.
+ pid_t result = waitpid(pid, NULL, 0);
+ if (result < 0) {
petkov 2011/01/07 17:39:34 LOG_IF(ERROR, result < 0) << "..."
adlr 2011/01/07 21:13:42 Done.
+ LOG(ERROR) << "waitpid() failed";
+ }
+ return FALSE; // Don't call this callback again
+}
+} // namespace {}
+
+void ScheduleCrashReporterUpload() {
+ g_timeout_add_seconds(0, &TriggerCrashReporterUpload, NULL);
petkov 2011/01/07 17:39:34 any benefit/drawback to using g_idle_add? probably
adlr 2011/01/07 21:13:42 good thought. we may as well use that. i put it in
+}
+
bool SetProcessPriority(ProcessPriority priority) {
int prio = static_cast<int>(priority);
LOG(INFO) << "Setting process priority to " << prio;
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine