kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [1/3] kudu git commit: Check sanity of standard file descriptors when starting daemons
Date Thu, 10 Nov 2016 18:22:53 GMT
Repository: kudu
Updated Branches:
  refs/heads/master af9fc13cf -> ba2ae3de4


Check sanity of standard file descriptors when starting daemons

This adds a sanity check at daemon startup that the standard file
descriptors are open. If they are closed at startup, then those numeric
FDs will be reused by other open files later, and it's possible that a
library trying to write to stderr accidentally writes to some other open
file (such as our data!)

Change-Id: Ie57efbb63c588e39ac70777ba7b21496aae7fc27
Reviewed-on: http://gerrit.cloudera.org:8080/5030
Reviewed-by: Adar Dembo <adar@cloudera.com>
Reviewed-by: Jean-Daniel Cryans <jdcryans@apache.org>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/6b60bfdd
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/6b60bfdd
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/6b60bfdd

Branch: refs/heads/master
Commit: 6b60bfdd3e361e87a255938bcb58d930fe8fdcf4
Parents: af9fc13
Author: Todd Lipcon <todd@apache.org>
Authored: Wed Nov 9 16:50:00 2016 -0800
Committer: Todd Lipcon <todd@apache.org>
Committed: Thu Nov 10 04:48:18 2016 +0000

----------------------------------------------------------------------
 src/kudu/util/init.cc | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/6b60bfdd/src/kudu/util/init.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/init.cc b/src/kudu/util/init.cc
index fa55b05..3fa634a 100644
--- a/src/kudu/util/init.cc
+++ b/src/kudu/util/init.cc
@@ -17,6 +17,9 @@
 
 #include "kudu/util/init.h"
 
+#include <fcntl.h>
+#include <unistd.h>
+
 #include <string>
 
 #include "kudu/gutil/cpu.h"
@@ -35,6 +38,31 @@ Status BadCPUStatus(const base::CPU& cpu, const char* instruction_set)
{
       cpu.cpu_brand(), instruction_set));
 }
 
+bool IsFdOpen(int fd) {
+  return fcntl(fd, F_GETFL) != -1;
+}
+
+// Checks that the standard file descriptors are open when the process
+// starts.
+//
+// If these descriptors aren't open, we can run into serious issues:
+// we later might open some other files which end up reusing the same
+// file descriptor numbers as stderr, and then some library like glog
+// may decide to write a log message to what it thinks is stderr. That
+// would then overwrite one of our important data files and cause
+// corruption!
+void CheckStandardFds() {
+  if (!IsFdOpen(STDIN_FILENO) ||
+      !IsFdOpen(STDOUT_FILENO) ||
+      !IsFdOpen(STDERR_FILENO)) {
+    // We can't use LOG(FATAL) here because glog isn't initialized yet, and even if it
+    // were, it would try to write to stderr, which might end up writing the log message
+    // into some unexpected place. This is a rare enough issue that people can deal with
+    // the core dump.
+    abort();
+  }
+}
+
 Status CheckCPUFlags() {
   base::CPU cpu;
   if (!cpu.has_sse42()) {
@@ -49,6 +77,7 @@ Status CheckCPUFlags() {
 }
 
 void InitKuduOrDie() {
+  CheckStandardFds();
   CHECK_OK(CheckCPUFlags());
   // NOTE: this function is called before flags are parsed.
   // Do not add anything in here which is flag-dependent.


Mime
View raw message