apply retry logic to get an user type using gum api.
[platform/core/appfw/pkgmgr-server.git] / src / request.c
index ad964c1..7a5ba92 100644 (file)
@@ -11,6 +11,8 @@
 #include "pkgmgr-server.h"
 #include "package-manager.h"
 
+#define RETRY_MAX 5
+#define RETRY_WAIT_USEC (1000000 / 2) /* 0.5 sec */
 #define PKGMGR_DBUS_SERVICE "org.tizen.pkgmgr"
 #define PKGMGR_DBUS_OBJECT_PATH "/org/tizen/pkgmgr"
 
@@ -200,10 +202,21 @@ static int __is_admin_user(uid_t uid)
 {
        GumUser *guser;
        GumUserType ut = GUM_USERTYPE_NONE;
+       int retry_cnt = 0;
+
+       do {
+               guser = gum_user_get_sync(uid, FALSE);
+               if (guser == NULL) {
+                       ERR("cannot get user information from gumd, retry");
+                       retry_cnt++;
+                       usleep(RETRY_WAIT_USEC);
+                       continue;
+               }
+               break;
+       } while (retry_cnt <= RETRY_MAX);
 
-       guser = gum_user_get_sync(uid, FALSE);
        if (guser == NULL) {
-               ERR("cannot get user information from gumd");
+               ERR("cannot get user information from gumd, failed");
                return -1;
        }