mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
core: rework job_get_timeout() to use usec_t and handle USEC_INFINITY time events correctly
This commit is contained in:
parent
8e5de09f44
commit
7a7821c878
@ -972,17 +972,21 @@ static int busname_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
|
||||
return unit_kill_common(u, who, signo, -1, BUSNAME(u)->control_pid, error);
|
||||
}
|
||||
|
||||
static int busname_get_timeout(Unit *u, uint64_t *timeout) {
|
||||
static int busname_get_timeout(Unit *u, usec_t *timeout) {
|
||||
BusName *n = BUSNAME(u);
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
if (!n->timer_event_source)
|
||||
return 0;
|
||||
|
||||
r = sd_event_source_get_time(n->timer_event_source, timeout);
|
||||
r = sd_event_source_get_time(n->timer_event_source, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (t == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1165,10 +1165,10 @@ void job_shutdown_magic(Job *j) {
|
||||
asynchronous_sync();
|
||||
}
|
||||
|
||||
int job_get_timeout(Job *j, uint64_t *timeout) {
|
||||
int job_get_timeout(Job *j, usec_t *timeout) {
|
||||
usec_t x = USEC_INFINITY, y = USEC_INFINITY;
|
||||
Unit *u = j->unit;
|
||||
uint64_t x = -1, y = -1;
|
||||
int r = 0, q = 0;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
|
||||
@ -1176,20 +1176,18 @@ int job_get_timeout(Job *j, uint64_t *timeout) {
|
||||
r = sd_event_source_get_time(j->timer_event_source, &x);
|
||||
if (r < 0)
|
||||
return r;
|
||||
r = 1;
|
||||
}
|
||||
|
||||
if (UNIT_VTABLE(u)->get_timeout) {
|
||||
q = UNIT_VTABLE(u)->get_timeout(u, &y);
|
||||
if (q < 0)
|
||||
return q;
|
||||
r = UNIT_VTABLE(u)->get_timeout(u, &y);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (r == 0 && q == 0)
|
||||
if (x == USEC_INFINITY && y == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = MIN(x, y);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -227,6 +227,8 @@ char *job_dbus_path(Job *j);
|
||||
|
||||
void job_shutdown_magic(Job *j);
|
||||
|
||||
int job_get_timeout(Job *j, usec_t *timeout) _pure_;
|
||||
|
||||
const char* job_type_to_string(JobType t) _const_;
|
||||
JobType job_type_from_string(const char *s) _pure_;
|
||||
|
||||
@ -239,6 +241,4 @@ JobMode job_mode_from_string(const char *s) _pure_;
|
||||
const char* job_result_to_string(JobResult t) _const_;
|
||||
JobResult job_result_from_string(const char *s) _pure_;
|
||||
|
||||
int job_get_timeout(Job *j, uint64_t *timeout) _pure_;
|
||||
|
||||
const char* job_type_to_access_method(JobType t);
|
||||
|
@ -1556,17 +1556,21 @@ static void mount_shutdown(Manager *m) {
|
||||
m->mount_monitor = NULL;
|
||||
}
|
||||
|
||||
static int mount_get_timeout(Unit *u, uint64_t *timeout) {
|
||||
static int mount_get_timeout(Unit *u, usec_t *timeout) {
|
||||
Mount *m = MOUNT(u);
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
if (!m->timer_event_source)
|
||||
return 0;
|
||||
|
||||
r = sd_event_source_get_time(m->timer_event_source, timeout);
|
||||
r = sd_event_source_get_time(m->timer_event_source, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (t == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -345,17 +345,21 @@ static int scope_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
|
||||
return unit_kill_common(u, who, signo, -1, -1, error);
|
||||
}
|
||||
|
||||
static int scope_get_timeout(Unit *u, uint64_t *timeout) {
|
||||
static int scope_get_timeout(Unit *u, usec_t *timeout) {
|
||||
Scope *s = SCOPE(u);
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
r = sd_event_source_get_time(s->timer_event_source, timeout);
|
||||
r = sd_event_source_get_time(s->timer_event_source, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (t == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -3111,17 +3111,21 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
|
||||
unit_add_to_dbus_queue(u);
|
||||
}
|
||||
|
||||
static int service_get_timeout(Unit *u, uint64_t *timeout) {
|
||||
static int service_get_timeout(Unit *u, usec_t *timeout) {
|
||||
Service *s = SERVICE(u);
|
||||
uint64_t t;
|
||||
int r;
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
r = sd_event_source_get_time(s->timer_event_source, timeout);
|
||||
r = sd_event_source_get_time(s->timer_event_source, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (t == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -2770,17 +2770,21 @@ static int socket_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
|
||||
return unit_kill_common(u, who, signo, -1, SOCKET(u)->control_pid, error);
|
||||
}
|
||||
|
||||
static int socket_get_timeout(Unit *u, uint64_t *timeout) {
|
||||
static int socket_get_timeout(Unit *u, usec_t *timeout) {
|
||||
Socket *s = SOCKET(u);
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
r = sd_event_source_get_time(s->timer_event_source, timeout);
|
||||
r = sd_event_source_get_time(s->timer_event_source, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (t == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1396,17 +1396,21 @@ static int swap_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
|
||||
return unit_kill_common(u, who, signo, -1, SWAP(u)->control_pid, error);
|
||||
}
|
||||
|
||||
static int swap_get_timeout(Unit *u, uint64_t *timeout) {
|
||||
static int swap_get_timeout(Unit *u, usec_t *timeout) {
|
||||
Swap *s = SWAP(u);
|
||||
usec_t t;
|
||||
int r;
|
||||
|
||||
if (!s->timer_event_source)
|
||||
return 0;
|
||||
|
||||
r = sd_event_source_get_time(s->timer_event_source, timeout);
|
||||
r = sd_event_source_get_time(s->timer_event_source, &t);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (t == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
*timeout = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,8 @@ struct UnitVTable {
|
||||
/* Called whenever CLOCK_REALTIME made a jump */
|
||||
void (*time_change)(Unit *u);
|
||||
|
||||
int (*get_timeout)(Unit *u, uint64_t *timeout);
|
||||
/* Returns the next timeout of a unit */
|
||||
int (*get_timeout)(Unit *u, usec_t *timeout);
|
||||
|
||||
/* This is called for each unit type and should be used to
|
||||
* enumerate existing devices and load them. However,
|
||||
|
Loading…
Reference in New Issue
Block a user