chiark / gitweb /
automount: convert failure boolean to enum
authorLennart Poettering <lennart@poettering.net>
Fri, 3 Feb 2012 02:27:25 +0000 (03:27 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Feb 2012 04:06:04 +0000 (05:06 +0100)
src/automount.c
src/automount.h
src/dbus-automount.c
src/dbus-automount.h
src/mount.c
src/socket.c

index aa38492..507fc25 100644 (file)
@@ -288,20 +288,22 @@ static void automount_dump(Unit *u, FILE *f, const char *prefix) {
 
         fprintf(f,
                 "%sAutomount State: %s\n"
+                "%sResult: %s\n"
                 "%sWhere: %s\n"
                 "%sDirectoryMode: %04o\n",
                 prefix, automount_state_to_string(a->state),
+                prefix, automount_result_to_string(a->result),
                 prefix, a->where,
                 prefix, a->directory_mode);
 }
 
-static void automount_enter_dead(Automount *a, bool success) {
+static void automount_enter_dead(Automount *a, AutomountResult f) {
         assert(a);
 
-        if (!success)
-                a->failure = true;
+        if (f != AUTOMOUNT_SUCCESS)
+                a->result = f;
 
-        automount_set_state(a, a->failure ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
+        automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
 }
 
 static int open_dev_autofs(Manager *m) {
@@ -565,7 +567,7 @@ fail:
                 repeat_unmout(a->where);
 
         log_error("Failed to initialize automounter: %s", strerror(-r));
-        automount_enter_dead(a, false);
+        automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
 }
 
 static void automount_enter_runnning(Automount *a) {
@@ -605,7 +607,7 @@ static void automount_enter_runnning(Automount *a) {
         return;
 
 fail:
-        automount_enter_dead(a, false);
+        automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
         dbus_error_free(&error);
 }
 
@@ -624,7 +626,7 @@ static int automount_start(Unit *u) {
         if (UNIT_DEREF(a->mount)->load_state != UNIT_LOADED)
                 return -ENOENT;
 
-        a->failure = false;
+        a->result = AUTOMOUNT_SUCCESS;
         automount_enter_waiting(a);
         return 0;
 }
@@ -636,7 +638,7 @@ static int automount_stop(Unit *u) {
 
         assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
 
-        automount_enter_dead(a, true);
+        automount_enter_dead(a, AUTOMOUNT_SUCCESS);
         return 0;
 }
 
@@ -650,7 +652,7 @@ static int automount_serialize(Unit *u, FILE *f, FDSet *fds) {
         assert(fds);
 
         unit_serialize_item(u, f, "state", automount_state_to_string(a->state));
-        unit_serialize_item(u, f, "failure", yes_no(a->failure));
+        unit_serialize_item(u, f, "result", automount_result_to_string(a->result));
         unit_serialize_item_format(u, f, "dev-id", "%u", (unsigned) a->dev_id);
 
         SET_FOREACH(p, a->tokens, i)
@@ -682,13 +684,15 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
                         log_debug("Failed to parse state value %s", value);
                 else
                         a->deserialized_state = state;
-        } else if (streq(key, "failure")) {
-                int b;
+        } else if (streq(key, "result")) {
+                AutomountResult f;
+
+                f = automount_result_from_string(value);
+                if (f < 0)
+                        log_debug("Failed to parse result value %s", value);
+                else if (f != AUTOMOUNT_SUCCESS)
+                        a->result = f;
 
-                if ((b = parse_boolean(value)) < 0)
-                        log_debug("Failed to parse failure value %s", value);
-                else
-                        a->failure = b || a->failure;
         } else if (streq(key, "dev-id")) {
                 unsigned d;
 
@@ -804,7 +808,7 @@ static void automount_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
         return;
 
 fail:
-        automount_enter_dead(a, false);
+        automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
 }
 
 static void automount_shutdown(Manager *m) {
@@ -822,7 +826,7 @@ static void automount_reset_failed(Unit *u) {
         if (a->state == AUTOMOUNT_FAILED)
                 automount_set_state(a, AUTOMOUNT_DEAD);
 
-        a->failure = false;
+        a->result = AUTOMOUNT_SUCCESS;
 }
 
 static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
@@ -834,6 +838,13 @@ static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
 
+static const char* const automount_result_table[_AUTOMOUNT_RESULT_MAX] = {
+        [AUTOMOUNT_SUCCESS] = "success",
+        [AUTOMOUNT_FAILURE_RESOURCES] = "resources"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(automount_result, AutomountResult);
+
 const UnitVTable automount_vtable = {
         .suffix = ".automount",
         .object_size = sizeof(Automount),
@@ -870,6 +881,7 @@ const UnitVTable automount_vtable = {
 
         .bus_interface = "org.freedesktop.systemd1.Automount",
         .bus_message_handler = bus_automount_message_handler,
+        .bus_invalidating_properties =  bus_automount_invalidating_properties,
 
         .shutdown = automount_shutdown
 };
index 8334c97..19baee2 100644 (file)
@@ -35,6 +35,13 @@ typedef enum AutomountState {
         _AUTOMOUNT_STATE_INVALID = -1
 } AutomountState;
 
+typedef enum AutomountResult {
+        AUTOMOUNT_SUCCESS,
+        AUTOMOUNT_FAILURE_RESOURCES,
+        _AUTOMOUNT_RESULT_MAX,
+        _AUTOMOUNT_RESULT_INVALID = -1
+} AutomountResult;
+
 struct Automount {
         Unit meta;
 
@@ -51,7 +58,7 @@ struct Automount {
 
         Set *tokens;
 
-        bool failure:1;
+        AutomountResult result;
 };
 
 extern const UnitVTable automount_vtable;
@@ -63,4 +70,7 @@ int automount_add_one_mount_link(Automount *a, Mount *m);
 const char* automount_state_to_string(AutomountState i);
 AutomountState automount_state_from_string(const char *s);
 
+const char* automount_result_to_string(AutomountResult i);
+AutomountResult automount_result_from_string(const char *s);
+
 #endif
index 938768b..8e45f81 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <errno.h>
+
 #include "dbus-unit.h"
 #include "dbus-automount.h"
 #include "dbus-common.h"
@@ -27,6 +29,7 @@
         " <interface name=\"org.freedesktop.systemd1.Automount\">\n" \
         "  <property name=\"Where\" type=\"s\" access=\"read\"/>\n"  \
         "  <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
+        "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
         " </interface>\n"
 
 #define INTROSPECTION                                                \
 
 const char bus_automount_interface[] _introspect_("Automount") = BUS_AUTOMOUNT_INTERFACE;
 
+const char bus_automount_invalidating_properties[] =
+        "Result\0";
+
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_automount_append_automount_result, automount_result, AutomountResult);
+
 static const BusProperty bus_automount_properties[] = {
         { "Where",         bus_property_append_string, "s", offsetof(Automount, where),    true },
         { "DirectoryMode", bus_property_append_mode,   "u", offsetof(Automount, directory_mode) },
+        { "Result",        bus_automount_append_automount_result, "s", offsetof(Automount, result) },
         { NULL, }
 };
 
index 84b573c..2fc8345 100644 (file)
@@ -29,5 +29,6 @@
 DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_automount_interface[];
+extern const char bus_automount_invalidating_properties[];
 
 #endif
index 0eba1a5..3411b73 100644 (file)
@@ -750,6 +750,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
 
         fprintf(f,
                 "%sMount State: %s\n"
+                "%sResult: %s\n"
                 "%sWhere: %s\n"
                 "%sWhat: %s\n"
                 "%sFile System Type: %s\n"
@@ -759,6 +760,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
                 "%sFrom fragment: %s\n"
                 "%sDirectoryMode: %04o\n",
                 prefix, mount_state_to_string(m->state),
+                prefix, mount_result_to_string(m->result),
                 prefix, m->where,
                 prefix, strna(p->what),
                 prefix, strna(p->fstype),
index f247d09..15a517b 100644 (file)
@@ -407,6 +407,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
 
         fprintf(f,
                 "%sSocket State: %s\n"
+                "%sResult: %s\n"
                 "%sBindIPv6Only: %s\n"
                 "%sBacklog: %u\n"
                 "%sSocketMode: %04o\n"
@@ -418,6 +419,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 "%sPassCredentials: %s\n"
                 "%sTCPCongestion: %s\n",
                 prefix, socket_state_to_string(s->state),
+                prefix, socket_result_to_string(s->result),
                 prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
                 prefix, s->backlog,
                 prefix, s->socket_mode,