mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
- log-identity: config option to set sys log identity, patch from
"Robin H. Johnson" <robbat2@gentoo.org> git-svn-id: file:///svn/unbound/trunk@3917 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
b8cd36af89
commit
680e14cb65
11 changed files with 2156 additions and 2089 deletions
|
|
@ -244,10 +244,21 @@ checkrlimits(struct config_file* cfg)
|
|||
#endif /* S_SPLINT_S */
|
||||
}
|
||||
|
||||
/** set default logfile identity based on value from argv[0] at startup **/
|
||||
static void
|
||||
log_ident_set_fromdefault(struct config_file* cfg,
|
||||
const char *log_default_identity)
|
||||
{
|
||||
if(cfg->log_identity == NULL || cfg->log_identity[0] == 0)
|
||||
log_ident_set(log_default_identity);
|
||||
else
|
||||
log_ident_set(cfg->log_identity);
|
||||
}
|
||||
|
||||
/** set verbosity, check rlimits, cache settings */
|
||||
static void
|
||||
apply_settings(struct daemon* daemon, struct config_file* cfg,
|
||||
int cmdline_verbose, int debug_mode)
|
||||
int cmdline_verbose, int debug_mode, const char* log_default_identity)
|
||||
{
|
||||
/* apply if they have changed */
|
||||
verbosity = cmdline_verbose + cfg->verbosity;
|
||||
|
|
@ -258,6 +269,7 @@ apply_settings(struct daemon* daemon, struct config_file* cfg,
|
|||
}
|
||||
daemon_apply_cfg(daemon, cfg);
|
||||
checkrlimits(cfg);
|
||||
log_ident_set_fromdefault(cfg, log_default_identity);
|
||||
}
|
||||
|
||||
#ifdef HAVE_KILL
|
||||
|
|
@ -587,9 +599,10 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
|
|||
* @param cmdline_verbose: verbosity resulting from commandline -v.
|
||||
* These increase verbosity as specified in the config file.
|
||||
* @param debug_mode: if set, do not daemonize.
|
||||
* @param log_default_identity: Default identity to report in logs
|
||||
*/
|
||||
static void
|
||||
run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
|
||||
run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode, const char* log_default_identity)
|
||||
{
|
||||
struct config_file* cfg = NULL;
|
||||
struct daemon* daemon = NULL;
|
||||
|
|
@ -611,7 +624,7 @@ run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
|
|||
cfgfile);
|
||||
log_warn("Continuing with default config settings");
|
||||
}
|
||||
apply_settings(daemon, cfg, cmdline_verbose, debug_mode);
|
||||
apply_settings(daemon, cfg, cmdline_verbose, debug_mode, log_default_identity);
|
||||
if(!done_setup)
|
||||
config_lookup_uid(cfg);
|
||||
|
||||
|
|
@ -619,7 +632,7 @@ run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
|
|||
if(!daemon_open_shared_ports(daemon))
|
||||
fatal_exit("could not open ports");
|
||||
if(!done_setup) {
|
||||
perform_setup(daemon, cfg, debug_mode, &cfgfile);
|
||||
perform_setup(daemon, cfg, debug_mode, &cfgfile);
|
||||
done_setup = 1;
|
||||
} else {
|
||||
/* reopen log after HUP to facilitate log rotation */
|
||||
|
|
@ -666,6 +679,7 @@ main(int argc, char* argv[])
|
|||
int c;
|
||||
const char* cfgfile = CONFIGFILE;
|
||||
const char* winopt = NULL;
|
||||
const char* log_ident_default;
|
||||
int cmdline_verbose = 0;
|
||||
int debug_mode = 0;
|
||||
#ifdef UB_ON_WINDOWS
|
||||
|
|
@ -678,7 +692,8 @@ main(int argc, char* argv[])
|
|||
#endif
|
||||
|
||||
log_init(NULL, 0, NULL);
|
||||
log_ident_set(strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0]);
|
||||
log_ident_default = strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0];
|
||||
log_ident_set(log_ident_default);
|
||||
/* parse the options */
|
||||
while( (c=getopt(argc, argv, "c:dhvw:")) != -1) {
|
||||
switch(c) {
|
||||
|
|
@ -711,7 +726,7 @@ main(int argc, char* argv[])
|
|||
if(winopt) {
|
||||
#ifdef UB_ON_WINDOWS
|
||||
wsvc_command_option(winopt, cfgfile, cmdline_verbose,
|
||||
cmdline_cfg);
|
||||
cmdline_cfg, log_ident_default);
|
||||
#else
|
||||
fatal_exit("option not supported");
|
||||
#endif
|
||||
|
|
@ -722,7 +737,7 @@ main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
run_daemon(cfgfile, cmdline_verbose, debug_mode);
|
||||
run_daemon(cfgfile, cmdline_verbose, debug_mode, log_ident_default);
|
||||
log_init(NULL, 0, NULL); /* close logfile */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
3 November 2016: Wouter
|
||||
- .gitattributes line for githubs code language display.
|
||||
- log-identity: config option to set sys log identity, patch from
|
||||
"Robin H. Johnson" <robbat2@gentoo.org>
|
||||
|
||||
2 November 2016: Wouter
|
||||
- iana portlist update.
|
||||
|
|
|
|||
|
|
@ -275,9 +275,13 @@ server:
|
|||
# logfile: ""
|
||||
|
||||
# Log to syslog(3) if yes. The log facility LOG_DAEMON is used to
|
||||
# log to, with identity "unbound". If yes, it overrides the logfile.
|
||||
# log to. If yes, it overrides the logfile.
|
||||
# use-syslog: yes
|
||||
|
||||
# Log identity to report. if empty, defaults to the name of argv[0]
|
||||
# (usually "unbound").
|
||||
# log-identity: ""
|
||||
|
||||
# print UTC timestamp in ascii to logfile, default is epoch in seconds.
|
||||
# log-time-ascii: no
|
||||
|
||||
|
|
|
|||
|
|
@ -534,6 +534,13 @@ The log facility LOG_DAEMON is used, with identity "unbound".
|
|||
The logfile setting is overridden when use\-syslog is turned on.
|
||||
The default is to log to syslog.
|
||||
.TP
|
||||
.B log\-identity: \fI<string>
|
||||
If "" is given (default), then the name of the executable, usually "unbound"
|
||||
is used to report to the log. Enter a string to override it
|
||||
with that, which is useful on systems that run more than one instance of
|
||||
unbound, with different configurations, so that the logs can be easily
|
||||
distinguished against.
|
||||
.TP
|
||||
.B log\-time\-ascii: \fI<yes or no>
|
||||
Sets logfile lines to use a timestamp in UTC ascii. Default is no, which
|
||||
prints the seconds since 1970 in brackets. No effect if using syslog, in
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ config_create(void)
|
|||
cfg->ssl_port = 853;
|
||||
cfg->ssl_upstream = 0;
|
||||
cfg->use_syslog = 1;
|
||||
cfg->log_identity = NULL; /* changed later with argv[0] */
|
||||
cfg->log_time_ascii = 0;
|
||||
cfg->log_queries = 0;
|
||||
#ifndef USE_WINSOCK
|
||||
|
|
@ -370,6 +371,7 @@ int config_set_option(struct config_file* cfg, const char* opt,
|
|||
log_set_time_asc(cfg->log_time_ascii); }
|
||||
else S_SIZET_NONZERO("max-udp-size:", max_udp_size)
|
||||
else S_YNO("use-syslog:", use_syslog)
|
||||
else S_STR("log-identity:", log_identity)
|
||||
else S_YNO("extended-statistics:", stat_extended)
|
||||
else S_YNO("statistics-cumulative:", stat_cumulative)
|
||||
else S_YNO("do-ip4:", do_ip4)
|
||||
|
|
@ -680,6 +682,7 @@ config_get_option(struct config_file* cfg, const char* opt,
|
|||
else O_YNO(opt, "statistics-cumulative", stat_cumulative)
|
||||
else O_YNO(opt, "extended-statistics", stat_extended)
|
||||
else O_YNO(opt, "use-syslog", use_syslog)
|
||||
else O_STR(opt, "log-identity", log_identity)
|
||||
else O_YNO(opt, "log-time-ascii", log_time_ascii)
|
||||
else O_DEC(opt, "num-threads", num_threads)
|
||||
else O_IFC(opt, "interface", num_ifs, ifs)
|
||||
|
|
|
|||
|
|
@ -229,6 +229,8 @@ struct config_file {
|
|||
int log_time_ascii;
|
||||
/** log queries with one line per query */
|
||||
int log_queries;
|
||||
/** log identity to report */
|
||||
char* log_identity;
|
||||
|
||||
/** do not report identity (id.server, hostname.bind) */
|
||||
int hide_identity;
|
||||
|
|
|
|||
2702
util/configlexer.c
2702
util/configlexer.c
File diff suppressed because it is too large
Load diff
|
|
@ -328,6 +328,7 @@ del-holddown{COLON} { YDVAR(1, VAR_DEL_HOLDDOWN) }
|
|||
keep-missing{COLON} { YDVAR(1, VAR_KEEP_MISSING) }
|
||||
permit-small-holddown{COLON} { YDVAR(1, VAR_PERMIT_SMALL_HOLDDOWN) }
|
||||
use-syslog{COLON} { YDVAR(1, VAR_USE_SYSLOG) }
|
||||
log-identity{COLON} { YDVAR(1, VAR_LOG_IDENTITY) }
|
||||
log-time-ascii{COLON} { YDVAR(1, VAR_LOG_TIME_ASCII) }
|
||||
log-queries{COLON} { YDVAR(1, VAR_LOG_QUERIES) }
|
||||
local-zone{COLON} { YDVAR(2, VAR_LOCAL_ZONE) }
|
||||
|
|
|
|||
1476
util/configparser.c
1476
util/configparser.c
File diff suppressed because it is too large
Load diff
|
|
@ -222,7 +222,8 @@ extern int yydebug;
|
|||
VAR_ACCESS_CONTROL_VIEW = 432,
|
||||
VAR_VIEW_FIRST = 433,
|
||||
VAR_SERVE_EXPIRED = 434,
|
||||
VAR_FAKE_DSA = 435
|
||||
VAR_FAKE_DSA = 435,
|
||||
VAR_LOG_IDENTITY = 436
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
|
|
@ -404,6 +405,7 @@ extern int yydebug;
|
|||
#define VAR_VIEW_FIRST 433
|
||||
#define VAR_SERVE_EXPIRED 434
|
||||
#define VAR_FAKE_DSA 435
|
||||
#define VAR_LOG_IDENTITY 436
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
|
|
@ -414,7 +416,7 @@ union YYSTYPE
|
|||
|
||||
char* str;
|
||||
|
||||
#line 418 "util/configparser.h" /* yacc.c:1909 */
|
||||
#line 420 "util/configparser.h" /* yacc.c:1909 */
|
||||
};
|
||||
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ extern struct config_parser_state* cfg_parser;
|
|||
%token VAR_LOCAL_ZONE_OVERRIDE VAR_ACCESS_CONTROL_TAG_ACTION
|
||||
%token VAR_ACCESS_CONTROL_TAG_DATA VAR_VIEW VAR_ACCESS_CONTROL_VIEW
|
||||
%token VAR_VIEW_FIRST VAR_SERVE_EXPIRED VAR_FAKE_DSA
|
||||
%token VAR_LOG_IDENTITY
|
||||
|
||||
%%
|
||||
toplevelvars: /* empty */ | toplevelvars toplevelvar ;
|
||||
|
|
@ -204,7 +205,7 @@ content_server: server_num_threads | server_verbosity | server_port |
|
|||
server_local_zone_override | server_access_control_tag_action |
|
||||
server_access_control_tag_data | server_access_control_view |
|
||||
server_qname_minimisation_strict | server_serve_expired |
|
||||
server_fake_dsa
|
||||
server_fake_dsa | server_log_identity
|
||||
;
|
||||
stubstart: VAR_STUB_ZONE
|
||||
{
|
||||
|
|
@ -1909,6 +1910,14 @@ server_disable_dnssec_lame_check: VAR_DISABLE_DNSSEC_LAME_CHECK STRING_ARG
|
|||
(strcmp($2, "yes")==0);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_log_identity: VAR_LOG_IDENTITY STRING_ARG
|
||||
{
|
||||
OUTYY(("P(server_log_identity:%s)\n", $2));
|
||||
free(cfg_parser->cfg->log_identity);
|
||||
cfg_parser->cfg->log_identity = $2;
|
||||
}
|
||||
;
|
||||
%%
|
||||
|
||||
/* parse helper routines could be here */
|
||||
|
|
|
|||
Loading…
Reference in a new issue