Skip to content

Commit

Permalink
backend truncates log file on start
Browse files Browse the repository at this point in the history
  • Loading branch information
bnicolae committed Sep 23, 2020
1 parent 97b6c55 commit 2f153ec
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/backend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) {
FATAL("cannot lock " << ready_file << ", error = " << strerror(errno));

// check if an instance is already running
int log_fd = open(log_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
int log_fd = open(log_file.c_str(), O_WRONLY | O_CREAT, 0644);
if (log_fd == -1)
FATAL("cannot open " << log_file << ", error = " << strerror(errno));
locked = flock(log_fd, LOCK_EX | LOCK_NB);
Expand All @@ -69,6 +69,7 @@ int main(int argc, char *argv[]) {
} else
FATAL("cannot acquire lock on: " << log_file << ", error = " << strerror(errno));
}
ftruncate(log_fd, 0);

// initialization complete, deamonize the backend
struct sigaction action;
Expand All @@ -78,6 +79,7 @@ int main(int argc, char *argv[]) {
if (child_id < 0 || (child_id == 0 && setsid() == -1))
FATAL("cannot fork to enter daemon mode, error = " << strerror(errno));
if (child_id > 0) { // parent waits for signal
close(log_fd);
action.sa_handler = child_handler;
sigaction(SIGCHLD, &action, NULL);
pause();
Expand Down

0 comments on commit 2f153ec

Please sign in to comment.