summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/service_common.h1
-rw-r--r--packaging/data-provider-master.spec2
-rw-r--r--src/service_common.c34
-rw-r--r--src/utility_service.c50
5 files changed, 77 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50bf37e..ce2dbca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -105,7 +105,7 @@ ADD_EXECUTABLE(${PROJECT_NAME}
src/service_common.c
)
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_LDFLAGS} "-ldl")
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_LDFLAGS} "-ldl -lrt")
INSTALL(FILES ${CMAKE_SOURCE_DIR}/data-provider-master.rule DESTINATION /opt/etc/smack/accesses.d PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/data/abi.ini DESTINATION /usr/share/data-provider-master PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
diff --git a/include/service_common.h b/include/service_common.h
index e60de2b..7e02404 100644
--- a/include/service_common.h
+++ b/include/service_common.h
@@ -36,6 +36,7 @@ extern int service_common_multicast_packet(struct tcb *tcb, struct packet *packe
extern int service_common_unicast_packet(struct tcb *tcb, struct packet *packet);
extern struct service_event_item *service_common_add_timer(struct service_context *svc_ctx, double timer, int (*timer_cb)(struct service_context *svc_cx, void *data), void *data);
+extern int service_common_update_timer(struct service_event_item *item, double timer);
extern int service_common_del_timer(struct service_context *svc_ctx, struct service_event_item *item);
extern int service_common_fd(struct service_context *ctx);
diff --git a/packaging/data-provider-master.spec b/packaging/data-provider-master.spec
index 803ba21..8646312 100644
--- a/packaging/data-provider-master.spec
+++ b/packaging/data-provider-master.spec
@@ -1,6 +1,6 @@
Name: data-provider-master
Summary: Master service provider for liveboxes
-Version: 0.25.18
+Version: 0.25.19
Release: 1
Group: HomeTF/Livebox
License: Flora License
diff --git a/src/service_common.c b/src/service_common.c
index d48e013..3a888e0 100644
--- a/src/service_common.c
+++ b/src/service_common.c
@@ -24,6 +24,7 @@
#include <sys/timerfd.h>
#include <unistd.h>
#include <fcntl.h>
+#include <time.h>
#include <dlog.h>
#include <Eina.h>
@@ -971,7 +972,6 @@ HAPI int service_common_multicast_packet(struct tcb *tcb, struct packet *packet,
HAPI struct service_event_item *service_common_add_timer(struct service_context *svc_ctx, double timer, int (*timer_cb)(struct service_context *svc_cx, void *data), void *data)
{
struct service_event_item *item;
- struct itimerspec spec;
item = calloc(1, sizeof(*item));
if (!item) {
@@ -987,13 +987,7 @@ HAPI struct service_event_item *service_common_add_timer(struct service_context
return NULL;
}
- spec.it_interval.tv_sec = (time_t)timer;
- spec.it_interval.tv_nsec = (timer - spec.it_interval.tv_sec) * 1000000000;
- spec.it_value.tv_sec = 0;
- spec.it_value.tv_nsec = 0;
-
- if (timerfd_settime(item->info.timer.fd, 0, &spec, NULL) < 0) {
- ErrPrint("Error: %s\n", strerror(errno));
+ if (service_common_update_timer(item, timer) < 0) {
if (close(item->info.timer.fd) < 0) {
ErrPrint("close: %s\n", strerror(errno));
}
@@ -1008,6 +1002,30 @@ HAPI struct service_event_item *service_common_add_timer(struct service_context
return item;
}
+HAPI int service_common_update_timer(struct service_event_item *item, double timer)
+{
+ struct itimerspec spec;
+
+ spec.it_interval.tv_sec = (time_t)timer;
+ spec.it_interval.tv_nsec = (timer - spec.it_interval.tv_sec) * 1000000000;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &spec.it_value) < 0) {
+ ErrPrint("clock_gettime: %s\n", strerror(errno));
+ return -EFAULT;
+ }
+
+ spec.it_value.tv_sec += spec.it_interval.tv_sec;
+ spec.it_value.tv_nsec += spec.it_interval.tv_nsec;
+
+ if (timerfd_settime(item->info.timer.fd, TFD_TIMER_ABSTIME, &spec, NULL) < 0) {
+ ErrPrint("Error: %s\n", strerror(errno));
+ return -EFAULT;
+ }
+
+ DbgPrint("Armed interval: %u %u\n", spec.it_interval.tv_sec, spec.it_interval.tv_nsec);
+ return 0;
+}
+
/*!
* \note
* SERVER THREAD
diff --git a/src/utility_service.c b/src/utility_service.c
index 5b98b5b..87ad081 100644
--- a/src/utility_service.c
+++ b/src/utility_service.c
@@ -40,6 +40,10 @@
#define LAUNCH_TIMEOUT 10.0f
#endif
+#ifndef TTL_TIMEOUT
+#define TTL_TIMEOUT 30.0f
+#endif
+
static struct info {
Eina_List *pending_list;
Eina_List *context_list;
@@ -47,9 +51,11 @@ static struct info {
struct tcb *svc_daemon;
int svc_daemon_is_launched;
+ int svc_daemon_pid;
struct service_event_item *launch_timer;
struct service_event_item *delay_launcher;
+ struct service_event_item *ttl_timer;
} s_info = {
.pending_list = NULL,
.context_list = NULL, /*!< \WARN: This is only used for SERVICE THREAD */
@@ -57,9 +63,11 @@ static struct info {
.svc_daemon = NULL,
.svc_daemon_is_launched = 0,
+ .svc_daemon_pid = -1,
.launch_timer = NULL,
.delay_launcher = NULL,
+ .ttl_timer = NULL,
};
struct pending_item {
@@ -187,6 +195,7 @@ static int launch_timeout_cb(struct service_context *svc_ctx, void *data)
s_info.launch_timer = NULL;
s_info.svc_daemon_is_launched = 0;
+ s_info.svc_daemon_pid = -1;
return -ECANCELED; /* Delete this timer */
}
@@ -224,6 +233,7 @@ static inline int launch_svc(struct service_context *svc_ctx)
default:
DbgPrint("Launched: %s(%d)\n", SVC_PKG, pid);
s_info.svc_daemon_is_launched = 1;
+ s_info.svc_daemon_pid = pid;
s_info.launch_timer = service_common_add_timer(svc_ctx, LAUNCH_TIMEOUT, launch_timeout_cb, NULL);
if (!s_info.launch_timer) {
ErrPrint("Unable to create launch timer\n");
@@ -235,8 +245,21 @@ static inline int launch_svc(struct service_context *svc_ctx)
static int lazy_launcher_cb(struct service_context *svc_ctx, void *data)
{
- s_info.svc_daemon_is_launched = launch_svc(svc_ctx) == LB_STATUS_SUCCESS;
s_info.delay_launcher = NULL;
+
+ (void)launch_svc(svc_ctx);
+ return -ECANCELED;
+}
+
+static int ttl_timer_cb(struct service_context *svc_ctx, void *data)
+{
+ DbgPrint("TTL Timer is expired: PID(%d)\n", s_info.svc_daemon_pid);
+ (void)aul_terminate_pid(s_info.svc_daemon_pid);
+
+ s_info.ttl_timer = NULL;
+ s_info.svc_daemon_is_launched = 0;
+ s_info.svc_daemon_pid = -1;
+ s_info.svc_daemon = NULL;
return -ECANCELED;
}
@@ -247,11 +270,17 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat
int ret;
if (!packet) {
- DbgPrint("TCB %p is terminated (NIL packet)\n", tcb);
+ DbgPrint("TCB %p is terminated (NIL packet), %d\n", tcb, s_info.svc_daemon_pid);
if (tcb == s_info.svc_daemon) {
s_info.svc_daemon = NULL;
s_info.svc_daemon_is_launched = 0;
+ s_info.svc_daemon_pid = -1;
+
+ if (s_info.ttl_timer) {
+ service_common_del_timer(tcb_svc_ctx(tcb), s_info.ttl_timer);
+ s_info.ttl_timer = NULL;
+ }
}
return LB_STATUS_SUCCESS;
@@ -284,6 +313,10 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat
}
put_reply_tcb(tcb, packet_seq(packet));
+
+ if (s_info.ttl_timer && service_common_update_timer(s_info.ttl_timer, TTL_TIMEOUT) < 0) {
+ ErrPrint("Failed to update timer\n");
+ }
}
break;
@@ -304,6 +337,19 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat
s_info.launch_timer = NULL;
}
+ s_info.ttl_timer = service_common_add_timer(tcb_svc_ctx(tcb), TTL_TIMEOUT, ttl_timer_cb, NULL);
+ if (!s_info.ttl_timer) {
+ ErrPrint("Failed to add TTL timer\n");
+ if (s_info.svc_daemon_pid > 0) {
+ ret = aul_terminate_pid(s_info.svc_daemon_pid);
+ ErrPrint("Terminate: %d\n", ret);
+ s_info.svc_daemon_pid = -1;
+ }
+ s_info.svc_daemon_is_launched = 0;
+ return LB_STATUS_ERROR_FAULT;
+ }
+ DbgPrint("TTL Timer is added: %p\n", s_info.ttl_timer);
+
s_info.svc_daemon = tcb;
flush_pended_request();
}