Commit 1e0f4cc7 authored by Jean-Paul Saman's avatar Jean-Paul Saman Committed by Christophe Massiot

Add -l option for syslog support

Use -l to log to the syslog daemon instead of the stderror. This is very
usefull when running unattended.
parent 877dd45e
...@@ -67,6 +67,7 @@ int b_enable_epg = 0; ...@@ -67,6 +67,7 @@ int b_enable_epg = 0;
int b_unique_tsid = 0; int b_unique_tsid = 0;
volatile int b_hup_received = 0; volatile int b_hup_received = 0;
int i_verbose = DEFAULT_VERBOSITY; int i_verbose = DEFAULT_VERBOSITY;
int i_syslog = 0;
uint16_t i_src_port = DEFAULT_PORT; uint16_t i_src_port = DEFAULT_PORT;
in_addr_t i_src_addr = { 0 }; in_addr_t i_src_addr = { 0 };
int b_src_rawudp = 0; int b_src_rawudp = 0;
...@@ -351,6 +352,7 @@ void usage() ...@@ -351,6 +352,7 @@ void usage()
msg_Raw( NULL, " -h --help display this full help" ); msg_Raw( NULL, " -h --help display this full help" );
msg_Raw( NULL, " -i --priority <RT pritority>" ); msg_Raw( NULL, " -i --priority <RT pritority>" );
msg_Raw( NULL, " -q be quiet (less verbosity, repeat or use number for even quieter)" ); msg_Raw( NULL, " -q be quiet (less verbosity, repeat or use number for even quieter)" );
msg_Raw( NULL, " -l --logger use syslog for logging messages instead of stderr" );
msg_Raw( NULL, " -r --remote-socket <remote socket>" ); msg_Raw( NULL, " -r --remote-socket <remote socket>" );
msg_Raw( NULL, " -V --version only display the version" ); msg_Raw( NULL, " -V --version only display the version" );
exit(1); exit(1);
...@@ -362,6 +364,8 @@ int main( int i_argc, char **pp_argv ) ...@@ -362,6 +364,8 @@ int main( int i_argc, char **pp_argv )
int i_error; int i_error;
int c; int c;
int b_enable_syslog = 0;
DisplayVersion(); DisplayVersion();
if ( i_argc == 1 ) if ( i_argc == 1 )
...@@ -393,12 +397,13 @@ int main( int i_argc, char **pp_argv ) ...@@ -393,12 +397,13 @@ int main( int i_argc, char **pp_argv )
{ "rtp-input", required_argument, NULL, 'D' }, { "rtp-input", required_argument, NULL, 'D' },
{ "asi-adapter", required_argument, NULL, 'A' }, { "asi-adapter", required_argument, NULL, 'A' },
{ "epg-passthrough", no_argument, NULL, 'e' }, { "epg-passthrough", no_argument, NULL, 'e' },
{ "logger", no_argument, NULL, 'l' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ 0, 0, 0, 0} { 0, 0, 0, 0}
}; };
while ( ( c = getopt_long(i_argc, pp_argv, "q::c:r:t:o:i:a:n:f:F:R:s:S:v:pb:m:uWUTd:D:A:ehV", long_options, NULL)) != -1 ) while ( ( c = getopt_long(i_argc, pp_argv, "q::c:r:t:o:i:a:n:f:F:R:s:S:v:pb:m:uWUTd:D:A:lehV", long_options, NULL)) != -1 )
{ {
switch ( c ) switch ( c )
{ {
...@@ -660,6 +665,10 @@ int main( int i_argc, char **pp_argv ) ...@@ -660,6 +665,10 @@ int main( int i_argc, char **pp_argv )
b_enable_epg = 1; b_enable_epg = 1;
break; break;
case 'l':
b_enable_syslog = 1;
break;
case 'T': case 'T':
b_unique_tsid = 1; b_unique_tsid = 1;
break; break;
...@@ -676,6 +685,9 @@ int main( int i_argc, char **pp_argv ) ...@@ -676,6 +685,9 @@ int main( int i_argc, char **pp_argv )
if ( optind < i_argc || pf_Open == NULL ) if ( optind < i_argc || pf_Open == NULL )
usage(); usage();
if ( b_enable_syslog )
msg_Connect( pp_argv[0] );
msg_Warn( NULL, "restarting" ); msg_Warn( NULL, "restarting" );
if ( b_output_udp ) if ( b_output_udp )
...@@ -717,4 +729,7 @@ int main( int i_argc, char **pp_argv ) ...@@ -717,4 +729,7 @@ int main( int i_argc, char **pp_argv )
demux_Run(); demux_Run();
} }
if ( b_enable_syslog )
msg_Disconnect();
} }
...@@ -100,6 +100,7 @@ typedef struct output_t ...@@ -100,6 +100,7 @@ typedef struct output_t
uint8_t i_config; uint8_t i_config;
} output_t; } output_t;
extern int i_syslog;
extern int i_verbose; extern int i_verbose;
extern output_t **pp_outputs; extern output_t **pp_outputs;
extern int i_nb_outputs; extern int i_nb_outputs;
...@@ -139,11 +140,19 @@ extern void (*pf_UnsetFilter)( int i_fd, uint16_t i_pid ); ...@@ -139,11 +140,19 @@ extern void (*pf_UnsetFilter)( int i_fd, uint16_t i_pid );
/***************************************************************************** /*****************************************************************************
* Prototypes * Prototypes
*****************************************************************************/ *****************************************************************************/
/* Connect/Disconnect from syslogd */
void msg_Connect( const char *ident );
void msg_Disconnect( void );
/* */
void msg_Info( void *_unused, const char *psz_format, ... ); void msg_Info( void *_unused, const char *psz_format, ... );
void msg_Err( void *_unused, const char *psz_format, ... ); void msg_Err( void *_unused, const char *psz_format, ... );
void msg_Warn( void *_unused, const char *psz_format, ... ); void msg_Warn( void *_unused, const char *psz_format, ... );
void msg_Dbg( void *_unused, const char *psz_format, ... ); void msg_Dbg( void *_unused, const char *psz_format, ... );
void msg_Raw( void *_unused, const char *psz_format, ... ); void msg_Raw( void *_unused, const char *psz_format, ... );
/* */
mtime_t mdate( void ); mtime_t mdate( void );
void msleep( mtime_t delay ); void msleep( mtime_t delay );
void hexDump( uint8_t *p_data, uint32_t i_len ); void hexDump( uint8_t *p_data, uint32_t i_len );
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "version.h" #include "version.h"
int i_verbose = 3; int i_verbose = 3;
int i_syslog = 0;
void usage() void usage()
{ {
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include <syslog.h>
#include "dvblast.h" #include "dvblast.h"
...@@ -45,6 +46,24 @@ ...@@ -45,6 +46,24 @@
#define VERB_INFO 2 #define VERB_INFO 2
#define VERB_WARN 1 #define VERB_WARN 1
/*****************************************************************************
* msg_Connect
*****************************************************************************/
void msg_Connect( const char *ident )
{
i_syslog = 1;
openlog( ident, LOG_NDELAY | LOG_PID, LOG_USER );
}
/*****************************************************************************
* msg_Disconnect
*****************************************************************************/
void msg_Disconnect( void )
{
i_syslog = 0;
closelog();
}
/***************************************************************************** /*****************************************************************************
* msg_Info * msg_Info
*****************************************************************************/ *****************************************************************************/
...@@ -57,6 +76,9 @@ void msg_Info( void *_unused, const char *psz_format, ... ) ...@@ -57,6 +76,9 @@ void msg_Info( void *_unused, const char *psz_format, ... )
va_start( args, psz_format ); va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "info: %s\n", psz_format ); snprintf( psz_fmt, MAX_MSG, "info: %s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_INFO, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args ); vfprintf( stderr, psz_fmt, args );
} }
} }
...@@ -71,6 +93,9 @@ void msg_Err( void *_unused, const char *psz_format, ... ) ...@@ -71,6 +93,9 @@ void msg_Err( void *_unused, const char *psz_format, ... )
va_start( args, psz_format ); va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "error: %s\n", psz_format ); snprintf( psz_fmt, MAX_MSG, "error: %s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_ERR, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args ); vfprintf( stderr, psz_fmt, args );
} }
...@@ -86,6 +111,9 @@ void msg_Warn( void *_unused, const char *psz_format, ... ) ...@@ -86,6 +111,9 @@ void msg_Warn( void *_unused, const char *psz_format, ... )
va_start( args, psz_format ); va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "warning: %s\n", psz_format ); snprintf( psz_fmt, MAX_MSG, "warning: %s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_WARNING, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args ); vfprintf( stderr, psz_fmt, args );
} }
} }
...@@ -102,6 +130,9 @@ void msg_Dbg( void *_unused, const char *psz_format, ... ) ...@@ -102,6 +130,9 @@ void msg_Dbg( void *_unused, const char *psz_format, ... )
va_start( args, psz_format ); va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "debug: %s\n", psz_format ); snprintf( psz_fmt, MAX_MSG, "debug: %s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_DEBUG, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args ); vfprintf( stderr, psz_fmt, args );
} }
} }
...@@ -116,6 +147,9 @@ void msg_Raw( void *_unused, const char *psz_format, ... ) ...@@ -116,6 +147,9 @@ void msg_Raw( void *_unused, const char *psz_format, ... )
va_start( args, psz_format ); va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "%s\n", psz_format ); snprintf( psz_fmt, MAX_MSG, "%s\n", psz_format );
if ( i_syslog )
vsyslog( LOG_NOTICE, psz_fmt, args );
else
vfprintf( stderr, psz_fmt, args ); vfprintf( stderr, psz_fmt, args );
} }
......
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