daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
f336be
From 1ed560ffff6753d79f2f1da81447e5f8d3628ec1 Mon Sep 17 00:00:00 2001
f336be
From: Alexander Solganik <solganik@gmail.com>
f336be
Date: Wed, 29 Apr 2015 10:06:40 +0300
f336be
Subject: [PATCH] machined: force machined to dispatch messages
f336be
f336be
Fixes  https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=1172387.
f336be
f336be
Machined works in the follwing way :
f336be
f336be
loop :
f336be
       1) perform GC (Note at the end)
f336be
       2) read messages from DBUS and dispatch one
f336be
       3) if more messages pending goto (1)
f336be
       3) perform GC (NOTE at the end)
f336be
       4) poll on DBUS fd
f336be
       5) goto step 1
f336be
f336be
This works fine, except that in step (3) and (1)
f336be
there is a message send/reply receive of
f336be
 r = bus_method_call_with_reply(
f336be
                        manager->bus,
f336be
                        "org.freedesktop.systemd1",
f336be
                        "/org/freedesktop/systemd1",
f336be
                        "org.freedesktop.systemd1.Manager",
f336be
                        "StopUnit",
f336be
                        &reply,
f336be
                        error,
f336be
                        DBUS_TYPE_STRING, &unit,
f336be
                        DBUS_TYPE_STRING, &fail,
f336be
                        DBUS_TYPE_INVALID);
f336be
f336be
which causes network layer to read/write messages to DBUS fd. In case that any
f336be
other message gets in during this send/receive cycle it wont be processed till
f336be
next stage (2) which will occur only in case that more messages are received
f336be
by machined.
f336be
f336be
Cherry-picked from: rhel-only
f336be
Resolves: #1243401
f336be
---
f336be
 src/machine/machined.c | 8 ++++++--
f336be
 src/machine/machined.h | 2 +-
f336be
 2 files changed, 7 insertions(+), 3 deletions(-)
f336be
f336be
diff --git a/src/machine/machined.c b/src/machine/machined.c
f336be
index ad804a1..531e7ad 100644
f336be
--- a/src/machine/machined.c
f336be
+++ b/src/machine/machined.c
f336be
@@ -243,20 +243,23 @@ fail:
f336be
         return r;
f336be
 }
f336be
 
f336be
-void manager_gc(Manager *m, bool drop_not_started) {
f336be
+bool manager_gc(Manager *m, bool drop_not_started) {
f336be
         Machine *machine;
f336be
+        bool dbus_send_receive_performed = false;
f336be
 
f336be
         assert(m);
f336be
 
f336be
         while ((machine = m->machine_gc_queue)) {
f336be
                 LIST_REMOVE(Machine, gc_queue, m->machine_gc_queue, machine);
f336be
                 machine->in_gc_queue = false;
f336be
+                dbus_send_receive_performed = true;
f336be
 
f336be
                 if (machine_check_gc(machine, drop_not_started) == 0) {
f336be
                         machine_stop(machine);
f336be
                         machine_free(machine);
f336be
                 }
f336be
         }
f336be
+        return dbus_send_receive_performed;
f336be
 }
f336be
 
f336be
 int manager_startup(Manager *m) {
f336be
@@ -301,7 +304,8 @@ int manager_run(Manager *m) {
f336be
                 if (dbus_connection_dispatch(m->bus) != DBUS_DISPATCH_COMPLETE)
f336be
                         continue;
f336be
 
f336be
-                manager_gc(m, true);
f336be
+                if (manager_gc(m, true))
f336be
+                       continue;
f336be
 
f336be
                 n = epoll_wait(m->epoll_fd, &event, 1, -1);
f336be
                 if (n < 0) {
f336be
diff --git a/src/machine/machined.h b/src/machine/machined.h
f336be
index 780f516..3245e05 100644
f336be
--- a/src/machine/machined.h
f336be
+++ b/src/machine/machined.h
f336be
@@ -59,7 +59,7 @@ int manager_enumerate_machines(Manager *m);
f336be
 int manager_startup(Manager *m);
f336be
 int manager_run(Manager *m);
f336be
 
f336be
-void manager_gc(Manager *m, bool drop_not_started);
f336be
+bool manager_gc(Manager *m, bool drop_not_started);
f336be
 
f336be
 int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine);
f336be