Commit 4a64feb6 authored by Marc Ariberti's avatar Marc Ariberti

* More elaborated logging system (stdout/err, file and/org syslog)

  * Now takes only the first field (space separated) in the config file
parent 85d7bd19
......@@ -4,6 +4,8 @@
HEAD
* More elaborated logging system
* Now takes only the first field (space separated) in the config file
* The number of defined channels is now unlimited (now use a linked list)
* When the configuration is updated, miniVLCS reloads itself
......
......@@ -2,7 +2,7 @@
* vlcs.c: VideoLAN Channel Server socket facility
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: vlcs.c,v 1.6 2002/05/25 17:42:53 marcari Exp $
* $Id: vlcs.c,v 1.7 2002/05/25 20:12:44 marcari Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -32,6 +32,7 @@
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <syslog.h>
#include <errno.h>
#include <arpa/inet.h>
......@@ -73,6 +74,112 @@ typedef struct channel_s
channel_t * p_channels;
FILE * log_file;
/* logging system */
void log_Init( void )
{
#ifdef vsyslog_NAME
openlog( vsyslog_NAME, LOG_PERROR, SYSLOG_FACILITY );
#endif
#ifdef LOG_FILE
log_file = fopen( LOG_FILE, "a" );
#endif
}
void log_Close( void )
{
#ifdef vsyslog_NAME
closelog();
#endif
#ifdef LOG_FILE
fclose(log_file);
#endif
}
void log_Info(char * format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef LOG_STDOUT
vfprintf(stdout, format, ap);
#endif
#ifdef LOG_FILE
vfprintf(log_file, format, ap);
#endif
#ifdef vsyslog_NAME
vsyslog(LOG_INFO, format, ap);
#endif
va_end(ap);
}
void log_Warn(char * format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef LOG_STDOUT
vfprintf(stderr, format, ap);
#endif
#ifdef LOG_FILE
vfprintf(log_file, format, ap);
#endif
#ifdef vsyslog_NAME
vsyslog(LOG_WARNING, format, ap);
#endif
va_end(ap);
}
void log_Error(char * format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef LOG_STDOUT
vfprintf(stderr, format, ap);
#endif
#ifdef LOG_FILE
vfprintf(log_file, format, ap);
#endif
#ifdef vsyslog_NAME
vsyslog(LOG_ERR, format, ap);
#endif
va_end(ap);
}
void log_Alert(char * format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef LOG_STDOUT
vfprintf(stderr, format, ap);
#endif
#ifdef LOG_FILE
vfprintf(log_file, format, ap);
#endif
#ifdef vsyslog_NAME
vsyslog(LOG_ALERT, format, ap);
#endif
va_end(ap);
}
/* Socket management */
void socket_Init( void )
......@@ -87,17 +194,14 @@ void socket_Init( void )
if( i_handle < 0 )
{
syslog( LOG_ALERT, "Cannot open socket (%s), exiting\n",
strerror(errno) );
closelog();
exit( -1 );
log_Alert( "Cannot open socket (%s), exiting\n", strerror(errno) );
Close( -1 );
}
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR, &i_opt, sizeof(i_opt) )
< 0 )
{
syslog( LOG_ALERT, "Cannot setsockopt (%s), exiting\n",
strerror(errno) );
log_Alert("Cannot setsockopt (%s), exiting\n", strerror(errno) );
Close( -1 );
}
......@@ -112,7 +216,7 @@ void socket_Init( void )
sa_server.sin_port = ntohs( VLCS_PORT );
if( bind( i_handle, (struct sockaddr *)&sa_server, sizeof(sa_server) ) < 0 )
{
syslog( LOG_ALERT, "Cannot bind (%s), exiting\n", strerror(errno) );
log_Alert("Cannot bind (%s), exiting\n", strerror(errno) );
Close( -1 );
}
}
......@@ -141,7 +245,7 @@ void socket_Get( void )
{
return;
}
syslog( LOG_ALERT, "Cannot select (%s), exiting\n", strerror(errno) );
log_Alert( "Cannot select (%s), exiting\n", strerror(errno) );
Close( -1 );
}
......@@ -155,12 +259,12 @@ void socket_Get( void )
{
return;
}
syslog( LOG_CRIT, "Duh my controlling terminal has gone fishing\n" );
log_Alert( "Duh my controlling terminal has gone fishing\n" );
}
else if( p_buffer[0] == 'q' )
{
/* Quit */
syslog( LOG_ALERT, "Exiting now on admin's request\n" );
log_Alert( "Exiting now on admin's request\n" );
Close( 0 );
}
}
......@@ -185,7 +289,7 @@ void socket_Get( void )
{
return;
}
printf( "Cannot recvfrom (%s)\n", strerror(errno) );
log_Error( "Cannot recvfrom (%s)\n", strerror(errno) );
return;
}
p_buffer[i_len] = '\0';
......@@ -194,14 +298,14 @@ void socket_Get( void )
&i_time, psz_macad ) != 4 )
{
socket_Send( &sa_client, "E: Bad request" );
printf( "sscanf failed (%s)\n", p_buffer );
log_Error( "sscanf failed (%s)\n", p_buffer );
return;
}
if ( i_version < 13 )
{
socket_Send( &sa_client, "E: Version mismatch, please upgrade your software" );
syslog( LOG_CRIT, "Break-in attempt ! (%s)\n",
log_Alert( "Break-in attempt ! (%s)\n",
inet_ntoa( sa_client.sin_addr ) );
return;
}
......@@ -211,7 +315,7 @@ void socket_Get( void )
i_channel > i_channel_max )
{
socket_Send( &sa_client, "E: Channel doesn't exist" );
printf( "Bad channel (%s)\n", psz_channel );
log_Error( "Bad channel (%s)\n", psz_channel );
return;
}
......@@ -222,7 +326,7 @@ void socket_Get( void )
if( p_channel == NULL )
{
socket_Send( &sa_client, "E: Channel doesn't exist" );
printf( "Bad channel (%s)\n", psz_channel );
log_Error( "Bad channel (%s)\n", psz_channel );
return;
}
i_channel--;
......@@ -238,7 +342,7 @@ void socket_Send( struct sockaddr_in * p_sa, char * psz_message )
time(&tm);
/* TODO: remove this ugly kludge */
fprintf(stderr, "%s : %s => %s\n",
log_Info("%s : %s => %s\n",
config_RemoveLF( asctime( localtime( &tm ) ) ),
inet_ntoa( p_sa->sin_addr ),
psz_message
......@@ -253,7 +357,7 @@ void socket_Send( struct sockaddr_in * p_sa, char * psz_message )
{
continue;
}
syslog( LOG_CRIT, "Cannot sendto (%s)\n", strerror(errno) );
log_Alert( "Cannot sendto (%s)\n", strerror(errno) );
}
break;
}
......@@ -275,7 +379,7 @@ void config_DestroyList( void )
}
p_channels = NULL;
printf("List of channels initialized\n");
log_Info("List of channels initialized\n");
}
char * config_RemoveLF( char * str )
......@@ -319,7 +423,7 @@ void config_AddList( char * psz_item )
i_channel_max++;
printf("Adding channel %d : %s\n", i_channel_max, p_new->psz_vlc_config);
log_Info("Adding channel %d : %s\n", i_channel_max, p_new->psz_vlc_config);
}
time_t config_GetModificationTime( void )
......@@ -333,6 +437,7 @@ time_t config_GetModificationTime( void )
void config_ReadFile( void )
{
char psz_vlc_command[2048];
char psz_buffer[2048];
FILE * p_config;
......@@ -343,8 +448,7 @@ void config_ReadFile( void )
p_config = fopen( CHANNEL_CONF, "r" );
if( p_config == NULL )
{
syslog( LOG_ALERT, "Cannot fopen " CHANNEL_CONF " (%s)\n",
strerror(errno) );
log_Alert( "Cannot fopen " CHANNEL_CONF " (%s)\n", strerror(errno) );
exit( -1 );
}
......@@ -355,7 +459,8 @@ void config_ReadFile( void )
{
if( psz_buffer[0] != '#' && psz_buffer[0] != '\0' )
{
config_AddList(psz_buffer);
sscanf(psz_buffer, "%s", psz_vlc_command);
config_AddList(psz_vlc_command);
}
}
......@@ -365,16 +470,17 @@ void config_ReadFile( void )
void Close( int i_ret )
{
close( i_handle );
closelog();
log_Close();
exit( i_ret );
}
int main( int argc, char ** argv )
{
signal(SIGINT, Close);
log_Init();
config_ReadFile();
socket_Init();
openlog( SYSLOG_NAME, LOG_PERROR, SYSLOG_FACILITY );
for( ; ; )
{
......
I: nostream
udp:@239.255.255.42
I:nostream
udp:@239.255.255.42 star_wars star 9999 vthr
udp:@239.255.255.43
udp:@239.255.255.44
udp:@239.255.255.45
......
......@@ -2,7 +2,7 @@
* vlcs.h: VideoLAN Channel Server configuration
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: vlcs.h,v 1.2 2002/05/23 21:47:44 marcari Exp $
* $Id: vlcs.h,v 1.3 2002/05/25 20:12:44 marcari Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -28,7 +28,14 @@
#define VLCS_VERSION 13
#define VLCS_PORT 6010
#define CHANNEL_CONF "vlcs.conf"
#define SYSLOG_NAME "VLCS"
#define LOG_STDOUT
/* undefine this symbol if you do not want to log to a file */
#define LOG_FILE "vlcs.log"
/* uncomment this symbol if you want to log to syslog */
/* #define SYSLOG_NAME "VLCS" */
#define SYSLOG_FACILITY LOG_DAEMON
/* Database is reloaded at xx:12:00 */
#undef DEBUG
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment