From 81cbec21ad0e3ea70d94ee3f07b3bf157450a696 Mon Sep 17 00:00:00 2001 From: Christophe Massiot Date: Wed, 15 Jul 2015 20:47:39 +0000 Subject: [PATCH] add -l option for syslog logging --- aggregartp.c | 19 +++++++--- ingests.c | 18 ++++++++-- multicat.c | 19 +++++++--- multicat_validate.c | 18 ++++++++-- reordertp.c | 18 ++++++++-- util.c | 84 +++++++++++++++++++++++++++++++++++++-------- util.h | 4 ++- 7 files changed, 148 insertions(+), 32 deletions(-) diff --git a/aggregartp.c b/aggregartp.c index da262e7..0bcbe20 100644 --- a/aggregartp.c +++ b/aggregartp.c @@ -1,7 +1,7 @@ /***************************************************************************** * aggregartp.c: split an RTP stream for several contribution links ***************************************************************************** - * Copyright (C) 2009, 2011, 2014 VideoLAN + * Copyright (C) 2009, 2011, 2014-2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -84,7 +85,7 @@ static uint64_t i_retx_buffer = DEFAULT_RETX_BUFFER * 27000; static void usage(void) { - msg_Raw( NULL, "Usage: aggregartp [-i ] [-t ] [-w] [-o ] [-U] [-x ] [-X ] [-m ] [-R ] @ [,] ... [,]" ); + msg_Raw( NULL, "Usage: aggregartp [-i ] [-l ] [-t ] [-w] [-o ] [-U] [-x ] [-X ] [-m ] [-R ] @ [,] ... [,]" ); msg_Raw( NULL, " host format: [[:]][@[]]" ); msg_Raw( NULL, " -w: overwrite RTP timestamps" ); msg_Raw( NULL, " -o: overwrite RTP SSRC" ); @@ -249,6 +250,7 @@ int main( int i_argc, char **pp_argv ) { int c; int i_priority = -1; + const char *psz_syslog_tag = NULL; int i_ttl = 0; bool b_udp = false; struct pollfd *pfd = malloc(sizeof(struct pollfd)); @@ -260,7 +262,7 @@ int main( int i_argc, char **pp_argv ) pfd[i_nb_retx - 1].fd = i_fd; \ pfd[i_nb_retx - 1].events = POLLIN; - while ( (c = getopt( i_argc, pp_argv, "i:t:wo:x:X:Um:R:h" )) != -1 ) + while ( (c = getopt( i_argc, pp_argv, "i:l:t:wo:x:X:Um:R:h" )) != -1 ) { switch ( c ) { @@ -268,6 +270,10 @@ int main( int i_argc, char **pp_argv ) i_priority = strtol( optarg, NULL, 0 ); break; + case 'l': + psz_syslog_tag = optarg; + break; + case 't': i_ttl = strtol( optarg, NULL, 0 ); break; @@ -326,6 +332,9 @@ int main( int i_argc, char **pp_argv ) if ( optind >= i_argc - 1 ) usage(); + if ( psz_syslog_tag != NULL ) + msg_Openlog( psz_syslog_tag, LOG_NDELAY, LOG_USER ); + i_input_fd = OpenSocket( pp_argv[optind], 0, DEFAULT_PORT, 0, NULL, &b_input_tcp, NULL ); if ( i_input_fd == -1 ) @@ -490,6 +499,8 @@ int main( int i_argc, char **pp_argv ) } } + if ( psz_syslog_tag != NULL ) + msg_Closelog(); + return EXIT_SUCCESS; } - diff --git a/ingests.c b/ingests.c index 40e38e4..282855f 100644 --- a/ingests.c +++ b/ingests.c @@ -1,7 +1,7 @@ /***************************************************************************** * ingests.c: create the aux file for a transport stream file ***************************************************************************** - * Copyright (C) 2009, 2011 VideoLAN + * Copyright (C) 2009, 2011, 2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -59,7 +60,7 @@ static uint64_t i_last_stc = 0; static void usage(void) { - msg_Raw( NULL, "Usage: ingests -p [-m ] " ); + msg_Raw( NULL, "Usage: ingests [-l ] -p [-m ] " ); exit(EXIT_FAILURE); } @@ -184,6 +185,7 @@ static void TSHandle( uint8_t *p_ts ) *****************************************************************************/ int main( int i_argc, char **pp_argv ) { + const char *psz_syslog_tag = NULL; uint8_t *p_buffer; unsigned int i_payload_size = DEFAULT_PAYLOAD_SIZE; mode_t i_mode; @@ -192,11 +194,15 @@ int main( int i_argc, char **pp_argv ) { int c; - if ( (c = getopt(i_argc, pp_argv, "p:m:h")) == -1 ) + if ( (c = getopt(i_argc, pp_argv, "l:p:m:h")) == -1 ) break; switch ( c ) { + case 'l': + psz_syslog_tag = optarg; + break; + case 'p': i_pcr_pid = strtoul(optarg, NULL, 0); break; @@ -220,6 +226,9 @@ int main( int i_argc, char **pp_argv ) if ( optind >= i_argc || !i_pcr_pid ) usage(); + if ( psz_syslog_tag != NULL ) + msg_Openlog( psz_syslog_tag, LOG_NDELAY, LOG_USER ); + i_mode = StatFile( pp_argv[optind] ); if ( S_ISCHR( i_mode ) || S_ISFIFO( i_mode ) || S_ISDIR( i_mode ) ) usage(); @@ -262,6 +271,9 @@ int main( int i_argc, char **pp_argv ) fclose( p_output_aux ); close( i_fd ); + if ( psz_syslog_tag != NULL ) + msg_Closelog(); + return 0; } diff --git a/multicat.c b/multicat.c index ac8e212..854deca 100644 --- a/multicat.c +++ b/multicat.c @@ -1,7 +1,7 @@ /***************************************************************************** * multicat.c: netcat-equivalent for multicast ***************************************************************************** - * Copyright (C) 2009, 2011-2012 VideoLAN + * Copyright (C) 2009, 2011-2012, 2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef SIOCGSTAMPNS # define HAVE_TIMESTAMPS @@ -93,7 +94,7 @@ void (*pf_ExitWrite)(void); static void usage(void) { - msg_Raw( NULL, "Usage: multicat [-i ] [-t ] [-X] [-T ] [-f] [-p ] [-s ] [-n ] [-k ] [-d ] [-a] [-r ] [-S ] [-u] [-U] [-m ] [-R ] [-w] " ); + msg_Raw( NULL, "Usage: multicat [-i ] [-l ] [-t ] [-X] [-T ] [-f] [-p ] [-s ] [-n ] [-k ] [-d ] [-a] [-r ] [-S ] [-u] [-U] [-m ] [-R ] [-w] " ); msg_Raw( NULL, " item format: " ); msg_Raw( NULL, " host format: [[:]][@[]]" ); msg_Raw( NULL, " -X: also pass-through all packets to stdout" ); @@ -762,6 +763,7 @@ static void GetPCR( const uint8_t *p_buffer, size_t i_read_size ) int main( int i_argc, char **pp_argv ) { int i_priority = -1; + const char *psz_syslog_tag = NULL; bool b_passthrough = false; int i_stc_fd = -1; off_t i_skip_chunks = 0, i_nb_chunks = -1; @@ -775,7 +777,7 @@ int main( int i_argc, char **pp_argv ) sigset_t set; /* Parse options */ - while ( (c = getopt( i_argc, pp_argv, "i:t:XT:fp:s:n:k:d:ar:S:uUm:R:wh" )) != -1 ) + while ( (c = getopt( i_argc, pp_argv, "i:l:t:XT:fp:s:n:k:d:ar:S:uUm:R:wh" )) != -1 ) { switch ( c ) { @@ -783,6 +785,10 @@ int main( int i_argc, char **pp_argv ) i_priority = strtol( optarg, NULL, 0 ); break; + case 'l': + psz_syslog_tag = optarg; + break; + case 't': i_ttl = strtol( optarg, NULL, 0 ); break; @@ -869,6 +875,9 @@ int main( int i_argc, char **pp_argv ) if ( optind >= i_argc - 1 ) usage(); + if ( psz_syslog_tag != NULL ) + msg_Openlog( psz_syslog_tag, LOG_NDELAY, LOG_USER ); + /* Open sockets */ if ( udp_InitRead( pp_argv[optind], i_asked_payload_size, i_skip_chunks, i_seek ) < 0 ) @@ -1087,6 +1096,8 @@ dropped_packet: pf_ExitRead(); pf_ExitWrite(); + if ( psz_syslog_tag != NULL ) + msg_Closelog(); + return b_error ? EXIT_FAILURE : EXIT_SUCCESS; } - diff --git a/multicat_validate.c b/multicat_validate.c index 79055da..97ce816 100644 --- a/multicat_validate.c +++ b/multicat_validate.c @@ -1,7 +1,7 @@ /***************************************************************************** * multicat_validate.c: validate position in directory input ***************************************************************************** - * Copyright (C) 2009, 2011 VideoLAN + * Copyright (C) 2009, 2011, 2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -31,6 +31,7 @@ #include #include #include +#include #include "util.h" @@ -49,7 +50,7 @@ static bool b_status = false; static void usage(void) { - msg_Raw( NULL, "Usage: multicat_validate [-k ] [-r ] [-W ] [-m ] " ); + msg_Raw( NULL, "Usage: multicat_validate [-l ] [-k ] [-r ] [-W ] [-m ] " ); msg_Raw( NULL, " -k: start at the given position (in 27 MHz units, negative = from the end)" ); msg_Raw( NULL, " -r: in directory mode, rotate file after this duration (default: 97200000000 ticks = 1 hour)" ); msg_Raw( NULL, " -W: maximum tolerated wait time before the forthcoming packet (by default: 27000000 ticks = 1 second)" ); @@ -97,6 +98,7 @@ retry: *****************************************************************************/ int main( int i_argc, char **pp_argv ) { + const char *psz_syslog_tag = NULL; off_t i_nb_skipped_chunks; FILE *p_input_aux; int c; @@ -104,10 +106,14 @@ int main( int i_argc, char **pp_argv ) setvbuf(stdout, NULL, _IOLBF, 0); - while ( (c = getopt( i_argc, pp_argv, "k:r:W:m:h" )) != -1 ) + while ( (c = getopt( i_argc, pp_argv, "l:k:r:W:m:h" )) != -1 ) { switch ( c ) { + case 'l': + psz_syslog_tag = optarg; + break; + case 'k': i_delay = strtoull( optarg, NULL, 0 ); break; @@ -135,6 +141,9 @@ int main( int i_argc, char **pp_argv ) psz_dir_name = pp_argv[optind]; printf( "0\n" ); + if ( psz_syslog_tag != NULL ) + msg_Openlog( psz_syslog_tag, LOG_NDELAY, LOG_USER ); + if ( i_delay <= 0 ) { i_delay *= -1; @@ -196,4 +205,7 @@ int main( int i_argc, char **pp_argv ) HandleSTC( i_stc ); } + + if ( psz_syslog_tag != NULL ) + msg_Closelog(); } diff --git a/reordertp.c b/reordertp.c index 7735986..d53da09 100644 --- a/reordertp.c +++ b/reordertp.c @@ -1,7 +1,7 @@ /***************************************************************************** * reordertp.c: rebuild an RTP stream from several aggregated links ***************************************************************************** - * Copyright (C) 2009, 2011, 2014 VideoLAN + * Copyright (C) 2009, 2011, 2014-2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -113,7 +114,7 @@ static int i_last_retx_input = 0; static void usage(void) { - msg_Raw( NULL, "Usage: reordertp [-i ] [-t ] [-b ] [-U] [-g ] [-j ] [-r <# of clock ref>] [-n ] [-x ] [-X ] [-m ] [-R ] ... [] " ); + msg_Raw( NULL, "Usage: reordertp [-i ] [-l ] [-t ] [-b ] [-U] [-g ] [-j ] [-r <# of clock ref>] [-n ] [-x ] [-X ] [-m ] [-R ] ... [] " ); msg_Raw( NULL, " host format: [[:]][@[]]" ); msg_Raw( NULL, " -U: strip RTP header" ); msg_Raw( NULL, " -b: buffer length in ms [default 400]" ); @@ -439,6 +440,7 @@ int main( int i_argc, char **pp_argv ) { int i, c; int i_priority = -1; + const char *psz_syslog_tag = NULL; int i_ttl = 0; struct pollfd *pfd = NULL; int i_fd; @@ -454,7 +456,7 @@ int main( int i_argc, char **pp_argv ) pfd[i_nb_inputs - 1].fd = i_fd; \ pfd[i_nb_inputs - 1].events = POLLIN | POLLERR | POLLRDHUP | POLLHUP; - while ( (c = getopt( i_argc, pp_argv, "i:t:b:g:j:r:n:x:X:Um:R:h" )) != -1 ) + while ( (c = getopt( i_argc, pp_argv, "i:l:t:b:g:j:r:n:x:X:Um:R:h" )) != -1 ) { switch ( c ) { @@ -462,6 +464,10 @@ int main( int i_argc, char **pp_argv ) i_priority = strtol( optarg, NULL, 0 ); break; + case 'l': + psz_syslog_tag = optarg; + break; + case 't': i_ttl = strtol( optarg, NULL, 0 ); break; @@ -522,6 +528,9 @@ int main( int i_argc, char **pp_argv ) if ( optind >= i_argc - 1 ) usage(); + if ( psz_syslog_tag != NULL ) + msg_Openlog( psz_syslog_tag, LOG_NDELAY, LOG_USER ); + while ( optind < i_argc - 1 ) { i_fd = OpenSocket( pp_argv[optind], 0, DEFAULT_PORT, 0, NULL, @@ -656,6 +665,9 @@ int main( int i_argc, char **pp_argv ) } } + if ( psz_syslog_tag != NULL ) + msg_Closelog(); + return EXIT_SUCCESS; } diff --git a/util.c b/util.c index 4714c2e..73ff891 100644 --- a/util.c +++ b/util.c @@ -1,7 +1,7 @@ /***************************************************************************** * util.c: Utils for the multicat suite ***************************************************************************** - * Copyright (C) 2004, 2009, 2011 VideoLAN + * Copyright (C) 2004, 2009, 2011, 2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -42,6 +42,7 @@ #include #include #include +#include #include "util.h" @@ -55,6 +56,25 @@ #define PSZ_TS_EXT "ts" int i_verbose = VERB_DBG; +static int b_syslog = 0; + +/***************************************************************************** + * msg_Openlog + *****************************************************************************/ +void msg_Openlog( const char *ident, int option, int facility ) +{ + openlog(ident, option, facility); + b_syslog = 1; +} + +/***************************************************************************** + * msg_Closelog + *****************************************************************************/ +void msg_Closelog( void ) +{ + closelog(); + b_syslog = 0; +} /***************************************************************************** * msg_Info @@ -62,14 +82,23 @@ int i_verbose = VERB_DBG; void msg_Info( void *_unused, const char *psz_format, ... ) { if ( i_verbose >= VERB_INFO ) + return; + + va_list args; + va_start( args, psz_format ); + + if ( !b_syslog ) { - va_list args; char psz_fmt[MAX_MSG]; - va_start( args, psz_format ); - snprintf( psz_fmt, MAX_MSG, "info: %s\n", psz_format ); vfprintf( stderr, psz_fmt, args ); } + else + { + vsyslog( LOG_INFO, psz_format, args ); + } + + va_end( args ); } /***************************************************************************** @@ -78,11 +107,20 @@ void msg_Info( void *_unused, const char *psz_format, ... ) void msg_Err( void *_unused, const char *psz_format, ... ) { va_list args; - char psz_fmt[MAX_MSG]; va_start( args, psz_format ); - snprintf( psz_fmt, MAX_MSG, "error: %s\n", psz_format ); - vfprintf( stderr, psz_fmt, args ); + if ( !b_syslog ) + { + char psz_fmt[MAX_MSG]; + snprintf( psz_fmt, MAX_MSG, "error: %s\n", psz_format ); + vfprintf( stderr, psz_fmt, args ); + } + else + { + vsyslog( LOG_ERR, psz_format, args ); + } + + va_end( args ); } /***************************************************************************** @@ -91,14 +129,23 @@ void msg_Err( void *_unused, const char *psz_format, ... ) void msg_Warn( void *_unused, const char *psz_format, ... ) { if ( i_verbose >= VERB_WARN ) + return; + + va_list args; + va_start( args, psz_format ); + + if ( !b_syslog ) { - va_list args; char psz_fmt[MAX_MSG]; - va_start( args, psz_format ); - snprintf( psz_fmt, MAX_MSG, "warning: %s\n", psz_format ); vfprintf( stderr, psz_fmt, args ); } + else + { + vsyslog( LOG_WARNING, psz_format, args ); + } + + va_end( args ); } /***************************************************************************** @@ -107,18 +154,27 @@ void msg_Warn( void *_unused, const char *psz_format, ... ) void msg_Dbg( void *_unused, const char *psz_format, ... ) { if ( i_verbose >= VERB_DBG ) + return; + + va_list args; + va_start( args, psz_format ); + + if ( !b_syslog ) { - va_list args; char psz_fmt[MAX_MSG]; - va_start( args, psz_format ); - snprintf( psz_fmt, MAX_MSG, "debug: %s\n", psz_format ); vfprintf( stderr, psz_fmt, args ); } + else + { + vsyslog( LOG_DEBUG, psz_format, args ); + } + + va_end( args ); } /***************************************************************************** - * msg_Raw + * msg_Raw: only used for usage() *****************************************************************************/ void msg_Raw( void *_unused, const char *psz_format, ... ) { diff --git a/util.h b/util.h index 23ec3d9..41fb0af 100644 --- a/util.h +++ b/util.h @@ -1,7 +1,7 @@ /***************************************************************************** * util.h: Utils for the multicat suite ***************************************************************************** - * Copyright (C) 2009, 2011, 2014 VideoLAN + * Copyright (C) 2009, 2011, 2014-2015 VideoLAN * $Id$ * * Authors: Christophe Massiot @@ -74,6 +74,8 @@ struct udprawpkt { /***************************************************************************** * Prototypes *****************************************************************************/ +void msg_Openlog( const char *ident, int option, int facility ); +void msg_Closelog( void ); void msg_Info( void *_unused, const char *psz_format, ... ); void msg_Err( void *_unused, const char *psz_format, ... ); void msg_Warn( void *_unused, const char *psz_format, ... ); -- GitLab