]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
reopen log files on usespace daemons when getting a HUP signal
authorYehuda Sadeh <yehuda@hq.newdream.net>
Mon, 3 Nov 2008 19:27:33 +0000 (11:27 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Mon, 3 Nov 2008 19:27:33 +0000 (11:27 -0800)
src/config.cc
src/config.h

index 397d0ee3e93ff8aab34edfded511d77cbc32b4aa..8200672d8555644e1cf38c1be68941ff35a4dac0 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <signal.h>
 
 // for tstring stringtable
 #include "include/tstring.h"
@@ -86,6 +87,8 @@ ostream *_derr = &std::cerr;
 char _dout_file[100] = {0};
 char _dout_dir[1000] = {0};
 char _dout_symlink_path[1000] = {0};
+bool _dout_is_open;
+bool _dout_need_open;
 
 // page size crap, see page.h
 int _get_bits_of(int v) {
@@ -594,6 +597,11 @@ void parse_config_option_string(string& s)
   parse_config_options(nargs, false);
 }
 
+void sighup_handler(int signum)
+{
+  _dout_need_open = true;
+}
+
 void parse_config_options(std::vector<const char*>& args, bool open)
 {
   std::vector<const char*> nargs;
@@ -1171,7 +1179,6 @@ void parse_config_options(std::vector<const char*>& args, bool open)
   }
   */
   if (g_conf.dout_dir && g_conf.file_logs && open) {
-    char fn[80];
     char hostname[80];
     gethostname(hostname, 79);
 
@@ -1184,19 +1191,36 @@ void parse_config_options(std::vector<const char*>& args, bool open)
     }
     sprintf(_dout_file, "%s.%d", hostname, getpid());
 
-    sprintf(fn, "%s/%s", _dout_dir, _dout_file);
-    std::ofstream *out = new std::ofstream(fn, ios::trunc|ios::out);
-    if (!out->is_open()) {
-      std::cerr << "error opening output file " << fn << std::endl;
-      delete out;
-    } else {
-      _dout = out;
-    }
+    _dout_is_open = false;
+    _dout_need_open = true;
+
+    open_dout_file();
   }
 
+  signal(SIGHUP, sighup_handler);
+
   args = nargs;
 }
 
+void open_dout_file()
+{
+  char fn[80];
+  if (_dout && _dout_is_open) {
+    delete _dout;
+  }
+
+  sprintf(fn, "%s/%s", _dout_dir, _dout_file);
+  std::ofstream *out = new std::ofstream(fn, ios::trunc|ios::out);
+  if (!out->is_open()) {
+    std::cerr << "error opening output file " << fn << std::endl;
+    delete out;
+  } else {
+    _dout_need_open = false;
+    _dout_is_open = true;
+    _dout = out;
+  }
+}
+
 int rename_output_file()  // after calling daemon()
 {
   if (g_conf.dout_dir) {
@@ -1228,3 +1252,4 @@ int create_courtesy_output_symlink(const char *type, int n)
   return 0;
 }
 
+
index d719e6e47dc5898e4db79744de2bc967fa49babf..6da73885caed22086cff4a68fbf63d52abf47dd3 100644 (file)
@@ -380,8 +380,24 @@ static const _dendl_t dendl = 0;
 class _bad_endl_use_dendl_t { public: _bad_endl_use_dendl_t(int) {} };
 static const _bad_endl_use_dendl_t endl = 0;
 
+// the streams
+extern ostream *_dout;
+extern ostream *_derr;
+extern bool _dout_need_open;
+extern bool _dout_is_open;
+
+extern void open_dout_file();
+
 inline ostream& operator<<(ostream& out, _dbeginl_t) {
   _dout_lock.Lock();
+
+  if (_dout_need_open) {
+    if (_dout && _dout_is_open) {
+      delete _dout;
+    }
+    open_dout_file();
+  }
+
   return out;
 }
 inline ostream& operator<<(ostream& out, _dendl_t) {
@@ -394,9 +410,6 @@ inline ostream& operator<<(ostream& out, _bad_endl_use_dendl_t) {
   return out;
 }
 
-// the streams
-extern ostream *_dout;
-extern ostream *_derr;
 
 // generic macros
 #define generic_dout(x) if ((x) <= g_conf.debug) *_dout << dbeginl