@@ -446,6 +446,29 @@ wait_rsyslog_startup_pid() {
446446 wait_startup_pid $RSYSLOG_PIDBASE $1 .pid
447447}
448448
449+ # wait until the pid file for rsyslog instance $1 exists and is populated
450+ wait_rsyslog_instance_pid () {
451+ local pidfile=" $RSYSLOG_PIDBASE $1 .pid"
452+ local pid
453+
454+ while : ; do
455+ if [ -s " $pidfile " ]; then
456+ # pid files may not end with a trailing newline, so shell `read`
457+ # can report failure even when it consumed a valid pid.
458+ pid=$( cat " $pidfile " 2> /dev/null)
459+ if [[ " $pid " =~ ^[0-9]+$ ]]; then
460+ break
461+ fi
462+ fi
463+ if [ $( date +%s) -gt $(( TB_STARTTEST + TB_STARTUP_MAX_RUNTIME )) ]; then
464+ printf ' %s ABORT! Timeout waiting on valid pid file %s after %d seconds\n' \
465+ " $( tb_timestamp) " " $pidfile " $TB_STARTUP_MAX_RUNTIME >&2
466+ error_exit 1
467+ fi
468+ $TESTTOOL_DIR /msleep 100
469+ done
470+ }
471+
449472# wait for startup of an arbitrary process
450473# $1 - pid file name
451474# $2 - startup file name (optional, only checked if given)
@@ -1082,7 +1105,8 @@ get_mainqueuesize() {
10821105
10831106# get pid of rsyslog instance $1
10841107getpid () {
1085- printf ' %s' " $( cat $RSYSLOG_PIDBASE $1 .pid) "
1108+ wait_rsyslog_instance_pid " $1 "
1109+ printf ' %s' " $( cat $RSYSLOG_PIDBASE $1 .pid) "
10861110}
10871111
10881112# grep for (partial) content. $1 is the content to check for, $2 the file to check
@@ -1382,6 +1406,7 @@ shutdown_when_empty() {
13821406 echo " RSYSLOG_PIDBASE is EMPTY! - bug in test? (instance $1 )"
13831407 error_exit 1
13841408 fi
1409+ wait_rsyslog_instance_pid " $1 "
13851410 cp $RSYSLOG_PIDBASE $1 .pid $RSYSLOG_PIDBASE $1 .pid.save
13861411 $TESTTOOL_DIR /msleep 500 # wait a bit (think about slow testbench machines!)
13871412 kill $( cat $RSYSLOG_PIDBASE $1 .pid) # note: we do not wait for the actual termination!
@@ -1390,6 +1415,7 @@ shutdown_when_empty() {
13901415# shut rsyslogd down without emptying the queue. $2 is the instance.
13911416shutdown_immediate () {
13921417 pidfile=$RSYSLOG_PIDBASE ${1:- } .pid
1418+ wait_rsyslog_instance_pid " $1 "
13931419 cp $pidfile $pidfile .save
13941420 kill $( cat $pidfile )
13951421}
@@ -1678,6 +1704,7 @@ issue_HUP() {
16781704 else
16791705 sleeptime=1000
16801706 fi
1707+ wait_rsyslog_instance_pid " $1 "
16811708 kill -HUP $( cat $RSYSLOG_PIDBASE $1 .pid)
16821709 printf ' HUP issued to pid %d - waiting for it to become processed\n' \
16831710 $( cat $RSYSLOG_PIDBASE $1 .pid)
0 commit comments