Debian Codegraph @

tests/syslogd.sh

raw
1 #!/bin/sh
2
3 # Copyright (C) 2011-2026 Free Software Foundation, Inc.
4 #
5 # This file is part of GNU Inetutils.
6 #
7 # GNU Inetutils is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # GNU Inetutils is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20 # Tests to establish functionality of SYSLOG daemon.
21 #
22 # Written by Mats Erik Andersson.
23
24 # Prerequisites:
25 #
26 # * Shell: SVR4 Bourne shell, or newer.
27 #
28 # * id(1), kill(1), mktemp(1), netstat(8), uname(1).
29
30
31 # Is usage explanation in demand?
32 #
33 if test "$1" = "-h" || test "$1" = "--help" || test "$1" = "--usage"; then
34 cat <<HERE
35 Test utility for syslogd and logger.
36
37 The following environment variables are used:
38
39 NOCLEAN No clean up of testing directory, if set.
40 VERBOSE Be verbose, if set.
41 OPTIONS Base options to build upon.
42 IU_TESTDIR If set, use this as testing dir. Unless
43 NOCLEAN is also set, any created \$IU_TESTDIR
44 will be erased after the test. A non-existing
45 directory must be named as a template for mktemp(1).
46 OBSCURE If set, make additional tests that are prone to
47 false negatives in some setups lacking full
48 connectivity.
49 REMOTE_LOGHOST Add this host as a receiving loghost.
50 TARGET Receiving IPv4 address.
51 TARGET6 Receiving IPv6 address.
52
53 HERE
54 exit 0
55 fi
56
57 # Step into `tests/', should the invocation
58 # have been made outside of it.
59 #
60 [ -d src ] && [ -f tests/syslogd.sh ] && cd tests/
61
62 . ./tools.sh
63
64 if test -z "${VERBOSE+set}"; then
65 silence=:
66 fi
67
68 # Portability fix for SVR4
69 PWD="${PWD:-`pwd`}"
70 USER="${USER:-`id -u -n`}"
71
72 $need_mktemp || exit_no_mktemp
73 $need_netstat || exit_no_netstat
74
75 # Execution control. Initialise early!
76 #
77 do_cleandir=false
78 do_socket_length=true
79 do_unix_socket=true
80 do_inet_socket=true
81 do_standard_port=true
82
83 # The UNIX socket name length is preset by the system
84 # and is also system dependent.
85 #
86 # A long name consists of 103 or 107 non-NUL characters,
87 # whereas the excessive string contains 104 or 108 characters.
88 # BSD allocates only 104, while Glibc and Solaris admit 108
89 # characters in "sun_path", a count which includes the final NUL.
90
91 iu_socklen_max=104 # BSD flavour!
92
93 IU_OS=`uname -s`
94 if test "$IU_OS" = "Linux" || test "$IU_OS" = "SunOS"; then
95 # Aim at the boundary of 108 characters.
96 iu_socklen_max=108
97 fi
98
99 # The executables under test.
100 #
101 SYSLOGD=${SYSLOGD:-../src/syslogd$EXEEXT}
102 LOGGER=${LOGGER:-../src/logger$EXEEXT}
103
104 if [ ! -x $SYSLOGD ]; then
105 echo "Missing executable '$SYSLOGD'. Failing." >&2
106 exit 77
107 fi
108
109 if [ ! -x $LOGGER ]; then
110 echo "Missing executable '$LOGGER'. Failing." >&2
111 exit 77
112 fi
113
114 if [ $VERBOSE ]; then
115 set -x
116 $SYSLOGD --version | $SED '1q'
117 $LOGGER --version | $SED '1q'
118 fi
119
120 # For file creation below IU_TESTDIR.
121 umask 0077
122
123 # Keep any external assignment of testing directory.
124 # Otherwise a randomisation is included.
125 #
126 : ${IU_TESTDIR:=$PWD/iu_syslog.XXXXXX}
127
128 if [ ! -d "$IU_TESTDIR" ]; then
129 do_cleandir=true
130 IU_TESTDIR="`$MKTEMP -d "$IU_TESTDIR" 2>/dev/null`" ||
131 {
132 echo 'Failed at creating test directory. Aborting.' >&2
133 exit 77
134 }
135 elif expr X"$IU_TESTDIR" : X'[./]\{1,\}$' >/dev/null; then
136 # Eliminating directories: all mixtures of . and / only.
137 echo 'Dangerous input for test directory. Aborting.' >&2
138 exit 77
139 fi
140
141 # The SYSLOG daemon uses four files and one directory.
142 #
143 CONF="$IU_TESTDIR"/syslog.conf
144 CONFD="$IU_TESTDIR"/syslog.d
145 PID="$IU_TESTDIR"/syslogd.pid
146 OUT="$IU_TESTDIR"/messages
147 OUT_NOTICE="$IU_TESTDIR"/notice
148 : ${SOCKET:=$IU_TESTDIR/log}
149
150 mkdir -p "$CONFD"
151
152 # Are we able to write in IU_TESTDIR?
153 # This could happen with preset IU_TESTDIR.
154 #
155 touch "$OUT" || {
156 echo 'No write access in test directory. Aborting.' >&2
157 exit 1
158 }
159
160 # Some automated build environments dig deep chroots, i.e.,
161 # make the paths to this working directory disturbingly long.
162 # Check SOCKET for this calamity.
163 #
164 if test `expr X"$SOCKET" : X".*"` -gt $iu_socklen_max; then
165 do_unix_socket=false
166 cat <<-EOT >&2
167 WARNING! The working directory uses a disturbingly long path.
168 We are not able to construct a UNIX socket on top of it.
169 Therefore disabling socket messaging in this test run.
170 EOT
171 fi
172
173 # Erase the testing directory.
174 #
175 clean_testdir () {
176 if test -f "$PID" && kill -0 "`cat "$PID"`" >/dev/null 2>&1; then
177 kill "`cat "$PID"`" || kill -9 "`cat "$PID"`"
178 fi
179 if test -z "${NOCLEAN+no}" && $do_cleandir; then
180 rm -r -f "$IU_TESTDIR"
181 fi
182 if $do_socket_length && test -d "$IU_TMPDIR"; then
183 rmdir "$IU_TMPDIR" # Should be empty.
184 fi
185 }
186
187 # Clean artifacts as execution stops.
188 #
189 trap clean_testdir EXIT HUP INT QUIT TERM
190
191 # Test at this port.
192 # Standard is syslog at 514/udp.
193 PROTO=udp
194 PORT=${PORT:-514}
195
196 # locate_port proto port
197 #
198 locate_port () {
199 if [ "`uname -s`" = "SunOS" ]; then
200 $NETSTAT -na -finet -finet6 -P$1 |
201 $GREP "\.$2[^0-9]" >/dev/null 2>&1
202 else
203 $NETSTAT -na |
204 $GREP "^$1[46]\{0,2\}.*[^0-9]$2[^0-9]" >/dev/null 2>&1
205 fi
206 }
207
208 # Receivers for INET sockets.
209 : ${TARGET:=127.0.0.1}
210 : ${TARGET6:=::1}
211
212 # For testing of critical lengths for UNIX socket names,
213 # we need a well defined base directory; choose $TMPDIR.
214 IU_TMPDIR=${TMPDIR:=/tmp}
215
216 if test ! -d "$IU_TMPDIR"; then
217 do_socket_length=false
218 cat <<-EOT >&2
219 WARNING! Disabling socket length test since the directory
220 "$IU_TMPDIR", for temporary storage, does not exist.
221 EOT
222 else
223 # Append a slash if it is missing.
224 expr X"$IU_TMPDIR" : X'.*/$' >/dev/null || IU_TMPDIR="$IU_TMPDIR/"
225
226 IU_TMPDIR="`$MKTEMP -d "${IU_TMPDIR}iu.XXXXXX" 2>/dev/null`" ||
227 { # Directory creation failed. Disable test.
228 cat <<-EOT >&2
229 WARNING! Unable to create temporary directory below
230 "${TMPDIR:-/tmp}" for socket length test.
231 Now disabling this subtest.
232 EOT
233 do_socket_length=false
234 }
235 fi
236
237 iu_eighty=0123456789
238 iu_eighty=${iu_eighty}${iu_eighty}
239 iu_eighty=${iu_eighty}${iu_eighty}
240 iu_eighty=${iu_eighty}${iu_eighty}
241
242 # This good name base will be expanded.
243 IU_GOOD_BASE=${IU_TMPDIR}/_iu
244
245 # Add a single character to violate the size condition.
246 IU_BAD_BASE=${IU_TMPDIR}/X_iu
247
248 if test `expr X"$IU_GOOD_BASE" : X".*"` -gt $iu_socklen_max; then
249 # Maximum socket length is already less than prefix.
250 echo 'WARNING! Disabling socket length test. Too long base name' >&2
251 do_socket_length=false
252 fi
253
254 if $do_socket_length; then
255 # Compute any patching needed to get socket names
256 # touching the limit of allowed length.
257 iu_patch=''
258 iu_pt="$IU_GOOD_BASE" # Computational helper.
259
260 if test `expr X"$iu_pt$iu_eighty" : X".*"` -le $iu_socklen_max; then
261 iu_patch="$iu_patch$iu_eighty" && iu_pt="$iu_pt$iu_eighty"
262 fi
263
264 count=`expr X"$iu_pt" : X".*"`
265 count=`expr $iu_socklen_max - $count`
266
267 # $count gives the number, and $iu_eighty the characters.
268 if test $count -gt 0; then
269 iu_patch="$iu_patch`expr X"$iu_eighty" : X"\(.\{1,$count\}\)"`"
270 fi
271
272 IU_LONG_SOCKET="$IU_GOOD_BASE$iu_patch"
273 IU_EXCESSIVE_SOCKET="$IU_BAD_BASE$iu_patch"
274 fi
275
276 # All messages intended for post-detection are
277 # to be uniformly tagged.
278 TAG="syslogd-test"
279
280 # Remove old files in use by daemon.
281 rm -f "$OUT" "$OUT_NOTICE" "$PID" "$CONF"
282
283 # Full testing at the standard port needs a superuser.
284 # Randomise if necessary to get an underprivileged port.
285 test `func_id_uid` = 0 || do_standard_port=false
286
287 if test `func_id_uid` != 0 && test $PORT -le 1023; then
288 $silence cat <<-EOT >&2
289 WARNING!! The preset port $PORT/$PROTO is not usable,
290 since you are underprivileged. Now attempting
291 a randomised higher port.
292 EOT
293 PORT=`expr $PORT + 3917 + ${RANDOM:-$$} % 2711`
294 fi
295
296 # Is the INET port already in use? If so,
297 # randomise somewhat.
298 if locate_port $PROTO $PORT; then
299 echo "Port $PORT/$PROTO is in use. Randomising port somewhat." >&2
300 PORT=`expr $PORT + 2711 + ${RANDOM:-$$} % 917`
301 fi
302
303 # Test a final time.
304 if locate_port $PROTO $PORT; then
305 cat <<-EOT >&2
306 The INET port $PORT/$PROTO is already in use.
307 Skipping test of INET socket this time.
308 EOT
309 do_inet_socket=false
310 fi
311
312 # A minimal, catch-all configuration, with some discarded oddities.
313 #
314 cat > "$CONF" <<-EOT
315 *.* $OUT
316 # Test the removal of leading blanks and correct line wrapping.
317 *.notice \\
318 $OUT_NOTICE
319 # Empty priority and action.
320 12345
321 # Missing action.
322 *.*
323 # Empty priority.
324 *. /dev/null
325 # Priority out of range.
326 user.8 /dev/null
327 # Unknown facility.
328 bom.7 /dev/null
329 # Facility out of range for all known systems.
330 512.err /dev/null
331 EOT
332
333 # Add a user recipient in verbose mode.
334 $silence false || echo "*.* $USER" >> "$CONF"
335
336 # Testing a remote log host known not to exist,
337 # will introduce sizable timeout. We avoid it
338 # unless told to include this test, based on
339 # OBSCURE in our environment.
340 if [ -n "$OBSCURE" ]; then
341 # Append an invalid recipient.
342 cat >> "$CONF" <<-EOT
343 # Test incorrect forwarding.
344 *.* @not.in.existence
345 EOT
346 fi
347
348 # Set REMOTE_LOGHOST to activate forwarding
349 #
350 if [ -n "$REMOTE_LOGHOST" ]; then
351 # Append a forwarding stanza.
352 cat >> "$CONF" <<-EOT
353 # Forwarding remotely
354 *.* @$REMOTE_LOGHOST
355 EOT
356 fi
357
358 # Attempt to start the server after first
359 # building the desired option list.
360 #
361 ## Base configuration.
362 IU_OPTIONS="--rcfile='$CONF' --rcdir='$CONFD' --pidfile='$PID'"
363 if $do_unix_socket; then
364 IU_OPTIONS="$IU_OPTIONS --socket='$SOCKET'"
365 else
366 # The empty string will disable the standard socket.
367 IU_OPTIONS="$IU_OPTIONS --socket=''"
368 fi
369 if $do_socket_length; then
370 IU_OPTIONS="$IU_OPTIONS -a '$IU_LONG_SOCKET' -a '$IU_EXCESSIVE_SOCKET'"
371 fi
372
373 ## Enable INET service when possible.
374 if $do_inet_socket; then
375 IU_OPTIONS="$IU_OPTIONS --ipany --inet -B$PORT --hop"
376 fi
377 ## Bring in additional options from command line.
378 ## Disable kernel messages otherwise.
379 if [ -c /dev/klog ]; then
380 : OPTIONS=${OPTIONS:=--no-klog}
381 fi
382 IU_OPTIONS="$IU_OPTIONS $OPTIONS"
383
384 # The eval-construct allows white space in file names,
385 # based on the use of single quotes in IU_OPTIONS.
386 eval $SYSLOGD $IU_OPTIONS
387
388 # Wait a moment in order to avoid an obvious
389 # race condition with the server daemon on
390 # slow systems.
391 #
392 sleep 1
393
394 # Test to see whether the service got started.
395 #
396 if [ ! -r "$PID" ]; then
397 echo "The service daemon never started. Failing." >&2
398 exit 1
399 fi
400
401 # Declare the number of implemented tests,
402 # as well as an exit code.
403 #
404 TESTCASES=0
405 SUCCESSES=0
406 EXITCODE=1
407
408 # Check that the excessively long UNIX socket name was rejected.
409 if $do_socket_length; then
410 TESTCASES=`expr $TESTCASES + 1`
411 # Messages can be truncated in the message log, so make a best
412 # effort to limit the length of the string we are searching for.
413 # Allowing 55 characters for IU_BAD_BASE is almost aggressive.
414 # A host name of length six would allow 64 characters
415 pruned=`expr "UNIX socket name too long.*${IU_BAD_BASE}" : '\(.\{1,82\}\)'`
416 if $GREP "$pruned" "$OUT" >/dev/null 2>&1; then
417 SUCCESSES=`expr $SUCCESSES + 1`
418 fi
419 fi
420
421 # Send messages on two sockets: IPv4 and UNIX.
422 #
423 if $do_unix_socket; then
424 TESTCASES=`expr $TESTCASES + 1`
425 $LOGGER -h "$SOCKET" -p user.info -t "$TAG" \
426 "Sending BSD message. (pid $$)"
427 fi
428
429 if $do_socket_length; then
430 TESTCASES=`expr $TESTCASES + 1`
431 $LOGGER -h "$IU_LONG_SOCKET" -p user.info \
432 -t "$TAG" "Sending via long socket name. (pid $$)"
433 fi
434
435 if $do_inet_socket; then
436 if test "$TEST_IPV4" != "no" && test -n "$TARGET"; then
437 TESTCASES=`expr $TESTCASES + 1`
438 $LOGGER -4 -h "$TARGET:$PORT" -p user.info -t "$TAG" \
439 "Sending IPv4 message. (pid $$)"
440 fi # TEST_IPV4 && TARGET
441
442 if test "$TEST_IPV6" != "no" && test -n "$TARGET6"; then
443 TESTCASES=`expr $TESTCASES + 1`
444 $LOGGER -6 -h "[$TARGET6]:$PORT" -p user.info -t "$TAG" \
445 "Sending IPv6 message. (pid $$)"
446 fi # TEST_IPV6 && TARGET6
447 fi # do_inet_socket
448
449 # Send message of priority notice, via local socket, IPv4, or IPv6,
450 # whatever is there. The presence is checked in $OUT and in $OUT_NOTICE,
451 # so merit value is 2 for each placed message.
452 COUNT_WRAP=0
453
454 if $do_unix_socket; then
455 TESTCASES=`expr $TESTCASES + 2`
456 COUNT_WRAP=`expr $COUNT_WRAP + 1`
457 $LOGGER -h "$SOCKET" -p daemon.notice -t "$TAG" \
458 "Attempting to locate wrapped unix configuration. (pid $$)"
459 fi # do_unix_socket
460
461 if $do_inet_socket; then
462 if test "$TEST_IPV4" != "no" && test -n "$TARGET"; then
463 TESTCASES=`expr $TESTCASES + 2`
464 COUNT_WRAP=`expr $COUNT_WRAP + 1`
465 $LOGGER -4 -h "$TARGET:$PORT" -p daemon.notice -t "$TAG" \
466 "Attempting to locate wrapped IPv4 configuration. (pid $$)"
467 fi # TEST_IPV4 && TARGET
468
469 if test "$TEST_IPV6" != "no" && test -n "$TARGET6"; then
470 TESTCASES=`expr $TESTCASES + 2`
471 COUNT_WRAP=`expr $COUNT_WRAP + 1`
472 $LOGGER -6 -h "[$TARGET6]:$PORT" -p daemon.notice -t "$TAG" \
473 "Attempting to locate wrapped IPv6 configuration. (pid $$)"
474 fi # TEST_IPV6 && TARGET6
475 fi # do_inet_socket
476
477 # Generate a more elaborate message routing, aimed at confirming
478 # discrimination of severity and facility. This is made active
479 # by sending SIGHUP to the server process.
480 #
481 OUT_UNOTICE="$IU_TESTDIR"/usernotice.log
482 OUT_USER="$IU_TESTDIR"/user.log
483 OUT_DEBUG="$IU_TESTDIR"/debug.log
484 OUT_LOCAL0="$IU_TESTDIR"/local0.log
485
486 # Create the new files to avoid false negatives.
487 : > "$OUT_UNOTICE"
488 : > "$OUT_USER"
489 : > "$OUT_DEBUG"
490 : > "$OUT_LOCAL0"
491
492 cat > "$CONF" <<-EOT
493 *.* $OUT
494 user.=info $OUT_USER
495 user.=notice $OUT_UNOTICE
496 EOT
497
498 cat > "$CONFD/debug" <<-EOT
499 *.=debug $OUT_DEBUG
500 EOT
501
502 cat > "$CONFD/local0" <<-EOT
503 local0.=notice $OUT_LOCAL0
504 EOT
505
506 # Use another tag for better discrimination.
507 TAG2="syslogd-reload-test"
508
509 # Load the new configuration
510 kill -HUP `cat "$PID"`
511 sleep 2
512
513 if $do_unix_socket; then
514 # Two messages of weight 2, ensuring that missing
515 # and misplaced messages are not yielding negatives.
516 TESTCASES=`expr $TESTCASES + 4`
517 $LOGGER -h "$SOCKET" -p user.info -t "$TAG2" \
518 "user.info as BSD message. (pid $$)"
519 $LOGGER -h "$SOCKET" -p user.debug -t "$TAG2" \
520 "user.debug as BSD message. (pid $$)"
521
522 # Numerical priority:
523 # user.info = (1 << 3).6 = 8.6
524 TESTCASES=`expr $TESTCASES + 2`
525 $LOGGER -h "$SOCKET" -p 8.6 -t "$TAG2" \
526 "user.info using numerical priority. (pid $$)"
527
528 # Numerical facility and default priority:
529 # local0.notice = (16 << 3).5 = 128.5
530 TESTCASES=`expr $TESTCASES + 2`
531 $LOGGER -h "$SOCKET" -p 128 -t "$TAG2" \
532 "local0.notice using numerical facility. (pid $$)"
533
534 # Default facility and priority:
535 # user.notice
536 TESTCASES=`expr $TESTCASES + 2`
537 $LOGGER -h "$SOCKET" -t "$TAG2" \
538 "Default facility in BSD message. (pid $$)"
539
540 # A message of facility `kern' from a user process should
541 # be rewritten for `user' by SYSLOGD.
542 TESTCASES=`expr $TESTCASES + 2`
543 $LOGGER -h "$SOCKET" -t "$TAG2" \
544 "Fake kern facility in BSD message. (pid $$)"
545
546 # An undefined facility should be rewritten for the default
547 # facility `user' by SYSLOGD. Typically, LOG_NFACILITIES
548 # is 24, while LOG_FACMASK is 1016, so a value in excess
549 # of (24 << 8), i.e., 192 is sufficient.
550 # The priority `info' will be overwritten as `notice'.
551 TESTCASES=`expr $TESTCASES + 2`
552 $LOGGER -h "$SOCKET" -p 512.info -t "$TAG2" \
553 "Illegal facility in BSD message. (pid $$)"
554 fi # do_unix_socket
555
556 if $do_inet_socket; then
557 # Two messages of weight 2, ensuring that missing
558 # and misplaced messages are not yielding negatives.
559 if test "$TEST_IPV4" != "no" && test -n "$TARGET"; then
560 TESTCASES=`expr $TESTCASES + 4`
561 $LOGGER -4 -h "$TARGET:$PORT" -p user.info -t "$TAG2" \
562 "user.info as IPv4 message. (pid $$)"
563 $LOGGER -4 -h "$TARGET:$PORT" -p user.debug -t "$TAG2" \
564 "user.debug as IPv4 message. (pid $$)"
565 fi # TEST_IPV4 && TARGET
566
567 if test "$TEST_IPV6" != "no" && test -n "$TARGET6"; then
568 TESTCASES=`expr $TESTCASES + 4`
569 $LOGGER -6 -h "[$TARGET6]:$PORT" -p user.info -t "$TAG2" \
570 "user.info as IPv6 message. (pid $$)"
571 $LOGGER -6 -h "[$TARGET6]:$PORT" -p user.debug -t "$TAG2" \
572 "user.debug as IPv6 message. (pid $$)"
573 fi # TEST_IPV6 && TARGET6
574 fi # do_inet_socket
575
576 # Remove previous SYSLOG daemon.
577 test -r "$PID" && kill -0 "`cat "$PID"`" >/dev/null 2>&1 &&
578 kill "`cat "$PID"`"
579
580 # Check functionality of standard port, i.e., execution
581 # where neither syslogd nor logger have been instructed
582 # to use specific ports for inet sockets.
583 #
584 locate_port $PROTO 514 && do_standard_port=false
585
586 if $do_standard_port; then
587 echo 'Checking also standard port 514/udp.' >&2
588
589 # New configuration, but continuing old message file.
590 rm -f "$PID"
591 cat > "$CONF" <<-EOT
592 *.* $OUT
593 EOT
594
595 # Only INET socket, no UNIX socket.
596 $SYSLOGD --rcfile="$CONF" --pidfile="$PID" --socket='' \
597 --inet --ipany $OPTIONS
598 sleep 1
599
600 if test "$TEST_IPV4" != "no" && test -n "$TARGET"; then
601 TESTCASES=`expr $TESTCASES + 1`
602 $LOGGER -4 -h "$TARGET" -p user.info -t "$TAG" \
603 "IPv4 to standard port. (pid $$)"
604 fi # TEST_IPV4 && TARGET
605
606 if test "$TEST_IPV6" != "no" && test -n "$TARGET6"; then
607 TESTCASES=`expr $TESTCASES + 1`
608 $LOGGER -6 -h "[$TARGET6]" -p user.info -t "$TAG" \
609 "IPv6 to standard port. (pid $$)"
610 fi # TEST_IPV6 && TARGET6
611 fi # do_standard_port
612
613 # Delay detection due to observed race condition.
614 sleep 3
615
616 # Detection of registered messages.
617 #
618 # Initial message logging.
619 COUNT=`$GREP -c "$TAG" "$OUT"`
620
621 # All notices in $OUT_NOTICE should be present also in $OUT.
622 # Assign value 1 to full outcome.
623 COUNT_NOTICE=`$SED -n '$=' "$OUT_NOTICE"`
624 wrapped=`$FGREP -c -f "$OUT_NOTICE" "$OUT"`
625
626 # Provoke a later total miscount, if message counts do not match now.
627 if $do_unix_socket || $do_inet_socket; then
628 test $COUNT_NOTICE -eq $wrapped ||
629 COUNT_WRAP=`expr $COUNT_WRAP - $COUNT_NOTICE + $wrapped`
630 fi
631
632 # Second set-up after SIGHUP.
633 COUNT2=`$GREP -c "$TAG2" "$OUT_USER"`
634 COUNT3=`$GREP -c "$TAG2" "$OUT_DEBUG"`
635 COUNT4=`$EGREP -c "$TAG2.*(Default|Fake kern|Illegal) facility" \
636 "$OUT_UNOTICE"`
637 COUNT5=`$GREP -c "$TAG2" "$OUT_LOCAL0"`
638
639 # No debug message should enter with selector 'user.info'.
640 COUNT2_debug=`$GREP -c "$TAG2.*user.debug" "$OUT_USER"`
641
642 # No info message should enter with selector '*.=debug'.
643 COUNT3_info=`$GREP -c "$TAG2.*user.info" "$OUT_DEBUG"`
644
645 # No info or debug message should enter with selector 'user.=notice'.
646 COUNT4_notice=`$EGREP -c "$TAG2.*user.(info|debug)" \
647 "$OUT_UNOTICE"`
648 # Undefined facility should overwrite also the priority.
649 COUNT4_illegal=`$GREP -c "$TAG2.*Illegal facility" "$OUT_USER"`
650
651 # No user message should enter with selector 'local0', and conversely.
652 COUNT5_user=`$GREP -c "$TAG2.*user" "$OUT_LOCAL0"`
653 COUNT5_local=`cat "$OUT_USER" "$OUT_UNOTICE" "$OUT_DEBUG" | \
654 $GREP -c "$TAG2.*local0"`
655
656 SUCCESSES=`expr $SUCCESSES + $COUNT + $COUNT_WRAP \
657 + 2 \* $COUNT2 - $COUNT2_debug \
658 + 2 \* $COUNT3 - $COUNT3_info \
659 + 2 \* $COUNT4 - $COUNT4_notice - $COUNT4_illegal \
660 + 2 \* $COUNT5 - $COUNT5_user - $COUNT5_local`
661
662 if [ -n "${VERBOSE+yes}" ]; then
663 cat <<-EOT
664 ---------- Successfully detected messages. ----------
665 `$GREP "$TAG" "$OUT"`
666 `$GREP -h "$TAG2" "$OUT_UNOTICE" "$OUT_USER" "$OUT_DEBUG" \
667 "$OUT_LOCAL0"`
668 ---------- Full message log for syslogd. ------------
669 `cat "$OUT"`
670 ---------- Notices during first stage. --------------
671 `cat "$OUT_NOTICE"`
672 ---------- User notice message log. -----------------
673 `cat "$OUT_UNOTICE"`
674 ---------- User info message log. -------------------
675 `cat "$OUT_USER"`
676 ---------- Debug message log. -----------------------
677 `cat "$OUT_DEBUG"`
678 ---------- Local0 message log. ----------------------
679 `cat "$OUT_LOCAL0"`
680 -----------------------------------------------------
681 EOT
682 fi
683
684 test $SUCCESSES -eq $TESTCASES && $silence false \
685 || echo "Registered $SUCCESSES successes out of $TESTCASES."
686
687 # Report incomplete test setup.
688 $do_inet_socket ||
689 echo 'NOTICE: Port specified INET socket test was not run' >&2
690 $do_standard_port ||
691 echo 'NOTICE: Standard port test was not run.' >&1
692
693 if [ "$SUCCESSES" -eq "$TESTCASES" ]; then
694 $silence echo "Successful testing."
695 EXITCODE=0
696 else
697 echo "Failing some tests."
698 # Tell about the symptoms.
699
700 # local socket transport
701 if $do_unix_socket; then
702 if $GREP "$TAG2.*info.*BSD" "$OUT_USER" >/dev/null 2>&1; then
703 :
704 else
705 echo >&2 '** UDP socket did not convey info msg after HUP.'
706 fi
707 if $GREP "$TAG2.*debug.*BSD" "$OUT_DEBUG" >/dev/null 2>&1; then
708 :
709 else
710 echo >&2 '** UDP socket did not convey debug msg after HUP.'
711 fi
712 fi # do_unix_socket
713
714 # UDP transport
715 if $do_inet_socket; then
716 if $GREP "$TAG2.*info.*IPv" "$OUT_USER" >/dev/null 2>&1; then
717 :
718 else
719 echo >&2 '** IP socket did not convey info msg after HUP.'
720 fi
721 if $GREP "$TAG2.*debug.*IPv" "$OUT_DEBUG" >/dev/null 2>&1; then
722 :
723 else
724 echo >&2 '** IP socket did not convey debug msg after HUP.'
725 fi
726 fi # do_inet_socket
727
728 # Automated build robots fail regularly at registering
729 # any messages in the debug file.
730 if test ! -s "$OUT_USER"; then
731 echo >&2 '**** The file "user.log" was empty. Investigate! ****'
732 fi
733 if test ! -s "$OUT_DEBUG"; then
734 echo >&2 '**** The file "debug.log" was empty. Investigate! ****'
735 fi
736 fi
737
738 # Remove the daemon process.
739 test -r "$PID" && kill -0 "`cat "$PID"`" >/dev/null 2>&1 &&
740 kill "`cat "$PID"`"
741
742 exit $EXITCODE