Change livedump_pid() return codes 58/255758/4
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Tue, 23 Mar 2021 09:55:39 +0000 (10:55 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 24 Mar 2021 08:45:15 +0000 (09:45 +0100)
livedump_pid() returns 0 on success, otherwise a negative error value
TIZEN_ERROR_PERMISSION_DENIED - privilege error
TIZEN_ERROR_NO_SUCH_PROCESS - no such process
TIZEN_ERROR_IO_ERROR - other error

Change-Id: If961771e745e98212ca9ded959dfa504b197f030
Signed-off-by: Konrad Kuchciak <k.kuchciak@samsung.com>
src/bugreport/libbugreport-service.c
src/bugreport/libbugreport.h
tests/system/utils/libbugreport-servicetest.c

index 671ecb3..0e731dc 100644 (file)
@@ -22,6 +22,7 @@
 
 #define LOG_TAG "LIBBUGREPORT"
 
+#include "libbugreport.h"
 #include "shared/log.h"
 
 #define BUS_NAME "org.tizen.system.crash.livedump"
@@ -44,13 +45,13 @@ static GDBusConnection* dbus_init(void)
        return conn;
 }
 
-bool livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len)
+int livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len)
 {
-       bool res = true;
+       int res = TIZEN_ERROR_NONE;
        GDBusConnection *conn = dbus_init();
 
        if (!conn)
-               return false;
+               return TIZEN_ERROR_IO_ERROR;
 
        GVariant *parameters = g_variant_new("(is)", pid, dump_reason);
 
@@ -68,15 +69,21 @@ bool livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t
                                       &error);
        if (!reply || error) {
                _E("Error while calling livedump_pid via dbus (pid=%d, reason=%s): %s", pid, dump_reason, error ? error->message : "");
-               if (error)
+               res = TIZEN_ERROR_IO_ERROR;
+
+               if (error) {
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                               res = TIZEN_ERROR_PERMISSION_DENIED;
+                       if (error->code == CS_ERR_NO_PROC)
+                               res = TIZEN_ERROR_NO_SUCH_PROCESS;
                        g_error_free(error);
-               res = false;
+               }
                goto exit;
        }
 
        if (!g_variant_is_of_type(reply, G_VARIANT_TYPE("(s)"))) {
                _E("reply is not of the correct type (s)");
-               res = false;
+               res = TIZEN_ERROR_IO_ERROR;
                goto exit;
        }
 
@@ -86,7 +93,7 @@ bool livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t
                strncpy(report_path, reply_str, report_path_len);
        } else {
                _E("Report path (%s) is longer than report_path_len", reply_str);
-               res = false;
+               res = TIZEN_ERROR_IO_ERROR;
        }
 exit:
        g_object_unref(conn);
index 92782e5..570f298 100644 (file)
  * @param dump_reason the reason that should be included in the raport.
  * @param report_path pointer to the buffer in which will be saved the report path.
  * @param report_path_len lenght of buffer for the report path.
- * @return true on success and false on error.
+ * @return 0 on success, otherwise a negative error value
+ * @retval #TIZEN_ERROR_NONE Success
+ * @retval #TIZEN_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #TIZEN_ERROR_NO_SUCH_PROCESS No such process
+ * @retval #TIZEN_ERROR_IO_ERROR Internal error occurred
  */
-extern bool livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len);
+extern int livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len);
index 0422b9f..12a9e5c 100644 (file)
@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
        pid_t pid = strtol(argv[optind], NULL, 10);
 
        char BUFF[PATH_MAX];
-       bool res = livedump_pid(pid, dump_reason, BUFF, PATH_MAX);
-       printf("res: %s\nreport_path: %s\n", res ? "true" : "false", BUFF);
+       int res = livedump_pid(pid, dump_reason, BUFF, PATH_MAX);
+       printf("res: %s (%d)\nreport_path: %s\n", res == CS_ERR_NO_ERROR ? "true" : "false", res, BUFF);
        return res ? EXIT_SUCCESS : EXIT_FAILURE;
 }