From 516c4ba5c60a8ca67a68b6b3f2278cf178770eed Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Mon, 2 Oct 2023 13:20:15 -0500 Subject: server: close log-file when server exits The server should close the handle to the logging file on server exit. Signed-off-by: Danny Holman --- server/src/mini-rat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/src/mini-rat.c b/server/src/mini-rat.c index 6112d71..5579201 100644 --- a/server/src/mini-rat.c +++ b/server/src/mini-rat.c @@ -146,7 +146,7 @@ void parse_cmd(int sock, char *line) { } else if (strlen(argv[0]) == 0) { // Do nothing } else { - printf("Invalid command\n"); + dprintf(sock, "Invalid command\n"); } free(argv); return; @@ -174,8 +174,9 @@ int main(int argc, char* argv[]) { sigaction(SIGTERM, &action, NULL); sigaction(SIGHUP, &action, NULL); - //FILE *logfile = fopen("log.txt", "w"); - init_logging(stderr); + FILE *logfile = fopen("log.txt", "w"); + init_logging(logfile); + uint16_t port = 1122; pthread_t listen_thread; pthread_create(&listen_thread, NULL, listener, (void*)&port); @@ -191,5 +192,6 @@ int main(int argc, char* argv[]) { log_msg(LOG_INFO, "Mini-RAT shutting down\n"); pthread_cancel(listen_thread); pthread_cancel(clisten_thread); + close_logfile(); return 0; } -- cgit v1.2.3