chiark / gitweb /
core: add function to tell when job will time out
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Jan 2014 05:57:34 +0000 (00:57 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Jan 2014 06:23:16 +0000 (01:23 -0500)
Things will continue when either the job timeout
or the unit timeout is reached. Add functionality to
access that info.

src/core/job.c
src/core/job.h
src/core/mount.c
src/core/scope.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/unit.h

index 7faa8da0ed7cf1bb13a738172574f3fc718c8230..e6529b61e9707352fd8260b5a0b48c32f90c8a61 100644 (file)
@@ -1086,6 +1086,37 @@ void job_shutdown_magic(Job *j) {
         asynchronous_sync();
 }
 
         asynchronous_sync();
 }
 
+int job_get_timeout(Job *j, uint64_t *timeout) {
+        Unit *u = j->unit;
+        uint64_t x = -1, y = -1;
+        int r = 0, q = 0;
+
+        assert(u);
+
+        if (j->timer_event_source) {
+                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;
+        }
+
+        if (r == 0 && q == 0)
+                return 0;
+
+        *timeout = MIN(x, y);
+
+        log_info("job_get_timeout %s %d/%"PRIu64" %d/%"PRIu64" -> 1/%"PRIu64,
+                 j->unit->id, r, x, q, y, *timeout);
+
+        return 1;
+}
+
 static const char* const job_state_table[_JOB_STATE_MAX] = {
         [JOB_WAITING] = "waiting",
         [JOB_RUNNING] = "running"
 static const char* const job_state_table[_JOB_STATE_MAX] = {
         [JOB_WAITING] = "waiting",
         [JOB_RUNNING] = "running"
index 0500e1208b18f01fb3d87bd1ea8fe65cd8abff71..8cc3a02192595c30eaa76150ce40cbb543849c51 100644 (file)
@@ -222,3 +222,5 @@ 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_;
 
 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_;
index bce50548bf3cef11577fc7a8e5984dc4c49a8d8f..90da88382606593d2c38d51c4b42c42b10bc76f3 100644 (file)
@@ -1583,6 +1583,20 @@ static void mount_shutdown(Manager *m) {
         }
 }
 
         }
 }
 
