From a299c1d3cd1bd33431226885aa9531c77f272a6e Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 16 Aug 2016 19:07:26 +0900 Subject: [PATCH] Fix getting DBus bus type 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 --- client/include/comm_client.h | 4 +++- client/src/comm_client_gdbus.c | 23 +++++++++++++++++++++-- client/src/pkgmgr.c | 12 ++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/client/include/comm_client.h b/client/include/comm_client.h index fcb6921..b295351 100644 --- a/client/include/comm_client.h +++ b/client/include/comm_client.h @@ -26,13 +26,15 @@ #include +#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); diff --git a/client/src/comm_client_gdbus.c b/client/src/comm_client_gdbus.c index ea9e7c3..23c25cc 100644 --- a/client/src/comm_client_gdbus.c +++ b/client/src/comm_client_gdbus.c @@ -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); diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index a5bfd68..c106a20 100644 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -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) { -- 2.7.4