summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-02-03 04:03:21 +0100
committerLennart Poettering <lennart@poettering.net>2012-02-03 05:06:04 +0100
commit067d72c9fe698d305a07db17fc5b328e4a17cc8f (patch)
tree0df3076b1d1fe5d9161dedef78812867470507a2 /src
parent81a5c6d03ef1e43e33bfb5ad006cf883c927a339 (diff)
timer: convert failure bool into enum
Diffstat (limited to 'src')
-rw-r--r--src/automount.c2
-rw-r--r--src/dbus-timer.c7
-rw-r--r--src/timer.c37
-rw-r--r--src/timer.h12
4 files changed, 46 insertions, 12 deletions
diff --git a/src/automount.c b/src/automount.c
index 507fc258d6..cf2fb60cdf 100644
--- a/src/automount.c
+++ b/src/automount.c
@@ -881,7 +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,
+ .bus_invalidating_properties = bus_automount_invalidating_properties,
.shutdown = automount_shutdown
};
diff --git a/src/dbus-timer.c b/src/dbus-timer.c
index 0988b3e118..b396aed047 100644
--- a/src/dbus-timer.c
+++ b/src/dbus-timer.c
@@ -31,6 +31,7 @@
" <property name=\"Unit\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Timers\" type=\"a(stt)\" access=\"read\"/>\n" \
" <property name=\"NextElapseUSec\" type=\"t\" access=\"read\"/>\n" \
+ " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
@@ -51,7 +52,8 @@ const char bus_timer_interface[] _introspect_("Timer") = BUS_TIMER_INTERFACE;
const char bus_timer_invalidating_properties[] =
"Timers\0"
- "NextElapseUSec\0";
+ "NextElapseUSec\0"
+ "Result\0";
static int bus_timer_append_timers(DBusMessageIter *i, const char *property, void *data) {
Timer *p = data;
@@ -113,10 +115,13 @@ static int bus_timer_append_unit(DBusMessageIter *i, const char *property, void
return dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t) ? 0 : -ENOMEM;
}
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_timer_append_timer_result, timer_result, TimerResult);
+
static const BusProperty bus_timer_properties[] = {
{ "Unit", bus_timer_append_unit, "s", 0 },
{ "Timers", bus_timer_append_timers, "a(stt)", 0 },
{ "NextElapseUSec", bus_property_append_usec, "t", offsetof(Timer, next_elapse) },
+ { "Result", bus_timer_append_timer_result,"s", offsetof(Timer, result) },
{ NULL, }
};
diff --git a/src/timer.c b/src/timer.c
index ce7fd6bb3a..e318fee201 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -133,8 +133,10 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sTimer State: %s\n"
+ "%sResult: %s\n"
"%sUnit: %s\n",
prefix, timer_state_to_string(t->state),
+ prefix, timer_result_to_string(t->result),
prefix, UNIT_DEREF(t->unit)->id);
LIST_FOREACH(value, v, t->values)
@@ -183,13 +185,13 @@ static int timer_coldplug(Unit *u) {
return 0;
}
-static void timer_enter_dead(Timer *t, bool success) {
+static void timer_enter_dead(Timer *t, TimerResult f) {
assert(t);
- if (!success)
- t->failure = true;
+ if (f != TIMER_SUCCESS)
+ t->result = f;
- timer_set_state(t, t->failure ? TIMER_FAILED : TIMER_DEAD);
+ timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD);
}
static void timer_enter_waiting(Timer *t, bool initial) {
@@ -273,7 +275,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
fail:
log_warning("%s failed to enter waiting state: %s", UNIT(t)->id, strerror(-r));
- timer_enter_dead(t, false);
+ timer_enter_dead(t, TIMER_FAILURE_RESOURCES);
}
static void timer_enter_running(Timer *t) {
@@ -295,7 +297,7 @@ static void timer_enter_running(Timer *t) {
fail:
log_warning("%s failed to queue unit startup job: %s", UNIT(t)->id, bus_error(&error, r));
- timer_enter_dead(t, false);
+ timer_enter_dead(t, TIMER_FAILURE_RESOURCES);
dbus_error_free(&error);
}
@@ -309,7 +311,7 @@ static int timer_start(Unit *u) {
if (UNIT_DEREF(t->unit)->load_state != UNIT_LOADED)
return -ENOENT;
- t->failure = false;
+ t->result = TIMER_SUCCESS;
timer_enter_waiting(t, true);
return 0;
}
@@ -320,7 +322,7 @@ static int timer_stop(Unit *u) {
assert(t);
assert(t->state == TIMER_WAITING || t->state == TIMER_RUNNING || t->state == TIMER_ELAPSED);
- timer_enter_dead(t, true);
+ timer_enter_dead(t, TIMER_SUCCESS);
return 0;
}
@@ -332,6 +334,7 @@ static int timer_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(fds);
unit_serialize_item(u, f, "state", timer_state_to_string(t->state));
+ unit_serialize_item(u, f, "result", timer_result_to_string(t->result));
return 0;
}
@@ -351,6 +354,15 @@ static int timer_deserialize_item(Unit *u, const char *key, const char *value, F
log_debug("Failed to parse state value %s", value);
else
t->deserialized_state = state;
+ } else if (streq(key, "result")) {
+ TimerResult f;
+
+ f = timer_result_from_string(value);
+ if (f < 0)
+ log_debug("Failed to parse result value %s", value);
+ else if (f != TIMER_SUCCESS)
+ t->result = f;
+
} else
log_debug("Unknown serialization key '%s'", key);
@@ -443,7 +455,7 @@ static void timer_reset_failed(Unit *u) {
if (t->state == TIMER_FAILED)
timer_set_state(t, TIMER_DEAD);
- t->failure = false;
+ t->result = TIMER_SUCCESS;
}
static const char* const timer_state_table[_TIMER_STATE_MAX] = {
@@ -466,6 +478,13 @@ static const char* const timer_base_table[_TIMER_BASE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
+static const char* const timer_result_table[_TIMER_RESULT_MAX] = {
+ [TIMER_SUCCESS] = "success",
+ [TIMER_FAILURE_RESOURCES] = "resources"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(timer_result, TimerResult);
+
const UnitVTable timer_vtable = {
.suffix = ".timer",
.object_size = sizeof(Timer),
diff --git a/src/timer.h b/src/timer.h
index d5cbc11561..f5c5c64f25 100644
--- a/src/timer.h
+++ b/src/timer.h
@@ -56,6 +56,13 @@ typedef struct TimerValue {
bool disabled;
} TimerValue;
+typedef enum TimerResult {
+ TIMER_SUCCESS,
+ TIMER_FAILURE_RESOURCES,
+ _TIMER_RESULT_MAX,
+ _TIMER_RESULT_INVALID = -1
+} TimerResult;
+
struct Timer {
Unit meta;
@@ -67,7 +74,7 @@ struct Timer {
Watch timer_watch;
- bool failure;
+ TimerResult result;
};
void timer_unit_notify(Unit *u, UnitActiveState new_state);
@@ -80,4 +87,7 @@ TimerState timer_state_from_string(const char *s);
const char *timer_base_to_string(TimerBase i);
TimerBase timer_base_from_string(const char *s);
+const char* timer_result_to_string(TimerResult i);
+TimerResult timer_result_from_string(const char *s);
+
#endif