[libvirt] [libvirt-glib] RFC: delay event handle freeing to avoid dead lock
by Marc-André Lureau
Can be reproduced with the updated test.
---
examples/conn-test.c | 20 +++++++++++++++-----
libvirt-glib/libvirt-glib-event.c | 17 +++++++++++++----
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/examples/conn-test.c b/examples/conn-test.c
index 08045a4..8ea5ad7 100644
--- a/examples/conn-test.c
+++ b/examples/conn-test.c
@@ -31,12 +31,19 @@ do_connection_open(GObject *source,
{
GVirConnection *conn = GVIR_CONNECTION(source);
GError *err = NULL;
- GMainLoop *loop = opaque;
if (!gvir_connection_open_finish(conn, res, &err)) {
g_error("%s", err->message);
}
g_print("Connected to libvirt\n");
+ g_object_unref(conn);
+}
+
+static void quit(gpointer data,
+ GObject *where_the_object_was)
+{
+ GMainLoop *loop = data;
+
g_main_loop_quit(loop);
}
@@ -47,19 +54,22 @@ int main(int argc, char **argv)
gvir_init_object(&argc, &argv);
- if (argc != 2)
+ if (argc != 2) {
g_error("syntax: %s URI", argv[0]);
-
- conn = gvir_connection_new(argv[1]);
+ return 1;
+ }
loop = g_main_loop_new(g_main_context_default(),
TRUE);
- gvir_connection_open_async(conn, NULL, do_connection_open, loop);
+ conn = gvir_connection_new(argv[1]);
+ g_object_weak_ref(G_OBJECT(conn), quit, loop);
+
gvir_connection_open_async(conn, NULL, do_connection_open, loop);
g_main_loop_run(loop);
+
return 0;
}
diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
index a785c93..8b1bddf 100644
--- a/libvirt-glib/libvirt-glib-event.c
+++ b/libvirt-glib/libvirt-glib-event.c
@@ -195,6 +195,18 @@ cleanup:
g_mutex_unlock(eventlock);
}
+static gboolean
+_handle_remove(gpointer data)
+{
+ struct gvir_event_handle *h = data;
+
+ if (h->ff)
+ (h->ff)(h->opaque);
+ free(h);
+
+ return FALSE;
+}
+
static int
gvir_event_handle_remove(int watch)
{
@@ -217,10 +229,7 @@ gvir_event_handle_remove(int watch)
g_source_remove(data->source);
data->source = 0;
data->events = 0;
- if (data->ff)
- (data->ff)(data->opaque);
- free(data);
-
+ g_idle_add(_handle_remove, data);
ret = 0;
cleanup:
--
1.7.6.2
13 years, 1 month
[libvirt] [PATCH 0/2] qemu: make PCI multifunction support more manual
by Laine Stump
Problems have been encountered/realized with the practice of
unconditionally setting the multifunction bit for all functions of all
devices. PATCH 2/2 remedies that (details in its own commit
comment). PATCH 1/2 is a one-liner I fixed in the meantime which will
cause a simple conflict if it's not applied to other branches at the
same time as PATCH 2/2, so I'm sending them together.
13 years, 1 month
[libvirt] [PATCH] virsh: do not unlink NULL file
by Marc-André Lureau
error:could not take a screenshot of xp
==6216== Syscall param unlink(pathname) points to unaddressable byte(s)
==6216== at 0x373A0D4937: unlink (syscall-template.S:82)
==6216== by 0x40FD73: cmdScreenshot (virsh.c:3070)
==6216== by 0x42BA0D: vshCommandRun (virsh.c:14920)
==6216== by 0x42EC97: main (virsh.c:16379)
==6216== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==6216==
error:Requested operation is not valid: domain is not running
---
tools/virsh.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 1909dce..89d355f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3004,7 +3004,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
unsigned int screen = 0;
unsigned int flags = 0; /* currently unused */
int ret = false;
- bool created = true;
+ bool created = false;
bool generated = false;
char *mime = NULL;
@@ -3039,13 +3039,13 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
}
if ((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
- created = false;
if (errno != EEXIST ||
(fd = open(file, O_WRONLY|O_TRUNC, 0666)) < 0) {
vshError(ctl, _("cannot create file %s"), file);
goto cleanup;
}
- }
+ } else
+ created = true;
if (virStreamRecvAll(st, vshStreamSink, &fd) < 0) {
vshError(ctl, _("could not receive data from domain %s"), name);
--
1.7.6.2
13 years, 1 month