manager: introduce watch_init() initializer for watches

This commit is contained in:
Lennart Poettering 2012-11-22 00:38:55 +01:00
parent 0b2665c33d
commit 68b29a9fca
4 changed files with 15 additions and 4 deletions

View File

@ -1363,7 +1363,8 @@ static int process_event(Manager *m, struct epoll_event *ev) {
ssize_t k;
/* Some timer event, to be dispatched to the units */
if ((k = read(w->fd, &v, sizeof(v))) != sizeof(v)) {
k = read(w->fd, &v, sizeof(v));
if (k != sizeof(v)) {
if (k < 0 && (errno == EINTR || errno == EAGAIN))
break;
@ -2307,3 +2308,10 @@ bool manager_get_show_status(Manager *m) {
return plymouth_running();
}
void watch_init(Watch *w) {
assert(w);
w->type = WATCH_INVALID;
w->fd = -1;
}

View File

@ -291,3 +291,5 @@ void manager_recheck_journal(Manager *m);
void manager_set_show_status(Manager *m, bool b);
bool manager_get_show_status(Manager *m);
void watch_init(Watch *w);

View File

@ -127,9 +127,9 @@ static void service_init(Unit *u) {
s->restart_usec = DEFAULT_RESTART_USEC;
s->type = _SERVICE_TYPE_INVALID;
s->watchdog_watch.type = WATCH_INVALID;
watch_init(&s->watchdog_watch);
watch_init(&s->timer_watch);
s->timer_watch.type = WATCH_INVALID;
#ifdef HAVE_SYSV_COMPAT
s->sysv_start_priority = -1;
s->sysv_start_priority_from_rcnd = -1;

View File

@ -1580,7 +1580,8 @@ int unit_watch_timer(Unit *u, usec_t delay, Watch *w) {
} else if (w->type == WATCH_INVALID) {
ours = true;
if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0)
fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC);
if (fd < 0)
return -errno;
} else
assert_not_reached("Invalid watch type");