Re: [PATCHv2 3/3] command: add virCommandAbort for cleanup paths

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

 



On 03/23/2011 05:48 PM, Eric Blake wrote:
> Sometimes, an asynchronous helper is started (such as a compressor
> or iohelper program), but a later error means that we want to
> abort that child.  Make this easier.
> 
> Note that since daemons and virCommandRunAsync can't mix, the only
> time virCommandFree can reap a process is if someone did
> virCommandRunAsync for a non-daemon and didn't stash the pid.
> 
> * src/util/command.h (virCommandAbort): New prototype.
> * src/util/command.c (_virCommand): Add new field.
> (virCommandRunAsync, virCommandWait): Track whether pid was used.
> (virCommandFree): Reap child if caller did not request pid.
> (virCommandAbort): New function.
> * src/libvirt_private.syms (command.h): Export it.
> * tests/commandtest.c (test19): New test.
> ---
> 
> v2: no change, but by adding patch 2, it should make it clear
> that this patch is doing the right thing about not reaping
> a long-running daemon.

Actually, I'm going to squash this in, and make v2 different than v1 by
enhancing the tests for daemons:

diff --git i/tests/commandtest.c w/tests/commandtest.c
index 527b95a..c313a2c 100644
--- i/tests/commandtest.c
+++ w/tests/commandtest.c
@@ -696,6 +696,14 @@ static int test18(const void *unused ATTRIBUTE_UNUSED)
         printf("cannot read pidfile\n");
         goto cleanup;
     }
+
+    virCommandFree(cmd);
+    cmd = NULL;
+    if (kill(pid, 0) != 0) {
+        printf("daemon should still be running\n");
+        goto cleanup;
+    }
+
     while (kill(pid, SIGINT) != -1)
         usleep(100*1000);


Hmm, should we have a virCommandRunDaemon(cmd, pid_t*) helper function
that runs a command as a daemon and returns its pid by reading a
temporary pidfile?

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]