minisatip: use syslog for logs, do not start when tuners are not ready

This commit is contained in:
Jaroslav Kysela 2015-03-31 16:36:26 +02:00
parent 60089c3c31
commit bbeda3d499
1 changed files with 137 additions and 15 deletions

View File

@ -1,8 +1,13 @@
diff --git a/adapter.c b/adapter.c
index 285faea..6ca7dd5 100755
index 285faea..e07e8a3 100755
--- a/adapter.c
+++ b/adapter.c
@@ -33,6 +33,9 @@
@@ -29,10 +29,14 @@
#include <linux/dvb/dmx.h>
#include <poll.h>
#include <linux/ioctl.h>
+#include <errno.h>
#include "socketworks.h"
#include "dvb.h"
#include "adapter.h"
@ -12,7 +17,7 @@ index 285faea..6ca7dd5 100755
adapter a[MAX_ADAPTERS];
extern struct struct_opts opts;
@@ -49,7 +52,12 @@ find_adapters ()
@@ -49,7 +53,12 @@ find_adapters ()
for (i = 0; i < 8; i++)
for (j = 0; j < 8; j++)
{
@ -25,7 +30,21 @@ index 285faea..6ca7dd5 100755
fd = open (buf, O_RDONLY | O_NONBLOCK);
//LOG("testing device %s -> fd: %d",buf,fd);
if (fd >= 0)
@@ -122,9 +130,18 @@ init_hw ()
@@ -61,6 +70,13 @@ find_adapters ()
if (na == MAX_ADAPTERS)
return;
}
+#ifdef AXE
+ if (i < 4 && fd < 0) {
+ LOGL(0, "AXE - cannot open %s: %i", buf, errno);
+ sleep(60);
+ exit(239);
+ }
+#endif
}
for (na; na < MAX_ADAPTERS; na++)
a[na].pa = a[na].fn = -1;
@@ -122,9 +138,18 @@ init_hw ()
find_adapters ();
LOG ("trying to open [%d] adapter %d and frontend %d", i, a[i].pa,
a[i].fn);
@ -44,7 +63,7 @@ index 285faea..6ca7dd5 100755
a[i].dvr = open (buf, O_RDONLY | O_NONBLOCK);
if (a[i].fe < 0 || a[i].dvr < 0)
{
@@ -151,10 +168,12 @@ init_hw ()
@@ -151,10 +176,12 @@ init_hw ()
num_adapters++;
LOG ("opened DVB adapter %d fe:%d dvr:%d", i, a[i].fe, a[i].dvr);
@ -57,7 +76,7 @@ index 285faea..6ca7dd5 100755
init_dvb_parameters (&a[i].tp);
mark_pids_deleted (i, -1, NULL);
update_pids (i);
@@ -194,6 +213,22 @@ close_adapter (int na)
@@ -194,6 +221,22 @@ close_adapter (int na)
mark_pids_deleted (na, -1, NULL);
update_pids (na);
// if(a[na].dmx>0)close(a[na].dmx);
@ -80,7 +99,7 @@ index 285faea..6ca7dd5 100755
if (a[na].fe > 0)
close (a[na].fe);
if (a[na].sock >= 0)
@@ -366,7 +401,30 @@ close_adapter_for_stream (int sid, int aid)
@@ -366,7 +409,30 @@ close_adapter_for_stream (int sid, int aid)
// delete the attached PIDs as well
mark_pids_deleted (aid, sid, NULL);
update_pids (aid);
@ -112,7 +131,7 @@ index 285faea..6ca7dd5 100755
// close_adapter (aid);
}
@@ -684,7 +742,11 @@ describe_adapter (int sid, int aid)
@@ -684,7 +750,11 @@ describe_adapter (int sid, int aid)
memset (dad, 0, sizeof (dad));
x = 0;
// do just max 3 signal check 1s after tune
@ -124,7 +143,7 @@ index 285faea..6ca7dd5 100755
{
int new_gs = 1;
ts = getTick ();
@@ -701,11 +763,20 @@ describe_adapter (int sid, int aid)
@@ -701,11 +771,20 @@ describe_adapter (int sid, int aid)
if (ad->max_snr <= ad->snr) ad->max_snr = (ad->snr>0)?ad->snr:1;
LOG ("get_signal%s took %d ms for adapter %d handle %d (status: %d, ber: %d, strength:%d, snr: %d, max_strength: %d, max_snr: %d %d)",
new_gs?"":"_new", getTick () - ts, aid, ad->fe, ad->status, ad->ber, ad->strength, ad->snr, ad->max_strength, ad->max_snr, opts.force_scan);
@ -145,7 +164,7 @@ index 285faea..6ca7dd5 100755
}
if(use_ad)
{
@@ -715,14 +786,14 @@ describe_adapter (int sid, int aid)
@@ -715,14 +794,14 @@ describe_adapter (int sid, int aid)
}
if (t->sys == SYS_DVBS || t->sys == SYS_DVBS2)
sprintf (dad, "ver=1.0;src=%d;tuner=%d,%d,%d,%d,%d,%s,%s,%s,%s,%s,%d,%s;pids=",
@ -373,10 +392,48 @@ index 5701bd2..bfb1cdd 100755
}
diff --git a/minisatip.c b/minisatip.c
index d4076ba..581d1bd 100755
index d4076ba..06db623 100755
--- a/minisatip.c
+++ b/minisatip.c
@@ -483,6 +483,11 @@ http_response (sockets *s, int rc, char *ah, char *desc, int cseq, int lr)
@@ -36,6 +36,7 @@
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <syslog.h>
#include "socketworks.h"
#include "stream.h"
#include "adapter.h"
@@ -62,6 +63,7 @@ usage ()
-c X: bandwidth capping for the output to the network (default: unlimited)\n\
-b X: set the DVR buffer to X KB (default: %dKB)\n\
-l increases the verbosity (you can use multiple -l), logging to stdout in foreground mode or in /tmp/log when a daemon\n\
+ -g use syslog instead stdout for logging, multiple -g - print to stderr as well\n\
-p url: specify playlist url using X_SATIPM3U header \n\
-u unicable_string: defines the unicable adapters (A) and their slot (S) and frequency (F):\n\
\tThe format is: A1:S1-F1[,A2:S2-F2[,...]] \n\
@@ -101,7 +103,7 @@ set_options (int argc, char *argv[])
opts.file_line = 0;
memset(opts.playlist, sizeof(opts.playlist), 0);
- while ((opt = getopt (argc, argv, "flr:a:t:d:w:p:shc:b:m:p:e:x:u:j:")) != -1)
+ while ((opt = getopt (argc, argv, "flr:a:t:d:w:p:shc:b:m:p:e:x:u:j:g")) != -1)
{
// printf("options %d %c %s\n",opt,opt,optarg);
switch (opt)
@@ -143,6 +145,12 @@ set_options (int argc, char *argv[])
break;
}
+ case SYSLOG_OPT:
+ {
+ opts.slog++;
+ break;
+ }
+
case HELP_OPT:
{
usage ();
@@ -483,6 +491,11 @@ http_response (sockets *s, int rc, char *ah, char *desc, int cseq, int lr)
#define RBUF 4000
@ -388,7 +445,7 @@ index d4076ba..581d1bd 100755
int
read_rtsp (sockets * s)
{
@@ -507,8 +512,7 @@ read_rtsp (sockets * s)
@@ -507,8 +520,7 @@ read_rtsp (sockets * s)
}
}
@ -398,7 +455,7 @@ index d4076ba..581d1bd 100755
{
if( s->rlen > RBUF - 10 )
{
@@ -726,8 +730,7 @@ read_http (sockets * s)
@@ -726,8 +738,7 @@ read_http (sockets * s)
"%s"
"</device></root>";
@ -408,10 +465,12 @@ index d4076ba..581d1bd 100755
{
if( s->rlen > RBUF - 10 )
{
@@ -987,7 +990,11 @@ main (int argc, char *argv[])
@@ -987,7 +998,13 @@ main (int argc, char *argv[])
set_options (argc, argv);
if (opts.daemon)
becomeDaemon ();
+ if (opts.slog)
+ openlog ("minisatip", LOG_NDELAY|LOG_NOWAIT|LOG_PID|(opts.slog>1?LOG_PERROR:0), LOG_DAEMON);
+#ifdef AXE
+ LOGL(0, "Starting minisatip version %s, compiled with AXE DVB API",VERSION);
+#else
@ -420,6 +479,69 @@ index d4076ba..581d1bd 100755
readBootID();
if ((ssdp = udp_bind (NULL, 1900)) < 1)
FAIL ("SSDP: Could not bind on udp port 1900");
@@ -1021,7 +1038,9 @@ main (int argc, char *argv[])
select_and_execute ();
unlink(PID_FILE);
free_all ();
- return 0;
+ if (opts.slog)
+ closelog();
+ return 0;
}
@@ -1247,12 +1266,16 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
idx = 1;
else if ( idx < 0)
idx = 0;
- if(opts.file_line)
+ if(opts.file_line && !opts.slog)
len1 = snprintf(output[idx], sizeof(output[0]), "[%s] %s:%d: ", get_current_timestamp_log(), file, line);
- else
+ else if (!opts.slog)
len1 = snprintf(output[idx], sizeof(output[0]), "[%s]: ", get_current_timestamp_log());
+ else if (opts.file_line) {
+ len1 = 0;
+ output[idx][0] = '\0';
+ }
/* Write the error message */
- len = len1;
+ len = len1 = len1 < sizeof(output[0]) ? len1 : sizeof(output[0]) - 1;
both = 0;
va_start(arg, fmt);
len += vsnprintf(output[idx] + len, sizeof(output[0]) - len, fmt, arg);
@@ -1271,9 +1294,9 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
}
if(both){
- puts(output[1-idx]);
+ if(opts.slog)syslog(LOG_NOTICE, "%s", output[1-idx]); else puts(output[1-idx]);
both = 0;
}
- if(times==0)puts(output[idx]);
+ if(times==0) if(opts.slog)syslog(LOG_NOTICE, "%s", output[idx]); else puts(output[idx]);
fflush(stdout);
}
diff --git a/minisatip.h b/minisatip.h
index 821e756..4f4e6ac 100755
--- a/minisatip.h
+++ b/minisatip.h
@@ -30,6 +30,7 @@ void set_options (int argc, char *argv[]);
#define ENABLE_ADAPTERS_OPT 'e'
#define UNICABLE_OPT 'u'
#define JESS_OPT 'j'
+#define SYSLOG_OPT 'g'
#define PID_FILE "/var/run/minisatip.pid"
struct struct_opts
@@ -39,6 +40,7 @@ struct struct_opts
char *disc_host; //discover host
char mac[13];
unsigned int log,
+ slog,
start_rtp,
http_port;
int timeout_sec;
diff --git a/socketworks.c b/socketworks.c
index b4891f1..1857089 100755
--- a/socketworks.c