]> git.pld-linux.org Git - packages/syslog-ng.git/blame - syslog-ng-fixes.patch
- up from git
[packages/syslog-ng.git] / syslog-ng-fixes.patch
CommitLineData
eb4e1b63
AM
1diff --git a/configure.in b/configure.in
2index d5f0769..1605bff 100644
3--- a/configure.in
4+++ b/configure.in
5@@ -49,10 +49,8 @@ fi
93dd2058 6
eb4e1b63
AM
7 if test "x$prefix" = "xNONE"; then
8 prefix=$ac_default_prefix
9- pidfiledir="/var/run"
10-else
11- pidfiledir="${prefix}/var/run"
12 fi
13+pidfiledir="${localstatedir}"
14
15 AM_CONFIG_HEADER(config.h)
16
17@@ -70,7 +68,7 @@ AC_ARG_WITH(pidfile-dir,
18
19 AC_ARG_WITH(timezone-dir,
20 [ --with-timezone-dir=path Use path as the directory to get the timezone files],
21- timezone_dir=$with_timezone_dir)
22+ timezonedir=$with_timezone_dir)
23
24 AC_ARG_WITH(ld-library-path,
25 [ --with-ld-library-path=path Set LD_LIBRARY_PATH during runtime to the value given],
26@@ -92,10 +90,13 @@ AC_ARG_ENABLE(ssl,
27 [ --enable-ssl Enable SSL support.],,enable_ssl="auto")
28
29 AC_ARG_ENABLE(dynamic-linking,
30- [ --enable-dynamic-linking Link glib and eventlog dynamically instead of statically.])
31+ [ --enable-dynamic-linking Link glib and eventlog dynamically instead of statically.],,enable_dynamic_linking="auto")
32
33 AC_ARG_ENABLE(static-linking,
34- [ --enable-static-linking Link everything statically.])
35+ [ --enable-static-linking Link everything statically.],,enable_static_linking="auto")
36+
37+AC_ARG_ENABLE(mixed-linking,
38+ [ --enable-mixed-linking Link 3rd party libraries statically, system libraries dynamically],,enable_mixed_linking="auto")
39
40 AC_ARG_ENABLE(ipv6,
41 [ --enable-ipv6 Enable support for IPv6.],,enable_ipv6="auto")
42@@ -319,9 +320,6 @@ dnl ***************************************************************************
43 dnl OpenSSL headers/libraries
44 dnl ***************************************************************************
45
46-OPENSSL_LIBS=""
47-OPENSSL_CPPFLAGS=""
48-
49 # openssl is needed for:
50 # * TLS support
51
52@@ -360,7 +358,13 @@ dnl libdbi headers/libraries
53 dnl ***************************************************************************
54
55 AC_CHECK_LIB(dl, dlsym, DL_LIBS="-ldl")
56-PKG_CHECK_MODULES(LIBDBI, dbi >= $LIBDBI_MIN_VERSION,, LIBDBI_LIBS="")
57+PKG_CHECK_MODULES(LIBDBI, dbi >= $LIBDBI_MIN_VERSION,, libdbi_pkgconfig_not_found="1")
58+
59+if test "$libdbi_pkgconfig_not_found" -eq 1; then
60+ dnl if libdbi has no .pc file, try it without one
61+ AC_CHECK_LIB(dbi, dbi_initialize, LIBDBI_LIBS="-ldbi"; LIBDBI_CFLAGS="-I/usr/include")
62+fi
63+
64
65 dnl ***************************************************************************
66 dnl Some more checks based on the detected settings above
67@@ -606,8 +610,42 @@ int main()
68 fi
69 fi
70
71-if test "x$enable_dynamic_linking" = "xyes" -a "x$enable_static_linking" = "xyes"; then
72- AC_MSG_ERROR([You cannot specify dynamic and static linking at the same time.])
73+if test "$enable_dynamic_linking" = "auto" -a "$enable_static_linking" = "auto" -a "$enable_mixed_linking" = "auto"; then
74+ enable_dynamic_linking="yes"
75+ enable_static_linking="no"
76+ enable_mixed_linking="no"
77+fi
78+
79+linkopts=0
80+if test "x$enable_dynamic_linking" = "xyes"; then
81+ linkopts=`expr $linkopts + 1`
82+fi
83+if test "x$enable_static_linking" = "xyes"; then
84+ linkopts=`expr $linkopts + 1`
85+fi
86+if test "x$enable_mixed_linking" = "xyes"; then
87+ linkopts=`expr $linkopts + 1`
88+fi
89+
90+if test "$linkopts" -gt 1; then
91+ AC_MSG_ERROR([You cannot specify multiple linking options at the same time (--enable-dynamic-linking, --enable-static-linking, --enable-mixed-linking).])
92+fi
93+
94+if test "x$enable_dynamic_linking" = "xyes"; then
95+ enable_dynamic_linking="yes"
96+ enable_static_linking="no"
97+ enable_mixed_linking="no"
98+ linking_mode="dynamic"
99+elif test "x$enable_static_linking" = "xyes"; then
100+ enable_dynamic_linking="no"
101+ enable_static_linking="yes"
102+ enable_mixed_linking="no"
103+ linking_mode="static"
104+elif test "x$enable_mixed_linking" = "xyes"; then
105+ enable_dynamic_linking="no"
106+ enable_static_linking="no"
107+ enable_mixed_linking="yes"
108+ linking_mode="mixed"
109 fi
110
111 if test "x$enable_dynamic_linking" != "xyes" -a "x$blb_cv_static_glib" = "xno"; then
112@@ -615,7 +653,7 @@ if test "x$enable_dynamic_linking" != "xyes" -a "x$blb_cv_static_glib" = "xno";
113 fi
114
115 if test "x$enable_dynamic_linking" != "xyes" -a "x$blb_cv_static_openssl" = "xno"; then
116- AC_MSG_ERROR([static OpenSSL libraries not found (libssl.a and libcrypto.a), either link OpenSSL statically using the --enable-dynamic-linking, or install a static OpenSSL])
117+ AC_MSG_ERROR([static OpenSSL libraries not found (libssl.a, libcrypto.a and their external dependencies like libz.a), either link OpenSSL statically using the --enable-dynamic-linking, or install a static OpenSSL])
118 fi
119
120
121@@ -672,8 +710,8 @@ AC_DEFINE_UNQUOTED(PATH_PREFIX, "`patheval $prefix`", [prefix directory])
122 AC_DEFINE_UNQUOTED(PATH_SYSCONFDIR, "`patheval $sysconfdir`", [sysconfdir])
123 AC_DEFINE_UNQUOTED(PATH_LOCALSTATEDIR, "`patheval $localstatedir`", [local state directory])
124 AC_DEFINE_UNQUOTED(PATH_PIDFILEDIR, "`patheval $pidfiledir`", [local state directory])
125-if test -n "$timezone_dir"; then
126- AC_DEFINE_UNQUOTED(PATH_TIMEZONEDIR, "`patheval $timezone_dir`", [timezone base directory])
127+if test -n "$timezonedir"; then
128+ AC_DEFINE_UNQUOTED(PATH_TIMEZONEDIR, "`patheval $timezonedir`", [timezone base directory])
129 fi
130 if test -n "$env_ld_library_path"; then
131 AC_DEFINE_UNQUOTED(ENV_LD_LIBRARY_PATH, "$env_ld_library_path", [set LD_LIBRARY_PATH to this value])
132@@ -695,6 +733,8 @@ AC_DEFINE_UNQUOTED(ENABLE_ENV_WRAPPER, `enable_value $enable_env_wrapper`, [Enab
133
134 AM_CONDITIONAL(ENABLE_ENV_WRAPPER, [test "$enable_env_wrapper" = "yes"])
135
136+AC_SUBST(timezonedir)
137+AC_SUBST(pidfiledir)
138 AC_SUBST(DEPS_CPPFLAGS)
139 AC_SUBST(DEPS_LIBS)
140 AC_SUBST(BASE_LIBS)
141@@ -729,6 +769,7 @@ echo " compiler : $CC"
142 echo " compiler options : $CFLAGS $CPPFLAGS"
143 echo " linker flags : $LDFLAGS $LIBS"
144 echo " prefix : $prefix"
145+echo " linking mode : $linking_mode"
146 echo " Features:"
147 echo " Sun STREAMS support : ${enable_sun_streams:=no}"
148 echo " Sun Door support : ${enable_sun_door:=no}"
149diff --git a/contrib/balabit-initscripts/init-functions b/contrib/balabit-initscripts/init-functions
150index e1898a8..c3b18ef 100644
151--- a/contrib/balabit-initscripts/init-functions
152+++ b/contrib/balabit-initscripts/init-functions
153@@ -6,12 +6,35 @@ NORMAL=
154 FANCYTTY=
155 PSOPTS=
156
157-case `uname -s` in
158+ECHO=echo
159+
160+OS=`uname -s`
161+
162+disable_xpg_echo() {
163+ # \X chars only passed to echo under bash, if xpg_echo enabled or echo -e
164+ # used on Linux.
165+ if [ -n "$BASH_VERSION" ];then
166+ shopt -s xpg_echo
167+ fi
168+}
169+
170+case $OS in
171 # default ps -e cuts the process' name at 8 characters, so we have to list it
172 # in a long form
173- SunOS) PSOPTS=" -o pid -o tty -o time -o comm" ;;
174+ SunOS)
175+ PSOPTS=" -o pid -o tty -o time -o comm"
176+ disable_xpg_echo
177+ ;;
178+ Linux)
179+ if [ -z "$BASH_VERSION" ]; then
180+ # beware of dash's builtin echo ...
181+ ECHO="/bin/echo -e"
182+ fi
183+ ;;
184+ *) disable_xpg_echo ;;
185 esac
186
187+
188 _checkpid() {
189 _pid=$1
190 _proc=$2
191@@ -30,7 +53,7 @@ _pid_from_pidfile() {
192 pid=
193
194 if [ -f "$pidfile" ];then
195- pid=`head -1 $pidfile`
196+ pid=`head -1 $pidfile 2> /dev/null`
197 if [ $? -ne 0 ]; then
198 # on slow machines (or ones under high load) the pidfile could be
199 # erased between -f and `head` ...
200@@ -195,17 +218,17 @@ log_use_fancy_output() {
201
202
203 log_success_msg() {
204- echo "$@"
205+ $ECHO "$@"
206 }
207
208 log_failure_msg() {
209 log_use_fancy_output
210- echo "${RED}$@${NORMAL}"
211+ $ECHO "${RED}$@${NORMAL}"
212 }
213
214 log_warning_msg() {
215 log_use_fancy_output
216- echo "${YELLOW}$@${NORMAL}"
217+ $ECHO "${YELLOW}$@${NORMAL}"
218 }
219
220 # NON-LSB Functions
221@@ -215,7 +238,7 @@ log_begin_msg() {
222 return 1
223 fi
224
225- echo "$@\c "
226+ $ECHO "$@\c "
227 }
228
229 log_daemon_msg() {
230@@ -224,11 +247,11 @@ log_daemon_msg() {
231 fi
232
233 if [ -z "$2" ]; then
234- echo "$1:\c "
235+ $ECHO "$1:\c "
236 return
237 fi
238
239- echo "$1: $2\c "
240+ $ECHO "$1: $2\c "
241 }
242
243 log_progress_msg() {
244@@ -237,9 +260,9 @@ log_progress_msg() {
245 fi
246
247 if [ $1 -eq 0 ]; then
248- echo "."
249+ $ECHO "."
250 else
251- echo " failed"
252+ $ECHO " failed"
253 fi
254 }
255
256@@ -250,23 +273,23 @@ log_end_msg() {
257
258 log_fancy_output
259 if [ $1 -eq 0 ];then
260- echo "."
261+ $ECHO "."
262 else
263- echo "${RED}failed!${NORMAL}"
264+ $ECHO "${RED}failed!${NORMAL}"
265 fi
266 return $1
267 }
268
269 log_action_msg() {
270- echo "$@."
271+ $ECHO "$@."
272 }
273
274 log_action_begin_msg() {
275- echo "$@...\c "
276+ $ECHO "$@...\c "
277 }
278
279 log_action_cont_msg() {
280- echo "$@...\c "
281+ $ECHO "$@...\c "
282 }
283
284 log_action_end_msg() {
285@@ -278,15 +301,12 @@ log_action_end_msg() {
286
287 log_fancy_output
288 if [ $1 -eq 0 ]; then
289- echo "done${end}"
290+ $ECHO "done${end}"
291 else
292- echo "${RED}failed${end}${NORMAL}"
293+ $ECHO "${RED}failed${end}${NORMAL}"
294 fi
295 }
296
297-# \X chars only passed to echo under bash, if xpg_echo enabled....
298-if [ -n "$BASH_VERSION" ];then
299- shopt -s xpg_echo
300-fi
301
302 # vim: ft=sh ts=2 expandtab
303+
304diff --git a/contrib/balabit-initscripts/init.d b/contrib/balabit-initscripts/init.d
305index ff2e249..589da86 100644
306--- a/contrib/balabit-initscripts/init.d
307+++ b/contrib/balabit-initscripts/init.d
308@@ -25,6 +25,7 @@ SYSLOGNG_PREFIX=/opt/syslog-ng
309 SYSLOGNG="$SYSLOGNG_PREFIX/sbin/syslog-ng"
310 CONFFILE=$SYSLOGNG_PREFIX/etc/syslog-ng.conf
311 PIDFILE=$SYSLOGNG_PREFIX/var/run/syslog-ng.pid
312+SYSLOGPIDFILE="/var/run/syslog.pid"
313
314 INIT_FUNCTIONS=/lib/lsb/init-functions
315 SLNG_INIT_FUNCTIONS=$SYSLOGNG_PREFIX/lib/init-functions
316@@ -64,6 +65,17 @@ if [ -f /etc/lsb-release ]; then
317 . /etc/lsb-release
318 fi
319
320+if [ -f "/etc/redhat-release" ];then
321+ # redhat uses a different syslogd pidfile...
322+ SYSLOGPIDFILE="/var/run/syslogd.pid"
323+fi
324+
325+if [ "$OS" = "SunOS" ] || [ "$OS" = "Solaris" ];then
326+ if [ "`uname -r`" = "5.8" ];then
327+ SYSLOGPIDFILE="/etc/syslog.pid"
328+ fi
329+fi
330+
331 if [ -f /lib/lsb/init-functions ];then
332 # long list of exclusions...
333 if [ -f "/etc/redhat-release" ] || [ -f "/etc/SuSE-release" ];then
334@@ -117,7 +129,7 @@ check_syntax() {
335
336 slng_waitforpid() {
337 _pid=$1
338- _process=$2
339+ _process=$2
340 _cnt=$MAXWAIT
341
342 # no pid, return...
343@@ -147,6 +159,11 @@ returnmessage() {
344
345 syslogng_start() {
346 echo_n "Starting syslog-ng: "
347+ PID=`pidofproc -p ${PIDFILE} ${SYSLOGNG} | head -1`
348+ if [ -n "$PID" ] && [ $PID -gt 0 ] ;then
349+ log_success_msg "already running: $PID"
350+ return $retval
351+ fi
352 start_daemon -p ${PIDFILE} ${SYSLOGNG} ${SYSLOGNG_OPTIONS}
353 retval=$?
354 returnmessage $retval
355@@ -154,6 +171,13 @@ syslogng_start() {
356 if [ "$OS" = "Linux" ] && [ -d $SUBSYSDIR ];then
357 touch $SUBSYSDIR/syslog-ng
358 fi
359+ # remove symlinks
360+ if [ -h $SYSLOGPIDFILE ];then
361+ rm -f $SYSLOGPIDFILE
362+ fi
363+ if [ ! -f $SYSLOGPIDFILE ];then
364+ ln -s $PIDFILE $SYSLOGPIDFILE
365+ fi
366 fi
367 return $retval
368 }
369@@ -180,6 +204,9 @@ syslogng_stop() {
370 fi
371 if [ $retval -eq 0 ];then
372 rm -f $SUBSYSDIR/syslog-ng ${PIDFILE}
373+ if [ -h $SYSLOGPIDFILE ];then
374+ rm -f $SYSLOGPIDFILE
375+ fi
376 fi
377 return $retval
378 }
379@@ -270,6 +297,14 @@ case "$1" in
380 force-reload)
381 syslogng_restart
382 ;;
383+ reload-or-restart)
384+ PID=`pidofproc -p ${PIDFILE} ${SYSLOGNG} | head -1`
385+ if [ -n "$PID" ] && [ $PID -gt 0 ] ;then
386+ syslogng_reload
387+ else
388+ syslogng_start
389+ fi
390+ ;;
391 status)
392 syslogng_status
393 ;;
394@@ -284,4 +319,4 @@ esac
395
396 exit $retval
397
398-# vim: ts=2 ft=sh
399+# vim: ts=2 ft=sh noexpandtab
400diff --git a/contrib/balabit-initscripts/init.d.freebsd b/contrib/balabit-initscripts/init.d.freebsd
401index 997b4db..de04473 100644
402--- a/contrib/balabit-initscripts/init.d.freebsd
403+++ b/contrib/balabit-initscripts/init.d.freebsd
404@@ -33,9 +33,13 @@ command="$SYSLOGNG_PREFIX/sbin/syslog-ng"
405 required_files="$SYSLOGNG_PREFIX/etc/syslog-ng.conf"
406
407 start_precmd="syslog_ng_start_precmd"
408+start_postcmd="syslog_ng_start_postcmd"
409+stop_postcmd="syslog_ng_stop_postcmd"
410 reload_precmd="syslog_ng_reload_precmd"
411 extra_commands="reload"
412
413+# get original syslog pidfile from initscript.
414+_syslogd_pidfile=`sed -n -e 's/^pidfile="\([^"]*\)"/\1/p' /etc/rc.d/syslogd 2> /dev/null`
415 syslog_ng_start_precmd() {
416 if [ ! -L /dev/log ]; then
417 ln -s /var/run/log /dev/log
418@@ -50,6 +54,26 @@ syslog_ng_reload_precmd() {
419 fi
420 }
421
422+syslog_ng_start_postcmd() {
423+ if [ -n "$_syslogd_pidfile" ]; then
424+ # remove symlinks
425+ if [ -h $_syslogd_pidfile ]; then
426+ rm -f $_syslogd_pidfile
427+ fi
428+ if [ ! -f $_syslogd_pidfile ]; then
429+ ln -s "$pidfile" "$_syslogd_pidfile"
430+ fi
431+ fi
432+}
433+
434+syslog_ng_stop_postcmd() {
435+ if [ -n "$_syslogd_pidfile" ]; then
436+ if [ -h $_syslogd_pidfile ]; then
437+ rm -f "$_syslogd_pidfile"
438+ fi
439+ fi
440+}
441+
442 load_rc_config "$name"
443
444 case $1 in
445diff --git a/contrib/cygwin-packaging/cygwin-postinstall b/contrib/cygwin-packaging/cygwin-postinstall
446index 4b7bf7d..e812ead 100755
447--- a/contrib/cygwin-packaging/cygwin-postinstall
448+++ b/contrib/cygwin-packaging/cygwin-postinstall
449@@ -21,11 +21,11 @@ then
450 exit 3
451 fi
452 mkdir -p "${DESTDIR}/usr/bin"
453-mkdir -p "${DESTDIR}/usr/share/doc/syslog-ng"
454+#mkdir -p "${DESTDIR}/usr/share/doc/syslog-ng"
455 mkdir -p "${DESTDIR}/usr/share/doc/Cygwin"
456 cp contrib/cygwin-packaging/syslog-ng-config "${DESTDIR}/usr/bin"
457-cp -rp doc/examples/syslog-ng.conf.s* doc/reference/syslog-ng.[tx]* "${DESTDIR}/usr/share/doc/syslog-ng"
458-tar xzfC doc/reference/syslog-ng.html.tar.gz "${DESTDIR}/usr/share/doc/syslog-ng"
459+#cp -rp doc/examples/syslog-ng.conf.s* doc/reference/syslog-ng.[tx]* "${DESTDIR}/usr/share/doc/syslog-ng"
460+#tar xzfC doc/reference/syslog-ng.html.tar.gz "${DESTDIR}/usr/share/doc/syslog-ng"
461 cat > "${DESTDIR}/usr/share/doc/Cygwin/syslog-ng.README" <<'EOF'
462 If you want to use syslog-ng, just run the /usr/bin/syslog-ng-config
463 script. This script will create a default configuration file
464@@ -42,15 +42,15 @@ The syslog-ng package has been built using the following command
465 sequence from the top level source dir:
466
467 ./configure \
468- --disable-ipv6 \
469- --disable-tcp-wrapper \
470 --prefix=/usr \
471 --sysconfdir=/etc \
472 --libexecdir='$(prefix)/sbin' \
473 --localstatedir=/var \
474 --datadir='$(prefix)/share' \
475 --mandir='$(prefix)/share/man' \
476- --infodir='$(prefix)/share/info'
477+ --infodir='$(prefix)/share/info' \
478+ --enable-dynamic-linking \
479+ --with-pidfile-dir=/var
480 make
481 make install-strip
482 contrib/cygwin-packaging/cygwin-postinstall
483diff --git a/contrib/cygwin-packaging/syslog-ng-config b/contrib/cygwin-packaging/syslog-ng-config
484index 790f0cc..7ae5fec 100755
485--- a/contrib/cygwin-packaging/syslog-ng-config
486+++ b/contrib/cygwin-packaging/syslog-ng-config
487@@ -205,13 +205,13 @@ if [ ! -f "${SYSCONFDIR}/syslog-ng.conf" ]
488 then
489 echo "Creating default ${SYSCONFDIR}/syslog-ng.conf file"
490 cat > ${SYSCONFDIR}/syslog-ng.conf << EOF
491+@version 3.0
492 options {
493 keep_hostname(yes);
494- chain_hostnames(no);
495 owner("system");
496 group("root");
497 perm(0664);
498- sync(0);
499+ flush_lines(0);
500 };
501
502 source applications {
503@@ -220,7 +220,7 @@ source applications {
504 };
505
506 source kernel {
507- file("/dev/kmsg", log_prefix("kernel: "));
508+ file("/dev/kmsg", program_override("kernel: "));
509 };
510
511 destination messages {
512@@ -240,42 +240,35 @@ EOF
513 fi
514 setfacl -m u:system:rw- "${SYSCONFDIR}/syslog-ng.conf"
515
516-# Check if running on NT
517-_sys="`uname`"
518-_nt=`expr "${_sys}" : "CYGWIN_NT"`
519-# On NT ask if syslog-ng should be installed as service
520-if [ ${_nt} -gt 0 ]
521+# Check if syslogd is installed and remove on user request.
522+if cygrunsrv -Q syslogd > /dev/null 2>&1
523 then
524- # Check if syslogd is installed and remove on user request.
525- if cygrunsrv -Q syslogd > /dev/null 2>&1
526+ echo "Warning: The syslogd service is already installed. You can not"
527+ echo "run both, syslogd and syslog-ng in parallel."
528+ echo
529+ if request "Do you want to deinstall the syslogd service in favor of syslog-ng?"
530 then
531- echo "Warning: The syslogd service is already installed. You can not"
532- echo "run both, syslogd and syslog-ng in parallel."
533- echo
534- if request "Do you want to deinstall the syslogd service in favor of syslog-ng?"
535- then
536- cygrunsrv -E syslogd
537- cygrunsrv -R syslogd
538- fi
539+ cygrunsrv -E syslogd
540+ cygrunsrv -R syslogd
541 fi
542- # Install syslog-ng service if it is not already installed
543- if ! cygrunsrv -Q syslog-ng > /dev/null 2>&1
544+fi
545+# Install syslog-ng service if it is not already installed
546+if ! cygrunsrv -Q syslog-ng > /dev/null 2>&1
547+then
548+ echo
549+ echo
550+ echo "Warning: The following function requires administrator privileges!"
551+ echo
552+ echo "Do you want to install syslog-ng as service?"
553+ if request "(Say \"no\" if it's already installed as service)"
554 then
555- echo
556- echo
557- echo "Warning: The following function requires administrator privileges!"
558- echo
559- echo "Do you want to install syslog-ng as service?"
560- if request "(Say \"no\" if it's already installed as service)"
561+ if cygrunsrv -I syslog-ng -d "CYGWIN syslog-ng" -p /usr/sbin/syslog-ng -a "-F --fd-limit 256"
562 then
563- if cygrunsrv -I syslog-ng -d "CYGWIN syslog-ng" -p /usr/sbin/syslog-ng -a -F
564- then
565- echo
566- echo "The service has been installed under LocalSystem account."
567- echo "To start the service, call \`net start syslog-ng' or \`cygrunsrv -S syslog-ng'."
568- echo
569- echo "Check ${SYSCONFDIR}/syslog-ng.conf first, if it suits your needs."
570- fi
571+ echo
572+ echo "The service has been installed under LocalSystem account."
573+ echo "To start the service, call \`net start syslog-ng' or \`cygrunsrv -S syslog-ng'."
574+ echo
575+ echo "Check ${SYSCONFDIR}/syslog-ng.conf first, if it suits your needs."
576 fi
577 fi
578 fi
579diff --git a/contrib/solaris-packaging/syslog-ng.method b/contrib/solaris-packaging/syslog-ng.method
580index f0fee58..d819a3c 100755
581--- a/contrib/solaris-packaging/syslog-ng.method
582+++ b/contrib/solaris-packaging/syslog-ng.method
583@@ -13,6 +13,7 @@ SYSLOGNG_PREFIX=/opt/syslog-ng
584 SYSLOGNG="$SYSLOGNG_PREFIX/sbin/syslog-ng"
585 CONFFILE=$SYSLOGNG_PREFIX/etc/syslog-ng.conf
586 PIDFILE=$SYSLOGNG_PREFIX/var/run/syslog-ng.pid
587+SYSLOGPIDFILE=/var/run/syslog.pid
588
589 OPTIONS=
590 MAXWAIT=30
591@@ -56,7 +57,7 @@ slng_stop() {
592
593 _process=`basename $SYSLOGNG`
594 slng_waitforpid "$_process" $syspid
595- _ret=$?
596+ _ret=$?
597 if [ $_ret -eq 0 ]; then
598 kill -KILL $syspid
599 $_ret=$?
600@@ -68,6 +69,9 @@ slng_stop() {
601 [ $? -ne 0 ] && exit $SMF_EXIT_ERR_FATAL
602 fi
603 rm -f $PIDFILE
604+ if [ -h $SYSLOGPIDFILE ];then
605+ rm -f $SYSLOGPIDFILE
606+ fi
607 return $SMF_EXIT_OK
608 fi
609 return $SMF_EXIT_ERR_FATAL
610@@ -93,6 +97,13 @@ slng_start () {
611 fi
612 check_syntax
613 $SYSLOGNG $OPTIONS
614+ # remove symlinks
615+ if [ -h $SYSLOGPIDFILE ];then
616+ rm -f $SYSLOGPIDFILE
617+ fi
618+ if [ ! -f $SYSLOGPIDFILE ];then
619+ ln -s $PIDFILE $SYSLOGPIDFILE
620+ fi
621 return $SMF_EXIT_OK
622 fi
623 return $SMF_EXIT_ERR_FATAL
624diff --git a/src/affile.c b/src/affile.c
625index 6d48915..5721a1a 100644
626--- a/src/affile.c
627+++ b/src/affile.c
628@@ -40,11 +40,12 @@
629
630 static gboolean
631 affile_open_file(gchar *name, gint flags,
632- uid_t uid, gid_t gid, mode_t mode,
633- uid_t dir_uid, gid_t dir_gid, mode_t dir_mode,
634- gboolean create_dirs, gboolean privileged, gint *fd)
635+ uid_t uid, gid_t gid, mode_t mode,
636+ uid_t dir_uid, gid_t dir_gid, mode_t dir_mode,
637+ gboolean create_dirs, gboolean privileged, gboolean is_pipe, gint *fd)
638 {
639 cap_t saved_caps;
640+ struct stat st;
641
642 if (strstr(name, "../") || strstr(name, "/.."))
643 {
644@@ -63,20 +64,43 @@ affile_open_file(gchar *name, gint flags,
645 g_process_cap_modify(CAP_DAC_READ_SEARCH, TRUE);
646 g_process_cap_modify(CAP_SYS_ADMIN, TRUE);
647 }
648+ if (stat(name, &st) >= 0)
649+ {
650+ if (is_pipe && !S_ISFIFO(st.st_mode))
651+ {
652+ msg_error("Error opening pipe, underlying file is not a FIFO, it should be used by file()",
653+ evt_tag_str("filename", name),
654+ NULL);
655+ goto exit;
656+ }
657+ else if (!is_pipe && S_ISFIFO(st.st_mode))
658+ {
659+ msg_error("Error opening file, underlying file is a FIFO, it should be used by pipe()",
660+ evt_tag_str("filename", name),
661+ NULL);
662+ goto exit;
663+ }
664+ }
665 *fd = open(name, flags, mode);
666+ if (is_pipe && *fd < 0 && errno == ENOENT)
667+ {
668+ if (mkfifo(name, 0666) >= 0)
669+ *fd = open(name, flags, 0666);
670+ }
671
672 if (*fd != -1)
673 {
674 g_fd_set_cloexec(*fd, TRUE);
675
676 g_process_cap_modify(CAP_DAC_OVERRIDE, TRUE);
677- if (uid != -1)
678+ if (uid != (uid_t) -1)
679 fchown(*fd, uid, -1);
680- if (gid != -1)
681+ if (gid != (gid_t) -1)
682 fchown(*fd, -1, gid);
683- if (mode != -1)
684+ if (mode != (mode_t) -1)
685 fchmod(*fd, mode);
686 }
687+ exit:
688 if (privileged)
689 {
690 g_process_cap_restore(saved_caps);
691@@ -99,7 +123,7 @@ affile_sd_open_file(AFFileSourceDriver *self, gchar *name, gint *fd)
692 else
693 flags = O_RDONLY | O_NOCTTY | O_NONBLOCK | O_LARGEFILE;
694
695- if (affile_open_file(name, flags, -1, -1, -1, 0, 0, 0, 0, !!(self->flags & AFFILE_PRIVILEGED), fd))
696+ if (affile_open_file(name, flags, -1, -1, -1, 0, 0, 0, 0, !!(self->flags & AFFILE_PRIVILEGED), !!(self->flags & AFFILE_PIPE), fd))
697 return TRUE;
698 return FALSE;
699 }
700@@ -196,9 +220,15 @@ affile_sd_notify(LogPipe *s, LogPipe *sender, gint notify_code, gpointer user_da
701 transport = log_transport_plain_new(fd, 0);
702 transport->timeout = 10;
703
704- self->reader = log_reader_new(log_proto_plain_new_server(transport, self->reader_options.padding, self->reader_options.msg_size, LPPF_NOMREAD | ((self->reader_options.follow_freq > 0) ? LPPF_IGNORE_EOF : 0)),
705- LR_LOCAL);
706-
707+ self->reader = log_reader_new(
708+ log_proto_plain_new_server(transport, self->reader_options.padding,
709+ self->reader_options.msg_size,
710+ ((self->reader_options.follow_freq > 0)
711+ ? LPPF_IGNORE_EOF
712+ : LPPF_NOMREAD)
713+ ),
714+ LR_LOCAL);
715+
716 log_reader_set_options(self->reader, s, &self->reader_options, 1, SCS_FILE, self->super.id, self->filename->str);
717
718 log_reader_set_follow_filename(self->reader, self->filename->str);
719@@ -290,10 +320,16 @@ affile_sd_init(LogPipe *s)
720 transport->timeout = 10;
721
722 /* FIXME: we shouldn't use reader_options to store log protocol parameters */
723- self->reader = log_reader_new(log_proto_plain_new_server(transport, self->reader_options.padding, self->reader_options.msg_size, LPPF_NOMREAD | ((self->reader_options.follow_freq > 0) ? LPPF_IGNORE_EOF : 0)),
724- LR_LOCAL);
725+ self->reader = log_reader_new(
726+ log_proto_plain_new_server(transport, self->reader_options.padding,
727+ self->reader_options.msg_size,
728+ ((self->reader_options.follow_freq > 0)
729+ ? LPPF_IGNORE_EOF
730+ : LPPF_NOMREAD)
731+ ),
732+ LR_LOCAL);
733 log_reader_set_options(self->reader, s, &self->reader_options, 1, SCS_FILE, self->super.id, self->filename->str);
734-
735+
736 log_reader_set_follow_filename(self->reader, self->filename->str);
737
738 /* NOTE: if the file could not be opened, we ignore the last
739@@ -458,7 +494,7 @@ affile_dw_init(LogPipe *s)
740 if (affile_open_file(self->filename->str, flags,
741 self->owner->file_uid, self->owner->file_gid, self->owner->file_perm,
742 self->owner->dir_uid, self->owner->dir_gid, self->owner->dir_perm,
743- !!(self->owner->flags & AFFILE_CREATE_DIRS), FALSE, &fd))
744+ !!(self->owner->flags & AFFILE_CREATE_DIRS), FALSE, !!(self->owner->flags & AFFILE_PIPE), &fd))
745 {
746 guint write_flags;
747
748diff --git a/src/afsocket.c b/src/afsocket.c
749index ad8e198..af788f6 100644
750--- a/src/afsocket.c
751+++ b/src/afsocket.c
752@@ -90,12 +90,12 @@ afsocket_open_socket(GSockAddr *bind_addr, int stream_or_dgram, int *fd)
753 else
754 sock = socket(bind_addr->sa.sa_family, SOCK_DGRAM, 0);
93dd2058 755
eb4e1b63
AM
756- g_fd_set_nonblock(sock, TRUE);
757- g_fd_set_cloexec(sock, TRUE);
758 if (sock != -1)
759 {
760 cap_t saved_caps;
761
762+ g_fd_set_nonblock(sock, TRUE);
763+ g_fd_set_cloexec(sock, TRUE);
764 saved_caps = g_process_cap_save();
765 g_process_cap_modify(CAP_NET_BIND_SERVICE, TRUE);
766 g_process_cap_modify(CAP_DAC_OVERRIDE, TRUE);
767@@ -208,7 +208,9 @@ afsocket_sc_init(LogPipe *s)
768 if ((self->owner->flags & AFSOCKET_SYSLOG_PROTOCOL) == 0)
769 {
770 /* plain protocol */
771- proto = log_proto_plain_new_server(transport, self->owner->reader_options.padding, self->owner->reader_options.msg_size, (self->owner->flags & AFSOCKET_DGRAM) ? LPPF_PKTTERM : 0);
772+ proto = log_proto_plain_new_server(transport, self->owner->reader_options.padding,
773+ self->owner->reader_options.msg_size,
774+ (self->owner->flags & AFSOCKET_DGRAM) ? (LPPF_PKTTERM + LPPF_IGNORE_EOF) : 0);
775 }
776 else
777 {
778diff --git a/src/afsql.c b/src/afsql.c
779index 96c5b22..dcbc02e 100644
780--- a/src/afsql.c
781+++ b/src/afsql.c
782@@ -940,6 +940,7 @@ afsql_dd_new()
783 self->frac_digits = -1;
784
785 self->validated_tables = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
786+ g_static_mutex_init(&self->queue_lock);
787
788 init_sequence_number(&self->seq_num);
789 return &self->super;
3c798031 790diff --git a/src/cfg-grammar.y b/src/cfg-grammar.y
eb4e1b63 791index 9902d84..2ad453a 100644
3c798031
AM
792--- a/src/cfg-grammar.y
793+++ b/src/cfg-grammar.y
eb4e1b63
AM
794@@ -52,6 +52,7 @@ LogParser *last_parser;
795 FilterRE *last_re_filter;
796 LogRewrite *last_rewrite;
797 gint last_addr_family = AF_INET;
798+gchar *last_include_file;
799
800 #if ENABLE_SSL
801 TLSContext *last_tls_context;
802@@ -92,17 +93,20 @@ cfg_check_template(LogTemplate *template)
803 return TRUE;
804 }
805
806+
807 %}
808
809 %union {
810+ gint token;
811 gint64 num;
812+ double fnum;
813 char *cptr;
814 void *ptr;
815 FilterExprNode *node;
816 }
817
818 /* statements */
819-%token KW_SOURCE KW_FILTER KW_PARSER KW_DESTINATION KW_LOG KW_OPTIONS
820+%token KW_SOURCE KW_FILTER KW_PARSER KW_DESTINATION KW_LOG KW_OPTIONS KW_INCLUDE
821
822 /* source & destination items */
823 %token KW_INTERNAL KW_FILE KW_PIPE KW_UNIX_STREAM KW_UNIX_DGRAM
824@@ -154,7 +158,7 @@ cfg_check_template(LogTemplate *template)
825
826 /* socket related options */
827 %token KW_KEEP_ALIVE KW_MAX_CONNECTIONS
828-%token KW_LOCALIP KW_IP KW_LOCALPORT KW_PORT KW_DESTPORT KW_FRAMED
829+%token KW_LOCALIP KW_IP KW_LOCALPORT KW_PORT KW_DESTPORT
830 %token KW_IP_TTL KW_SO_BROADCAST KW_IP_TOS KW_SO_SNDBUF KW_SO_RCVBUF KW_SO_KEEPALIVE KW_SPOOF_SOURCE
831
832 /* misc options */
833@@ -182,6 +186,7 @@ cfg_check_template(LogTemplate *template)
834 %token DOTDOT
835 %token <cptr> IDENTIFIER
836 %token <num> NUMBER
837+%token <fnum> FLOAT
838 %token <cptr> STRING
3c798031 839
eb4e1b63
AM
840 %left KW_OR
841@@ -276,6 +281,32 @@ cfg_check_template(LogTemplate *template)
3c798031
AM
842 %type <ptr> string_list
843 %type <ptr> string_list_build
844
eb4e1b63
AM
845+%type <token> reserved_words_as_strings
846+
847+%type <token> KW_PARSER
848+%type <token> KW_REWRITE
849+%type <token> KW_INCLUDE
850+%type <token> KW_SYSLOG
851+%type <token> KW_COLUMNS
852+%type <token> KW_DELIMITERS
853+%type <token> KW_QUOTES
854+%type <token> KW_QUOTE_PAIRS
855+%type <token> KW_NULL
856+%type <token> KW_CSV_PARSER
857+%type <token> KW_DB_PARSER
858+%type <token> KW_ENCODING
859+%type <token> KW_SET
860+%type <token> KW_SUBST
861+%type <token> KW_VALUE
862+%type <token> KW_PROGRAM_OVERRIDE
863+%type <token> KW_HOST_OVERRIDE
864+%type <token> KW_TRANSPORT
865+%type <token> KW_TRUSTED_KEYS
866+%type <token> KW_TRUSTED_DN
867+%type <token> KW_MESSAGE
868+%type <token> KW_TYPE
869+%type <token> KW_SQL
870+
871 %%
872
873 start
874@@ -283,7 +314,21 @@ start
875 ;
876
877 stmts
878- : stmt ';' stmts
879+ : stmt ';'
880+ {
881+ if (last_include_file && !cfg_lex_process_include(last_include_file))
882+ {
883+ free(last_include_file);
884+ last_include_file = NULL;
885+ YYERROR;
886+ }
887+ if (last_include_file)
888+ {
889+ free(last_include_file);
890+ last_include_file = NULL;
891+ }
892+ }
893+ stmts
894 |
895 ;
896
897@@ -296,6 +341,7 @@ stmt
898 | KW_REWRITE rewrite_stmt { cfg_add_rewrite(configuration, $2); }
899 | KW_TEMPLATE template_stmt { cfg_add_template(configuration, $2); }
900 | KW_OPTIONS options_stmt { }
901+ | KW_INCLUDE include_stmt { }
902 ;
903
904 source_stmt
905@@ -319,6 +365,9 @@ dest_stmt
906 log_stmt
907 : '{' log_items log_forks log_flags '}' { LogPipeItem *pi = log_pipe_item_append_tail($2, $3); $$ = log_connection_new(pi, $4); }
908 ;
909+
910+include_stmt
911+ : string { last_include_file = $1; }
912
913 log_items
914 : log_item ';' log_items { log_pipe_item_append($1, $3); $$ = $1; }
915@@ -442,7 +491,7 @@ source_affile_option
3c798031
AM
916 affile_sd_set_pri_level(last_driver, level);
917 free($3);
918 }
919- | KW_FACILITY '(' string ')'
eb4e1b63 920+ | KW_FACILITY '(' string ')'
3c798031
AM
921
922 {
923 int facility = -1;
eb4e1b63
AM
924@@ -708,7 +757,8 @@ source_reader_option
925 | KW_LOG_MSG_SIZE '(' NUMBER ')' { last_reader_options->msg_size = $3; }
926 | KW_LOG_FETCH_LIMIT '(' NUMBER ')' { last_reader_options->fetch_limit = $3; }
927 | KW_PAD_SIZE '(' NUMBER ')' { last_reader_options->padding = $3; }
928- | KW_FOLLOW_FREQ '(' NUMBER ')' { last_reader_options->follow_freq = $3; }
929+ | KW_FOLLOW_FREQ '(' FLOAT ')' { last_reader_options->follow_freq = (long) ($3 * 1000); }
930+ | KW_FOLLOW_FREQ '(' NUMBER ')' { last_reader_options->follow_freq = ($3 * 1000); }
931 | KW_KEEP_TIMESTAMP '(' yesno ')' { last_reader_options->super.keep_timestamp = $3; }
932 | KW_ENCODING '(' string ')' { last_reader_options->text_encoding = g_strdup($3); free($3); }
933 ;
934@@ -777,7 +827,7 @@ dest_afpipe
935 dest_afpipe_params
936 : string
937 {
938- last_driver = affile_dd_new($1, AFFILE_NO_EXPAND | AFFILE_PIPE);
939+ last_driver = affile_dd_new($1, AFFILE_PIPE);
940 free($1);
941 last_writer_options = &((AFFileDestDriver *) last_driver)->writer_options;
942 last_writer_options->flush_lines = 0;
943@@ -1282,7 +1332,7 @@ filter_fac_list
3c798031
AM
944 ;
945
946 filter_fac
947- : string
eb4e1b63 948+ : string
3c798031
AM
949 {
950 int n = syslog_name_lookup_facility_by_name($1);
951 if (n == -1)
eb4e1b63
AM
952@@ -1461,6 +1511,34 @@ dnsmode
953 string
954 : IDENTIFIER
955 | STRING
956+ | reserved_words_as_strings { $$ = cfg_lex_get_keyword_string($1); }
957+ ;
958+
959+reserved_words_as_strings
960+ /* these keywords were introduced in syslog-ng 3.0 */
961+ : KW_PARSER
962+ | KW_REWRITE
963+ | KW_INCLUDE
964+ | KW_SYSLOG
965+ | KW_COLUMNS
966+ | KW_DELIMITERS
967+ | KW_QUOTES
968+ | KW_QUOTE_PAIRS
969+ | KW_NULL
970+ | KW_CSV_PARSER
971+ | KW_DB_PARSER
972+ | KW_ENCODING
973+ | KW_SET
974+ | KW_SUBST
975+ | KW_VALUE
976+ | KW_PROGRAM_OVERRIDE
977+ | KW_HOST_OVERRIDE
978+ | KW_TRANSPORT
979+ | KW_TRUSTED_KEYS
980+ | KW_TRUSTED_DN
981+ | KW_MESSAGE
982+ | KW_TYPE
983+ | KW_SQL
984 ;
985
986 string_or_number
987@@ -1483,14 +1561,8 @@ extern int linenum;
988 void
989 yyerror(char *msg)
990 {
991- fprintf(stderr, "%s in %s at line %d.\n", msg, configuration->filename, linenum);
992+ fprintf(stderr, "%s in %s at line %d.\n\n"
993+ "syslog-ng documentation: http://www.balabit.com/support/documentation/?product=syslog-ng\n"
994+ "mailing list: https://lists.balabit.hu/mailman/listinfo/syslog-ng\n", msg, cfg_lex_get_current_file(), cfg_lex_get_current_lineno());
995 }
996
997-void
998-yyparser_reset(void)
999-{
1000- last_driver = NULL;
1001- last_reader_options = NULL;
1002- last_writer_options = NULL;
1003- last_template = NULL;
1004-}
1005diff --git a/src/cfg-lex.l b/src/cfg-lex.l
1006index c9db716..dba726a 100644
1007--- a/src/cfg-lex.l
1008+++ b/src/cfg-lex.l
1009@@ -31,6 +31,7 @@
1010
1011 #include <string.h>
1012 #include <strings.h>
1013+#include <sys/stat.h>
1014
1015 struct keyword
1016 {
1017@@ -52,6 +53,7 @@ static struct keyword keywords[] = {
1018 { "destination", KW_DESTINATION },
1019 { "log", KW_LOG },
1020 { "options", KW_OPTIONS },
1021+ { "include", KW_INCLUDE },
1022
1023 /* source or destination items */
1024 { "file", KW_FILE },
1025@@ -162,7 +164,6 @@ static struct keyword keywords[] = {
1026 { "localport", KW_LOCALPORT },
1027 { "port", KW_PORT },
1028 { "destport", KW_DESTPORT },
1029- { "framed", KW_FRAMED },
1030 { "ip_ttl", KW_IP_TTL },
1031 { "ip_tos", KW_IP_TOS },
1032 { "so_broadcast", KW_SO_BROADCAST },
1033@@ -229,7 +230,20 @@ static struct keyword keywords[] = {
1034
1035 #define MAX_REGEXP_LEN 1024
1036
1037-int linenum = 1;
1038+typedef struct _CfgIncludeLevel
1039+{
1040+ GSList *files;
1041+ gchar *current_file;
1042+ gint linenum;
1043+ struct yy_buffer_state *yybuf;
1044+} CfgIncludeLevel;
1045+
1046+#define MAX_INCLUDE_DEPTH 16
1047+
1048+static CfgIncludeLevel include_stack[MAX_INCLUDE_DEPTH];
1049+static gint include_depth = 0;
1050+
1051+
1052 int lex_filter_params = 0;
1053 char buf[MAX_REGEXP_LEN];
1054 char *str;
1055@@ -237,6 +251,7 @@ char *str;
1056 static int check_reserved_words(char *token);
1057 static void append_string(int length, char *str);
1058 static void append_char(char c);
1059+static gboolean cfg_start_next_include(gboolean first_on_this_level);
1060
1061 %}
1062
1063@@ -254,9 +269,10 @@ word [^ \#'"\(\)\{\}\\;\n\t,|\.]
1064 %%
3c798031 1065
eb4e1b63
AM
1066 \#.*$ ;
1067-\r?\n { linenum++; }
1068+\r?\n { include_stack[include_depth].linenum++; }
1069 {white}+ ;
1070 \.\. { return DOTDOT; }
1071+(-|\+)?{digit}+\.{digit}+ { yylval.fnum = strtod(yytext, NULL); return FLOAT; }
1072 0x{digit}+ { yylval.num = strtoll(yytext, NULL, 16); return NUMBER; }
1073 0{digit}+ { yylval.num = strtoll(yytext, NULL, 8); return NUMBER; }
1074 (-|\+)?{digit}+ { yylval.num = strtoll(yytext, NULL, 10); return NUMBER; }
1075@@ -298,16 +314,13 @@ word [^ \#'"\(\)\{\}\\;\n\t,|\.]
1076 return STRING;
1077 }
1078
1079+
1080+<INITIAL><<EOF>> { if (!cfg_start_next_include(FALSE)) yyterminate(); }
3c798031
AM
1081+
1082 %%
eb4e1b63
AM
1083-int
1084-lex_init(FILE *file, gint init_line_num)
1085-{
1086- yyrestart(file);
1087- linenum = init_line_num;
1088- return 0;
1089-}
1090
1091-int
1092+
1093+static int
1094 check_reserved_words(char *token)
1095 {
1096 int i, j;
1097@@ -339,6 +352,7 @@ check_reserved_words(char *token)
1098 break;
1099 }
1100 keywords[i].kw_status = KWS_NORMAL;
1101+ yylval.token = keywords[i].kw_token;
1102 return keywords[i].kw_token;
1103 }
1104 }
1105@@ -364,3 +378,246 @@ append_char(char c)
1106 str++;
1107 *str = 0;
1108 }
1109+
1110+const gchar *
1111+cfg_lex_get_current_file(void)
1112+{
1113+ CfgIncludeLevel *level = &include_stack[include_depth];
1114+
1115+ return level->current_file;
1116+}
1117+
1118+gint
1119+cfg_lex_get_current_lineno(void)
1120+{
1121+ CfgIncludeLevel *level = &include_stack[include_depth];
1122+
1123+ return level->linenum;
1124+}
1125+
1126+char *
1127+cfg_lex_get_keyword_string(int kw)
1128+{
1129+ int i;
1130+ for (i = 0; i < (sizeof(keywords) / sizeof(struct keyword)); i++)
1131+ {
1132+ if (keywords[i].kw_token == kw)
1133+ {
1134+ msg_warning("WARNING: Your configuration uses a newly introduced reserved word as identifier, please use a different name",
1135+ evt_tag_str("keyword", keywords[i].kw_name),
1136+ evt_tag_str("filename", cfg_lex_get_current_file()),
1137+ evt_tag_int("line", cfg_lex_get_current_lineno()),
1138+ NULL);
1139+ return strdup(keywords[i].kw_name);
1140+ }
1141+ }
1142+ g_assert_not_reached();
1143+}
1144+
1145+
1146+
1147+static gboolean
1148+cfg_start_next_include(gboolean first_on_this_level)
1149+{
1150+ FILE *include_file;
1151+ CfgIncludeLevel *level = &include_stack[include_depth];
1152+ gchar *filename;
1153+ struct yy_buffer_state *yybuf;
1154+
1155+ g_assert(level->yybuf == NULL);
1156+
1157+ if (include_depth == 0)
1158+ {
1159+ return FALSE;
1160+ }
1161+
1162+ if (!first_on_this_level)
1163+ {
1164+ msg_debug("Finishing include file",
1165+ evt_tag_str("filename", level->current_file),
1166+ evt_tag_int("depth", include_depth),
1167+ NULL);
1168+ }
1169+
1170+ if (!level->files)
1171+ {
1172+ yybuf = YY_CURRENT_BUFFER;
1173+ g_free(level->current_file);
1174+ level->current_file = NULL;
1175+ include_depth--;
1176+ yy_switch_to_buffer(include_stack[include_depth].yybuf);
1177+ include_stack[include_depth].yybuf = NULL;
1178+ if (!first_on_this_level)
1179+ yy_delete_buffer(yybuf);
1180+
1181+ return TRUE;
1182+ }
1183+
1184+ filename = (gchar *) level->files->data;
1185+ level->files = g_slist_delete_link(level->files, level->files);
1186+
1187+ include_file = fopen(filename, "r");
1188+ if (!include_file)
1189+ {
1190+ msg_error("Error opening include file",
1191+ evt_tag_str("filename", filename),
1192+ evt_tag_int("depth", include_depth),
1193+ NULL);
1194+ g_free(filename);
1195+ return FALSE;
1196+ }
1197+ msg_debug("Starting to read include file",
1198+ evt_tag_str("filename", filename),
1199+ evt_tag_int("depth", include_depth),
1200+ NULL);
1201+ if (level->current_file)
1202+ g_free(level->current_file);
1203+ level->current_file = filename;
1204+ level->linenum = 1;
1205+
1206+ yybuf = YY_CURRENT_BUFFER;
1207+ yy_switch_to_buffer(yy_create_buffer(include_file, YY_BUF_SIZE));
1208+ if (!first_on_this_level)
1209+ yy_delete_buffer(yybuf);
1210+ return TRUE;
1211+}
1212+
1213+gboolean
1214+cfg_lex_process_include(const gchar *filename)
1215+{
1216+ struct stat st;
1217+ gchar buf[1024];
1218+ CfgIncludeLevel *level;
1219+
1220+ if (include_depth >= MAX_INCLUDE_DEPTH - 1)
1221+ {
1222+ msg_error("Include file depth is too deep, increase MAX_INCLUDE_DEPTH and recompile",
1223+ evt_tag_str("filename", filename),
1224+ evt_tag_int("depth", include_depth),
1225+ NULL);
1226+ return FALSE;
1227+ }
1228+
1229+ if (filename[0] != '/')
1230+ {
1231+ g_snprintf(buf, sizeof(buf), "%s/%s", PATH_SYSCONFDIR, filename);
1232+ filename = buf;
1233+ }
1234+
1235+ if (stat(filename, &st) < 0)
1236+ {
1237+ msg_error("Include file/directory not found",
1238+ evt_tag_str("filename", filename),
1239+ evt_tag_errno("error", errno),
1240+ NULL);
1241+ return FALSE;
1242+ }
1243+ include_stack[include_depth].yybuf = YY_CURRENT_BUFFER;
1244+ include_depth++;
1245+ level = &include_stack[include_depth];
1246+ if (S_ISDIR(st.st_mode))
1247+ {
1248+ GDir *dir;
1249+ GError *error = NULL;
1250+ const gchar *entry;
1251+
1252+ dir = g_dir_open(filename, 0, &error);
1253+ if (!dir)
1254+ {
1255+ msg_error("Error opening directory for reading",
1256+ evt_tag_str("filename", filename),
1257+ evt_tag_str("error", error->message),
1258+ NULL);
1259+ goto drop_level;
1260+ }
1261+ while ((entry = g_dir_read_name(dir)))
1262+ {
1263+ const gchar *p;
1264+
1265+ for (p = entry; *p; p++)
1266+ {
1267+ if (!((*p >= 'a' && *p <= 'z') ||
1268+ (*p >= 'A' && *p <= 'Z') ||
1269+ (*p >= '0' && *p <= '9') ||
1270+ (*p == '_') || (*p == '-') || (*p == '.')))
1271+ {
1272+ msg_debug("Skipping include file, does not match pattern [\\-_a-zA-Z0-9]+",
1273+ evt_tag_str("filename", entry),
1274+ NULL);
1275+ p = NULL;
1276+ break;
1277+ }
1278+ }
1279+ if (p)
1280+ {
1281+ gchar *full_filename = g_build_filename(filename, entry, NULL);
1282+ if (stat(full_filename, &st) < 0 || S_ISDIR(st.st_mode))
1283+ {
1284+ msg_debug("Skipping include file as it is a directory",
1285+ evt_tag_str("filename", entry),
1286+ NULL);
1287+ g_free(full_filename);
1288+ continue;
1289+ }
1290+ level->files = g_slist_insert_sorted(level->files, full_filename, (GCompareFunc) strcmp);
1291+ msg_debug("Adding include file",
1292+ evt_tag_str("filename", entry),
1293+ NULL);
1294+ }
1295+ }
1296+ g_dir_close(dir);
1297+ if (!level->files)
1298+ {
1299+ /* no include files in the specified directory */
1300+ msg_debug("No files in this include directory",
1301+ evt_tag_str("dir", filename),
1302+ NULL);
1303+ include_depth--;
1304+ include_stack[include_depth].yybuf = NULL;
1305+ return TRUE;
1306+ }
1307+ }
1308+ else
1309+ {
1310+ g_assert(level->files == NULL);
1311+ level->files = g_slist_prepend(level->files, g_strdup(filename));
1312+ }
1313+ return cfg_start_next_include(TRUE);
1314+ drop_level:
1315+ g_slist_foreach(level->files, (GFunc) g_free, NULL);
1316+ g_slist_free(level->files);
1317+ level->files = NULL;
1318+ return FALSE;
1319+}
1320+
1321+int
1322+cfg_lex_init(FILE *file, gint init_line_num)
1323+{
1324+ CfgIncludeLevel *level;
1325+
1326+ yyrestart(file);
1327+ level = &include_stack[0];
1328+ level->current_file = g_strdup(configuration->filename);
1329+ level->linenum = init_line_num;
1330+ return 0;
1331+}
1332+
1333+void
1334+cfg_lex_deinit(void)
1335+{
1336+ gint i;
1337+
1338+ for (i = 0; i < include_depth; i++)
1339+ {
1340+ CfgIncludeLevel *level = &include_stack[i];
1341+
1342+ if (level->current_file)
1343+ g_free(level->current_file);
1344+
1345+ g_slist_foreach(level->files, (GFunc) g_free, NULL);
1346+ g_slist_free(level->files);
1347+ level->files = NULL;
1348+ if (level->yybuf)
1349+ yy_delete_buffer(level->yybuf);
1350+ }
1351+}
1352diff --git a/src/cfg.c b/src/cfg.c
1353index 23d93b6..45e5119 100644
1354--- a/src/cfg.c
1355+++ b/src/cfg.c
1356@@ -34,6 +34,8 @@
1357 #include "logparser.h"
1358 #include "serialize.h"
1359
1360+#include <sys/types.h>
1361+#include <signal.h>
1362 #include <stdio.h>
1363 #include <string.h>
3c798031 1364
eb4e1b63
AM
1365@@ -203,15 +205,6 @@ cfg_deinit(GlobalConfig *cfg)
1366 return log_center_deinit(cfg->center);
1367 }
1368
1369-/* extern declarations in the generated parser & lexer */
1370-extern FILE *yyin;
1371-extern int yyparse();
1372-extern void lex_init(FILE *, gint lineno);
1373-extern int yydebug;
1374-extern int linenum;
1375-
1376-extern void yyparser_reset(void);
1377-
1378 gboolean
1379 cfg_read_pragmas(GlobalConfig *self, FILE *cfg, gint *lineno)
1380 {
1381@@ -358,8 +351,9 @@ cfg_new(gchar *fname)
1382 self->chain_hostnames = TRUE;
1383 }
1384
1385- lex_init(cfg, lineno);
1386+ cfg_lex_init(cfg, lineno);
1387 res = yyparse();
1388+ cfg_lex_deinit();
1389 fclose(cfg);
1390 if (!res)
1391 {
1392@@ -481,7 +475,15 @@ cfg_reload_config(gchar *fname, GlobalConfig *cfg)
1393 {
1394 msg_error("Error initializing new configuration, reverting to old config", NULL);
1395 cfg_persist_config_move(new_cfg, cfg);
1396- cfg_init(cfg);
1397+ if (!cfg_init(cfg))
1398+ {
1399+ /* hmm. hmmm, error reinitializing old configuration, we're hosed.
1400+ * Best is to kill ourselves in the hope that the supervisor
1401+ * restarts us.
1402+ */
1403+ kill(getpid(), SIGQUIT);
1404+ g_assert_not_reached();
1405+ }
1406 return cfg;
1407 }
1408 }
1409diff --git a/src/cfg.h b/src/cfg.h
1410index d7b4edc..91f3060 100644
1411--- a/src/cfg.h
1412+++ b/src/cfg.h
1413@@ -28,6 +28,7 @@
1414
1415 #include <sys/types.h>
1416 #include <regex.h>
1417+#include <stdio.h>
1418
1419 struct _LogSourceGroup;
1420 struct _LogDestGroup;
1421@@ -148,6 +149,19 @@ void cfg_persist_set_version(GlobalConfig *cfg, const gint version);
1422
1423 void persist_config_free(PersistentConfig *persist);
1424
1425+/* defined in the lexer */
1426+void yyerror(char *msg);
1427+int yylex();
1428+int cfg_lex_init(FILE *file, gint init_line_num);
1429+void cfg_lex_deinit(void);
1430+gboolean cfg_lex_process_include(const gchar *filename);
1431+const gchar *cfg_lex_get_current_file(void);
1432+gint cfg_lex_get_current_lineno(void);
1433+char *cfg_lex_get_keyword_string(int kw);
1434+
1435+/* defined in the parser */
1436+int yyparse(void);
1437+
1438 static inline gboolean
1439 cfg_check_current_config_version(gint req)
1440 {
1441diff --git a/src/filter.c b/src/filter.c
1442index 0d1fe57..3a14fdd 100644
1443--- a/src/filter.c
1444+++ b/src/filter.c
1445@@ -375,6 +375,11 @@ filter_netmask_eval(FilterExprNode *s, LogMessage *msg)
1446 {
1447 addr.s_addr = htonl(INADDR_LOOPBACK);
1448 }
1449+ else
1450+ {
1451+ /* no address information, return FALSE */
1452+ return s->comp;
1453+ }
1454 return ((addr.s_addr & self->netmask.s_addr) == (self->address.s_addr)) ^ s->comp;
1455
1456 }
1457diff --git a/src/gprocess.c b/src/gprocess.c
1458index 5a4a76f..004f57c 100644
1459--- a/src/gprocess.c
1460+++ b/src/gprocess.c
1461@@ -87,7 +87,9 @@ static struct
1462 GProcessMode mode;
1463 const gchar *name;
1464 const gchar *user;
1465+ uid_t uid;
1466 const gchar *group;
1467+ gid_t gid;
1468 const gchar *chroot_dir;
1469 const gchar *pidfile;
1470 const gchar *pidfile_dir;
1471@@ -109,9 +111,15 @@ static struct
1472 .argv = NULL,
1473 .argv_start = NULL,
1474 .argv_env_len = 0,
1475+#ifdef __CYGWIN__
1476+ .fd_limit_min = 256,
1477+#else
1478 .fd_limit_min = 4096,
1479+#endif
1480 .check_period = -1,
1481 .check_fn = NULL,
1482+ .uid = -1,
1483+ .gid = -1
1484 };
1485
1486 #if ENABLE_LINUX_CAPS
1487@@ -255,6 +263,8 @@ g_process_set_user(const gchar *user)
1488 {
1489 if (!process_opts.user)
1490 process_opts.user = user;
1491+
1492+
1493 }
1494
1495 /**
1496@@ -268,6 +278,7 @@ g_process_set_group(const gchar *group)
1497 {
1498 if (!process_opts.group)
1499 process_opts.group = group;
1500+
1501 }
1502
1503 /**
1504@@ -666,35 +677,20 @@ g_process_change_root(void)
1505 static gboolean
1506 g_process_change_user(void)
1507 {
1508- uid_t uid = -1;
1509- gid_t gid = -1;
1510-
1511 #if ENABLE_LINUX_CAPS
1512 if (process_opts.caps)
1513 prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
1514 #endif
1515
1516- if (process_opts.user && !resolve_user(process_opts.user, &uid))
1517- {
1518- g_process_message("Error resolving user; user='%s'", process_opts.user);
1519- return FALSE;
1520- }
1521-
1522- if (process_opts.group && !resolve_group(process_opts.group, &gid))
1523- {
1524- g_process_message("Error resolving group; group='%s'", process_opts.group);
1525- return FALSE;
1526- }
1527-
1528- if ((gint) gid != -1)
1529+ if ((gint) process_opts.gid != -1)
1530 {
1531- if (setgid(gid) < 0)
1532+ if (setgid(process_opts.gid) < 0)
1533 {
1534- g_process_message("Error in setgid(); group='%s', error='%s'", process_opts.group, g_strerror(errno));
1535+ g_process_message("Error in setgid(); group='%s', gid='%d', error='%s'", process_opts.group, (gint) process_opts.gid, g_strerror(errno));
1536 if (getuid() == 0)
1537 return FALSE;
1538 }
1539- if (process_opts.user && initgroups(process_opts.user, gid) < 0)
1540+ if (process_opts.user && initgroups(process_opts.user, process_opts.gid) < 0)
1541 {
1542 g_process_message("Error in initgroups(); user='%s', error='%s'", process_opts.user, g_strerror(errno));
1543 if (getuid() == 0)
1544@@ -702,11 +698,11 @@ g_process_change_user(void)
1545 }
1546 }
1547
1548- if ((gint) uid != -1)
1549+ if ((gint) process_opts.uid != -1)
1550 {
1551- if (setuid(uid) < 0)
1552+ if (setuid(process_opts.uid) < 0)
1553 {
1554- g_process_message("Error in setuid(); user='%s', error='%s'", process_opts.user, g_strerror(errno));
1555+ g_process_message("Error in setuid(); user='%s', uid='%d', error='%s'", process_opts.user, (gint) process_opts.uid, g_strerror(errno));
1556 if (getuid() == 0)
1557 return FALSE;
1558 }
1559@@ -763,6 +759,21 @@ g_process_change_caps(void)
1560
1561 #endif
1562
1563+static void
1564+g_process_resolve_names(void)
1565+{
1566+ if (process_opts.user && !resolve_user(process_opts.user, &process_opts.uid))
1567+ {
1568+ g_process_message("Error resolving user; user='%s'", process_opts.user);
1569+ process_opts.uid = (uid_t) -1;
1570+ }
1571+ if (process_opts.group && !resolve_group(process_opts.group, &process_opts.gid))
1572+ {
1573+ g_process_message("Error resolving group; group='%s'", process_opts.group);
1574+ process_opts.gid = (gid_t) -1;
1575+ }
1576+}
1577+
1578 /**
1579 * g_process_change_dir:
1580 *
1581@@ -1116,6 +1127,7 @@ g_process_start(void)
1582
1583 g_process_detach_tty();
1584 g_process_change_limits();
1585+ g_process_resolve_names();
1586
1587 if (process_opts.mode == G_PM_BACKGROUND)
1588 {
1589diff --git a/src/logmsg.c b/src/logmsg.c
1590index 9bad35f..d7f7558 100644
1591--- a/src/logmsg.c
1592+++ b/src/logmsg.c
1593@@ -264,6 +264,10 @@ log_msg_get_value(LogMessage *self, const gchar *value_name, gssize *length)
1594 return value;
1595 }
1596
1597+/**
1598+ * NOTE: the new_value is taken as a reference, e.g. it'll be assigned to
1599+ * the LogMessage and freed later on.
1600+ **/
1601 void
1602 log_msg_set_value(LogMessage *self, const gchar *value_name, gchar *new_value, gssize length)
1603 {
1604@@ -1065,7 +1069,7 @@ log_msg_parse_version(LogMessage *self, const guchar **data, gint *length)
1605 }
1606
1607 static void
1608-log_msg_parse_legacy_program_name(LogMessage *self, const guchar **data, gint *length)
1609+log_msg_parse_legacy_program_name(LogMessage *self, const guchar **data, gint *length, guint flags)
1610 {
1611 /* the data pointer will not change */
1612 const guchar *src, *prog_start;
1613@@ -1110,6 +1114,11 @@ log_msg_parse_legacy_program_name(LogMessage *self, const guchar **data, gint *l
1614 src++;
1615 left--;
1616 }
1617+ if (flags & LP_STORE_LEGACY_MSGHDR)
1618+ {
1619+ log_msg_set_value(self, "LEGACY_MSGHDR", g_strndup((gchar *) *data, *length - left), *length - left);
1620+ self->flags |= LF_LEGACY_MSGHDR;
1621+ }
1622 *data = src;
1623 *length = left;
1624 }
1625@@ -1573,7 +1582,7 @@ log_msg_parse_legacy(LogMessage *self, const guchar *data, gint length, guint fl
1626 log_msg_parse_skip_chars(self, &src, &left, " ", -1);
1627
1628 /* Try to extract a program name */
1629- log_msg_parse_legacy_program_name(self, &src, &left);
1630+ log_msg_parse_legacy_program_name(self, &src, &left, flags);
1631 }
1632
1633 /* If we did manage to find a hostname, store it. */
1634@@ -1598,7 +1607,7 @@ log_msg_parse_legacy(LogMessage *self, const guchar *data, gint length, guint fl
1635 else
1636 {
1637 /* Capture the program name */
1638- log_msg_parse_legacy_program_name(self, &src, &left);
1639+ log_msg_parse_legacy_program_name(self, &src, &left, flags);
1640 }
1641 self->timestamps[LM_TS_STAMP] = self->timestamps[LM_TS_RECVD];
1642 }
1643@@ -1607,7 +1616,7 @@ log_msg_parse_legacy(LogMessage *self, const guchar *data, gint length, guint fl
1644 self->message_len = left;
1645 if ((flags & LP_VALIDATE_UTF8) && g_utf8_validate((gchar *) src, left, NULL))
1646 self->flags |= LF_UTF8;
1647-
1648+
1649 return TRUE;
1650 }
1651
1652diff --git a/src/logmsg.h b/src/logmsg.h
1653index 17d4b5c..6e0a9be 100644
1654--- a/src/logmsg.h
1655+++ b/src/logmsg.h
1656@@ -47,6 +47,7 @@
1657 #define LP_ASSUME_UTF8 0x0080
1658 #define LP_VALIDATE_UTF8 0x0100
1659 #define LP_NO_MULTI_LINE 0x0200
1660+#define LP_STORE_LEGACY_MSGHDR 0x0400
1661
1662
1663 typedef struct _LogPathOptions LogPathOptions;
1664@@ -97,6 +98,13 @@ enum
1665 LF_OWN_MATCHES = 0x4000,
1666 LF_OWN_ALL = 0x7FF0,
1667 LF_CHAINED_HOSTNAME = 0x8000,
1668+
1669+ /* originally parsed from RFC 3164 format and the legacy message header
1670+ * was saved in $LEGACY_MSGHDR. This flag is a hack to avoid a hash lookup
1671+ * in the fast path and indicates that the parser has saved the legacy
1672+ * message header intact in a value named LEGACY_MSGHDR.
1673+ */
1674+ LF_LEGACY_MSGHDR = 0x00010000,
1675 };
1676
1677 typedef struct _LogMessageSDParam LogMessageSDParam;
1678@@ -129,12 +137,25 @@ typedef struct _LogMessageMatch
1679 guint16 ofs;
1680 guint16 len;
1681 #else
1682+
1683+#if GLIB_SIZEOF_VOID_P == 4
1684+ guint16 ofs;
1685+ guint8 __pad;
1686+ guint8 flags;
1687+ guint16 len;
1688+ guint8 builtin_value;
1689+ guint8 type;
1690+#elif GLIB_SIZEOF_VOID_P == 8
1691 guint16 ofs;
1692 guint16 len;
1693 guint8 builtin_value;
1694 guint8 type;
1695 guint8 __pad;
1696 guint8 flags;
1697+#else
1698+#error "Unknown pointer size"
1699+#endif
1700+
1701 #endif
1702 };
1703 };
1704@@ -156,9 +177,10 @@ struct _LogMessage
1705 */
1706 struct
1707 {
1708- guint16 flags;
1709- guint16 pri;
1710+ guint32 flags;
1711 guint32 message_len;
1712+ guint16 pri;
1713+ /* 6 bytes hole */
1714
1715 LogStamp timestamps[LM_TS_MAX];
1716 gchar * const host;
1717diff --git a/src/logproto.c b/src/logproto.c
1718index b2c30ee..9d7187b 100644
1719--- a/src/logproto.c
1720+++ b/src/logproto.c
1721@@ -8,11 +8,22 @@
1722 gboolean
1723 log_proto_set_encoding(LogProto *self, const gchar *encoding)
1724 {
1725- self->convert = g_iconv_open("utf-8", encoding);
1726 if (self->convert != (GIConv) -1)
1727 {
1728- return FALSE;
1729+ g_iconv_close(self->convert);
1730+ self->convert = (GIConv) -1;
1731+ }
1732+ if (self->encoding)
1733+ {
1734+ g_free(self->encoding);
1735+ self->encoding = NULL;
1736 }
1737+
1738+ self->convert = g_iconv_open("utf-8", encoding);
1739+ if (self->convert == (GIConv) -1)
1740+ return FALSE;
1741+
1742+ self->encoding = g_strdup(encoding);
1743 return TRUE;
1744 }
1745
1746@@ -23,6 +34,8 @@ log_proto_free(LogProto *s)
1747 s->free_fn(s);
1748 if (s->convert != (GIConv) -1)
1749 g_iconv_close(s->convert);
1750+ if (s->encoding)
1751+ g_free(s->encoding);
1752 log_transport_free(s->transport);
1753 g_free(s);
1754 }
1755@@ -159,6 +172,8 @@ struct _LogProtoPlainServer
1756 gsize buffer_size, buffer_end, buffer_pos;
1757 gsize padding_size, max_msg_size;
1758 GSockAddr *prev_saddr;
1759+ gchar raw_buffer_leftover[8];
1760+ gint raw_buffer_leftover_size;
1761 LogProtoStatus status;
1762 };
1763
1764@@ -487,7 +502,8 @@ log_proto_plain_server_fetch(LogProto *s, const guchar **msg, gsize *msg_len, GS
1765 /* if conversion is needed, we first read into an on-stack
1766 * buffer, and then convert it into our internal buffer */
1767
1768- raw_buffer = g_alloca(self->max_msg_size);
1769+ raw_buffer = g_alloca(self->max_msg_size + self->raw_buffer_leftover_size);
1770+ memcpy(raw_buffer, self->raw_buffer_leftover, self->raw_buffer_leftover_size);
1771 if (!self->padding_size)
1772 {
1773 avail = self->max_msg_size;
1774@@ -499,7 +515,7 @@ log_proto_plain_server_fetch(LogProto *s, const guchar **msg, gsize *msg_len, GS
1775 }
1776 }
1777
1778- rc = log_transport_read(self->super.transport, raw_buffer, avail, sa);
1779+ rc = log_transport_read(self->super.transport, raw_buffer + self->raw_buffer_leftover_size, avail, sa);
1780 if (sa && *sa)
1781 self->prev_saddr = *sa;
1782 if (rc < 0)
1783@@ -534,6 +550,13 @@ log_proto_plain_server_fetch(LogProto *s, const guchar **msg, gsize *msg_len, GS
1784 msg_verbose("EOF occurred while reading",
1785 evt_tag_int(EVT_TAG_FD, self->super.transport->fd),
1786 NULL);
1787+ if (self->raw_buffer_leftover_size > 0)
1788+ {
1789+ msg_error("EOF read on a channel with leftovers from previous character conversion, dropping input",
1790+ NULL);
1791+ self->status = LPS_EOF;
1792+ return self->status;
1793+ }
1794 self->status = LPS_EOF;
1795 if (log_proto_plain_server_fetch_from_buf(self, msg, msg_len, TRUE))
1796 {
1797@@ -562,6 +585,9 @@ log_proto_plain_server_fetch(LogProto *s, const guchar **msg, gsize *msg_len, GS
1798 }
1799 else
1800 {
1801+ rc += self->raw_buffer_leftover_size;
1802+ self->raw_buffer_leftover_size = 0;
1803+
1804 /* some data was read */
1805 if (self->super.convert != (GIConv) -1)
1806 {
1807@@ -581,22 +607,62 @@ log_proto_plain_server_fetch(LogProto *s, const guchar **msg, gsize *msg_len, GS
1808 switch (errno)
1809 {
1810 case EINVAL:
1811- /* Incomplete text, do not report an error */
1812+ /* Incomplete text, do not report an error, rather try to read again */
1813+ self->buffer_end = self->buffer_size - avail_out;
1814+
1815+ if (avail_in > 0)
1816+ {
1817+ if (avail_in > sizeof(self->raw_buffer_leftover))
1818+ {
1819+ msg_error("Invalid byte sequence, the remaining raw buffer is larger than the supported leftover size",
1820+ evt_tag_str("encoding", self->super.encoding),
1821+ evt_tag_int("avail_in", avail_in),
1822+ evt_tag_int("leftover_size", sizeof(self->raw_buffer_leftover)),
1823+ NULL);
1824+ self->status = LPS_ERROR;
1825+ return self->status;
1826+ }
1827+ memcpy(self->raw_buffer_leftover, raw_buffer, avail_in);
1828+ self->raw_buffer_leftover_size = avail_in;
1829+ msg_debug("Leftover characters remained after conversion, delaying message until another chunk arrives",
1830+ evt_tag_str("encoding", self->super.encoding),
1831+ evt_tag_int("avail_in", avail_in),
1832+ NULL);
1833+ return LPS_SUCCESS;
1834+ }
1835 break;
1836 case E2BIG:
1837
1838 self->buffer_end = self->buffer_size - avail_out;
1839 /* extend the buffer */
1840- self->buffer_size *= 2;
1841- self->buffer = g_realloc(self->buffer, self->buffer_size);
1842
1843- /* recalculate the out pointer, and add what we have now */
1844- ret = -1;
1845+ if (self->buffer_size < self->max_msg_size * 6)
1846+ {
1847+ self->buffer_size *= 2;
1848+ self->buffer = g_realloc(self->buffer, self->buffer_size);
1849+
1850+ /* recalculate the out pointer, and add what we have now */
1851+ ret = -1;
1852+ }
1853+ else
1854+ {
1855+ msg_error("Incoming byte stream requires a too large conversion buffer, probably invalid character sequence",
1856+ evt_tag_str("encoding", self->super.encoding),
1857+ evt_tag_printf("buffer", "%.*s", self->buffer_end, self->buffer),
1858+ NULL);
1859+ self->status = LPS_ERROR;
1860+ return self->status;
1861+ }
1862 break;
1863 case EILSEQ:
1864 default:
1865- msg_error("Invalid byte sequence or other error while converting input",
1866- NULL);
1867+ msg_notice("Invalid byte sequence or other error while converting input, skipping character",
1868+ evt_tag_str("encoding", self->super.encoding),
1869+ evt_tag_printf("char", "0x%02x", *(guchar *) raw_buffer),
1870+ NULL);
1871+ self->buffer_end = self->buffer_size - avail_out;
1872+ raw_buffer++;
1873+ avail_in--;
1874 break;
1875 }
1876 }
1877diff --git a/src/logproto.h b/src/logproto.h
1878index 8a03d75..f94e5df 100644
1879--- a/src/logproto.h
1880+++ b/src/logproto.h
1881@@ -18,6 +18,7 @@ struct _LogProto
1882 {
1883 LogTransport *transport;
1884 GIConv convert;
1885+ gchar *encoding;
1886 guint flags;
1887 gboolean (*read_state)(LogProto *s, SerializeArchive *archive);
1888 gboolean (*write_state)(LogProto *s, SerializeArchive *archive);
6682c9e6 1889diff --git a/src/logreader.c b/src/logreader.c
eb4e1b63 1890index f9567ff..ca800d0 100644
6682c9e6
AM
1891--- a/src/logreader.c
1892+++ b/src/logreader.c
eb4e1b63
AM
1893@@ -103,7 +103,7 @@ log_reader_fd_prepare(GSource *source,
1894
1895 if (self->reader->flags & LR_FOLLOW)
1896 {
1897- *timeout = self->reader->options->follow_freq * 1000;
1898+ *timeout = self->reader->options->follow_freq;
1899 return FALSE;
1900 }
1901
6682c9e6
AM
1902@@ -167,7 +167,7 @@ log_reader_fd_check(GSource *source)
1903
1904 if (self->reader->follow_filename && stat(self->reader->follow_filename, &followed_st) != -1)
1905 {
1906- if (fd < 0 || st.st_ino != followed_st.st_ino)
eb4e1b63 1907+ if (fd < 0 || (st.st_ino != followed_st.st_ino && followed_st.st_size > 0))
6682c9e6
AM
1908 {
1909 msg_trace("log_reader_fd_check file moved eof",
1910 evt_tag_int("pos", pos),
eb4e1b63
AM
1911@@ -278,6 +278,8 @@ log_reader_fetch_log(LogReader *self, LogProto *proto)
1912 parse_flags |= LP_VALIDATE_UTF8;
1913 if (self->options->options & LRO_NO_MULTI_LINE)
1914 parse_flags |= LP_NO_MULTI_LINE;
1915+ if (self->options->options & LRO_STORE_LEGACY_MSGHDR)
1916+ parse_flags |= LP_STORE_LEGACY_MSGHDR;
1917
1918 if (self->waiting_for_preemption)
1919 may_read = FALSE;
1920@@ -321,7 +323,7 @@ log_reader_fetch_log(LogReader *self, LogProto *proto)
1921 /* no more messages for now */
1922 break;
1923 }
1924- if (msg_len > 0)
1925+ if (msg_len > 0 || (self->options->options & LRO_EMPTY_LINES))
1926 {
1927 msg_count++;
63fcb57e 1928
eb4e1b63
AM
1929@@ -772,6 +774,10 @@ log_reader_options_lookup_flag(const gchar *flag)
1930 return LRO_VALIDATE_UTF8;
1931 if (strcmp(flag, "no-multi-line") == 0 || strcmp(flag, "no_multi_line") == 0)
1932 return LRO_NO_MULTI_LINE;
1933+ if (strcmp(flag, "store-legacy-msghdr") == 0 || strcmp(flag, "store_legacy_msghdr") == 0)
1934+ return LRO_STORE_LEGACY_MSGHDR;
1935+ if (strcmp(flag, "empty-lines") == 0 || strcmp(flag, "empty_lines") == 0)
1936+ return LRO_EMPTY_LINES;
1937 msg_error("Unknown parse flag", evt_tag_str("flag", flag), NULL);
1938 return 0;
1939 }
1940diff --git a/src/logreader.h b/src/logreader.h
1941index 8e5bc7c..11ff0da 100644
1942--- a/src/logreader.h
1943+++ b/src/logreader.h
1944@@ -43,6 +43,8 @@
1945 #define LRO_SYSLOG_PROTOCOL 0x0004
1946 #define LRO_VALIDATE_UTF8 0x0008
1947 #define LRO_NO_MULTI_LINE 0x0010
1948+#define LRO_STORE_LEGACY_MSGHDR 0x0020
1949+#define LRO_EMPTY_LINES 0x0040
1950
1951 typedef struct _LogReaderWatch LogReaderWatch;
1952
1953@@ -77,7 +79,7 @@ typedef struct _LogReader
1954 GSockAddr *peer_addr;
1955 gchar *follow_filename;
1956 ino_t inode;
1957- off_t size;
1958+ gint64 size;
1959
1960 } LogReader;
1961
1962@@ -86,7 +88,7 @@ void log_reader_set_follow_filename(LogPipe *self, const gchar *follow_filename)
1963 void log_reader_set_peer_addr(LogPipe *s, GSockAddr *peer_addr);
1964 void log_reader_set_immediate_check(LogPipe *s);
1965
1966-void log_reader_update_pos(LogReader *self, off_t ofs);
1967+void log_reader_update_pos(LogReader *self, gint64 ofs);
1968 void log_reader_save_state(LogReader *self, SerializeArchive *archive);
1969 void log_reader_restore_state(LogReader *self, SerializeArchive *archive);
1970
1971diff --git a/src/logwriter.c b/src/logwriter.c
1972index bb01148..5f77293 100644
1973--- a/src/logwriter.c
1974+++ b/src/logwriter.c
1975@@ -595,9 +595,20 @@ log_writer_format_log(LogWriter *self, LogMessage *lm, GString *result)
1976 g_string_append_len(result, lm->host, lm->host_len);
1977 g_string_append_c(result, ' ');
1978
1979- g_string_append_len(result, lm->program, lm->program_len);
1980- if (lm->program_len > 0)
1981+ if ((lm->flags & LF_LEGACY_MSGHDR))
1982 {
1983+ gssize length;
1984+ const gchar *msghdr;
1985+
1986+ msghdr = log_msg_get_value(lm, "LEGACY_MSGHDR", &length);
1987+ if (msghdr)
1988+ {
1989+ g_string_append_len(result, msghdr, length);
1990+ }
1991+ }
1992+ else if (lm->program_len > 0)
1993+ {
1994+ g_string_append_len(result, lm->program, lm->program_len);
1995 if (lm->pid_len > 0)
1996 {
1997 g_string_append_c(result, '[');
1998diff --git a/src/main.c b/src/main.c
1999index ba97f0c..f78dcc1 100644
2000--- a/src/main.c
2001+++ b/src/main.c
2002@@ -366,8 +366,6 @@ main(int argc, char *argv[])
2003
2004 g_process_set_name("syslog-ng");
2005
2006-#if ENABLE_LINUX_CAPS
2007-
2008 /* in this case we switch users early while retaining a limited set of
2009 * credentials in order to initialize/reinitialize the configuration.
2010 */
2011@@ -381,27 +379,11 @@ main(int argc, char *argv[])
2012 }
2013 else
63fcb57e 2014 {
eb4e1b63
AM
2015- g_process_startup_ok();
2016+ if (syntax_only)
2017+ g_process_startup_failed(0, TRUE);
2018+ else
2019+ g_process_startup_ok();
63fcb57e 2020 }
eb4e1b63
AM
2021-#else
2022-
2023- /* if Linux capabilities are not compiled in, the initial setup is
2024- * performed as the root user, and then the switch to a limited user
2025- * account is made. This is compatible how syslog-ng behaved before
2026- * capability support.
2027- */
2028-
2029- rc = initial_init(&cfg);
2030- if (rc)
2031- {
2032- return rc;
2033- }
2034- g_process_start();
2035- g_process_startup_ok();
2036-#endif
2037-
2038- if (syntax_only)
2039- return 0;
2040
2041 /* we are running as a non-root user from this point */
2042
2043@@ -424,6 +406,7 @@ main(int argc, char *argv[])
2044 app_shutdown();
2045 tls_deinit();
2046 z_mem_trace_dump();
2047+ g_process_finish();
2048 return rc;
2049 }
2050
2051diff --git a/src/memtrace.c b/src/memtrace.c
2052index ef4729a..eb33f4f 100644
2053--- a/src/memtrace.c
2054+++ b/src/memtrace.c
2055@@ -121,7 +121,7 @@ z_mem_trace_init(gchar *tracefile)
2056 for (i = 0; i < MEMTRACE_HASH_SIZE; i++)
2057 {
2058 mem_trace_hash[i].list = -1;
2059- memset(&mem_trace_hash[i].lock, 0, sizeof(GStaticMutex));
2060+ g_static_mutex_init(&mem_trace_hash[i].lock);
2061 }
2062 old_malloc = dlsym(RTLD_NEXT, "malloc");
2063 old_free = dlsym(RTLD_NEXT, "free");
2064diff --git a/src/misc.c b/src/misc.c
2065index 96fcdd2..364ead6 100644
2066--- a/src/misc.c
2067+++ b/src/misc.c
2068@@ -274,7 +274,7 @@ resolve_user(const char *user, uid_t *uid)
2069 struct passwd *pw;
2070
2071 *uid = 0;
2072- if (*user)
2073+ if (!(*user))
2074 return FALSE;
2075
2076 pw = getpwnam(user);
2077@@ -299,7 +299,7 @@ resolve_group(const char *group, gid_t *gid)
2078 struct group *gr;
2079
2080 *gid = 0;
2081- if (!*group)
2082+ if (!(*group))
2083 return FALSE;
2084
2085 gr = getgrnam(group);
2086diff --git a/src/sgroup.c b/src/sgroup.c
2087index add7ac9..27e863f 100644
2088--- a/src/sgroup.c
2089+++ b/src/sgroup.c
2090@@ -25,8 +25,10 @@
2091 #include "misc.h"
2092 #include "messages.h"
2093 #include "stats.h"
2094+#include "afinter.h"
2095
2096 #include <time.h>
2097+#include <string.h>
2098
2099 static gboolean
2100 log_source_group_init(LogPipe *s)
2101diff --git a/src/templates.c b/src/templates.c
2102index aee1f34..67b8217 100644
2103--- a/src/templates.c
2104+++ b/src/templates.c
2105@@ -339,17 +339,33 @@ log_macro_expand(GString *result, gint id, guint32 flags, gint ts_format, TimeZo
2106 }
2107 break;
2108 case M_MSGHDR:
2109- /* message, complete with program name and pid */
2110- result_append(result, msg->program, msg->program_len, !!(flags & LT_ESCAPE));
2111- if (msg->program_len > 0)
2112+ if ((msg->flags & LF_LEGACY_MSGHDR))
2113 {
2114- if (msg->pid_len > 0)
2115+ gssize length;
2116+ const gchar *msghdr;
2117+
2118+ /* fast path for now, as most messages come from legacy devices */
2119+
2120+ msghdr = log_msg_get_value(msg, "LEGACY_MSGHDR", &length);
2121+ if (msghdr)
2122 {
2123- result_append(result, "[", 1, !!(flags & LT_ESCAPE));
2124- result_append(result, msg->pid, msg->pid_len, !!(flags & LT_ESCAPE));
2125- result_append(result, "]", 1, !!(flags & LT_ESCAPE));
2126+ result_append(result, msghdr, length, !!(flags & LT_ESCAPE));
2127+ }
2128+ }
2129+ else
2130+ {
2131+ /* message, complete with program name and pid */
2132+ result_append(result, msg->program, msg->program_len, !!(flags & LT_ESCAPE));
2133+ if (msg->program_len > 0)
2134+ {
2135+ if (msg->pid_len > 0)
2136+ {
2137+ result_append(result, "[", 1, !!(flags & LT_ESCAPE));
2138+ result_append(result, msg->pid, msg->pid_len, !!(flags & LT_ESCAPE));
2139+ result_append(result, "]", 1, !!(flags & LT_ESCAPE));
2140+ }
2141+ result_append(result, ": ", 2, !!(flags & LT_ESCAPE));
2142 }
2143- result_append(result, ": ", 2, !!(flags & LT_ESCAPE));
2144 }
2145 break;
2146 case M_MESSAGE:
2147@@ -433,6 +449,9 @@ log_macro_expand(GString *result, gint id, guint32 flags, gint ts_format, TimeZo
2148 * local timezone
2149 */
2150 zone_ofs = (zone_info != NULL ? time_zone_info_get_offset(zone_info, stamp->time.tv_sec) : stamp->zone_offset);
2151+ if (zone_ofs == -1)
2152+ zone_ofs = stamp->zone_offset;
2153+
2154 t = stamp->time.tv_sec + zone_ofs;
2155 tm = gmtime_r(&t, &tm_storage);
2156
2157@@ -506,9 +525,6 @@ log_macro_expand(GString *result, gint id, guint32 flags, gint ts_format, TimeZo
2158 }
2159 break;
2160 }
2161-
2162-
2163-
2164 g_assert_not_reached();
2165 break;
2166 }
2167@@ -634,6 +650,9 @@ log_template_compile(LogTemplate *self, GError **error)
2168
2169 g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2170
2171+ if (self->compiled_template)
2172+ return TRUE;
2173+
2174 p = self->template;
2175
2176 while (*p)
2177@@ -754,7 +773,7 @@ log_template_append_format(LogTemplate *self, LogMessage *lm, guint flags, gint
2178
2179 flags |= self->flags;
2180
2181- if (self->compiled_template == NULL && !log_template_compile(self, NULL))
2182+ if (!log_template_compile(self, NULL))
2183 return;
2184
2185 for (p = self->compiled_template; p; p = g_list_next(p))
2186diff --git a/src/tlscontext.c b/src/tlscontext.c
2187index b22b546..c06ec88 100644
2188--- a/src/tlscontext.c
2189+++ b/src/tlscontext.c
2190@@ -102,28 +102,41 @@ tls_session_verify_dn(X509_STORE_CTX *ctx)
2191 }
2192
2193 int
2194-tls_session_verify(int ok, X509_STORE_CTX *ctx)
2195+tls_session_verify(TLSSession *self, int ok, X509_STORE_CTX *ctx)
2196 {
2197+ /* untrusted means that we have to accept the certificate even if it is untrusted */
2198+ if (self->ctx->verify_mode & TVM_UNTRUSTED)
2199+ return 1;
2200+
2201+ /* accept certificate if its fingerprint matches, again regardless whether x509 certificate validation was successful */
2202 if (tls_session_verify_fingerprint(ctx))
2203- return 1; /* success */
63fcb57e 2204+ {
eb4e1b63
AM
2205+ msg_debug("Certificate accepted because its fingerprint is listed", NULL);
2206+ return 1;
2207+ }
2208+
2209+ if (ok && ctx->error_depth != 0 && (ctx->current_cert->ex_flags & EXFLAG_CA) == 0)
2210+ {
2211+ msg_debug("Invalid certificate found in chain, basicConstraints.ca is unset in non-leaf certificate", NULL);
2212+ ctx->error = X509_V_ERR_INVALID_CA;
2213+ return 0;
2214+ }
2215
2216+ /* reject certificate if it is valid, but its DN is not trusted */
2217 if (ok && ctx->error_depth == 0 && !tls_session_verify_dn(ctx))
2218 {
2219+ msg_debug("Certificate valid, but DN constraints were not met, rejecting", NULL);
2220 ctx->error = X509_V_ERR_CERT_UNTRUSTED;
2221- return 0; /* fail */
2222+ return 0;
2223 }
2224-
2225- return ok;
2226-}
2227-
2228-int
2229-tls_session_ignore_errors(int ok, X509_STORE_CTX *ctx)
2230-{
2231 /* if the crl_dir is set in the configuration file but the directory is empty ignore this error */
2232- if (ok == 0 && ctx->error == X509_V_ERR_UNABLE_TO_GET_CRL)
2233- return 1;
2234- else
2235- return ok;
2236+ if (!ok && ctx->error == X509_V_ERR_UNABLE_TO_GET_CRL)
2237+ {
2238+ msg_notice("CRL directory is set but no CRLs found", NULL);
2239+ return 1;
2240+ }
2241+
2242+ return ok;
2243 }
2244
2245 int
2246@@ -132,10 +145,8 @@ tls_session_verify_callback(int ok, X509_STORE_CTX *ctx)
2247 SSL *ssl = X509_STORE_CTX_get_app_data(ctx);
2248 TLSSession *self = SSL_get_app_data(ssl);
2249
2250- ok = tls_session_verify(ok, ctx);
2251+ ok = tls_session_verify(self, ok, ctx);
2252
2253- ok = tls_session_ignore_errors(ok, ctx);
2254-
2255 tls_log_certificate_validation_progress(ok, ctx);
2256
2257 if (self->verify_func)
2258@@ -165,9 +176,6 @@ tls_session_set_verify(TLSSession *self, TLSSessionVerifyFunc verify_func, gpoin
2259 self->verify_func = verify_func;
2260 self->verify_data = verify_data;
2261 self->verify_data_destroy = verify_destroy;
2262-
2263- SSL_set_app_data(self->ssl, self);
2264- SSL_set_verify(self->ssl, SSL_get_verify_mode(self->ssl), tls_session_verify_callback);
2265 }
2266
2267 static TLSSession *
2268@@ -212,11 +220,13 @@ TLSSession *
2269 tls_context_setup_session(TLSContext *self)
2270 {
2271 SSL *ssl;
2272+ TLSSession *session;
2273 gint ssl_error;
2274
2275 if (!self->ssl_ctx)
2276 {
2277 gint verify_mode = 0;
2278+ gint verify_flags = X509_V_FLAG_POLICY_CHECK;
2279
2280 if (self->mode == TM_CLIENT)
2281 self->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
2282@@ -240,7 +250,9 @@ tls_context_setup_session(TLSContext *self)
2283 goto error;
2284
2285 if (self->crl_dir)
2286- X509_VERIFY_PARAM_set_flags(self->ssl_ctx->param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
2287+ verify_flags |= X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL;
2288+
2289+ X509_VERIFY_PARAM_set_flags(self->ssl_ctx->param, verify_flags);
2290
2291 switch (self->verify_mode)
2292 {
2293@@ -254,7 +266,7 @@ tls_context_setup_session(TLSContext *self)
2294 verify_mode = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE;
2295 break;
2296 case TVM_REQUIRED | TVM_UNTRUSTED:
2297- verify_mode = SSL_VERIFY_NONE | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
2298+ verify_mode = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
2299 break;
2300 case TVM_REQUIRED | TVM_TRUSTED:
2301 verify_mode = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
2302@@ -263,7 +275,7 @@ tls_context_setup_session(TLSContext *self)
2303 g_assert_not_reached();
2304 }
2305
2306- SSL_CTX_set_verify(self->ssl_ctx, verify_mode, NULL);
2307+ SSL_CTX_set_verify(self->ssl_ctx, verify_mode, tls_session_verify_callback);
2308 SSL_CTX_set_options(self->ssl_ctx, SSL_OP_NO_SSLv2);
2309 }
2310
2311@@ -273,7 +285,10 @@ tls_context_setup_session(TLSContext *self)
2312 SSL_set_connect_state(ssl);
2313 else
2314 SSL_set_accept_state(ssl);
2315- return tls_session_new(ssl, self);
2316+
2317+ session = tls_session_new(ssl, self);
2318+ SSL_set_app_data(ssl, session);
2319+ return session;
2320
2321 error:
2322 ssl_error = ERR_get_error();
2323diff --git a/src/tlscontext.h b/src/tlscontext.h
2324index ada8e18..568682d 100644
2325--- a/src/tlscontext.h
2326+++ b/src/tlscontext.h
2327@@ -7,7 +7,7 @@
2328
2329 #include "syslog-ng.h"
2330
2331-#ifdef ENABLE_SSL
2332+#if ENABLE_SSL
2333
2334 #include <openssl/ssl.h>
2335
2336@@ -69,6 +69,9 @@ gboolean tls_verify_certificate_name(X509 *cert, const gchar *hostname);
2337
2338 #else
2339
2340+typedef struct _TLSContext TLSContext;
2341+typedef struct _TLSSession TLSSession;
2342+
2343 #define tls_context_new(m)
2344
2345 #endif
2346diff --git a/src/tlstransport.c b/src/tlstransport.c
2347index 608a427..2f07625 100644
2348--- a/src/tlstransport.c
2349+++ b/src/tlstransport.c
2350@@ -1,5 +1,7 @@
2351 #include "tlstransport.h"
2352
2353+#if ENABLE_SSL
2354+
2355 #include "messages.h"
2356
2357 #include <openssl/ssl.h>
2358@@ -149,4 +151,4 @@ log_transport_tls_free_method(LogTransport *s)
2359 log_transport_free_method(s);
2360 }
2361
2362-
2363+#endif
2364diff --git a/tests/functional/func_test.py b/tests/functional/func_test.py
2365index d7af8ff..ffd0fae 100755
2366--- a/tests/functional/func_test.py
2367+++ b/tests/functional/func_test.py
2368@@ -2,6 +2,7 @@
2369
2370 import os, sys, signal, traceback, time, errno
2371 from socket import *
2372+import struct
2373
2374 padding = 'x' * 250
2375 session_counter = 0
2376@@ -39,12 +40,24 @@ class SocketSender(MessageSender):
2377 self.sock = socket(self.family, SOCK_STREAM)
2378
2379 self.sock.connect(self.sock_name)
2380+ self.sock.setsockopt(SOL_SOCKET, SO_SNDTIMEO, struct.pack('ll', 3, 0))
2381+ if self.dgram:
2382+ self.sock.send('')
2383
2384 def sendMessage(self, msg):
2385 line = '%s%s' % (msg, self.terminate_seq)
2386 if self.send_by_bytes:
2387 for c in line:
2388- self.sock.send(c)
2389+ try:
2390+ self.sock.send(c)
2391+ except error, e:
2392+ if e[0] == errno.ENOBUFS:
2393+ print 'got ENOBUFS, sleeping...'
2394+ time.sleep(0.5)
2395+ repeat = True
2396+ else:
2397+ print "hmm... got an error to the 'send' call, maybe syslog-ng is not accepting messages?"
2398+ raise
2399 else:
2400 repeat = True
2401 while repeat:
2402@@ -59,6 +72,9 @@ class SocketSender(MessageSender):
2403 print 'got ENOBUFS, sleeping...'
2404 time.sleep(0.5)
2405 repeat = True
2406+ else:
2407+ print "hmm... got an error to the 'send' call, maybe syslog-ng is not accepting messages?"
2408+ raise
2409
2410 def __str__(self):
2411 if self.family == AF_UNIX:
2412diff --git a/tests/unit/test_logqueue.c b/tests/unit/test_logqueue.c
2413index 6e9dd00..b27f08e 100644
2414--- a/tests/unit/test_logqueue.c
2415+++ b/tests/unit/test_logqueue.c
2416@@ -115,6 +115,91 @@ testcase_zero_diskbuf_alternating_send_acks()
2417 log_queue_free(q);
2418 }
2419
2420+#if 0
2421+
2422+/* no synchronization between the feed/consume threads, therefore it does
2423+ * not succeed reliably. commented out for now, will fix at the next
2424+ * logqueue related threaded issue */
2425+
2426+GStaticMutex threaded_lock = G_STATIC_MUTEX_INIT;
2427+
2428+gpointer
2429+threaded_feed(gpointer st)
2430+{
2431+ LogQueue *q = (LogQueue *) st;
2432+ char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: árvíztűrőtükörfúrógép";
2433+ gint i;
2434+ LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;
2435+ LogMessage *msg;
2436+
2437+ for (i = 0; i < 100000; i++)
2438+ {
2439+ msg = log_msg_new(msg_str, strlen(msg_str), g_sockaddr_inet_new("10.10.10.10", 1010), 0, NULL, -1);
2440+ log_msg_add_ack(msg, &path_options);
2441+ msg->ack_func = test_ack;
2442+
2443+ g_static_mutex_lock(&threaded_lock);
2444+ if (!log_queue_push_tail(q, msg, &path_options))
63fcb57e 2445+ {
eb4e1b63
AM
2446+ fprintf(stderr, "Queue unable to consume enough messages: %d\n", fed_messages);
2447+ return GUINT_TO_POINTER(1);
63fcb57e 2448+ }
eb4e1b63
AM
2449+ g_static_mutex_unlock(&threaded_lock);
2450+ }
2451+ return NULL;
2452+}
2453+
2454+gpointer
2455+threaded_consume(gpointer st)
2456+{
2457+ LogQueue *q = (LogQueue *) st;
2458+ LogMessage *msg;
2459+ LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;
2460+ gboolean success;
2461+ gint i;
2462+
2463+ for (i = 0; i < 100000; i++)
2464+ {
2465+ g_static_mutex_lock(&threaded_lock);
2466+ msg = NULL;
2467+ success = log_queue_pop_head(q, &msg, &path_options, FALSE);
2468+ g_static_mutex_unlock(&threaded_lock);
2469+
2470+ g_assert(!success || (success && msg != NULL));
2471+ if (!success)
63fcb57e 2472+ {
eb4e1b63
AM
2473+ fprintf(stderr, "Queue didn't return enough messages: i=%d\n", i);
2474+ return GUINT_TO_POINTER(1);
63fcb57e 2475+ }
eb4e1b63
AM
2476+
2477+ log_msg_ack(msg, &path_options);
2478+ log_msg_unref(msg);
63fcb57e 2479+ }
eb4e1b63
AM
2480+
2481+ return NULL;
2482+}
2483+
2484+void
2485+testcase_with_threads()
2486+{
2487+ LogQueue *q;
2488+ GThread *thread_feed, *thread_consume;
2489+ gint i;
2490+
2491+ for (i = 0; i < 100; i++)
2492+ {
2493+ q = log_queue_new(100000, 0, 64);
2494+ thread_feed = g_thread_create(threaded_feed, q, TRUE, NULL);
2495+
2496+ thread_consume = g_thread_create(threaded_consume, q, TRUE, NULL);
2497+ g_thread_join(thread_feed);
2498+ g_thread_join(thread_consume);
2499+
2500+ log_queue_free(q);
2501+ }
2502+}
2503+#endif
2504+
2505 int
2506 main()
2507 {
2508diff --git a/tests/unit/test_template.c b/tests/unit/test_template.c
2509index 675b9d6..c499d8d 100644
2510--- a/tests/unit/test_template.c
2511+++ b/tests/unit/test_template.c
2512@@ -18,9 +18,13 @@ testcase(LogMessage *msg, gchar *template, gchar *expected)
2513 {
2514 LogTemplate *templ;
2515 GString *res = g_string_sized_new(128);
2516+ static TimeZoneInfo *tzinfo = NULL;
2517+
2518+ if (!tzinfo)
2519+ tzinfo = time_zone_info_new(NULL);
2520
2521 templ = log_template_new("dummy", template);
2522- log_template_format(templ, msg, LT_ESCAPE, TS_FMT_BSD, NULL, 3, 0, res);
2523+ log_template_format(templ, msg, LT_ESCAPE, TS_FMT_BSD, tzinfo, 3, 0, res);
2524
2525 if (strcmp(res->str, expected) != 0)
63fcb57e 2526 {
eb4e1b63
AM
2527@@ -39,7 +43,7 @@ int
2528 main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
2529 {
2530 LogMessage *msg;
2531- char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: árvíztűrőtükörfúrógép";
2532+ char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]:árvíztűrőtükörfúrógép";
2533 GlobalConfig dummy;
2534
2535 if (argc > 1)
2536@@ -172,6 +176,14 @@ main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
2537 testcase(msg, "$PID", "");
2538 log_msg_unref(msg);
2539
2540+ msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]:árvíztűrőtükörfúrógép";
2541+
2542+ msg = log_msg_new(msg_str, strlen(msg_str), g_sockaddr_inet_new("10.10.10.10", 1010), LP_STORE_LEGACY_MSGHDR, NULL, -1);
2543+
2544+ testcase(msg, "$LEGACY_MSGHDR", "syslog-ng[23323]:");
2545+ testcase(msg, "$MSGHDR", "syslog-ng[23323]:");
2546+ log_msg_unref(msg);
2547+
2548 msg_str = "<132>1 2006-10-29T01:59:59.156+01:00 mymachine evntslog 3535 ID47 [exampleSDID@0 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@0 class=\"high\"] BOMAn application event log entry...";
2549 msg = log_msg_new(msg_str, strlen(msg_str), g_sockaddr_inet_new("10.10.10.10", 1010), LP_SYSLOG_PROTOCOL, NULL, -1);
2550
2551diff --git a/tgz2build/rules b/tgz2build/rules
2552index 57eb338..7f2c776 100644
2553--- a/tgz2build/rules
2554+++ b/tgz2build/rules
2555@@ -3,7 +3,7 @@ STAMPDIR=tgz2build/stamps
2556 DOCDIR=$(PREFIX)/doc
2557
2558
2559-CONFIGURE_OPTS := --prefix $(ZBS_PREFIX) --enable-ssl --enable-dynamic-linking --enable-sql --enable-spoof-source --disable-tcp-wrapper --disable-pcre --with-ld-library-path=$(ZBS_PREFIX)/lib
2560+CONFIGURE_OPTS := --prefix $(ZBS_PREFIX) --enable-ssl --enable-dynamic-linking --enable-sql --enable-spoof-source --disable-tcp-wrapper --disable-pcre --with-ld-library-path=$(ZBS_PREFIX)/lib --with-pidfile-dir=$(ZBS_PREFIX)/var/run
2561 INSTALL:=./install-sh
2562 RPATH=-Wl,-R/opt/syslog-ng/lib
2563
This page took 0.605428 seconds and 4 git commands to generate.