diff options
Diffstat (limited to 'log.h')
-rw-r--r-- | log.h | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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; +} |