+static int mount_get_timeout(Unit *u, uint64_t *timeout) {
+        Mount *m = MOUNT(u);
+        int r;
+
+        if (!m->timer_event_source)
+                return 0;
+
+        r = sd_event_source_get_time(m->timer_event_source, timeout);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 static int mount_enumerate(Manager *m) {
         int r;
         assert(m);
 static int mount_enumerate(Manager *m) {
         int r;
         assert(m);
@@ -1796,6 +1810,8 @@ const UnitVTable mount_vtable = {
         .bus_set_property = bus_mount_set_property,
         .bus_commit_properties = bus_mount_commit_properties,
 
         .bus_set_property = bus_mount_set_property,
         .bus_commit_properties = bus_mount_commit_properties,
 
+        .get_timeout = mount_get_timeout,
+
         .enumerate = mount_enumerate,
         .shutdown = mount_shutdown,
 
         .enumerate = mount_enumerate,
         .shutdown = mount_shutdown,
 
index 56c374660e6a8ae8f82d1dd6c03228af4003db8c..87983f6b1746aa9537b01bb0689afa5252d49dd8 100644 (file)
@@ -318,6 +318,20 @@ static int scope_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
         return unit_kill_common(u, who, signo, -1, -1, error);
 }
 
         return unit_kill_common(u, who, signo, -1, -1, error);
 }
 
+static int scope_get_timeout(Unit *u, uint64_t *timeout) {
+        Scope *s = SCOPE(u);
+        int r;
+
+        if (!s->timer_event_source)
+                return 0;
+
+        r = sd_event_source_get_time(s->timer_event_source, timeout);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 static int scope_serialize(Unit *u, FILE *f, FDSet *fds) {
         Scope *s = SCOPE(u);
 
 static int scope_serialize(Unit *u, FILE *f, FDSet *fds) {
         Scope *s = SCOPE(u);
 
@@ -478,6 +492,8 @@ const UnitVTable scope_vtable = {
 
         .kill = scope_kill,
 
 
         .kill = scope_kill,
 
+        .get_timeout = scope_get_timeout,
+
         .serialize = scope_serialize,
         .deserialize_item = scope_deserialize_item,
 
         .serialize = scope_serialize,
         .deserialize_item = scope_deserialize_item,
 
index a2f0e3577bf8ea51bb5289492ff67ca80a7f6ff7..d949f7a3632709fa9fc42228c8e472a1d723becb 100644 (file)
@@ -3401,6 +3401,20 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
                 unit_add_to_dbus_queue(u);
 }
 
                 unit_add_to_dbus_queue(u);
 }
 
+static int service_get_timeout(Unit *u, uint64_t *timeout) {
+        Service *s = SERVICE(u);
+        int r;
+
+        if (!s->timer_event_source)
+                return 0;
+
+        r = sd_event_source_get_time(s->timer_event_source, timeout);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 #ifdef HAVE_SYSV_COMPAT
 
 static int service_enumerate(Manager *m) {
 #ifdef HAVE_SYSV_COMPAT
 
 static int service_enumerate(Manager *m) {
@@ -3832,6 +3846,8 @@ const UnitVTable service_vtable = {
         .bus_set_property = bus_service_set_property,
         .bus_commit_properties = bus_service_commit_properties,
 
         .bus_set_property = bus_service_set_property,
         .bus_commit_properties = bus_service_commit_properties,
 
+        .get_timeout = service_get_timeout,
+
 #ifdef HAVE_SYSV_COMPAT
         .enumerate = service_enumerate,
 #endif
 #ifdef HAVE_SYSV_COMPAT
         .enumerate = service_enumerate,
 #endif
index 1f2a2c0aaf34e62a2bf5eec503cc808def88cd86..7eac0eb66de22a7489dd76dc9a05fefde774581d 100644 (file)
@@ -2344,6 +2344,20 @@ 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);
 }
 
         return unit_kill_common(u, who, signo, -1, SOCKET(u)->control_pid, error);
 }
 
+static int socket_get_timeout(Unit *u, uint64_t *timeout) {
+        Socket *s = SOCKET(u);
+        int r;
+
+        if (!s->timer_event_source)
+                return 0;
+
+        r = sd_event_source_get_time(s->timer_event_source, timeout);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = "dead",
         [SOCKET_START_PRE] = "start-pre",
 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = "dead",
         [SOCKET_START_PRE] = "start-pre",
@@ -2408,6 +2422,8 @@ const UnitVTable socket_vtable = {
 
         .kill = socket_kill,
 
 
         .kill = socket_kill,
 
+        .get_timeout = socket_get_timeout,
+
         .serialize = socket_serialize,
         .deserialize_item = socket_deserialize_item,
         .distribute_fds = socket_distribute_fds,
         .serialize = socket_serialize,
         .deserialize_item = socket_deserialize_item,
         .distribute_fds = socket_distribute_fds,
index 6b204df5841d1d682bd2025d7f77786d464431b0..26141e6a33a643db721e1554d36c126b6d9c149c 100644 (file)
@@ -1367,6 +1367,20 @@ 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);
 }
 
         return unit_kill_common(u, who, signo, -1, SWAP(u)->control_pid, error);
 }
 
+static int swap_get_timeout(Unit *u, uint64_t *timeout) {
+        Swap *s = SWAP(u);
+        int r;
+
+        if (!s->timer_event_source)
+                return 0;
+
+        r = sd_event_source_get_time(s->timer_event_source, timeout);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 static const char* const swap_state_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = "dead",
         [SWAP_ACTIVATING] = "activating",
 static const char* const swap_state_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = "dead",
         [SWAP_ACTIVATING] = "activating",
@@ -1429,6 +1443,8 @@ const UnitVTable swap_vtable = {
 
         .kill = swap_kill,
 
 
         .kill = swap_kill,
 
+        .get_timeout = swap_get_timeout,
+
         .serialize = swap_serialize,
         .deserialize_item = swap_deserialize_item,
 
         .serialize = swap_serialize,
         .deserialize_item = swap_deserialize_item,
 
index 45816eae353b94fe674c9a387f7f9c17e8c01ca6..c686aeccefda52913f5dde6d3d09ec9fd406ea0c 100644 (file)
@@ -410,6 +410,8 @@ struct UnitVTable {
         /* Called whenever CLOCK_REALTIME made a jump */
         void (*time_change)(Unit *u);
 
         /* Called whenever CLOCK_REALTIME made a jump */
         void (*time_change)(Unit *u);
 
+        int (*get_timeout)(Unit *u, uint64_t *timeout);
+
         /* This is called for each unit type and should be used to
          * enumerate existing devices and load them. However,
          * everything that is loaded here should still stay in
         /* This is called for each unit type and should be used to
          * enumerate existing devices and load them. However,
          * everything that is loaded here should still stay in