Browse code

core: added log_name config parameter

- log_name allows to set app name to be used when printing to syslog
- useful to filter log messages when running many instance on same server

Daniel-Constantin Mierla authored on 20/08/2009 07:41:02
Showing 4 changed files
... ...
@@ -281,6 +281,7 @@ DEBUG	debug
281 281
 FORK	fork
282 282
 LOGSTDERROR	log_stderror
283 283
 LOGFACILITY	log_facility
284
+LOGNAME		log_name
284 285
 LISTEN		listen
285 286
 ALIAS		alias
286 287
 SR_AUTO_ALIASES	auto_aliases
... ...
@@ -577,6 +578,7 @@ EAT_ABLE	[\ \t\b\r]
577 577
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
578 578
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
579 579
 <INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
580
+<INITIAL>{LOGNAME}	{ yylval.strval=yytext; return LOGNAME; }
580 581
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
581 582
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
582 583
 <INITIAL>{SR_AUTO_ALIASES}	{ count(); yylval.strval=yytext;
... ...
@@ -345,6 +345,7 @@ static int case_check_default(struct case_stms* stms);
345 345
 %token FORK
346 346
 %token LOGSTDERROR
347 347
 %token LOGFACILITY
348
+%token LOGNAME
348 349
 %token LISTEN
349 350
 %token ALIAS
350 351
 %token SR_AUTO_ALIASES
... ...
@@ -758,6 +759,8 @@ assign_stm:
758 758
 			default_core_cfg.log_facility=i_tmp;
759 759
 	}
760 760
 	| LOGFACILITY EQUAL error { yyerror("ID expected"); }
761
+	| LOGNAME EQUAL STRING { log_name=$3; }
762
+	| LOGNAME EQUAL error { yyerror("string value expected"); }
761 763
 	| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
762 764
 	| DNS EQUAL error { yyerror("boolean value expected"); }
763 765
 	| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
... ...
@@ -109,6 +109,7 @@ struct log_level_info {
109 109
 
110 110
 #define is_printable(level) (cfg_get(core, core_cfg, debug)>=(level))
111 111
 extern struct log_level_info log_level_info[];
112
+extern char *log_name;
112 113
 
113 114
 #ifndef NO_SIG_DEBUG
114 115
 /* protection against "simultaneous" printing from signal handlers */
... ...
@@ -321,6 +321,8 @@ int sig_flag = 0;              /* last signal received */
321 321
 int dont_fork = 0;
322 322
 int dont_daemonize = 0;
323 323
 int log_stderr = 0;
324
+/* set custom app name for syslog printing */
325
+char *log_name = 0;
324 326
 pid_t creator_pid = (pid_t) -1;
325 327
 int config_check = 0;
326 328
 /* check if reply first via host==us */
... ...
@@ -2059,7 +2061,7 @@ try_again:
2059 2059
 #endif /* USE_SCTP */
2060 2060
 	/* init_daemon? */
2061 2061
 	if (!dont_fork){
2062
-		if ( daemonize(argv[0]) <0 ) goto error;
2062
+		if ( daemonize((log_name==0)?argv[0]:log_name) <0 ) goto error;
2063 2063
 	}
2064 2064
 	if (install_sigs() != 0){
2065 2065
 		fprintf(stderr, "ERROR: could not install the signal handlers\n");