summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author <shinichiro.hamaji@gmail.com>2011-09-05 07:56:21 +0000
committer <shinichiro.hamaji@gmail.com>2011-09-05 07:56:21 +0000
commit54421697f4c0650b13c54ee16d6c44d5e912fda8 (patch)
tree7575e25a6d70578808ea80277a926c1449f41476 /src
parent204ef03af8671f4021d745a9080b86512d388bb1 (diff)
downloadglog-54421697f4c0650b13c54ee16d6c44d5e912fda8.tar.gz
glog-54421697f4c0650b13c54ee16d6c44d5e912fda8.tar.bz2
glog-54421697f4c0650b13c54ee16d6c44d5e912fda8.zip
Create a new log files after pid has changed
http://code.google.com/p/google-glog/issues/detail?id=51 http://code.google.com/p/google-glog/issues/detail?id=74 http://code.google.com/p/google-glog/issues/detail?id=82 git-svn-id: https://google-glog.googlecode.com/svn/trunk@94 eb4d4688-79bd-11dd-afb4-1d65580434c0
Diffstat (limited to 'src')
-rw-r--r--src/logging.cc3
-rw-r--r--src/utilities.cc9
-rw-r--r--src/utilities.h1
3 files changed, 12 insertions, 1 deletions
diff --git a/src/logging.cc b/src/logging.cc
index 868898f..ec0ff5b 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -745,7 +745,8 @@ void LogFileObject::Write(bool force_flush,
return;
}
- if (static_cast<int>(file_length_ >> 20) >= MaxLogSize()) {
+ if (static_cast<int>(file_length_ >> 20) >= MaxLogSize() ||
+ PidHasChanged()) {
if (file_ != NULL) fclose(file_);
file_ = NULL;
file_length_ = bytes_since_flush_ = 0;
diff --git a/src/utilities.cc b/src/utilities.cc
index 7e47690..6df20a4 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -221,6 +221,15 @@ int32 GetMainThreadPid() {
return g_main_thread_pid;
}
+bool PidHasChanged() {
+ int32 pid = getpid();
+ if (g_main_thread_pid == pid) {
+ return false;
+ }
+ g_main_thread_pid = pid;
+ return true;
+}
+
pid_t GetTID() {
// On Linux and FreeBSD, we try to use gettid().
#if defined OS_LINUX || defined OS_FREEBSD || defined OS_MACOSX
diff --git a/src/utilities.h b/src/utilities.h
index ee54f94..af9d0d4 100644
--- a/src/utilities.h
+++ b/src/utilities.h
@@ -159,6 +159,7 @@ typedef double WallTime;
WallTime WallTime_Now();
int32 GetMainThreadPid();
+bool PidHasChanged();
pid_t GetTID();