blob: 8c5e94c553623cd4193128e879f6ea5f271ba977 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 || (int64_t)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;
}
|