Fix getting DBus bus type 56/84056/3
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 16 Aug 2016 10:07:26 +0000 (19:07 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 22 Aug 2016 05:36:15 +0000 (22:36 -0700)
Installer now send signal to both of bus types.
The pkgmgr client will connect with proper bus type.

- Request -> system bus
- Listen(system) -> system bus
- Listen(user) -> session bus

Change-Id: If597cecf44e70f8ea9c9264fcdb37bc943057fc5
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
client/include/comm_client.h
client/src/comm_client_gdbus.c
client/src/pkgmgr.c

index fcb6921..b295351 100644 (file)
 
 #include <glib.h>
 
+#include "package-manager.h"
+
 typedef struct comm_client comm_client;
 typedef void (*status_cb) (void *cb_data, uid_t target_uid, const char *req_id,
                           const char *pkg_type, const char *pkgid,
                           const char *appid,    const char *key,
                           const char *val);
 
-comm_client *comm_client_new(void);
+comm_client *comm_client_new(client_type type);
 int comm_client_free(comm_client *cc);
 
 int comm_client_request(comm_client *cc, const char *method, GVariant *params, GVariant **result);
index ea9e7c3..23c25cc 100644 (file)
@@ -147,6 +147,25 @@ void _free_sig_cb_data(void *data)
        free(sig_cb_data);
 }
 
+#define REGULAR_USER 5000
+static int _is_system_user(void)
+{
+       uid_t uid = getuid();
+
+       if (uid < REGULAR_USER)
+               return 1;
+       else
+               return 0;
+}
+
+static GBusType _get_bus_type(client_type type)
+{
+       if (type == PC_REQUEST || _is_system_user())
+               return G_BUS_TYPE_SYSTEM;
+       else
+               return G_BUS_TYPE_SESSION;
+}
+
 /*******************
  * API description
  */
@@ -154,7 +173,7 @@ void _free_sig_cb_data(void *data)
 /**
  * Create a new comm_client object
  */
-comm_client *comm_client_new(void)
+comm_client *comm_client_new(client_type type)
 {
        GError *error = NULL;
        comm_client *cc = NULL;
@@ -170,7 +189,7 @@ comm_client *comm_client_new(void)
        }
 
        /* Connect to gdbus. Gets shared BUS */
-       cc->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       cc->conn = g_bus_get_sync(_get_bus_type(type), NULL, &error);
        if (error) {
                ERR("gdbus connection error (%s)", error->message);
                g_error_free(error);
index a5bfd68..c106a20 100644 (file)
@@ -823,7 +823,7 @@ static int __change_op_cb_for_getsize(pkgmgr_client *pc)
        mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE;
 
 
-       mpc->info.request.cc = comm_client_new();
+       mpc->info.request.cc = comm_client_new(PC_REQUEST);
        retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
 
        ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_GET_SIZE, mpc->info.request.cc, __operation_callback, pc);
@@ -860,7 +860,7 @@ static int __change_op_cb_for_enable_disable(pkgmgr_client *pc, bool is_disable)
                mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP;
 
 
-       mpc->info.request.cc = comm_client_new();
+       mpc->info.request.cc = comm_client_new(PC_REQUEST);
        retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed");
 
        if (is_disable)
@@ -945,13 +945,13 @@ API pkgmgr_client *pkgmgr_client_new(client_type ctype)
        pc->tep_path = NULL;
 
        if (pc->ctype == PC_REQUEST) {
-               pc->info.request.cc = comm_client_new();
+               pc->info.request.cc = comm_client_new(PC_REQUEST);
                trym_if(pc->info.request.cc == NULL, "client creation failed");
 
                ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.request.cc, __operation_callback, pc);
                trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret);
        } else if (pc->ctype == PC_LISTENING) {
-               pc->info.listening.cc = comm_client_new();
+               pc->info.listening.cc = comm_client_new(PC_LISTENING);
                trym_if(pc->info.listening.cc == NULL, "client creation failed");
 
                ret = comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL, pc->info.listening.cc, __status_callback, pc);
@@ -1078,7 +1078,7 @@ static int __change_op_cb_for_enable_disable_splash_screen(pkgmgr_client *pc,
        else
                mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN;
 
-       mpc->info.request.cc = comm_client_new();
+       mpc->info.request.cc = comm_client_new(PC_REQUEST);
        if (mpc->info.request.cc == NULL) {
                ERR("client creation failed");
                return PKGMGR_R_ENOMEM;
@@ -1802,7 +1802,7 @@ API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type)
        mpc->ctype = PC_LISTENING;
        mpc->status_type = status_type;
 
-       mpc->info.listening.cc = comm_client_new();
+       mpc->info.listening.cc = comm_client_new(PC_LISTENING);
        retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed");
 
        if ((mpc->status_type & PKGMGR_CLIENT_STATUS_INSTALL) == PKGMGR_CLIENT_STATUS_INSTALL) {