autotest: problem testing daemons, with possible fix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi folks,

I've been using autotest for a couple of years, for unit tests
and overall system systems of large daemons, that daemonize
themselves using the daemon(3) function (originally from 4.4BSD,
also in glibc).

Until now I've been using a workaround for starting the daemon
because "something" was preventing AT_CHECK from determining that
the daemon startup had occurred correctly, so it was hanging in
the check.  Our workaround was a wrapper program which closes all
file descriptors before starting the daemon.

In some spare time recently I decided to debug the problem, because
I'd rather not need to (re)implement the wrapper program for every
application I write.

If I use the attached test program and autotest fragment and
run it, the AT_CHECK "hangs" for 10 seconds (for the sleep(10)),
even though it should exit very quickly as the process
daemonizes itself.

With a bit of poking around with lsof, I confirmed that the
daemon has fd 5 open and having that open in the child appears
to stop the testsuite from detecting that the process is
"finished" (i.e, backgrounded & daemonized).

If I explicitly close fd 5 before running the daemon, it works
as I would expect.  I.e, change
    AT_CHECK([unittest_daemon], [0], [], [])
to
    AT_CHECK([unittest_daemon 5>&-], [0], [], [])

Is there any reason that AT_CHECK doesn't close this fd before
executing the application?
I've attached a patch that performs this, against autoconf-2.68.


I note that this issue previously came up on the autoconf
list in the thread:
    http://lists.gnu.org/archive/html/autoconf/2009-08/msg00002.html
and it didn't seem to me that there was an adequate resolution
at that time.


regards,
Luke.
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	if (-1 == daemon(1, 0))
		exit(1);
	sleep(10);
	exit(0);
}
# $Id$

AT_SETUP([daemon])

AT_CHECK([unittest_daemon], [0], [], [])

AT_CLEANUP
--- lib/autotest/general.m4.orig	2010-11-24 15:44:35.000000000 +1100
+++ lib/autotest/general.m4	2010-11-24 15:45:56.000000000 +1100
@@ -1920,6 +1920,7 @@ AT_xfail
 (
   AS_ECHO(["AT_ordinal. $at_setup_line: testing $at_desc ..."])
   $at_traceon
+  exec AS_MESSAGE_LOG_FD<&-
 m4_undivert([TEST_SCRIPT])dnl Insert the code here
   set +x
   $at_times_p && times >"$at_times_file"

Attachment: pgpMsABzUuBJq.pgp
Description: PGP signature

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux