summaryrefslogtreecommitdiff
path: root/log.h
diff options
context:
space:
mode:
Diffstat (limited to 'log.h')
-rw-r--r--log.h26
1 files changed, 26 insertions, 0 deletions
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;
+}