[Libguestfs] setpgid() before exec'ing qemu

Angus Salkeld asalkeld at redhat.com
Mon Mar 14 11:35:25 UTC 2011


On Fri, Mar 11, 2011 at 05:43:52PM +0000, Richard W.M. Jones wrote:
> On Fri, Mar 11, 2011 at 05:26:50PM +0000, Richard W.M. Jones wrote:
> > As Chris says, any reason to be using kill_subprocess at all?
> 
> Actually as Chris *didn't* say, I was reading that wrong :-)
> 
> Anyway, I'd try deleting the handle.  AFAIK Python will run the
> destructor immediately, and the path taken via guestfs_close certainly
> kills the subprocess:
> 
> http://git.annexia.org/?p=libguestfs.git;a=blob;f=src/guestfs.c;h=8b7ab4d7713ccff93f6b9bf0a066970ce3c8e8bb;hb=HEAD#l169
> 
> If you're really worried about the subprocess staying around, then
> grab the PID (g.get_pid) and kill the process *after* deleting the
> handle.  (This is way outside the scope of the API ...)
We could do this but I think there is a little bug in libguestfs
that we can easily fix.

Attached is a simple python test case that fails for me.
I believe that the kill_subprocess() is killing what it should
then guestfs_close() is getting run again because "del g" calls
obj.__del__() and that calls guestfs_close().

It this code there is a waitpid() without a check to see if the
pid is > 0.
(I'll reply to this email with a patch)

Can someone (with a libguestfs that builds) test this?
I have been having problems setting up a libguestfs that can build
else I'de test this my self.

Thanks
Angus Salkeld

> 
> Rich.
> 
> -- 
> Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
> virt-top is 'top' for virtual machines.  Tiny program with many
> powerful monitoring features, net stats, disk stats, logging, etc.
> http://et.redhat.com/~rjones/virt-top
-------------- next part --------------
#!/usr/bin/env python

import os
import sys
import subprocess
import time
import signal
import guestfs

class ProcessMonitor(object):

    def __init__(self, command):
        self.p = subprocess.Popen(command)
        self.executible = command[0]
        self.rc = None

    def __del__(self):
        self.stop()

    def is_running(self):
        if self.rc != None:
            return False
        self.rc = self.p.poll()
        if self.rc != None:
            return False
        else:
            return True

    def stop(self):
        if self.is_running():
            os.kill(self.p.pid, signal.SIGTERM)
            self.rc = self.p.wait()

    def retcode_get(self):
        return self.rc

    def __str__(self):
        if self.is_running():
            return '%s(%d) is running' % (self.executible, self.p.pid)
        else:
            return '%s(%d) exited with %d' % (self.executible, self.p.pid, self.rc)

if __name__ == '__main__':

    qpidd = ProcessMonitor(['qpidd', '-p', '49000', '--auth', 'no'])
    print qpidd

    iso = '%s/Downloads/iso-images/gnome3_test_20110310_x86_64.iso' % os.environ['HOME']

    g = guestfs.GuestFS()
    g.add_drive_opts(iso, format='raw')
    g.launch()
    time.sleep(1)
    g.umount_all()
    g.kill_subprocess()
    del g

    qpidd.stop()
    print qpidd




More information about the Libguestfs mailing list