Fix sending of error code of screenshot failure 91/179091/2 accepted/tizen/unified/20180516.162352 submit/tizen/20180516.140048
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 15 May 2018 13:09:53 +0000 (16:09 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 16 May 2018 12:36:59 +0000 (15:36 +0300)
During a take screenshot, it may encounter an error. This case
was not checked. For this reason, the screenshot path was empty
and screenshot_send_to_socket() failed with an error.

Change-Id: I6d78487fc7e37d2feef45cbbbe4c369ca728f790
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
daemon/threads.c
ui_viewer/ui_viewer_utils.c

index 60f1d872ad784b395438f6d6f30c43a9d08eda0b..b5c80ccbed7a56d7926f961ff0aa8ef2152af6bb 100644 (file)
@@ -252,11 +252,20 @@ static void processing_ui_screenshot(const void *data, size_t len)
        err_code = *(uint32_t *)data;
        data += 4;
 
-       if (!save_data_to_tmpfile(path, suffixlen, sh_data, sh_len)) {
+       if (err_code == ERR_NO) {
+               if (save_data_to_tmpfile(path, suffixlen, sh_data, sh_len)) {
+                       LOGE("Cannot save screenshot\n");
+                       err_code = ERR_UNKNOWN;
+               }
+       }
+
+       if (err_code == ERR_NO) {
                sendACKToHost(NMSG_GET_UI_SCREENSHOT,
                              err_code, path, sizeof(path));
        } else {
-               LOGE("Cannot save screenshot\n");
+               char empty_path[] = "";
+               sendACKToHost(NMSG_GET_UI_SCREENSHOT,
+                             err_code, empty_path, sizeof(empty_path));
        }
 }
 
index 7ef7eadc388e38e51abb49d7adfd2183cf2ed883..ad1b3691e2c0e7989bd482a50f7eb5b407942303 100644 (file)
@@ -472,7 +472,7 @@ void print_log_ui_viewer_info_list(Eina_Bool rendering)
        set_hierarchy_status(HIERARCHY_NOT_RUNNING);
 }
 
-static int screenshot_send_to_socket(enum ErrorCode err, const char *path)
+static int screenshot_send_to_socket(const char *path)
 {
        struct file_data *fdata;
        void *buf, *p;
@@ -498,7 +498,7 @@ static int screenshot_send_to_socket(enum ErrorCode err, const char *path)
        }
 
        /* pack err */
-       p = pack_int32(buf, err);
+       p = pack_int32(buf, ERR_NO);
 
        /* pack img.png */
        memcpy(p, fdata->data, fdata->len);
@@ -511,16 +511,43 @@ static int screenshot_send_to_socket(enum ErrorCode err, const char *path)
        return 0;
 }
 
+static void screenshot_send_to_socket_error(enum ErrorCode err)
+{
+       char buf[4];
+
+       /* format:
+        * +-----+
+        * | err |
+        * +-----+
+        * |   4 |
+        */
+
+       /* pack err */
+       pack_int32(buf, err);
+
+       /* send screenshot error to manager */
+       msg_send(APP_MSG_GET_UI_SCREENSHOT, buf, sizeof(buf));
+}
+
 bool print_log_ui_obj_screenshot(Evas_Object *obj)
 {
-       int ret;
+       int ret = -1;
        enum ErrorCode err;
        char path[PATH_MAX];
 
        err = ui_obj_screenshot(obj, path);
-       ret = screenshot_send_to_socket(err, path);
-       if (err == ERR_NO)
-               remove(path);
+       if (err == ERR_NO) {
+               ret = screenshot_send_to_socket(path);
+               if (ret)
+                       err = ERR_UNKNOWN;
+
+               if (-1 == remove(path))
+                       PRINTERR("Cannot remove file, path='%s', erron=%d",
+                                path, errno);
+       }
+
+       if (err != ERR_NO)
+               screenshot_send_to_socket_error(err);
 
        return !ret;
 }