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

Side by Side Diff: base/logging.cc

Issue 460094: Make POSIX SIGTERM/SIGINT/SIGHUP handler async signal safe. (Closed)
Patch Set: move shutdown thread creation after UI thread is registered. Created 11 years 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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium 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 "base/logging.h" 5 #include "base/logging.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h>
8 #include <windows.h> 9 #include <windows.h>
9 typedef HANDLE FileHandle; 10 typedef HANDLE FileHandle;
10 typedef HANDLE MutexHandle; 11 typedef HANDLE MutexHandle;
12 // Windows warns on using write(). It prefers _write().
13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count))
14 // Windows doesn't define STDERR_FILENO. Define it here.
15 #define STDERR_FILENO 2
11 #elif defined(OS_MACOSX) 16 #elif defined(OS_MACOSX)
12 #include <CoreFoundation/CoreFoundation.h> 17 #include <CoreFoundation/CoreFoundation.h>
13 #include <mach/mach.h> 18 #include <mach/mach.h>
14 #include <mach/mach_time.h> 19 #include <mach/mach_time.h>
15 #include <mach-o/dyld.h> 20 #include <mach-o/dyld.h>
16 #elif defined(OS_LINUX) 21 #elif defined(OS_LINUX)
17 #include <sys/syscall.h> 22 #include <sys/syscall.h>
18 #include <time.h> 23 #include <time.h>
19 #endif 24 #endif
20 25
21 #if defined(OS_POSIX) 26 #if defined(OS_POSIX)
22 #include <errno.h> 27 #include <errno.h>
23 #include <stdlib.h> 28 #include <stdlib.h>
24 #include <stdio.h> 29 #include <stdio.h>
25 #include <string.h> 30 #include <string.h>
26 #include <unistd.h> 31 #include <unistd.h>
27 #define MAX_PATH PATH_MAX 32 #define MAX_PATH PATH_MAX
28 typedef FILE* FileHandle; 33 typedef FILE* FileHandle;
29 typedef pthread_mutex_t* MutexHandle; 34 typedef pthread_mutex_t* MutexHandle;
30 #endif 35 #endif
31 36
32 #include <ctime> 37 #include <ctime>
33 #include <iomanip> 38 #include <iomanip>
34 #include <cstring> 39 #include <cstring>
35 #include <algorithm> 40 #include <algorithm>
36 41
37 #include "base/base_switches.h" 42 #include "base/base_switches.h"
38 #include "base/command_line.h" 43 #include "base/command_line.h"
39 #include "base/debug_util.h" 44 #include "base/debug_util.h"
45 #include "base/eintr_wrapper.h"
40 #include "base/lock_impl.h" 46 #include "base/lock_impl.h"
41 #if defined(OS_POSIX) 47 #if defined(OS_POSIX)
42 #include "base/safe_strerror_posix.h" 48 #include "base/safe_strerror_posix.h"
43 #endif 49 #endif
44 #include "base/string_piece.h" 50 #include "base/string_piece.h"
45 #include "base/string_util.h" 51 #include "base/string_util.h"
46 #include "base/utf_string_conversions.h" 52 #include "base/utf_string_conversions.h"
47 53
48 namespace logging { 54 namespace logging {
49 55
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 #endif // OS_WIN 683 #endif // OS_WIN
678 684
679 void CloseLogFile() { 685 void CloseLogFile() {
680 if (!log_file) 686 if (!log_file)
681 return; 687 return;
682 688
683 CloseFile(log_file); 689 CloseFile(log_file);
684 log_file = NULL; 690 log_file = NULL;
685 } 691 }
686 692
693 void RawLog(int level, const char* message) {
694 if (level >= min_log_level) {
695 size_t bytes_written = 0;
696 const size_t message_len = strlen(message);
697 int rv;
698 while (bytes_written < message_len) {
699 rv = HANDLE_EINTR(
700 write(STDERR_FILENO, message + bytes_written,
701 message_len - bytes_written));
702 if (rv < 0) {
703 // Give up, nothing we can do now.
704 break;
705 }
706 bytes_written += rv;
707 }
708
709 if (message_len > 0 && message[message_len - 1] != '\n') {
710 do {
711 rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1));
712 if (rv < 0) {
713 // Give up, nothing we can do now.
714 break;
715 }
716 } while (rv != 1);
717 }
718 }
719
720 if (level == LOG_FATAL)
721 DebugUtil::BreakDebugger();
722 }
723
687 } // namespace logging 724 } // namespace logging
688 725
689 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { 726 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) {
690 return out << WideToUTF8(std::wstring(wstr)); 727 return out << WideToUTF8(std::wstring(wstr));
691 } 728 }
OLDNEW
« no previous file with comments | « base/logging.h ('k') | chrome/browser/browser_main.cc » ('j') | chrome/browser/browser_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698