Skip to content

Commit

Permalink
log uptime when exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed May 15, 2024
1 parent 2dd5272 commit b325669
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions readsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2944,11 +2944,27 @@ int main(int argc, char **argv) {
// writes state if Modes.state_dir is set
writeInternalState();

{
char *exitString = "Normal exit.";
if (Modes.exit != 1) {
exitString = "Abnormal exit.";
}
int64_t uptime = getUptime();

int days = uptime / (24 * HOURS);
uptime -= days * (24 * HOURS);
int hours = uptime / HOURS;
uptime -= hours * HOURS;
int minutes = uptime / MINUTES;
uptime -= minutes * MINUTES;
double seconds = uptime / (double) SECONDS;

log_with_timestamp("%s uptime: %2dd %2dh %2dm %.3fs",
exitString, days, hours, minutes, seconds);
}

if (Modes.exit != 1) {
log_with_timestamp("Abnormal exit. (runtime: %.3f s", getUptime() / (double) SECONDS);
cleanup_and_exit(1);
}

log_with_timestamp("Normal exit. (runtime: %.3f s", getUptime() / (double) SECONDS);
cleanup_and_exit(0);
}

0 comments on commit b325669

Please sign in to comment.