59
55
#include <getopt.h>
62
static gchar *cfgfilename = PATH_SYSLOG_NG_CONF;
59
#include <iv_signal.h>
63
61
static gchar *install_dat_filename = PATH_INSTALL_DAT;
64
62
static gchar *installer_version = NULL;
65
static const gchar *persist_file = PATH_PERSIST_CONFIG;
66
static gboolean syntax_only = FALSE;
67
63
static gboolean display_version = FALSE;
68
static gchar *ctlfilename = PATH_CONTROL_SOCKET;
69
static gchar *preprocess_into = NULL;
71
static volatile sig_atomic_t sig_hup_received = FALSE;
72
static volatile sig_atomic_t sig_term_received = FALSE;
73
static volatile sig_atomic_t sig_child_received = FALSE;
76
sig_hup_handler(int signo)
78
sig_hup_received = TRUE;
82
sig_term_handler(int signo)
84
sig_term_received = TRUE;
88
sig_child_handler(int signo)
90
sig_child_received = TRUE;
98
memset(&sa, 0, sizeof(sa));
99
sa.sa_handler = SIG_IGN;
100
sigaction(SIGPIPE, &sa, NULL);
101
sa.sa_handler = sig_hup_handler;
102
sigaction(SIGHUP, &sa, NULL);
103
sa.sa_handler = sig_term_handler;
104
sigaction(SIGTERM, &sa, NULL);
105
sa.sa_handler = sig_term_handler;
106
sigaction(SIGINT, &sa, NULL);
107
sa.sa_handler = sig_child_handler;
108
sigaction(SIGCHLD, &sa, NULL);
112
stats_timer(gpointer st)
114
stats_generate_log();
118
static GStaticMutex main_loop_lock = G_STATIC_MUTEX_INIT;
119
static GMainLoop *main_loop = NULL;
120
static GPollFunc system_poll_func = NULL;
123
main_loop_wakeup(void)
125
g_static_mutex_lock(&main_loop_lock);
127
g_main_context_wakeup(g_main_loop_get_context(main_loop));
128
g_static_mutex_unlock(&main_loop_lock);
132
main_context_poll(GPollFD *ufds, guint nfsd, gint timeout_)
134
gint ret = (*system_poll_func)(ufds, nfsd, timeout_);
135
update_g_current_time();
140
main_loop_run(GlobalConfig **cfg)
143
guint stats_timer_id = 0;
146
log_source_set_wakeup_func(main_loop_wakeup);
148
msg_notice("syslog-ng starting up",
149
evt_tag_str("version", VERSION),
151
main_loop = g_main_loop_new(NULL, TRUE);
152
if ((*cfg)->stats_freq > 0)
153
stats_timer_id = g_timeout_add((*cfg)->stats_freq * 1000, stats_timer, NULL);
155
control_init(ctlfilename, g_main_loop_get_context(main_loop));
157
system_poll_func = g_main_context_get_poll_func(g_main_loop_get_context(main_loop));
158
g_main_context_set_poll_func(g_main_loop_get_context(main_loop), main_context_poll);
159
while (g_main_loop_is_running(main_loop))
161
if ((*cfg)->time_sleep > 0)
165
ts.tv_sec = (*cfg)->time_sleep / 1000;
166
ts.tv_nsec = ((*cfg)->time_sleep % 1000) * 1E6;
168
nanosleep(&ts, NULL);
170
g_main_context_iteration(g_main_loop_get_context(main_loop), TRUE);
171
if (sig_hup_received)
174
sigaddset(&ss, SIGHUP);
175
sigprocmask(SIG_BLOCK, &ss, NULL);
176
sig_hup_received = FALSE;
178
/* this may handle multiple SIGHUP signals, however it doesn't
179
* really matter if we received only a single or multiple SIGHUPs
180
* until we make sure that we handle the last one. Since we
181
* blocked the SIGHUP signal and reset sig_hup_received to FALSE,
182
* we can be sure that if we receive an additional SIGHUP during
183
* signal processing we get the new one when we finished this, and
184
* handle that one as well. */
186
app_pre_config_loaded();
187
(*cfg) = cfg_reload_config(cfgfilename, (*cfg));
188
app_post_config_loaded();
189
msg_notice("Configuration reload request received, reloading configuration",
191
reset_cached_hostname();
192
if ((*cfg)->stats_freq > 0)
194
if (stats_timer_id != 0)
195
g_source_remove(stats_timer_id);
196
stats_timer_id = g_timeout_add((*cfg)->stats_freq * 1000, stats_timer, NULL);
198
stats_cleanup_orphans();
199
sigprocmask(SIG_UNBLOCK, &ss, NULL);
201
if (sig_term_received)
203
msg_info("Termination requested via signal, terminating", NULL);
204
sig_term_received = FALSE;
207
if (sig_child_received)
213
sigaddset(&ss, SIGCHLD);
214
sigprocmask(SIG_BLOCK, &ss, NULL);
215
sig_child_received = FALSE;
217
/* this may handle multiple SIGCHLD signals, however it doesn't
218
* matter if one or multiple SIGCHLD was received assuming that
219
* all exited child process are waited for */
223
pid = waitpid(-1, &status, WNOHANG);
224
child_manager_sigchild(pid, status);
227
sigprocmask(SIG_UNBLOCK, &ss, NULL);
231
msg_notice("syslog-ng shutting down",
232
evt_tag_str("version", VERSION),
235
while (g_main_context_iteration(NULL, FALSE) && iters < 3)
239
g_static_mutex_lock(&main_loop_lock);
240
g_main_loop_unref(main_loop);
242
g_static_mutex_unlock(&main_loop_lock);
64
static gboolean display_module_registry = FALSE;
65
static gboolean dummy = FALSE;
247
68
extern int cfg_parser_debug;
251
71
static GOptionEntry syslogng_options[] =
253
{ "cfgfile", 'f', 0, G_OPTION_ARG_STRING, &cfgfilename, "Set config file name, default=" PATH_SYSLOG_NG_CONF, "<config>" },
254
{ "persist-file", 'R', 0, G_OPTION_ARG_STRING, &persist_file, "Set the name of the persistent configuration file, default=" PATH_PERSIST_CONFIG, "<fname>" },
255
{ "module-path", 0, 0, G_OPTION_ARG_STRING, &module_path, "Set the list of colon separated directories to search for modules, default=" PATH_MODULEDIR, "<path>" },
256
{ "syntax-only", 's', 0, G_OPTION_ARG_NONE, &syntax_only, "Only read and parse config file", NULL},
257
{ "preprocess-into", 0, 0, G_OPTION_ARG_STRING, &preprocess_into, "Write the preprocessed configuration file to the file specified", "output" },
258
73
{ "version", 'V', 0, G_OPTION_ARG_NONE, &display_version, "Display version number (" PACKAGE " " VERSION ")", NULL },
259
{ "seed", 'S', 0, G_OPTION_ARG_NONE, &seed_rng, "Seed the RNG using ~/.rnd or $RANDFILE", NULL},
260
{ "control", 'c', 0, G_OPTION_ARG_STRING, &ctlfilename, "Set syslog-ng control socket, default=" PATH_CONTROL_SOCKET, "<ctlpath>" },
74
{ "module-path", 0, 0, G_OPTION_ARG_STRING, &module_path, "Set the list of colon separated directories to search for modules, default=" MODULE_PATH, "<path>" },
75
{ "module-registry", 0, 0, G_OPTION_ARG_NONE, &display_module_registry, "Display module information", NULL },
76
{ "default-modules", 0, 0, G_OPTION_ARG_STRING, &default_modules, "Set the set of auto-loaded modules, default=" DEFAULT_MODULES, "<module-list>" },
77
{ "seed", 'S', 0, G_OPTION_ARG_NONE, &dummy, "Does nothing, the need to seed the random generator is autodetected", NULL},
262
79
{ "yydebug", 'y', 0, G_OPTION_ARG_NONE, &cfg_parser_debug, "Enable configuration parser debugging", NULL },
268
* Returns: exit code to be returned to the calling process.
271
initial_init(GlobalConfig **cfg)
277
if (!cfg_read_config(*cfg, cfgfilename, syntax_only, preprocess_into))
287
if (!cfg_initial_init(*cfg, persist_file))
294
84
#define INSTALL_DAT_INSTALLER_VERSION "INSTALLER_VERSION"
329
if (!get_installer_version(&installer_version) || installer_version==NULL)
119
if (!get_installer_version(&installer_version) || installer_version == NULL)
331
installer_version=VERSION;
121
installer_version = VERSION;
333
123
printf(PACKAGE " " VERSION "\n"
334
124
"Installer-Version: %s\n"
335
125
"Revision: " SOURCE_REVISION "\n"
126
#if WITH_COMPILE_DATE
336
127
"Compile-Date: " __DATE__ " " __TIME__ "\n"
337
"Enable-Threads: %s\n"
129
"Default-Modules: %s\n"
130
"Available-Modules: ",
134
plugin_list_modules(stdout, FALSE);
136
printf("Enable-Debug: %s\n"
339
137
"Enable-GProf: %s\n"
340
138
"Enable-Memtrace: %s\n"
341
"Enable-Sun-STREAMS: %s\n"
342
139
"Enable-IPv6: %s\n"
343
140
"Enable-Spoof-Source: %s\n"
344
141
"Enable-TCP-Wrapper: %s\n"
347
142
"Enable-Linux-Caps: %s\n"
349
"Enable-Pacct: %s\n",
351
ON_OFF_STR(ENABLE_THREADS),
352
144
ON_OFF_STR(ENABLE_DEBUG),
353
145
ON_OFF_STR(ENABLE_GPROF),
354
146
ON_OFF_STR(ENABLE_MEMTRACE),
355
ON_OFF_STR(ENABLE_SUN_STREAMS_MODULE),
356
147
ON_OFF_STR(ENABLE_IPV6),
357
148
ON_OFF_STR(ENABLE_SPOOF_SOURCE),
358
149
ON_OFF_STR(ENABLE_TCP_WRAPPER),
359
ON_OFF_STR(ENABLE_SSL_MODULE),
360
ON_OFF_STR(ENABLE_SQL_MODULE),
361
150
ON_OFF_STR(ENABLE_LINUX_CAPS),
362
ON_OFF_STR(ENABLE_PCRE),
363
ON_OFF_STR(ENABLE_PACCT_MODULE));
151
ON_OFF_STR(ENABLE_PCRE));
155
#if ENABLE_LINUX_CAPS
156
#define BASE_CAPS "cap_net_bind_service,cap_net_broadcast,cap_net_raw," \
157
"cap_dac_read_search,cap_dac_override,cap_chown,cap_fowner=p "
162
static gchar *capsstr_syslog = BASE_CAPS "cap_syslog=ep";
163
static gchar *capsstr_sys_admin = BASE_CAPS "cap_sys_admin=ep";
165
/* Set up the minimal privilege we'll need
167
* NOTE: polling /proc/kmsg requires cap_sys_admin, otherwise it'll always
168
* indicate readability. Enabling/disabling cap_sys_admin on every poll
169
* invocation seems to be too expensive. So I enable it for now.
171
if (g_process_check_cap_syslog())
172
g_process_set_caps(capsstr_syslog);
174
g_process_set_caps(capsstr_sys_admin);
367
183
main(int argc, char *argv[])
371
186
GOptionContext *ctx;
372
187
GError *error = NULL;