Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side 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: fixes for review Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "update_engine/utils.h" 5 #include "update_engine/utils.h"
6 6
7 #include <sys/mount.h> 7 #include <sys/mount.h>
8 #include <sys/resource.h> 8 #include <sys/resource.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
11 #include <sys/wait.h>
11 #include <dirent.h> 12 #include <dirent.h>
12 #include <errno.h> 13 #include <errno.h>
13 #include <fcntl.h> 14 #include <fcntl.h>
14 #include <stdio.h> 15 #include <stdio.h>
15 #include <stdlib.h> 16 #include <stdlib.h>
16 #include <string.h> 17 #include <string.h>
17 #include <unistd.h> 18 #include <unistd.h>
18 19
19 #include <algorithm> 20 #include <algorithm>
20 21
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 vector<string> command; 495 vector<string> command;
495 command.push_back("/sbin/shutdown"); 496 command.push_back("/sbin/shutdown");
496 command.push_back("-r"); 497 command.push_back("-r");
497 command.push_back("now"); 498 command.push_back("now");
498 int rc = 0; 499 int rc = 0;
499 Subprocess::SynchronousExec(command, &rc); 500 Subprocess::SynchronousExec(command, &rc);
500 TEST_AND_RETURN_FALSE(rc == 0); 501 TEST_AND_RETURN_FALSE(rc == 0);
501 return true; 502 return true;
502 } 503 }
503 504
505 namespace {
506 // Do the actual trigger. We do it as a main-loop callback to (try to) get a
507 // consistent stack trace.
508 gboolean TriggerCrashReporterUpload(void* unused) {
509 pid_t pid = fork();
510 CHECK(pid >= 0) << "fork failed"; // fork() failed. Something is very wrong.
511 if (pid == 0) {
512 // We are the child. Crash.
513 abort(); // never returns
514 }
515 // We are the parent. Wait for child to terminate.
516 pid_t result = waitpid(pid, NULL, 0);
517 LOG_IF(ERROR, result < 0) << "waitpid() failed";
518 return FALSE; // Don't call this callback again
519 }
520 } // namespace {}
521
522 void ScheduleCrashReporterUpload() {
523 g_idle_add(&TriggerCrashReporterUpload, NULL);
524 }
525
504 bool SetProcessPriority(ProcessPriority priority) { 526 bool SetProcessPriority(ProcessPriority priority) {
505 int prio = static_cast<int>(priority); 527 int prio = static_cast<int>(priority);
506 LOG(INFO) << "Setting process priority to " << prio; 528 LOG(INFO) << "Setting process priority to " << prio;
507 TEST_AND_RETURN_FALSE(setpriority(PRIO_PROCESS, 0, prio) == 0); 529 TEST_AND_RETURN_FALSE(setpriority(PRIO_PROCESS, 0, prio) == 0);
508 return true; 530 return true;
509 } 531 }
510 532
511 int ComparePriorities(ProcessPriority priority_lhs, 533 int ComparePriorities(ProcessPriority priority_lhs,
512 ProcessPriority priority_rhs) { 534 ProcessPriority priority_rhs) {
513 return static_cast<int>(priority_rhs) - static_cast<int>(priority_lhs); 535 return static_cast<int>(priority_rhs) - static_cast<int>(priority_lhs);
514 } 536 }
515 537
516 int FuzzInt(int value, unsigned int range) { 538 int FuzzInt(int value, unsigned int range) {
517 int min = value - range / 2; 539 int min = value - range / 2;
518 int max = value + range - range / 2; 540 int max = value + range - range / 2;
519 return base::RandInt(min, max); 541 return base::RandInt(min, max);
520 } 542 }
521 543
522 const char* const kStatefulPartition = "/mnt/stateful_partition"; 544 const char* const kStatefulPartition = "/mnt/stateful_partition";
523 545
524 } // namespace utils 546 } // namespace utils
525 547
526 } // namespace chromeos_update_engine 548 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698