2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2010-01-23 01:52:57 +01:00
|
|
|
|
|
|
|
typedef struct Timer Timer;
|
|
|
|
|
2012-11-23 21:37:58 +01:00
|
|
|
#include "calendarspec.h"
|
2018-05-15 20:17:34 +02:00
|
|
|
#include "unit.h"
|
2010-01-23 01:52:57 +01:00
|
|
|
|
2010-05-24 01:45:54 +02:00
|
|
|
typedef enum TimerBase {
|
|
|
|
TIMER_ACTIVE,
|
|
|
|
TIMER_BOOT,
|
|
|
|
TIMER_STARTUP,
|
|
|
|
TIMER_UNIT_ACTIVE,
|
|
|
|
TIMER_UNIT_INACTIVE,
|
2012-11-23 21:37:58 +01:00
|
|
|
TIMER_CALENDAR,
|
2010-05-24 01:45:54 +02:00
|
|
|
_TIMER_BASE_MAX,
|
|
|
|
_TIMER_BASE_INVALID = -1
|
|
|
|
} TimerBase;
|
|
|
|
|
|
|
|
typedef struct TimerValue {
|
2012-11-23 21:37:58 +01:00
|
|
|
TimerBase base;
|
|
|
|
bool disabled;
|
|
|
|
|
2013-01-10 00:54:46 +01:00
|
|
|
usec_t value; /* only for monotonic events */
|
|
|
|
CalendarSpec *calendar_spec; /* only for calendar events */
|
2010-05-24 01:45:54 +02:00
|
|
|
usec_t next_elapse;
|
|
|
|
|
|
|
|
LIST_FIELDS(struct TimerValue, value);
|
|
|
|
} TimerValue;
|
|
|
|
|
2012-02-03 04:03:21 +01:00
|
|
|
typedef enum TimerResult {
|
|
|
|
TIMER_SUCCESS,
|
|
|
|
TIMER_FAILURE_RESOURCES,
|
core: move enforcement of the start limit into per-unit-type code again
Let's move the enforcement of the per-unit start limit from unit.c into the
type-specific files again. For unit types that know a concept of "result" codes
this allows us to hook up the start limit condition to it with an explicit
result code. Also, this makes sure that the state checks in clal like
service_start() may be done before the start limit is checked, as the start
limit really should be checked last, right before everything has been verified
to be in order.
The generic start limit logic is left in unit.c, but the invocation of it is
moved into the per-type files, in the various xyz_start() functions, so that
they may place the check at the right location.
Note that this change drops the enforcement entirely from device, slice, target
and scope units, since these unit types generally may not fail activation, or
may only be activated a single time. This is also documented now.
Note that restores the "start-limit-hit" result code that existed before
6bf0f408e4833152197fb38fb10a9989c89f3a59 already in the service code. However,
it's not introduced for all units that have a result code concept.
Fixes #3166.
2016-05-02 13:01:26 +02:00
|
|
|
TIMER_FAILURE_START_LIMIT_HIT,
|
2012-02-03 04:03:21 +01:00
|
|
|
_TIMER_RESULT_MAX,
|
|
|
|
_TIMER_RESULT_INVALID = -1
|
|
|
|
} TimerResult;
|
|
|
|
|
2010-01-23 01:52:57 +01:00
|
|
|
struct Timer {
|
2012-01-15 12:04:08 +01:00
|
|
|
Unit meta;
|
2010-01-23 01:52:57 +01:00
|
|
|
|
2013-11-21 22:07:51 +01:00
|
|
|
usec_t accuracy_usec;
|
2015-11-18 13:37:30 +01:00
|
|
|
usec_t random_usec;
|
2013-11-21 22:07:51 +01:00
|
|
|
|
2010-05-24 01:45:54 +02:00
|
|
|
LIST_HEAD(TimerValue, values);
|
2012-11-23 21:37:58 +01:00
|
|
|
usec_t next_elapse_realtime;
|
2014-03-24 16:09:54 +01:00
|
|
|
usec_t next_elapse_monotonic_or_boottime;
|
|
|
|
dual_timestamp last_trigger;
|
2010-01-23 01:52:57 +01:00
|
|
|
|
2010-05-24 05:25:33 +02:00
|
|
|
TimerState state, deserialized_state;
|
2010-05-24 01:45:54 +02:00
|
|
|
|
2013-11-19 21:12:59 +01:00
|
|
|
sd_event_source *monotonic_event_source;
|
|
|
|
sd_event_source *realtime_event_source;
|
2010-05-24 01:45:54 +02:00
|
|
|
|
2012-02-03 04:03:21 +01:00
|
|
|
TimerResult result;
|
2013-04-23 22:42:31 +02:00
|
|
|
|
2014-03-21 03:25:28 +01:00
|
|
|
bool persistent;
|
2014-03-24 16:09:54 +01:00
|
|
|
bool wake_system;
|
2015-11-17 20:13:36 +01:00
|
|
|
bool remain_after_elapse;
|
2019-03-14 21:36:47 +01:00
|
|
|
bool on_clock_change;
|
|
|
|
bool on_timezone_change;
|
2014-03-21 03:25:28 +01:00
|
|
|
|
|
|
|
char *stamp_path;
|
2010-01-23 01:52:57 +01:00
|
|
|
};
|
|
|
|
|
2017-06-22 20:59:48 +02:00
|
|
|
#define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
|
|
|
|
|
2013-01-17 02:27:06 +01:00
|
|
|
void timer_free_values(Timer *t);
|
|
|
|
|
2010-02-03 14:21:48 +01:00
|
|
|
extern const UnitVTable timer_vtable;
|
2010-01-23 01:52:57 +01:00
|
|
|
|
2013-05-03 04:51:50 +02:00
|
|
|
const char *timer_base_to_string(TimerBase i) _const_;
|
|
|
|
TimerBase timer_base_from_string(const char *s) _pure_;
|
2010-05-24 01:45:54 +02:00
|
|
|
|
2013-05-03 04:51:50 +02:00
|
|
|
const char* timer_result_to_string(TimerResult i) _const_;
|
|
|
|
TimerResult timer_result_from_string(const char *s) _pure_;
|
2018-05-15 20:17:34 +02:00
|
|
|
|
|
|
|
DEFINE_CAST(TIMER, Timer);
|