From f484331cf374031f68566162f16ba00eedc1b7f0 Mon Sep 17 00:00:00 2001 From: stderr64 Date: Thu, 17 Aug 2023 21:19:10 +0300 Subject: Recreated repository --- log.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 log.h (limited to 'log.h') diff --git a/log.h b/log.h new file mode 100644 index 0000000..6fd3235 --- /dev/null +++ b/log.h @@ -0,0 +1,26 @@ +#define LOG_INIT_SUCCESS 0 +#define LOG_INIT_FAILED -1 + +int log_init( server_config_t *sc, log_file_t *lf ){ + if ( strcmp((const char*)sc->log_enabled->valuestring, "no") == 0 ) + return LOG_INIT_SUCCESS; + if ( sc->log_file == NULL || (long long int)strlen(sc->log_file->valuestring) <= 0 ) + return LOG_INIT_FAILED; + lf->log_file = fopen( sc->log_file->valuestring, "a" ); + if ( lf->log_file == NULL ) + return LOG_INIT_FAILED; + if ( syscall(SYS_chmod, (const char*)sc->log_file->valuestring, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1 ) + return LOG_INIT_FAILED; + return LOG_INIT_SUCCESS; +} + +void log_write( server_config_t *scd, log_file_t *lf_info, char *log_message ){ + if ( strcmp((const char*)scd->log_enabled->valuestring, "no") == 0 ) + return; + if ( lf_info->log_file == NULL ) + return; + fprintf( lf_info->log_file, "%s\n", log_message ); + if ( fflush(lf_info->log_file) == EOF ) + fputs( "WARNING: failed to write buffered data to disk\n", stderr ); + return; +} -- cgit v1.2.3-86-g962b