" <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 \
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;
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, }
};
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)
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) {
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) {
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);
}
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;
}
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;
}
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;
}
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);
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] = {
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),