Browse Source

Add --notify-wait (-9) option (not set by default).

Using it prevents running of several notification scripts in parallel
which can lead to races if the scripts are used for logging.
Georgi Chorbadzhiyski 7 years ago
parent
commit
28dd637542
6 changed files with 29 additions and 3 deletions
  1. 3
    0
      ChangeLog
  2. 2
    0
      README
  3. 1
    0
      data.h
  4. 2
    0
      notify.c
  5. 13
    0
      tsdecrypt.1
  6. 8
    3
      tsdecrypt.c

+ 3
- 0
ChangeLog View File

@@ -1,6 +1,9 @@
1 1
 xxxx-xx-xx : Version -next
2 2
  * Add new notification message STREAM_NOT_ENCRYPTED. When stream is not
3 3
    encrypted no NO_CODE_WORD notifications are sent.
4
+ * Add --notify-wait (-9) option (not set by default). Using it prevents
5
+   running of several notification scripts in parallel which can lead to
6
+   races if the scripts are used for logging.
4 7
 
5 8
 2013-09-12 : Version 10.0
6 9
  * Add --ecm-only (-v) option. This allows processing of ECMs but without

+ 2
- 0
README View File

@@ -102,6 +102,8 @@ Main options:
102 102
  -i --ident <server>        | Format PROVIDER/CHANNEL. Default: empty
103 103
  -d --daemon <pidfile>      | Daemonize program and write pid file.
104 104
  -N --notify-program <prg>  | Execute <prg> to report events. Default: empty
105
+ -9 --notify-wait           | Enable one by one notification delivery.
106
+                            . Default: not set (async, deliver ASAP)
105 107
 
106 108
 Input options:
107 109
  -I --input <source>        | Where to read from. File or multicast address.

+ 1
- 0
data.h View File

@@ -359,6 +359,7 @@ struct ts {
359 359
 
360 360
 	struct notify		*notify;
361 361
 	char				*notify_program;
362
+	int					notify_wait;
362 363
 
363 364
 	unsigned int		input_buffer_time;
364 365
 	LIST				*input_buffer;

+ 2
- 0
notify.c View File

@@ -143,6 +143,8 @@ static void notify_func(struct ts *ts, int sync_msg, char *msg_id, char *msg_tex
143 143
 	np = calloc(1, sizeof(struct npriv));
144 144
 
145 145
 	np->sync = sync_msg;
146
+	if (ts->notify_wait)
147
+		np->sync = 1;
146 148
 	npriv_init_defaults(ts->notify, np);
147 149
 
148 150
 	strncpy(np->msg_id, msg_id, sizeof(np->ident) - 1);

+ 13
- 0
tsdecrypt.1 View File

@@ -30,6 +30,19 @@ and an example on how to create your own notification script.
30 30
 
31 31
 See \fBEVENTS\fR section for detailed description of the events.
32 32
 .TP
33
+\fB\-9\fR, \fB\-\-notify-wait\fR
34
+Wait for notification script to exit before starting another notification.
35
+
36
+By default notifications script is executed as soon as notification is
37
+received. But since several notifications might come at one time, there
38
+is no guarantee that notification script would be run sequentially. The
39
+notification script for newer notification might be run before an older
40
+notification.
41
+
42
+Setting this option makes sure that you'll have only one notify script
43
+running. \fB*NOTE*\fR if you set this option make sure that notification
44
+script does not take a lot of time to run or you'll run into problems.
45
+.TP
33 46
 \fB\-S\fR, \fB\-\-syslog\fR
34 47
 Write log messages to local syslog.
35 48
 .TP

+ 8
- 3
tsdecrypt.c View File

@@ -77,7 +77,7 @@ static void LOG_func(const char *msg) {
77 77
 		LOG(msg);
78 78
 }
79 79
 
80
-static const char short_options[] = "i:d:N:Sl:L:F:I:1:RzM:T:W:O:o:t:rk:g:upwxyc:C:Y:Q:A:s:U:P:B:46eZ:Ef:a:X:vqH:G:2:KJ:D:jbhVn:m:";
80
+static const char short_options[] = "i:d:N:9Sl:L:F:I:1:RzM:T:W:O:o:t:rk:g:upwxyc:C:Y:Q:A:s:U:P:B:46eZ:Ef:a:X:vqH:G:2:KJ:D:jbhVn:m:";
81 81
 
82 82
 // Unused short options: 035789
83 83
 static const struct option long_options[] = {
@@ -88,6 +88,7 @@ static const struct option long_options[] = {
88 88
 	{ "syslog-port",		required_argument, NULL, 'L' },
89 89
 	{ "log-file",			required_argument, NULL, 'F' },
90 90
 	{ "notify-program",		required_argument, NULL, 'N' },
91
+	{ "notify-wait",		no_argument,       NULL, '9' },
91 92
 
92 93
 	{ "input",				required_argument, NULL, 'I' },
93 94
 	{ "input-source",		required_argument, NULL, '1' },
@@ -160,6 +161,8 @@ static void show_help(struct ts *ts) {
160 161
 	printf(" -i --ident <server>        | Format PROVIDER/CHANNEL. Default: empty\n");
161 162
 	printf(" -d --daemon <pidfile>      | Daemonize program and write pid file.\n");
162 163
 	printf(" -N --notify-program <prg>  | Execute <prg> to report events. Default: empty\n");
164
+	printf(" -9 --notify-wait           | Enable one by one notification delivery.\n");
165
+	printf("                            . Default: not set (async, deliver ASAP)\n");
163 166
 	printf("\n");
164 167
 	printf("Input options:\n");
165 168
 	printf(" -I --input <source>        | Where to read from. File or multicast address.\n");
@@ -314,7 +317,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
314 317
 			case 'N': // --notify-program
315 318
 				ts->notify_program = optarg;
316 319
 				break;
317
-
320
+			case '9': // --notify-wait
321
+				ts->notify_wait = !ts->notify_wait;
322
+				break;
318 323
 			case 'S': // --syslog
319 324
 				ts->syslog_active = 1;
320 325
 				ts->syslog_remote = 0;
@@ -682,7 +687,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
682 687
 	if (ts->ident)
683 688
 		ts_LOGf("Ident      : %s\n", ts->ident);
684 689
 	if (ts->notify_program)
685
-		ts_LOGf("Notify prg : %s\n", ts->notify_program);
690
+		ts_LOGf("Notify prg : %s (%s)\n", ts->notify_program, ts->notify_wait ? "sync" : "async");
686 691
 	if (ts->pidfile)
687 692
 		ts_LOGf("Daemonize  : %s pid file.\n", ts->pidfile);
688 693
 	if (ts->syslog_active) {

Loading…
Cancel
Save