diff options
author | Eric Blake <eblake@redhat.com> | 2010-12-21 11:49:49 -0700 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2010-12-21 11:49:49 -0700 |
commit | c7f28dec60bcbaf95f5a419bb5a9cb5197089253 (patch) | |
tree | 50d4b4cf160e567ff15aab7c352a8186072342f1 /tests/commandtest.c | |
parent | build: skip vmware driver when building for RHEL (diff) | |
download | libvirt-c7f28dec60bcbaf95f5a419bb5a9cb5197089253.tar.gz libvirt-c7f28dec60bcbaf95f5a419bb5a9cb5197089253.tar.bz2 libvirt-c7f28dec60bcbaf95f5a419bb5a9cb5197089253.zip |
command: avoid hanging on daemon processes
* src/util/command.c (virCommandRun): Don't capture output on
daemons.
* tests/commandtest.c (test18): Expose the bug.
Reported by Laine Stump.
Diffstat (limited to 'tests/commandtest.c')
-rw-r--r-- | tests/commandtest.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/commandtest.c b/tests/commandtest.c index 333dd4d57..38a78166b 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -668,6 +668,47 @@ cleanup: return ret; } +/* + * Run long-running daemon, to ensure no hang. + */ +static int test18(const void *unused ATTRIBUTE_UNUSED) +{ + virCommandPtr cmd = virCommandNewArgList("sleep", "100", NULL); + char *pidfile = virFilePid(abs_builddir, "commandhelper"); + pid_t pid; + int ret = -1; + + if (!pidfile) + goto cleanup; + + virCommandSetPidFile(cmd, pidfile); + virCommandDaemonize(cmd); + + alarm(5); + if (virCommandRun(cmd, NULL) < 0) { + virErrorPtr err = virGetLastError(); + printf("Cannot run child %s\n", err->message); + goto cleanup; + } + alarm(0); + + if (virFileReadPid(abs_builddir, "commandhelper", &pid) != 0) { + printf("cannot read pidfile\n"); + goto cleanup; + } + while (kill(pid, SIGINT) != -1) + usleep(100*1000); + + ret = 0; + +cleanup: + virCommandFree(cmd); + unlink(pidfile); + VIR_FREE(pidfile); + return ret; +} + + static int mymain(int argc, char **argv) { @@ -732,6 +773,7 @@ mymain(int argc, char **argv) DO_TEST(test15); DO_TEST(test16); DO_TEST(test17); + DO_TEST(test18); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); } |