-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix error log bug by redirect fd
Signed-off-by: NaturalSelect <[email protected]>
- Loading branch information
1 parent
c63296b
commit 346f119
Showing
7 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "src/common/log_util.h" | ||
|
||
#include <gflags/gflags.h> | ||
#include <glog/logging.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
|
||
static int DisableStderr() { | ||
// NOTE: use "/dev/stderr" to reopen stderr fd | ||
int fd = ::open("/dev/null",O_APPEND|O_WRONLY); | ||
if (fd == -1) { | ||
return -1; | ||
} | ||
int r = ::dup2(fd,::fileno(stderr)); | ||
if (r == -1) { | ||
return r; | ||
} | ||
::close(fd); | ||
return 0; | ||
} | ||
|
||
void curve::common::InitGoogleLogging(const char *argv0) { | ||
if (!FLAGS_logtostderr && !FLAGS_alsologtostderr) { | ||
DisableStderr(); | ||
} | ||
google::InitGoogleLogging(argv0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef CURVEFS_SRC_COMMON_LOG_UTIL_H | ||
#define CURVEFS_SRC_COMMON_LOG_UTIL_H | ||
|
||
namespace curve { | ||
namespace common { | ||
|
||
extern void InitGoogleLogging(const char *argv0); | ||
|
||
}} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters