Add strerror equivalent in libprivilege for more informative error logging.
authorDamian Chromejko <d.chromejko@samsung.com>
Tue, 19 Nov 2013 08:53:24 +0000 (09:53 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 9 Dec 2013 19:47:34 +0000 (20:47 +0100)
[Issue#]      SSDWSSP-646
[Bug/Feature] Add strerror equivalent in libprivilege for more informative
              error logging.
[Cause]       Currently there is no way to check the reason for the
              error apart from looking directly into the code.
[Solution]    An strerror equivalent was created to convert error code
              to human-readable error description.
[Verfication] Build, install, run tests.

Change-Id: I9cd4416133e782d52cf9a8488e7b10fcf82546f2

include/privilege-control.h
src/privilege-control.c

index bbc1f96..1188491 100644 (file)
@@ -472,6 +472,13 @@ int perm_end(void);
  */
 int perm_add_additional_rules(const char** set_smack_rule_set);
 
+/**
+ * Get message connected to error code.
+ *
+ * @param errnum error code
+ * @return string describing the error code
+ */
+const char* perm_strerror(int errnum);
 
 #ifdef __cplusplus
 }
index 847d669..dbafc05 100644 (file)
@@ -1592,3 +1592,39 @@ API int perm_add_additional_rules(const char** smack_rules){
 
        return PC_OPERATION_SUCCESS;
 }
+
+API const char* perm_strerror(int errnum)
+{
+       switch (errnum) {
+       case PC_OPERATION_SUCCESS:
+               return "Success";
+       case PC_ERR_FILE_OPERATION:
+               return "File operation error";
+       case PC_ERR_MEM_OPERATION:
+               return "Memory operation error";
+       case PC_ERR_NOT_PERMITTED:
+               return "Operation not permitted";
+       case PC_ERR_INVALID_PARAM:
+               return "Invalid parameter";
+       case PC_ERR_INVALID_OPERATION:
+               return "Invalid operation";
+       case PC_ERR_DB_OPERATION:
+               return "Database operation error";
+       case PC_ERR_DB_LABEL_TAKEN:
+               return "Label taken by another application";
+       case PC_ERR_DB_QUERY_PREP:
+               return "Query failure during preparation";
+       case PC_ERR_DB_QUERY_BIND:
+               return "Query failure during binding";
+       case PC_ERR_DB_QUERY_STEP:
+               return "Query failure during stepping";
+       case PC_ERR_DB_CONNECTION:
+               return "Cannot establish a connection";
+       case PC_ERR_DB_NO_SUCH_APP:
+               return "No such application";
+       case PC_ERR_DB_PERM_FORBIDDEN:
+               return "Duplicate permission";
+       default:
+               return "Unknown error";
+       }
+}