chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
autogen.sh: diet and sync with udev and kmod
[elogind.git]
/
src
/
timer.c
diff --git
a/src/timer.c
b/src/timer.c
index 1580478949595cd0a6006fd0360ad8103d497efc..d127a117434a48a607d7d8d88dd6b0fb0e02fd29 100644
(file)
--- a/
src/timer.c
+++ b/
src/timer.c
@@
-1,4
+1,4
@@
-/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/*-*- Mode: C; c-basic-offset: 8
; indent-tabs-mode: nil
-*-*/
/***
This file is part of systemd.
/***
This file is part of systemd.
@@
-33,7
+33,7
@@
static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
[TIMER_WAITING] = UNIT_ACTIVE,
[TIMER_RUNNING] = UNIT_ACTIVE,
[TIMER_ELAPSED] = UNIT_ACTIVE,
[TIMER_WAITING] = UNIT_ACTIVE,
[TIMER_RUNNING] = UNIT_ACTIVE,
[TIMER_ELAPSED] = UNIT_ACTIVE,
- [TIMER_
MAINTENANCE] = UNIT_MAINTENANCE
+ [TIMER_
FAILED] = UNIT_FAILED
};
static void timer_init(Unit *u) {
};
static void timer_init(Unit *u) {
@@
-57,6
+57,8
@@
static void timer_done(Unit *u) {
}
unit_unwatch_timer(u, &t->timer_watch);
}
unit_unwatch_timer(u, &t->timer_watch);
+
+ unit_ref_unset(&t->unit);
}
static int timer_verify(Timer *t) {
}
static int timer_verify(Timer *t) {
@@
-78,9
+80,13
@@
static int timer_add_default_dependencies(Timer *t) {
assert(t);
assert(t);
- if (t->meta.manager->running_as == MANAGER_SYSTEM)
+ if (t->meta.manager->running_as == MANAGER_SYSTEM) {
+ if ((r = unit_add_dependency_by_name(UNIT(t), UNIT_BEFORE, SPECIAL_BASIC_TARGET, NULL, true)) < 0)
+ return r;
+
if ((r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0)
return r;
if ((r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0)
return r;
+ }
return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}
return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}
@@
-97,11
+103,18
@@
static int timer_load(Unit *u) {
if (u->meta.load_state == UNIT_LOADED) {
if (u->meta.load_state == UNIT_LOADED) {
- if (!t->unit)
- if ((r = unit_load_related_unit(u, ".service", &t->unit)))
+ if (!UNIT_DEREF(t->unit)) {
+ Unit *x;
+
+ r = unit_load_related_unit(u, ".service", &x);
+ if (r < 0)
return r;
return r;
- if ((r = unit_add_dependency(u, UNIT_BEFORE, t->unit, true)) < 0)
+ unit_ref_set(&t->unit, x);
+ }
+
+ r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(t->unit), true);
+ if (r < 0)
return r;
if (t->meta.default_dependencies)
return r;
if (t->meta.default_dependencies)
@@
-114,20
+127,15
@@
static int timer_load(Unit *u) {
static void timer_dump(Unit *u, FILE *f, const char *prefix) {
Timer *t = TIMER(u);
static void timer_dump(Unit *u, FILE *f, const char *prefix) {
Timer *t = TIMER(u);
- const char *prefix2;
- char *p2;
TimerValue *v;
char
timespan1[FORMAT_TIMESPAN_MAX];
TimerValue *v;
char
timespan1[FORMAT_TIMESPAN_MAX];
- p2 = strappend(prefix, "\t");
- prefix2 = p2 ? p2 : prefix;
-
fprintf(f,
"%sTimer State: %s\n"
"%sUnit: %s\n",
prefix, timer_state_to_string(t->state),
fprintf(f,
"%sTimer State: %s\n"
"%sUnit: %s\n",
prefix, timer_state_to_string(t->state),
- prefix,
t->unit
->meta.id);
+ prefix,
UNIT_DEREF(t->unit)
->meta.id);
LIST_FOREACH(value, v, t->values)
fprintf(f,
LIST_FOREACH(value, v, t->values)
fprintf(f,
@@
-135,8
+143,6
@@
static void timer_dump(Unit *u, FILE *f, const char *prefix) {
prefix,
timer_base_to_string(v->base),
strna(format_timespan(timespan1, sizeof(timespan1), v->value)));
prefix,
timer_base_to_string(v->base),
strna(format_timespan(timespan1, sizeof(timespan1), v->value)));
-
- free(p2);
}
static void timer_set_state(Timer *t, TimerState state) {
}
static void timer_set_state(Timer *t, TimerState state) {
@@
-155,7
+161,7
@@
static void timer_set_state(Timer *t, TimerState state) {
timer_state_to_string(old_state),
timer_state_to_string(state));
timer_state_to_string(old_state),
timer_state_to_string(state));
- unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state]);
+ unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state]
, true
);
}
static void timer_enter_waiting(Timer *t, bool initial);
}
static void timer_enter_waiting(Timer *t, bool initial);
@@
-168,9
+174,7
@@
static int timer_coldplug(Unit *u) {
if (t->deserialized_state != t->state) {
if (t->deserialized_state != t->state) {
- if (t->deserialized_state == TIMER_WAITING ||
- t->deserialized_state == TIMER_RUNNING ||
- t->deserialized_state == TIMER_ELAPSED)
+ if (t->deserialized_state == TIMER_WAITING)
timer_enter_waiting(t, false);
else
timer_set_state(t, t->deserialized_state);
timer_enter_waiting(t, false);
else
timer_set_state(t, t->deserialized_state);
@@
-185,7
+189,7
@@
static void timer_enter_dead(Timer *t, bool success) {
if (!success)
t->failure = true;
if (!success)
t->failure = true;
- timer_set_state(t, t->failure ? TIMER_
MAINTENANCE
: TIMER_DEAD);
+ timer_set_state(t, t->failure ? TIMER_
FAILED
: TIMER_DEAD);
}
static void timer_enter_waiting(Timer *t, bool initial) {
}
static void timer_enter_waiting(Timer *t, bool initial) {
@@
-204,9
+208,9
@@
static void timer_enter_waiting(Timer *t, bool initial) {
switch (v->base) {
case TIMER_ACTIVE:
switch (v->base) {
case TIMER_ACTIVE:
- if (state_translation_table[t->state] == UNIT_ACTIVE)
{
+ if (state_translation_table[t->state] == UNIT_ACTIVE)
base = t->meta.inactive_exit_timestamp.monotonic;
base = t->meta.inactive_exit_timestamp.monotonic;
-
}
else
+ else
base = n;
break;
base = n;
break;
@@
-221,18
+225,18
@@
static void timer_enter_waiting(Timer *t, bool initial) {
case TIMER_UNIT_ACTIVE:
case TIMER_UNIT_ACTIVE:
- if (
t->unit
->meta.inactive_exit_timestamp.monotonic <= 0)
+ if (
UNIT_DEREF(t->unit)
->meta.inactive_exit_timestamp.monotonic <= 0)
continue;
continue;
- base =
t->unit
->meta.inactive_exit_timestamp.monotonic;
+ base =
UNIT_DEREF(t->unit)
->meta.inactive_exit_timestamp.monotonic;
break;
case TIMER_UNIT_INACTIVE:
break;
case TIMER_UNIT_INACTIVE:
- if (
t->unit
->meta.inactive_enter_timestamp.monotonic <= 0)
+ if (
UNIT_DEREF(t->unit)
->meta.inactive_enter_timestamp.monotonic <= 0)
continue;
continue;
- base =
t->unit
->meta.inactive_enter_timestamp.monotonic;
+ base =
UNIT_DEREF(t->unit)
->meta.inactive_enter_timestamp.monotonic;
break;
default:
break;
default:
@@
-283,7
+287,7
@@
static void timer_enter_running(Timer *t) {
if (t->meta.job && t->meta.job->type == JOB_STOP)
return;
if (t->meta.job && t->meta.job->type == JOB_STOP)
return;
- if ((r = manager_add_job(t->meta.manager, JOB_START,
t->unit
, JOB_REPLACE, true, &error, NULL)) < 0)
+ if ((r = manager_add_job(t->meta.manager, JOB_START,
UNIT_DEREF(t->unit)
, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
timer_set_state(t, TIMER_RUNNING);
goto fail;
timer_set_state(t, TIMER_RUNNING);
@@
-300,9
+304,9
@@
static int timer_start(Unit *u) {
Timer *t = TIMER(u);
assert(t);
Timer *t = TIMER(u);
assert(t);
- assert(t->state == TIMER_DEAD || t->state == TIMER_
MAINTENANCE
);
+ assert(t->state == TIMER_DEAD || t->state == TIMER_
FAILED
);
- if (
t->unit
->meta.load_state != UNIT_LOADED)
+ if (
UNIT_DEREF(t->unit)
->meta.load_state != UNIT_LOADED)
return -ENOENT;
t->failure = false;
return -ENOENT;
t->failure = false;
@@
-379,37
+383,23
@@
static void timer_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
}
void timer_unit_notify(Unit *u, UnitActiveState new_state) {
}
void timer_unit_notify(Unit *u, UnitActiveState new_state) {
- char *n;
- int r;
Iterator i;
Iterator i;
+ Unit *k;
if (u->meta.type == UNIT_TIMER)
return;
if (u->meta.type == UNIT_TIMER)
return;
- SET_FOREACH(n, u->meta.names, i) {
- char *k;
- Unit *p;
+ SET_FOREACH(k, u->meta.dependencies[UNIT_TRIGGERED_BY], i) {
Timer *t;
TimerValue *v;
Timer *t;
TimerValue *v;
- if (!(k = unit_name_change_suffix(n, ".timer"))) {
- r = -ENOMEM;
- goto fail;
- }
-
- p = manager_get_unit(u->meta.manager, k);
- free(k);
-
- if (!p)
+ if (k->meta.type != UNIT_TIMER)
continue;
continue;
- if (
p
->meta.load_state != UNIT_LOADED)
+ if (
k
->meta.load_state != UNIT_LOADED)
continue;
continue;
- t = TIMER(p);
-
- if (t->unit != u)
- continue;
+ t = TIMER(k);
/* Reenable all timers that depend on unit state */
LIST_FOREACH(value, v, t->values)
/* Reenable all timers that depend on unit state */
LIST_FOREACH(value, v, t->values)
@@
-428,7
+418,7
@@
void timer_unit_notify(Unit *u, UnitActiveState new_state) {
case TIMER_RUNNING:
case TIMER_RUNNING:
- if (UNIT_IS_INACTIVE_OR_
MAINTENANCE
(new_state)) {
+ if (UNIT_IS_INACTIVE_OR_
FAILED
(new_state)) {
log_debug("%s got notified about unit deactivation.", t->meta.id);
timer_enter_waiting(t, false);
}
log_debug("%s got notified about unit deactivation.", t->meta.id);
timer_enter_waiting(t, false);
}
@@
-436,18
+426,24
@@
void timer_unit_notify(Unit *u, UnitActiveState new_state) {
break;
case TIMER_DEAD:
break;
case TIMER_DEAD:
- case TIMER_
MAINTENANCE
:
- ;
+ case TIMER_
FAILED
:
+
break
;
default:
assert_not_reached("Unknown timer state");
}
}
default:
assert_not_reached("Unknown timer state");
}
}
+}
- return;
+static void timer_reset_failed(Unit *u) {
+ Timer *t = TIMER(u);
-fail:
- log_error("Failed find timer unit: %s", strerror(-r));
+ assert(t);
+
+ if (t->state == TIMER_FAILED)
+ timer_set_state(t, TIMER_DEAD);
+
+ t->failure = false;
}
static const char* const timer_state_table[_TIMER_STATE_MAX] = {
}
static const char* const timer_state_table[_TIMER_STATE_MAX] = {
@@
-455,7
+451,7
@@
static const char* const timer_state_table[_TIMER_STATE_MAX] = {
[TIMER_WAITING] = "waiting",
[TIMER_RUNNING] = "running",
[TIMER_ELAPSED] = "elapsed",
[TIMER_WAITING] = "waiting",
[TIMER_RUNNING] = "running",
[TIMER_ELAPSED] = "elapsed",
- [TIMER_
MAINTENANCE] = "maintenance
"
+ [TIMER_
FAILED] = "failed
"
};
DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState);
};
DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState);
@@
-472,6
+468,10
@@
DEFINE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
const UnitVTable timer_vtable = {
.suffix = ".timer",
const UnitVTable timer_vtable = {
.suffix = ".timer",
+ .sections =
+ "Unit\0"
+ "Timer\0"
+ "Install\0",
.init = timer_init,
.done = timer_done,
.init = timer_init,
.done = timer_done,
@@
-492,5
+492,9
@@
const UnitVTable timer_vtable = {
.timer_event = timer_timer_event,
.timer_event = timer_timer_event,
- .bus_message_handler = bus_timer_message_handler
+ .reset_failed = timer_reset_failed,
+
+ .bus_interface = "org.freedesktop.systemd1.Timer",
+ .bus_message_handler = bus_timer_message_handler,
+ .bus_invalidating_properties = bus_timer_invalidating_properties
};
};