Browse Source

Cleanup ident handling.

Georgi Chorbadzhiyski 12 years ago
parent
commit
f8f7295862
3 changed files with 14 additions and 11 deletions
  1. 2
    1
      data.h
  2. 2
    1
      notify.c
  3. 10
    9
      tsdecrypt.c

+ 2
- 1
data.h View File

@@ -223,7 +223,8 @@ struct ts {
223 223
 	struct camd			camd;
224 224
 
225 225
 	// Config
226
-	char				ident[128];
226
+	char				*ident;
227
+
227 228
 	char				syslog_host[128];
228 229
 	int					syslog_port;
229 230
 	int					syslog_active;

+ 2
- 1
notify.c View File

@@ -116,11 +116,12 @@ static void *notify_thread(void *data) {
116 116
 
117 117
 struct notify *notify_alloc(struct ts *ts) {
118 118
 	unsigned int i;
119
-	if (!ts->ident[0] || !ts->notify_program)
119
+	if (!ts->ident || !ts->notify_program)
120 120
 		return NULL;
121 121
 	struct notify *n = calloc(1, sizeof(struct notify));
122 122
 	n->notifications = queue_new();
123 123
 	strncpy(n->ident, ts->ident, sizeof(n->ident) - 1);
124
+	n->ident[sizeof(n->ident) - 1] = '\0';
124 125
 	for (i=0; i<strlen(n->ident); i++) {
125 126
 		if (n->ident[i] == '/')
126 127
 			n->ident[i] = '-';

+ 10
- 9
tsdecrypt.c View File

@@ -281,8 +281,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
281 281
 		char *p = NULL;
282 282
 		switch (j) {
283 283
 			case 'i':
284
-				strncpy(ts->ident, optarg, sizeof(ts->ident) - 1);
285
-				ts->ident[sizeof(ts->ident) - 1] = 0;
284
+				ts->ident = optarg;
286 285
 				break;
287 286
 			case 'd':
288 287
 				ts->pidfile = optarg;
@@ -473,7 +472,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
473 472
 				exit(EXIT_SUCCESS);
474 473
 		}
475 474
 	}
476
-	if (!ts->ident[0]) {
475
+	if (!ts->ident) {
477 476
 		if (ts->syslog_active || ts->notify_program)
478 477
 			ident_err = 1;
479 478
 	}
@@ -502,7 +501,8 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
502 501
 		exit(EXIT_FAILURE);
503 502
 	}
504 503
 
505
-	ts_LOGf("Ident      : %s\n", ts->ident[0] ? ts->ident : "*NOT SET*");
504
+	if (ts->ident)
505
+		ts_LOGf("Ident      : %s\n", ts->ident);
506 506
 	if (ts->notify_program)
507 507
 		ts_LOGf("Notify prg : %s\n", ts->notify_program);
508 508
 	if (ts->pidfile)
@@ -613,11 +613,12 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
613 613
 	if (!ts->ecm_cw_log)
614 614
 		ts_LOGf("ECM/CW log : disabled\n");
615 615
 
616
-	for (i=0; i<(int)sizeof(ts->ident); i++) {
617
-		if (!ts->ident[i])
618
-			break;
619
-		if (ts->ident[i] == '/')
620
-			ts->ident[i] = '-';
616
+	if (ts->ident) {
617
+		int len = strlen(ts->ident);
618
+		for (i = 0; i < len; i++) {
619
+			if (ts->ident[i] == '/')
620
+				ts->ident[i] = '-';
621
+		}
621 622
 	}
622 623
 }
623 624
 

Loading…
Cancel
Save