Replace getting uid from logind to systemd and remove mult-user define 56/72656/1 accepted/tizen/common/20160603.150903 accepted/tizen/ivi/20160606.121109 accepted/tizen/mobile/20160606.120719 accepted/tizen/tv/20160606.120907 accepted/tizen/wearable/20160606.121033 submit/tizen/20160603.021103 submit/tizen/20160603.061849
authorJiyong Min <jiyong.min@samsung.com>
Thu, 2 Jun 2016 04:20:43 +0000 (13:20 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Thu, 2 Jun 2016 04:22:48 +0000 (13:22 +0900)
Change-Id: I9532c3b19acc8eaf87a50183fdc8678a14121275
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
CMakeLists.txt
packaging/capi-media-controller.spec
svc/CMakeLists.txt
svc/media_controller_svc.c

index f306b97..4d52595 100644 (file)
@@ -54,9 +54,6 @@ ENDIF("${ARCH}" MATCHES "^arm.*")
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DTIZEN_DEBUG")
 ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
-IF (MULTI_USER)
-ADD_DEFINITIONS("-DMULTI_USER")
-ENDIF(MULTI_USER)
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 
index edf01da..e6b18f0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-controller
 Summary:    A media controller library in Tizen Native API
-Version:    0.1.21
+Version:    0.1.22
 Release:    1
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -9,7 +9,6 @@ Source1:    mediacontroller.service
 Source2:    mediacontroller.socket
 Source3:    media-controller-user.service
 Source4:    mediacontroller-ipc.socket
-Source1001: media-controller_create_db.sh
 BuildRequires:  cmake
 BuildRequires:  sqlite
 BuildRequires:  pkgconfig(capi-base-common)
@@ -22,6 +21,7 @@ BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(libsystemd-daemon)
+BuildRequires:  pkgconfig(libsystemd-login)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
@@ -44,12 +44,6 @@ Requires:   %{name} = %{version}-%{release}
 %description devel
 This package provides a media controller library in Tizen Native API(Development files included)
 
-%if 0%{?TIZEN_PRODUCT_TV}
-%define multi_user 0
-%else
-%define multi_user 1
-%endif
-
 %prep
 %setup -q
 
@@ -59,12 +53,7 @@ export CFLAGS+=" -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow"
 export CFLAGS+=" -Wwrite-strings -Wswitch-default"
 export CFLAGS+=" -DGST_EXT_TIME_ANALYSIS -include stdint.h"
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DFULLVER=%{version} \
-%if 0%{?multi_user}
- -DMAJORVER=${MAJORVER} -DMULTI_USER=YES
-%else
- -DMAJORVER=${MAJORVER}
-%endif
+%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
 
 %__make %{?jobs:-j%jobs}
 
index 1a8004e..d9b0f6f 100755 (executable)
@@ -1,5 +1,5 @@
 # for package file
-SET(dependents "capi-base-common glib-2.0 gio-2.0 dlog dbus-glib-1 sqlite3 db-util libsystemd-daemon libtzplatform-config cynara-client cynara-session cynara-creds-socket")
+SET(dependents "capi-base-common glib-2.0 gio-2.0 dlog dbus-glib-1 sqlite3 db-util libsystemd-daemon libsystemd-login libtzplatform-config cynara-client cynara-session cynara-creds-socket")
 SET(fw_svc "media-controller-svc")
 
 PROJECT(${fw_svc})
index 23ba2e8..3847b92 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
 
 #include "media_controller_svc.h"
 #include "media_controller_private.h"
 static GMainLoop *g_mc_svc_mainloop = NULL;
 static int g_connection_cnt = -1;
 
-#ifdef MULTI_USER
-#define UID_DBUS_NAME           "org.freedesktop.login1"
-#define UID_DBUS_PATH           "/org/freedesktop/login1"
-#define UID_DBUS_INTERFACE      UID_DBUS_NAME".Manager"
-#define UID_DBUS_METHOD                 "ListUsers"
-
-static int __mc_dbus_get_uid(const char *dest, const char *path, const char *interface, const char *method, uid_t *uid)
+static int __mc_sys_get_uid(uid_t *uid)
 {
-       DBusConnection *conn = NULL;
-       DBusMessage *msg = NULL;
-       DBusMessage *reply = NULL;
-       DBusError err;
-       DBusMessageIter iiiter;
-       DBusMessageIter iter;
-       DBusMessageIter aiter, piter;
-       int result = 0;
-
-       int val_int = 0;
-       char *val_str = NULL;
-
-       conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-       if (!conn) {
-               mc_error("dbus_bus_get error");
-               return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
-       }
-
-       msg = dbus_message_new_method_call(dest, path, interface, method);
-       if (!msg) {
-               mc_error("dbus_message_new_method_call(%s:%s-%s)",
-               path, interface, method);
-               return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
-       }
-
-       dbus_message_iter_init_append(msg, &iiiter);
-
-       dbus_error_init(&err);
-
-       reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
-       dbus_message_unref(msg);
-       if (!reply) {
-               mc_error("dbus_connection_send error(%s:%s) %s %s:%s-%s",
-               err.name, err.message, dest, path, interface, method);
-               dbus_error_free(&err);
-               return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
-       }
-
-       dbus_message_iter_init(reply, &iter);
-       dbus_message_iter_recurse(&iter, &aiter);
-
-       result = 0;
-       while (dbus_message_iter_get_arg_type(&aiter) != DBUS_TYPE_INVALID) {
-               result++;
-               mc_debug("(%d)th block device information", result);
-
-               dbus_message_iter_recurse(&aiter, &piter);
-               dbus_message_iter_get_basic(&piter, &val_int);
-               mc_debug("\tType(%d)", val_int);
-
-               dbus_message_iter_next(&piter);
-               dbus_message_iter_get_basic(&piter, &val_str);
-               mc_debug("\tdevnode(%s)", val_str);
-
-               dbus_message_iter_next(&piter);
-               dbus_message_iter_get_basic(&piter, &val_str);
-               mc_debug("\tsyspath(%s)", val_str);
-
-               dbus_message_iter_next(&aiter);
+       uid_t *list = NULL;
+       int users = -1;
+       users = sd_get_uids(&list);
+       if (users > 0) {
+               *uid = list[0];
+               MC_SAFE_FREE(list);
+       } else {
+               mc_error("No login user!.");
        }
-
-       *uid = (uid_t) val_int;
-
-       return result;
+       return users;
 }
-#endif
 
 static int __create_socket_activation(void)
 {
@@ -321,16 +261,14 @@ gboolean mc_svc_thread(void *data)
        }
        memset(mc_svc_data, 0, sizeof(mc_svc_data_t));
 
-#ifdef MULTI_USER
-       ret = __mc_dbus_get_uid(UID_DBUS_NAME, UID_DBUS_PATH, UID_DBUS_INTERFACE, UID_DBUS_METHOD, &uid);
+       ret = __mc_sys_get_uid(&uid);
        if (ret < 0) {
-               mc_debug("Failed to send dbus (%d)", ret);
+               mc_debug("Failed to get login user (%d)", ret);
                MC_SAFE_FREE(mc_svc_data);
                return FALSE;
        } else {
-               mc_debug("%d get UID[%d]", ret, uid);
+               mc_debug("%d sys get UID[%d]", ret, uid);
        }
-#endif
 
        /* Connect media controller DB*/
        if (mc_db_util_connect(&(mc_svc_data->db_handle), uid) != MEDIA_CONTROLLER_ERROR_NONE) {