From b6b5303de376e075fe8303e141cad876c067bab0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 11 May 2020 15:47:32 +0900 Subject: [PATCH] Fix bugs of widget-mgr tool - Calls elm_exit() when the error is occurred. - Ignores the error of calling smack_setlabel(). - Checks whether the files are created or not. Change-Id: I364b23c94a9042a02d8024b87a7cda0566be1264 Signed-off-by: Hwankyu Jhun --- tool/widget-mgr.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 114 insertions(+), 7 deletions(-) diff --git a/tool/widget-mgr.c b/tool/widget-mgr.c index 0a71d6c..9719011 100644 --- a/tool/widget-mgr.c +++ b/tool/widget-mgr.c @@ -67,6 +67,12 @@ struct widget_info { unsigned int surf; }; +struct dump_info { + guint tag; + char *path; + int count; +}; + static gchar *help; static gpointer cmd_opt[CMD_MAX]; static GOptionEntry cmd_entries[] = { @@ -279,10 +285,8 @@ static int __create_directory(const char *path) fprintf(stderr, "chmod(%s) is failed. errno(%d)\n", path, ret); ret = smack_setlabel(path, "*", SMACK_LABEL_ACCESS); - if (ret != 0) { + if (ret != 0) fprintf(stderr, "smack_setlabel() is failed. error(%d)\n", ret); - return -1; - } return 0; } @@ -317,9 +321,6 @@ static void __screen_connector_toolkit_evas_added_cb(const char *appid, widget_info_list = g_list_remove(widget_info_list, info); __destroy_widget_info(info); - - if (widget_info_list == NULL) - elm_exit(); } static void __screen_connector_toolkit_evas_removed_cb(const char *appid, @@ -439,23 +440,119 @@ static void __foreach_widget_info_list(gpointer data, gpointer user_data) } } +static void __destroy_dump_info(struct dump_info *info) +{ + if (!info) + return; + + if (info->tag) + g_source_remove(info->tag); + + free(info->path); + free(info); +} + +static struct dump_info *__create_dump_info(const char *path, int count) +{ + struct dump_info *info; + + info = calloc(1, sizeof(struct dump_info)); + if (!info) { + fprintf(stderr, "Out of memory\n"); + return NULL; + } + + info->path = strdup(path); + if (!info->path) { + fprintf(stderr, "Failed to duplicate path(%s)\n", path); + free(info); + return NULL; + } + + info->count = count; + + return info; +} + +static int __get_image_count(const char *path) +{ + DIR *dp; + struct dirent *dentry = NULL; + char *ext; + int count = 0; + + if (!path) + return -1; + + dp = opendir(path); + if (dp == NULL) { + fprintf(stderr, "Failed to open dir(%s), errno(%d)", + path, errno); + return -1; + } + + while ((dentry = readdir(dp)) != NULL) { + if (dentry->d_name[0] == '.') + continue; + + ext = strrchr(dentry->d_name, '.'); + if (ext && strcmp(ext, ".jpg") == 0) + count++; + } + + return count; +} + +static gboolean __check_dump(gpointer data) +{ + struct dump_info *info = data; + int count; + + /* The image files should be generated more than twice the widgets(homescreen + widget-mgr). */ + count = __get_image_count(info->path); + if (count >= (info->count * 2)) { + printf("Images(%d) are created.\n", count); + info->tag = 0; + __destroy_dump_info(info); + elm_exit(); + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +static gboolean __terminate_cb(gpointer data) +{ + struct dump_info *info = data; + + __destroy_dump_info(info); + elm_exit(); + + return G_SOURCE_REMOVE; +} + static gboolean __dump_widgets(gpointer data) { const char *path = data; bundle *event_data; int ret; + int widget_cnt; + struct dump_info *info; if (path == NULL) path = "/tmp/widget_dump"; if (access(path, F_OK) != 0) { - if (__create_directory(path) < 0) + if (__create_directory(path) < 0) { + elm_exit(); return G_SOURCE_REMOVE; + } } event_data = bundle_create(); if (!event_data) { fprintf(stderr, "Failed to create bundle\n"); + elm_exit(); return G_SOURCE_REMOVE; } @@ -467,9 +564,19 @@ static gboolean __dump_widgets(gpointer data) bundle_free(event_data); + widget_cnt = g_list_length(widget_info_list); g_list_foreach(widget_info_list, __foreach_widget_info_list, (gpointer)path); + info = __create_dump_info(path, widget_cnt); + if (!info) { + elm_exit(); + return G_SOURCE_REMOVE; + } + + info->tag = g_timeout_add(500, __check_dump, info); + g_timeout_add(1000 * 10, __terminate_cb, info); + return G_SOURCE_REMOVE; } -- 2.7.4