From: Sung-jae Park Date: Mon, 10 Feb 2014 22:39:01 +0000 (+0900) Subject: Update liveinfo server X-Git-Tag: submit/tizen_mobile/20150527.071719~2^2~48^2~21^2~77^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ecb6a52dfaa0815cda4e7e9b57a677e4c568e2b;p=platform%2Fcore%2Fappfw%2Fdata-provider-master.git Update liveinfo server Change-Id: I1c50e24579f8c0feae0f006d037719cfee085607 --- diff --git a/include/liveinfo.h b/include/liveinfo.h index 9bb6db5..f951e26 100644 --- a/include/liveinfo.h +++ b/include/liveinfo.h @@ -29,5 +29,7 @@ extern pid_t liveinfo_pid(struct liveinfo *info); extern FILE *liveinfo_fifo(struct liveinfo *info); extern int liveinfo_open_fifo(struct liveinfo *info); extern void liveinfo_close_fifo(struct liveinfo *info); +extern void liveinfo_set_data(struct liveinfo *info, void *data); +extern void *liveinfo_data(struct liveinfo *info); /* End of a file */ diff --git a/packaging/data-provider-master.spec b/packaging/data-provider-master.spec index 1227656..5f29f9f 100755 --- 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.34.1 +Version: 0.34.2 Release: 1 Group: HomeTF/Livebox License: Flora diff --git a/src/liveinfo.c b/src/liveinfo.c index 738e467..9c8f217 100644 --- a/src/liveinfo.c +++ b/src/liveinfo.c @@ -46,6 +46,7 @@ struct liveinfo { char fifo_name[60]; pid_t pid; int handle; + void *data; }; HAPI int liveinfo_init(void) @@ -88,9 +89,28 @@ static inline int valid_requestor(pid_t pid) return 0; } + if (target.st_ino == src.st_ino) { + return 1; + } + + if (stat("/opt/usr/devel/usr/bin/dbox-mgr", &src) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return 0; + } + return target.st_ino == src.st_ino; } +HAPI void liveinfo_set_data(struct liveinfo *info, void *data) +{ + info->data = data; +} + +HAPI void *liveinfo_data(struct liveinfo *info) +{ + return info->data; +} + HAPI struct liveinfo *liveinfo_create(pid_t pid, int handle) { struct liveinfo *info; diff --git a/src/server.c b/src/server.c index 30bcf86..48d1017 100644 --- a/src/server.c +++ b/src/server.c @@ -7087,31 +7087,18 @@ out: return result; } -static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet) +static Eina_Bool lazy_slave_list_cb(void *info) { - Eina_List *l; + FILE *fp; Eina_List *list; - struct liveinfo *info; + Eina_List *l; struct slave_node *slave; - FILE *fp; - double timestamp; - - if (packet_get(packet, "d", ×tamp) != 1) { - ErrPrint("Invalid argument\n"); - goto out; - } - - info = liveinfo_find_by_pid(pid); - if (!info) { - ErrPrint("Invalid request\n"); - goto out; - } liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { liveinfo_close_fifo(info); - goto out; + return ECORE_CALLBACK_CANCEL; } list = (Eina_List *)slave_list(); @@ -7133,6 +7120,28 @@ static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct pa fprintf(fp, "EOD\n"); liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; +} + +static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet) +{ + struct liveinfo *info; + double timestamp; + + if (packet_get(packet, "d", ×tamp) != 1) { + ErrPrint("Invalid argument\n"); + goto out; + } + + info = liveinfo_find_by_pid(pid); + if (!info) { + ErrPrint("Invalid request\n"); + goto out; + } + + if (!ecore_timer_add(0.5f, lazy_slave_list_cb, info)) { + ErrPrint("Failed to add timer\n"); + } out: return NULL; } @@ -7153,25 +7162,18 @@ static inline const char *visible_state_string(enum livebox_visible_state state) return "Unknown"; } -static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet) +static Eina_Bool inst_list_cb(void *info) { - const char *pkgname; - struct liveinfo *info; + FILE *fp; + char *pkgname; struct pkg_info *pkg; Eina_List *l; Eina_List *inst_list; struct inst_info *inst; - FILE *fp; - - if (packet_get(packet, "s", &pkgname) != 1) { - ErrPrint("Invalid argument\n"); - goto out; - } - info = liveinfo_find_by_pid(pid); - if (!info) { - ErrPrint("Invalid request\n"); - goto out; + pkgname = liveinfo_data(info); + if (!pkgname) { + return ECORE_CALLBACK_CANCEL; } liveinfo_open_fifo(info); @@ -7179,15 +7181,18 @@ static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct pac if (!fp) { ErrPrint("Invalid fp\n"); liveinfo_close_fifo(info); - goto out; + free(pkgname); + return ECORE_CALLBACK_CANCEL; } if (!package_is_lb_pkgname(pkgname)) { ErrPrint("Invalid package name\n"); + free(pkgname); goto close_out; } pkg = package_find(pkgname); + free(pkgname); if (!pkg) { ErrPrint("Package is not exists\n"); goto close_out; @@ -7209,23 +7214,16 @@ close_out: fprintf(fp, "EOD\n"); liveinfo_close_fifo(info); -out: - return NULL; + return ECORE_CALLBACK_CANCEL; } -static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet) +static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet) { - Eina_List *l; - Eina_List *list; - Eina_List *inst_list; + const char *pkgname; + char *dup_pkgname; struct liveinfo *info; - struct pkg_info *pkg; - struct slave_node *slave; - FILE *fp; - const char *slavename; - double timestamp; - if (packet_get(packet, "d", ×tamp) != 1) { + if (packet_get(packet, "s", &pkgname) != 1) { ErrPrint("Invalid argument\n"); goto out; } @@ -7236,11 +7234,36 @@ static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct pack goto out; } + dup_pkgname = strdup(pkgname); + if (!dup_pkgname) { + ErrPrint("Invalid request\n"); + goto out; + } + + liveinfo_set_data(info, dup_pkgname); + inst_list_cb(info); + +out: + return NULL; +} + +static Eina_Bool pkg_list_cb(void *info) +{ + FILE *fp; + Eina_List *l; + Eina_List *list; + Eina_List *inst_list; + struct pkg_info *pkg; + struct slave_node *slave; + const char *slavename; + pid_t pid; + liveinfo_open_fifo(info); fp = liveinfo_fifo(info); if (!fp) { + DbgPrint("Failed to open a pipe\n"); liveinfo_close_fifo(info); - goto out; + return ECORE_CALLBACK_CANCEL; } list = (Eina_List *)package_list(); @@ -7265,10 +7288,42 @@ static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct pack package_fault_count(pkg), eina_list_count(inst_list) ); + DbgPrint("%d %s %s %s %d %d %d\n", + pid, + strlen(slavename) ? slavename : "(none)", + package_name(pkg), + package_abi(pkg), + package_refcnt(pkg), + package_fault_count(pkg), + eina_list_count(inst_list) + ); } fprintf(fp, "EOD\n"); + DbgPrint("EOD\n"); liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; +} + +static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet) +{ + struct liveinfo *info; + double timestamp; + + if (packet_get(packet, "d", ×tamp) != 1) { + ErrPrint("Invalid argument\n"); + goto out; + } + + DbgPrint("Package List: %lf\n", timestamp); + + info = liveinfo_find_by_pid(pid); + if (!info) { + ErrPrint("Invalid request\n"); + goto out; + } + + pkg_list_cb(info); out: return NULL; } @@ -7278,10 +7333,59 @@ static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct pa return NULL; } +static Eina_Bool pkg_ctrl_rmpack_cb(void *info) +{ + FILE *fp; + liveinfo_open_fifo(info); + fp = liveinfo_fifo(info); + if (!fp) { + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; + } + + fprintf(fp, "%d\n", ENOSYS); + fprintf(fp, "EOD\n"); + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool pkg_ctrl_rminst_cb(void *info) +{ + FILE *fp; + + liveinfo_open_fifo(info); + fp = liveinfo_fifo(info); + if (!fp) { + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; + } + + fprintf(fp, "%d\n", (int)liveinfo_data(info)); + fprintf(fp, "EOD\n"); + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool pkg_ctrl_faultinst_cb(void *info) +{ + FILE *fp; + + liveinfo_open_fifo(info); + fp = liveinfo_fifo(info); + if (!fp) { + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; + } + + fprintf(fp, "%d\n", (int)liveinfo_data(info)); + fprintf(fp, "EOD\n"); + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; +} + static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet) { struct liveinfo *info; - FILE *fp; char *cmd; char *pkgname; char *id; @@ -7297,56 +7401,65 @@ static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct pack goto out; } - liveinfo_open_fifo(info); - fp = liveinfo_fifo(info); - if (!fp) { - liveinfo_close_fifo(info); - goto out; - } - if (!strcmp(cmd, "rmpack")) { - fprintf(fp, "%d\n", ENOSYS); + pkg_ctrl_rmpack_cb(info); } else if (!strcmp(cmd, "rminst")) { struct inst_info *inst; inst = package_find_instance_by_id(pkgname, id); if (!inst) { - fprintf(fp, "%d\n", ENOENT); + liveinfo_set_data(info, (void *)ENOENT); } else { (void)instance_destroy(inst, INSTANCE_DESTROY_DEFAULT); - fprintf(fp, "%d\n", 0); + liveinfo_set_data(info, (void *)0); } + + pkg_ctrl_rminst_cb(info); } else if (!strcmp(cmd, "faultinst")) { struct inst_info *inst; inst = package_find_instance_by_id(pkgname, id); if (!inst) { - fprintf(fp, "%d\n", ENOENT); + liveinfo_set_data(info, (void *)ENOENT); } else { struct pkg_info *pkg; pkg = instance_package(inst); if (!pkg) { - fprintf(fp, "%d\n", EFAULT); + liveinfo_set_data(info, (void *)EFAULT); } else { (void)package_faulted(pkg); - fprintf(fp, "%d\n", 0); + liveinfo_set_data(info, (void *)0); } } - } - fprintf(fp, "EOD\n"); - liveinfo_close_fifo(info); + pkg_ctrl_faultinst_cb(info); + } out: return NULL; } +static Eina_Bool master_ctrl_cb(void *info) +{ + FILE *fp; + + liveinfo_open_fifo(info); + fp = liveinfo_fifo(info); + if (!fp) { + liveinfo_close_fifo(info); + return ECORE_CALLBACK_CANCEL; + } + fprintf(fp, "%d\nEOD\n", (int)liveinfo_data(info)); + liveinfo_close_fifo(info); + + return ECORE_CALLBACK_CANCEL; +} + static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet) { struct liveinfo *info; char *cmd; char *var; char *val; - FILE *fp; int ret = LB_STATUS_ERROR_INVALID; if (packet_get(packet, "sss", &cmd, &var, &val) != 3) { @@ -7374,14 +7487,8 @@ static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct p ret = g_conf.slave_max_load; } - liveinfo_open_fifo(info); - fp = liveinfo_fifo(info); - if (!fp) { - liveinfo_close_fifo(info); - goto out; - } - fprintf(fp, "%d\nEOD\n", ret); - liveinfo_close_fifo(info); + liveinfo_set_data(info, (void *)ret); + master_ctrl_cb(info); out: return NULL;