From: Yehuda Sadeh Date: Mon, 3 Nov 2008 19:27:33 +0000 (-0800) Subject: reopen log files on usespace daemons when getting a HUP signal X-Git-Tag: v0.5~113 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=76dd6d922f1e3c448d146af3e6741c6a07a6e4c4;p=ceph.git reopen log files on usespace daemons when getting a HUP signal --- diff --git a/src/config.cc b/src/config.cc index 397d0ee3e93f..8200672d8555 100644 --- a/src/config.cc +++ b/src/config.cc @@ -22,6 +22,7 @@ #include #include #include +#include // 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& args, bool open) { std::vector nargs; @@ -1171,7 +1179,6 @@ void parse_config_options(std::vector& 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& 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; } + diff --git a/src/config.h b/src/config.h index d719e6e47dc5..6da73885caed 100644 --- a/src/config.h +++ b/src/config.h @@ -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