multi-user: Fix service auto connect issue 27/31327/2 accepted/tizen/common/20141208.080901 accepted/tizen/ivi/20141217.060504 accepted/tizen/mobile/20141208.084229 accepted/tizen/tv/20141210.133225 accepted/tizen/wearable/20141210.194841 submit/tizen/20141208.013030
authorZhang zhengguang <zhengguang.zhang@intel.com>
Thu, 4 Dec 2014 05:25:42 +0000 (13:25 +0800)
committerZhang zhengguang <zhengguang.zhang@intel.com>
Mon, 8 Dec 2014 01:14:10 +0000 (09:14 +0800)
In curernt IVI image, systemd doesn't write utmp entries
for logged in users, so that ConnMan can't get the related
user info, under which condition, it doesn't need to forbid
service auto connect for this user.

Change-Id: I4ca33b2b43ac351d1be8c862808304d8a17d8d7d

src/service.c

index 86dffaf1408a54bd0acb1611322a488807ddceeb..974a08765d253245e1431a688798230db803cf56 100644 (file)
@@ -390,16 +390,16 @@ static GList *connman_service_get_login_users()
        setutxent();
 
        while ((utmp = getutxent()) != NULL) {
-               if (utmp->ut_user != USER_ROOT && utmp->ut_type != USER_PROCESS)
-                       continue;
+               DBG("User Name: %s", utmp->ut_user);
 
                pwd = getpwnam(utmp->ut_user);
-
-               if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
-                       user_list = g_list_append(user_list,
+               if (pwd) {
+                       if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
+                               user_list = g_list_append(user_list,
                                                GUINT_TO_POINTER(pwd->pw_uid));
 
-               DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
+                       DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
+               }
        }
 
        endutxent();
@@ -416,10 +416,14 @@ static bool is_service_owner_user_login(struct connman_service *service)
        if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
                return true;
 
-       user_list = connman_service_get_login_users();
-
        DBG("service favorite user id is: %d", service->user.favorite_user);
 
+       user_list = connman_service_get_login_users();
+       if (user_list == NULL) {
+               DBG("Can not get any logged in user info.");
+               return true;
+       }
+
        for (list = user_list; list; list = list->next) {
                uid_t uid = GPOINTER_TO_UINT(list->data);