Skip to content

Commit

Permalink
Fix bug in setting log files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Gauci committed Oct 9, 2018
1 parent 30c40fc commit 96fa77b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/terminal/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ string getIdpasskey() {

void setDaemonLogFile(string idpasskey, string daemonType) {
string first_idpass_chars = idpasskey.substr(0, 10);
string std_file =
string logFile =
string("/tmp/etserver_") + daemonType + "_" + first_idpass_chars;
FILE *stdout_stream = freopen("/tmp/etclient_err", "w+", stdout);
FILE *stdout_stream = freopen(logFile.c_str(), "w+", stdout);
setvbuf(stdout_stream, NULL, _IOLBF, BUFSIZ); // set to line buffering
FILE *stderr_stream = freopen("/tmp/etclient_err", "w+", stderr);
FILE *stderr_stream = freopen(logFile.c_str(), "w+", stderr);
setvbuf(stderr_stream, NULL, _IOLBF, BUFSIZ); // set to line buffering
}

Expand Down
4 changes: 2 additions & 2 deletions src/terminal/TerminalClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ int main(int argc, char** argv) {

strftime(buffer, sizeof(buffer), "%Y-%m-%d_%I-%M", timeinfo);
string current_time(buffer);
const char* err_filename = ("/tmp/etclient_err_" + current_time).c_str();
string errFilename = "/tmp/etclient_err_" + current_time;

FILE* stderr_stream = freopen(err_filename, "w+", stderr);
FILE* stderr_stream = freopen(errFilename.c_str(), "w+", stderr);
setvbuf(stderr_stream, NULL, _IOLBF, BUFSIZ); // set to line buffering

if (!FLAGS_jumphost.empty()) {
Expand Down
14 changes: 11 additions & 3 deletions src/terminal/TerminalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,18 @@ int main(int argc, char **argv) {
LOG(FATAL) << "Error creating daemon: " << strerror(errno);
}

const char *err_filename = "/tmp/etserver_err";
FILE *stdout_stream = freopen(err_filename, "w+", stdout);
time_t rawtime;
struct tm *timeinfo;
char buffer[80];

time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, sizeof(buffer), "%Y-%m-%d_%I-%M", timeinfo);
string current_time(buffer);
string errFilename = "/tmp/etclient_err_" + current_time;
FILE *stdout_stream = freopen(errFilename.c_str(), "w+", stdout);
setvbuf(stdout_stream, NULL, _IOLBF, BUFSIZ); // set to line buffering
FILE *stderr_stream = freopen(err_filename, "w+", stderr);
FILE *stderr_stream = freopen(errFilename.c_str(), "w+", stderr);
setvbuf(stderr_stream, NULL, _IOLBF, BUFSIZ); // set to line buffering
}
// Set log file for etserver process here.
Expand Down

1 comment on commit 96fa77b

@yiding
Copy link

@yiding yiding commented on 96fa77b Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've spent months trying to figure out what was dropping random files into my homedir, now I know.

Please sign in to comment.