#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <signal.h>
// for tstring stringtable
#include "include/tstring.h"
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) {
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;
}
*/
if (g_conf.dout_dir && g_conf.file_logs && open) {
- char fn[80];
char hostname[80];
gethostname(hostname, 79);
}
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) {
return 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) {
return out;
}
-// the streams
-extern ostream *_dout;
-extern ostream *_derr;
// generic macros
#define generic_dout(x) if ((x) <= g_conf.debug) *_dout << dbeginl