[systemd-commits] 2 commits - fixme src/bus-errors.h src/dbus.c src/manager.c src/manager.h src/socket.c src/special.h src/unit.c src/unit.h

Lennart Poettering lennart at kemper.freedesktop.org
Tue Aug 31 18:35:10 PDT 2010


 fixme            |    6 ++++++
 src/bus-errors.h |    1 +
 src/dbus.c       |   17 ++++++++++++-----
 src/manager.c    |   13 +++++++++++++
 src/manager.h    |    2 ++
 src/socket.c     |    2 +-
 src/special.h    |    1 +
 src/unit.c       |   14 ++++++++++++++
 src/unit.h       |    2 ++
 9 files changed, 52 insertions(+), 6 deletions(-)

New commits:
commit 18ffdfda48c327f56cac0aabdc6bada91cc9b7df
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Sep 1 03:35:04 2010 +0200

    unit: unify some code

diff --git a/src/manager.c b/src/manager.c
index ff1c70b..e2f13b2 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -2591,17 +2591,10 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) {
         assert(name);
 
         /* Returns true if the unit is inactive or going down */
-
         if (!(u = manager_get_unit(m, name)))
                 return true;
 
-        if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)))
-                return true;
-
-        if (u->meta.job && u->meta.job->type == JOB_STOP)
-                return true;
-
-        return false;
+        return unit_pending_inactive(u);
 }
 
 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
diff --git a/src/socket.c b/src/socket.c
index fd975fd..34068b9 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1167,7 +1167,7 @@ static void socket_enter_running(Socket *s, int cfd) {
 
         /* We don't take connections anymore if we are supposed to
          * shut down anyway */
-        if (s->meta.job && s->meta.job->type == JOB_STOP) {
+        if (unit_pending_inactive(UNIT(s))) {
                 if (cfd >= 0)
                         close_nointr_nofail(cfd);
                 else  {
diff --git a/src/unit.c b/src/unit.c
index bca4d97..d5ed5e1 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -2125,6 +2125,20 @@ Unit *unit_following(Unit *u) {
         return NULL;
 }
 
+bool unit_pending_inactive(Unit *u) {
+        assert(u);
+
+        /* Returns true if the unit is inactive or going down */
+
+        if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)))
+                return true;
+
+        if (u->meta.job && u->meta.job->type == JOB_STOP)
+                return true;
+
+        return false;
+}
+
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
diff --git a/src/unit.h b/src/unit.h
index 15e7fed..c85d968 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -499,6 +499,8 @@ void unit_reset_failed(Unit *u);
 
 Unit *unit_following(Unit *u);
 
+bool unit_pending_inactive(Unit *u);
+
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);
 
commit 8f6df3fa98ee74eaf5c34dddd272d2e3c10c3c27
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Sep 1 03:30:59 2010 +0200

    dbus: don't accept activation requests anymore if we are going down anyway

diff --git a/fixme b/fixme
index 58fb81e..c986d74 100644
--- a/fixme
+++ b/fixme
@@ -80,6 +80,12 @@ v9:
 
 * fix terminal setup
 
+* figure out ssh disconnect hang
+
+* home.mount failing should not be able to cancel umount.target (IgnoreDependencyFailure=yes borked?)
+
+* disallow further dbus+socket activation on shutdown
+
 External:
 
 * place /etc/inittab with explaining blurb.
diff --git a/src/bus-errors.h b/src/bus-errors.h
index a63350c..2db1b77 100644
--- a/src/bus-errors.h
+++ b/src/bus-errors.h
@@ -41,6 +41,7 @@
 #define BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE "org.freedesktop.systemd1.TransactionIsDestructive"
 #define BUS_ERROR_TRANSACTION_JOBS_CONFLICTING "org.freedesktop.systemd1.TransactionJobsConflicting"
 #define BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC "org.freedesktop.systemd1.TransactionOrderIsCyclic"
+#define BUS_ERROR_SHUTTING_DOWN "org.freedesktop.systemd1.ShuttingDown"
 
 static inline const char *bus_error(const DBusError *e, int r) {
         if (e && e->message)
diff --git a/src/dbus.c b/src/dbus.c
index 952806b..8c969ea 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -43,6 +43,7 @@
 #include "dbus-timer.h"
 #include "dbus-path.h"
 #include "bus-errors.h"
+#include "special.h"
 
 #define CONNECTIONS_MAX 52
 
@@ -383,13 +384,19 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
 
                         log_debug("Got D-Bus activation request for %s", name);
 
-                        r = manager_load_unit(m, name, NULL, &error, &u);
+                        if (manager_unit_pending_inactive(m, SPECIAL_DBUS_SERVICE) ||
+                            manager_unit_pending_inactive(m, SPECIAL_DBUS_SOCKET)) {
+                                r = -EADDRNOTAVAIL;
+                                dbus_set_error(&error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is shutting down.");
+                        } else {
+                                r = manager_load_unit(m, name, NULL, &error, &u);
 
-                        if (r >= 0 && u->meta.refuse_manual_start)
-                                r = -EPERM;
+                                if (r >= 0 && u->meta.refuse_manual_start)
+                                        r = -EPERM;
 
-                        if (r >= 0)
-                                r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, &error, NULL);
+                                if (r >= 0)
+                                        r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, &error, NULL);
+                        }
 
                         if (r < 0) {
                                 const char *id, *text;
diff --git a/src/manager.c b/src/manager.c
index 517473b..ff1c70b 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -2584,6 +2584,26 @@ int manager_set_console(Manager *m, const char *console) {
         return 0;
 }
 
+bool manager_unit_pending_inactive(Manager *m, const char *name) {
+        Unit *u;
+
+        assert(m);
+        assert(name);
+
+        /* Returns true if the unit is inactive or going down */
+
+        if (!(u = manager_get_unit(m, name)))
+                return true;
+
+        if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)))
+                return true;
+
+        if (u->meta.job && u->meta.job->type == JOB_STOP)
+                return true;
+
+        return false;
+}
+
 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
         [MANAGER_SYSTEM] = "system",
         [MANAGER_SESSION] = "session"
diff --git a/src/manager.h b/src/manager.h
index 77c2076..4455372 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -259,6 +259,8 @@ void manager_reset_failed(Manager *m);
 
 void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success);
 
+bool manager_unit_pending_inactive(Manager *m, const char *name);
+
 const char *manager_running_as_to_string(ManagerRunningAs i);
 ManagerRunningAs manager_running_as_from_string(const char *s);
 
diff --git a/src/special.h b/src/special.h
index 0cc5cc6..d0359db 100644
--- a/src/special.h
+++ b/src/special.h
@@ -59,6 +59,7 @@
 #define SPECIAL_POWEROFF_TARGET "poweroff.target"
 #define SPECIAL_REBOOT_TARGET "reboot.target"
 #define SPECIAL_DBUS_SERVICE "dbus.service"
+#define SPECIAL_DBUS_SOCKET "dbus.socket"
 #define SPECIAL_GETTY_TARGET "getty.target"
 #define SPECIAL_SERIAL_GETTY_SERVICE "serial-getty at .service"
 


More information about the systemd-commits mailing list