summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSung-jae Park <nicesj.park@samsung.com>2013-05-20 20:23:16 +0900
committerSung-jae Park <nicesj.park@samsung.com>2013-05-20 20:23:16 +0900
commit3f1f82cd5fae672047ecc091b1033dc21319ebf3 (patch)
treeb13131231f9f6302cb15eb2380e56ffe592046d1
parent822a00b45eb35319ccbc168eb32ae1387ac8945e (diff)
downloaddata-provider-master-3f1f82cd5fae672047ecc091b1033dc21319ebf3.tar.gz
data-provider-master-3f1f82cd5fae672047ecc091b1033dc21319ebf3.tar.bz2
data-provider-master-3f1f82cd5fae672047ecc091b1033dc21319ebf3.zip
Logging the critical message to a file.
The file will be unlinked every boot. So the log must has to be captured before reboot the device Change-Id: I1c2bc06b61cd7c429426b04bebbd499d267c1061
-rw-r--r--packaging/data-provider-master.spec2
-rw-r--r--src/critical_log.c2
-rw-r--r--src/fault_manager.c10
-rw-r--r--src/main.c120
-rw-r--r--src/service_common.c43
-rw-r--r--src/setting.c10
6 files changed, 117 insertions, 70 deletions
diff --git a/packaging/data-provider-master.spec b/packaging/data-provider-master.spec
index c1d54a9..94ded97 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.23.2
+Version: 0.23.3
Release: 1
Group: HomeTF/Livebox
License: Flora License
diff --git a/src/critical_log.c b/src/critical_log.c
index e4da632..3b6059c 100644
--- a/src/critical_log.c
+++ b/src/critical_log.c
@@ -98,6 +98,8 @@ HAPI int critical_log(const char *func, int line, const char *fmt, ...)
ret = vfprintf(s_info.fp, fmt, ap);
va_end(ap);
+ fflush(s_info.fp);
+
s_info.nr_of_lines++;
rotate_log();
return ret;
diff --git a/src/fault_manager.c b/src/fault_manager.c
index 6ece35e..86b61c0 100644
--- a/src/fault_manager.c
+++ b/src/fault_manager.c
@@ -34,6 +34,7 @@
#include "client_rpc.h"
#include "package.h"
#include "conf.h"
+#include "critical_log.h"
static struct info {
Eina_List *call_list;
@@ -139,11 +140,10 @@ HAPI void fault_broadcast_info(const char *pkgname, const char *filename, const
static inline void dump_fault_info(const char *name, pid_t pid, const char *pkgname, const char *filename, const char *funcname)
{
- ErrPrint("Fault processing ====\n");
- ErrPrint("Slavename: %s[%d]\n", name, pid);
- ErrPrint("Package: %s\n", pkgname);
- ErrPrint("Filename: %s\n", filename);
- ErrPrint("Funcname: %s\n", funcname);
+ CRITICAL_LOG("Slavename: %s[%d]\n" \
+ "Package: %s\n" \
+ "Filename: %s\n" \
+ "Funcname: %s\n", name, pid, pkgname, filename, funcname);
}
HAPI int fault_info_set(struct slave_node *slave, const char *pkgname, const char *id, const char *func)
diff --git a/src/main.c b/src/main.c
index e57fc6b..a235299 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/signalfd.h>
#include <Ecore.h>
#include <Ecore_X.h>
@@ -117,6 +118,13 @@ static inline int app_create(void)
DbgPrint("Server initialized: %d\n", ret);
event_init();
+
+ shortcut_service_init();
+ notification_service_init();
+ badge_service_init();
+ utility_service_init();
+ script_init();
+
return 0;
}
@@ -124,11 +132,30 @@ static inline int app_terminate(void)
{
int ret;
- event_fini();
+ ret = script_fini();
+ DbgPrint("script: %d\n", ret);
+
+ ret = utility_service_fini();
+ DbgPrint("utility: %d\n", ret);
+
+ ret = badge_service_fini();
+ DbgPrint("badge: %d\n", ret);
+
+ ret = notification_service_fini();
+ DbgPrint("noti: %d\n", ret);
+
+ ret = shortcut_service_fini();
+ DbgPrint("shortcut: %d\n", ret);
+
+ ret = event_fini();
+ DbgPrint("event: %d\n", ret);
ret = setting_fini();
DbgPrint("Finalize setting : %d\n", ret);
+ ret = buffer_handler_fini();
+ DbgPrint("buffer handler: %d\n", ret);
+
xmonitor_fini();
instance_fini();
@@ -154,22 +181,57 @@ static inline int app_terminate(void)
return 0;
}
-static void signal_handler(int signum, siginfo_t *info, void *unused)
+static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler)
{
+ struct signalfd_siginfo fdsi;
+ ssize_t size;
int fd;
- CRITICAL_LOG("Terminated(SIGTERM)\n");
- fd = creat("/tmp/.stop.provider", 0644);
- if (fd > 0)
- close(fd);
+ fd = ecore_main_fd_handler_fd_get(handler);
+ if (fd < 0) {
+ ErrPrint("Unable to get FD\n");
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ size = read(fd, &fdsi, sizeof(fdsi));
+ if (size != sizeof(fdsi)) {
+ ErrPrint("Unable to get siginfo: %s\n", strerror(errno));
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ if (fdsi.ssi_signo == SIGTERM) {
+ int cfd;
+
+ CRITICAL_LOG("Terminated(SIGTERM)\n");
+
+ cfd = creat("/tmp/.stop.provider", 0644);
+ if (cfd < 0 || close(cfd) < 0)
+ ErrPrint("stop.provider: %s\n", strerror(errno));
- exit(0);
+ vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
+ exit(0);
+ //ecore_main_loop_quit();
+ } else {
+ CRITICAL_LOG("Unknown SIG[%d] received\n", fdsi.ssi_signo);
+ }
+
+ return ECORE_CALLBACK_RENEW;
}
int main(int argc, char *argv[])
{
- struct sigaction act;
int ret;
+ sigset_t mask;
+ Ecore_Fd_Handler *signal_handler = NULL;
+
+ /*!
+ * \note
+ * Clear old contents files before start the master provider.
+ */
+ (void)util_unlink_files(ALWAYS_PATH);
+ (void)util_unlink_files(READER_PATH);
+ (void)util_unlink_files(IMAGE_PATH);
+ (void)util_unlink_files(SLAVE_LOG_PATH);
/*!
* How could we care this return values?
@@ -191,20 +253,23 @@ int main(int argc, char *argv[])
return -EFAULT;
}
- act.sa_sigaction = signal_handler;
- act.sa_flags = SA_SIGINFO;
+ sigemptyset(&mask);
- ret = sigemptyset(&act.sa_mask);
+ ret = sigaddset(&mask, SIGTERM);
if (ret < 0)
CRITICAL_LOG("Failed to do sigemptyset: %s\n", strerror(errno));
- ret = sigaddset(&act.sa_mask, SIGTERM);
+ ret = sigprocmask(SIG_BLOCK, &mask, NULL);
if (ret < 0)
CRITICAL_LOG("Failed to mask the SIGTERM: %s\n", strerror(errno));
- ret = sigaction(SIGTERM, &act, NULL);
- if (ret < 0)
- CRITICAL_LOG("Failed to add sigaction: %s\n", strerror(errno));
+ ret = signalfd(-1, &mask, 0);
+ if (ret < 0) {
+ CRITICAL_LOG("Failed to initiate the signalfd: %s\n", strerror(errno));
+ } else {
+ signal_handler = ecore_main_fd_handler_add(ret, ECORE_FD_READ, signal_cb, NULL, NULL, NULL);
+ CRITICAL_LOG("Signal handler initiated: %d\n", ret);
+ }
if (ecore_x_init(NULL) <= 0) {
CRITICAL_LOG("Failed to ecore x init\n");
@@ -236,21 +301,6 @@ int main(int argc, char *argv[])
conf_loader();
- /*!
- * \note
- * Clear old contents files before start the master provider.
- */
- (void)util_unlink_files(ALWAYS_PATH);
- (void)util_unlink_files(READER_PATH);
- (void)util_unlink_files(IMAGE_PATH);
- (void)util_unlink_files(SLAVE_LOG_PATH);
-
- shortcut_service_init();
- notification_service_init();
- badge_service_init();
- utility_service_init();
- script_init();
-
app_create();
vconf_set_bool(VCONFKEY_MASTER_STARTED, 1);
@@ -259,16 +309,14 @@ int main(int argc, char *argv[])
app_terminate();
- script_fini();
- utility_service_fini();
- badge_service_fini();
- notification_service_fini();
- shortcut_service_fini();
-
ecore_evas_shutdown();
evas_shutdown();
ecore_x_shutdown();
+
+ if (signal_handler)
+ ecore_main_fd_handler_del(signal_handler);
+
ecore_shutdown();
critical_log_fini();
diff --git a/src/service_common.c b/src/service_common.c
index 0190bf6..5b2a01a 100644
--- a/src/service_common.c
+++ b/src/service_common.c
@@ -400,42 +400,34 @@ static inline void tcb_destroy(struct service_context *svc_ctx, struct tcb *tcb)
* \note
* SERVER THREAD
*/
-static inline int find_max_fd(struct service_context *svc_ctx)
-{
- int fd;
- Eina_List *l;
- struct service_event_item *item;
-
- fd = svc_ctx->fd > svc_ctx->tcb_pipe[PIPE_READ] ? svc_ctx->fd : svc_ctx->tcb_pipe[PIPE_READ];
- fd = fd > svc_ctx->evt_pipe[PIPE_READ] ? fd : svc_ctx->evt_pipe[PIPE_READ];
-
- EINA_LIST_FOREACH(svc_ctx->event_list, l, item) {
- if (item->type == SERVICE_EVENT_TIMER && fd < item->info.timer.fd)
- fd = item->info.timer.fd;
- }
-
- fd += 1;
- return fd;
-}
-
-/*!
- * \note
- * SERVER THREAD
- */
-static inline void update_fdset(struct service_context *svc_ctx, fd_set *set)
+static inline int update_fdset(struct service_context *svc_ctx, fd_set *set)
{
Eina_List *l;
struct service_event_item *item;
+ int fd = 0;
FD_ZERO(set);
+
FD_SET(svc_ctx->fd, set);
+ fd = svc_ctx->fd;
+
FD_SET(svc_ctx->tcb_pipe[PIPE_READ], set);
+ if (svc_ctx->tcb_pipe[PIPE_READ] > fd)
+ fd = svc_ctx->tcb_pipe[PIPE_READ];
+
FD_SET(svc_ctx->evt_pipe[PIPE_READ], set);
+ if (svc_ctx->evt_pipe[PIPE_READ] > fd)
+ fd = svc_ctx->evt_pipe[PIPE_READ];
EINA_LIST_FOREACH(svc_ctx->event_list, l, item) {
- if (item->type == SERVICE_EVENT_TIMER)
+ if (item->type == SERVICE_EVENT_TIMER) {
FD_SET(item->info.timer.fd, set);
+ if (fd < item->info.timer.fd)
+ fd = item->info.timer.fd;
+ }
}
+
+ return fd + 1;
}
/*!
@@ -498,8 +490,7 @@ static void *server_main(void *data)
DbgPrint("Server thread is activated\n");
while (1) {
- fd = find_max_fd(svc_ctx);
- update_fdset(svc_ctx, &set);
+ fd = update_fdset(svc_ctx, &set);
ret = select(fd, &set, NULL, NULL, NULL);
if (ret < 0) {
diff --git a/src/setting.c b/src/setting.c
index 5f6bdaf..e7e5379 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -27,6 +27,7 @@
#include <vconf.h>
#include <dlog.h>
+#include <Ecore.h>
#include <Eina.h>
#include "client_life.h"
@@ -72,10 +73,15 @@ static void power_off_cb(keynode_t *node, void *user_data)
}
if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
- if (creat("/tmp/.stop.provider", 0644) < 0)
- ErrPrint("Failed to create .stop.provider [%s]\n", strerror(errno));
+ int fd;
+ fd = creat("/tmp/.stop.provider", 0644);
+ if (fd < 0 || close(fd) < 0)
+ ErrPrint("stop.provider [%s]\n", strerror(errno));
+
+ vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
exit(0);
+ //ecore_main_loop_quit();
} else {
ErrPrint("Unknown power state: %d\n", val);
}