chiark / gitweb /
unit: rework stop pending logic
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Apr 2013 00:57:41 +0000 (21:57 -0300)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Apr 2013 01:01:49 +0000 (22:01 -0300)
When a trigger unit wants to know if a stop is queued for it, we should
just check precisely that and do not check whether it is actually
stopped already. This is because we use these checks usually from state
change calls where the state variables are not updated yet.

This change splits unit_pending_inactive() into two calls
unit_inactive_or_pending() and unit_stop_pending(). The former checks
state and pending jobs, the latter only pending jobs.

src/core/automount.c
src/core/dbus.c
src/core/manager.c
src/core/manager.h
src/core/path.c
src/core/socket.c
src/core/timer.c
src/core/unit.c
src/core/unit.h

index e6eedda96fb05ce1251ab45bd810be5b0dc1d01d..a20d5340f207cf1567467d2ca47ee31f281a9eaa 100644 (file)
@@ -593,7 +593,7 @@ static void automount_enter_runnning(Automount *a) {
 
         /* We don't take mount requests anymore if we are supposed to
          * shut down anyway */
-        if (unit_pending_inactive(UNIT(a))) {
+        if (unit_stop_pending(UNIT(a))) {
                 log_debug_unit(UNIT(a)->id,
                                "Suppressing automount request on %s since unit stop is scheduled.", UNIT(a)->id);
                 automount_send_ready(a, -EHOSTDOWN);
index 67ab1ae7f70ba85bf8a3e134fa9433ff7a06d2b1..5a61a1a6547dff85d95b672aa77007b6bce7492d 100644 (file)
@@ -363,8 +363,8 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
 
                         log_debug("Got D-Bus activation request for %s", name);
 
-                        if (manager_unit_pending_inactive(m, SPECIAL_DBUS_SERVICE) ||
-                            manager_unit_pending_inactive(m, SPECIAL_DBUS_SOCKET)) {
+                        if (manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SERVICE) ||
+                            manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SOCKET)) {
                                 r = -EADDRNOTAVAIL;
                                 dbus_set_error(&error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is shutting down.");
                         } else {
index 2265ef7173716d0be419b7853e027a974137a396..c7f8f20a70612497399d85770d470746d5fbdf0e 100644 (file)
@@ -2328,7 +2328,7 @@ void manager_reset_failed(Manager *m) {
                 unit_reset_failed(u);
 }
 
-bool manager_unit_pending_inactive(Manager *m, const char *name) {
+bool manager_unit_inactive_or_pending(Manager *m, const char *name) {
         Unit *u;
 
         assert(m);
@@ -2339,7 +2339,7 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) {
         if (!u)
                 return true;
 
-        return unit_pending_inactive(u);
+        return unit_inactive_or_pending(u);
 }
 
 void manager_check_finished(Manager *m) {
index 649a8aac514d184490425bf530c162694bae9715..a0be2927f71a4111758dbcfbd101a0635a77b0ff 100644 (file)
@@ -291,7 +291,7 @@ void manager_reset_failed(Manager *m);
 void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success);
 void manager_send_unit_plymouth(Manager *m, Unit *u);
 
-bool manager_unit_pending_inactive(Manager *m, const char *name);
+bool manager_unit_inactive_or_pending(Manager *m, const char *name);
 
 void manager_check_finished(Manager *m);
 
index e1330f6c95e3a994355e37a5003bea9c82a4c3f8..ab1fe2eb6539852f8e27ed0b294bd35381fa74b1 100644 (file)
@@ -523,7 +523,7 @@ static void path_enter_running(Path *p) {
         dbus_error_init(&error);
 
         /* Don't start job if we are supposed to go down */
-        if (unit_pending_inactive(UNIT(p)))
+        if (unit_stop_pending(UNIT(p)))
                 return;
 
         r = manager_add_job(UNIT(p)->manager, JOB_START, UNIT_TRIGGER(UNIT(p)),
index 9f1af1e28f2c92accfa94de70a1b0da3e1d85687..c276afe38f185c0e80af720cb3092f6c99b97325 100644 (file)
@@ -1447,7 +1447,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 (unit_pending_inactive(UNIT(s))) {
+        if (unit_stop_pending(UNIT(s))) {
                 log_debug_unit(UNIT(s)->id,
                                "Suppressing connection request on %s since unit stop is scheduled.",
                                UNIT(s)->id);
@@ -1478,7 +1478,7 @@ static void socket_enter_running(Socket *s, int cfd) {
                 /* If there's already a start pending don't bother to
                  * do anything */
                 SET_FOREACH(u, UNIT(s)->dependencies[UNIT_TRIGGERS], i)
-                        if (unit_pending_active(u)) {
+                        if (unit_active_or_pending(u)) {
                                 pending = true;
                                 break;
                         }
index b8039d82ec3549bf98ff11a96f5f3daa752e4c5b..ff8c30583cb4cf4c594ab0e86c8459938dd67b5d 100644 (file)
@@ -374,7 +374,7 @@ static void timer_enter_running(Timer *t) {
         dbus_error_init(&error);
 
         /* Don't start job if we are supposed to go down */
-        if (unit_pending_inactive(UNIT(t)))
+        if (unit_stop_pending(UNIT(t)))
                 return;
 
         r = manager_add_job(UNIT(t)->manager, JOB_START, UNIT_TRIGGER(UNIT(t)),
index c0c3ce90a7af56d01307cde4b90a74d69ba653fb..b4a4f8cd2e28e2eda6867bb97ae9d4ad101a86f8 100644 (file)
@@ -1206,19 +1206,19 @@ static void unit_check_unneeded(Unit *u) {
                 return;
 
         SET_FOREACH(other, u->dependencies[UNIT_REQUIRED_BY], i)
-                if (unit_pending_active(other))
+                if (unit_active_or_pending(other))
                         return;
 
         SET_FOREACH(other, u->dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
-                if (unit_pending_active(other))
+                if (unit_active_or_pending(other))
                         return;
 
         SET_FOREACH(other, u->dependencies[UNIT_WANTED_BY], i)
-                if (unit_pending_active(other))
+                if (unit_active_or_pending(other))
                         return;
 
         SET_FOREACH(other, u->dependencies[UNIT_BOUND_BY], i)
-                if (unit_pending_active(other))
+                if (unit_active_or_pending(other))
                         return;
 
         log_info_unit(u->id, "Service %s is not needed anymore. Stopping.", u->id);
@@ -2651,21 +2651,30 @@ Unit *unit_following(Unit *u) {
         return NULL;
 }
 
-bool unit_pending_inactive(Unit *u) {
+bool unit_stop_pending(Unit *u) {
         assert(u);
 
-        /* Returns true if the unit is inactive or going down */
+        /* This call does check the current state of the unit. It's
+         * hence useful to be called from state change calls of the
+         * unit itself, where the state isn't updated yet. This is
+         * different from unit_inactive_or_pending() which checks both
+         * the current state and for a queued job. */
 
-        if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)))
-                return true;
+        return u->job && u->job->type == JOB_STOP;
+}
+
+bool unit_inactive_or_pending(Unit *u) {
+        assert(u);
+
+        /* Returns true if the unit is inactive or going down */
 
-        if (u->job && u->job->type == JOB_STOP)
+        if (unit_stop_pending(u))
                 return true;
 
         return false;
 }
 
-bool unit_pending_active(Unit *u) {
+bool unit_active_or_pending(Unit *u) {
         assert(u);
 
         /* Returns true if the unit is active or going up */
index 6bfe58c8bfaec36b34677fe219d1935e92c6596f..a086538c61f338d3d9658a75ccc5626ca7e4cb8c 100644 (file)
@@ -536,8 +536,9 @@ void unit_reset_failed(Unit *u);
 
 Unit *unit_following(Unit *u);
 
-bool unit_pending_inactive(Unit *u);
-bool unit_pending_active(Unit *u);
+bool unit_stop_pending(Unit *u);
+bool unit_inactive_or_pending(Unit *u);
+bool unit_active_or_pending(Unit *u);
 
 int unit_add_default_target_dependency(Unit *u, Unit *target);