HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/core/timer.c
Git blob: 441492dd159ba49b028acdc188baae2977a03700
Lines 1001–1139 of 1,139
if (r < 0)
return r;
return 2; /* Return the number of variables added to the env block */
}
static int activation_details_timer_append_pair(const ActivationDetails *details, char ***strv) {
const ActivationDetailsTimer *t = ASSERT_PTR(ACTIVATION_DETAILS_TIMER(details));
int r;
assert(strv);
assert(t);
if (!dual_timestamp_is_set(&t->last_trigger))
return 0;
r = strv_extend(strv, "trigger_timer_realtime_usec");
if (r < 0)
return r;
r = strv_extendf(strv, USEC_FMT, t->last_trigger.realtime);
if (r < 0)
return r;
r = strv_extend(strv, "trigger_timer_monotonic_usec");
if (r < 0)
return r;
r = strv_extendf(strv, USEC_FMT, t->last_trigger.monotonic);
if (r < 0)
return r;
return 2; /* Return the number of pairs added to the env block */
}
uint64_t timer_next_elapse_monotonic(const Timer *t) {
assert(t);
return (uint64_t) usec_shift_clock(t->next_elapse_monotonic_or_boottime,
TIMER_MONOTONIC_CLOCK(t), CLOCK_MONOTONIC);
}
static const char* const timer_base_table[_TIMER_BASE_MAX] = {
[TIMER_ACTIVE] = "OnActiveSec",
[TIMER_BOOT] = "OnBootSec",
[TIMER_STARTUP] = "OnStartupSec",
[TIMER_UNIT_ACTIVE] = "OnUnitActiveSec",
[TIMER_UNIT_INACTIVE] = "OnUnitInactiveSec",
[TIMER_CALENDAR] = "OnCalendar",
};
DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
char* timer_base_to_usec_string(TimerBase i) {
_cleanup_free_ char *buf = NULL;
const char *s;
size_t l;
s = timer_base_to_string(i);
if (endswith(s, "Sec")) {
/* s/Sec/USec/ */
l = strlen(s);
buf = new(char, l+2);
if (!buf)
return NULL;
memcpy(buf, s, l-3);
memcpy(buf+l-3, "USec", 5);
} else {
buf = strdup(s);
if (!buf)
return NULL;
}
return TAKE_PTR(buf);
}
static const char* const timer_result_table[_TIMER_RESULT_MAX] = {
[TIMER_SUCCESS] = "success",
[TIMER_FAILURE_RESOURCES] = "resources",
[TIMER_FAILURE_START_LIMIT_HIT] = "start-limit-hit",
};
DEFINE_STRING_TABLE_LOOKUP(timer_result, TimerResult);
const UnitVTable timer_vtable = {
.object_size = sizeof(Timer),
.sections =
"Unit\0"
"Timer\0"
"Install\0",
.private_section = "Timer",
.can_transient = true,
.can_fail = true,
.can_trigger = true,
.init = timer_init,
.done = timer_done,
.load = timer_load,
.coldplug = timer_coldplug,
.dump = timer_dump,
.start = timer_start,
.stop = timer_stop,
.clean = timer_clean,
.can_clean = timer_can_clean,
.serialize = timer_serialize,
.deserialize_item = timer_deserialize_item,
.active_state = timer_active_state,
.sub_state_to_string = timer_sub_state_to_string,
.trigger_notify = timer_trigger_notify,
.reset_failed = timer_reset_failed,
.time_change = timer_time_change,
.timezone_change = timer_timezone_change,
.bus_set_property = bus_timer_set_property,
.test_startable = timer_test_startable,
};
const ActivationDetailsVTable activation_details_timer_vtable = {
.object_size = sizeof(ActivationDetailsTimer),
.serialize = activation_details_timer_serialize,
.deserialize = activation_details_timer_deserialize,
.append_env = activation_details_timer_append_env,
.append_pair = activation_details_timer_append_pair,
};