1. Changed db path to support multi-user. 07/46107/9 accepted/tizen/mobile/20150818.153511 accepted/tizen/tv/20150818.155831 accepted/tizen/wearable/20150818.160106 submit/tizen/20150818.110016
authorYoung-Ae Kang <youngae.kang@samsung.com>
Mon, 17 Aug 2015 02:17:50 +0000 (11:17 +0900)
committerjomui <jongmun.woo@samsung.com>
Tue, 18 Aug 2015 08:57:07 +0000 (17:57 +0900)
2. geofence-server.service for systemd is added.
3. DBUS_SYSTEM_BUS is replaced with DBUS_SESSION_BUS.
4. Directory for dbus service files was changed from /usr/share/dbus-1/system-services/ to /usr/share/dbus-1/services/

Signed-off-by: Young-Ae Kang <youngae.kang@samsung.com>
Change-Id: I989844fca494289a094e42f75a88640eaa2a8916

CMakeLists.txt
geofence-server/CMakeLists.txt
geofence-server/config/geofence-server.conf
geofence-server/org.tizen.lbs.Providers.GeofenceServer.service.in
geofence-server/src/geofence_server_db.c [changed mode: 0644->0755]
packaging/geofence-server.service
packaging/geofence-server.spec

index 749eb11..42e70c4 100644 (file)
@@ -7,7 +7,7 @@ SET(BIN_DIR "${PREFIX}/bin")
 #Dependencies
 
 SET(common_dp "glib-2.0 geofence-dbus dlog gio-2.0 capi-appfw-app-manager")
-SET(server_dp "${common_dp} network vconf vconf-internal-keys gthread-2.0  gio-unix-2.0 sqlite3 db-util alarm-service deviced capi-location-manager capi-network-bluetooth capi-network-wifi libcore-context-manager")
+SET(server_dp "${common_dp} network vconf vconf-internal-keys gthread-2.0  gio-unix-2.0 sqlite3 db-util alarm-service deviced capi-location-manager capi-network-bluetooth capi-network-wifi libcore-context-manager libtzplatform-config")
 SET(module_dp "${common_dp} gmodule-2.0 capi-geofence-manager")
 
 # Set required packages
index 8d06754..207974b 100644 (file)
@@ -8,9 +8,12 @@ AUX_SOURCE_DIRECTORY(src SERVER_SRCS)
 
 INCLUDE_DIRECTORIES(src include)
 
+#Process will be launched by systemd. TODO: checking dbus auto activation
 CONFIGURE_FILE(org.tizen.lbs.Providers.GeofenceServer.service.in org.tizen.lbs.Providers.GeofenceServer.service @ONLY)
-INSTALL(FILES org.tizen.lbs.Providers.GeofenceServer.service DESTINATION /usr/share/dbus-1/system-services)
-INSTALL(FILES config/geofence-server.conf DESTINATION ${SYSCONF_DIR}/dbus-1/system.d)
+#INSTALL(FILES org.tizen.lbs.Providers.GeofenceServer.service DESTINATION /usr/share/dbus-1/system-services)
+#INSTALL(FILES config/geofence-server.conf DESTINATION ${SYSCONF_DIR}/dbus-1/system.d)
+INSTALL(FILES org.tizen.lbs.Providers.GeofenceServer.service DESTINATION /usr/share/dbus-1/services)
+INSTALL(FILES config/geofence-server.conf DESTINATION ${SYSCONF_DIR}/dbus-1/session.d)
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SERVER_SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${server_pkgs_LDFLAGS} -lm)
index 2b49ee6..88b47b3 100644 (file)
 
        <policy context="default">
                <allow own="org.tizen.lbs.Providers.GeofenceServer"/>
-               <allow send_destination="org.tizen.lbs.Providers.GeofenceServer"/>
+               <deny send_destination="org.tizen.lbs.Providers.GeofenceServer"/>
+               <check send_destination="org.tizen.lbs.Providers.GeofenceServer"
+                       send_interface="org.tizen.lbs.Geofence"
+                       privilege="http://tizen.org/privilege/location" />
                <allow receive_sender="org.tizen.lbs.Providers.GeofenceServer"/>
        </policy>
 </busconfig>
index c45ba2f..3841bc2 100644 (file)
@@ -1,5 +1,5 @@
 [D-BUS Service]
 Name=org.tizen.lbs.Providers.GeofenceServer
 Exec=@BIN_DIR@/geofence-server
-User=system
-Group=system
+#User=system
+#Group=system
old mode 100644 (file)
new mode 100755 (executable)
index 3c64ed8..317e7a3
 #include <string.h>
 #include <bluetooth.h>
 #include <wifi.h>
+#include <tzplatform_config.h>
+#include <sys/types.h>
+#include <fcntl.h>
 
 #include "debug_util.h"
 #include "geofence_server.h"
 #include "geofence_server_db.h"
 #include "geofence_server_private.h"
 
-#define GEOFENCE_SERVER_DB_FILE                ".geofence-server.db"
-#define GEOFENCE_SERVER_DB_PATH                "/opt/dbspace/"GEOFENCE_SERVER_DB_FILE
+/* dbspace path for Tizen 3.0 was changed.
+#define GEOFENCE_SERVER_DB_FILE                ".geofence-server.db"
+#define GEOFENCE_SERVER_DB_PATH                "/opt/dbspace/"GEOFENCE_SERVER_DB_FILE
+*/
+
+#define GEOFENCE_DB_NAME       ".geofence-server.db"
+#define GEOFENCE_DB_FILE       tzplatform_mkpath(TZ_USER_DB, GEOFENCE_DB_NAME)
 
 #define MAX_DATA_NAME          20
 #define DATA_LEN                       20
@@ -277,12 +285,12 @@ static inline int __geofence_manager_db_create_bssid_table(void)
        return FENCE_ERR_NONE;
 }
 
-static int __geofence_manager_open_db_handle(void)
+static int __geofence_manager_open_db_handle(const int open_flag)
 {
        LOGI_GEOFENCE("enter");
        int ret = SQLITE_OK;
 
-       ret = db_util_open_with_options(GEOFENCE_SERVER_DB_PATH, &db_info_s.handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, NULL);
+       ret = db_util_open_with_options(GEOFENCE_DB_FILE, &db_info_s.handle, open_flag, NULL);
        if (ret != SQLITE_OK) {
                LOGI_GEOFENCE("sqlite3_open_v2 Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle));
                return FENCE_ERR_SQLITE_FAIL;
@@ -507,6 +515,12 @@ static inline void __geofence_manager_db_create_table(void)
        int ret;
        begin_transaction();
 
+       ret = __geofence_manager_db_create_places_table();
+       if (ret < 0) {
+               rollback_transaction();
+               return;
+       }
+
        ret = __geofence_manager_db_create_geofence_table();
        if (ret < 0) {
                rollback_transaction();
@@ -653,6 +667,20 @@ void __geofence_manager_genarate_password(char *password)
        LOGD_GEOFENCE("result : %s", result);
 }
 
+
+static int __check_db_file()
+{
+       int fd = -1;
+
+    fd = open(GEOFENCE_DB_FILE, O_RDONLY);
+    if (fd < 0) {
+             LOGW_GEOFENCE("DB file(%s) is not exist.", GEOFENCE_DB_FILE);
+             return -1;
+     }
+     close(fd);
+     return 0;
+}
+
 /**
  * This function in DB and create  GeoFence/FenceGeocoordinate /FenceCurrentLocation four table on DB if necessary.
  *
@@ -663,23 +691,26 @@ int geofence_manager_db_init(void)
 {
        FUNC_ENTRANCE_SERVER;
        struct stat stat;
+       int open_flag = 0;
 
-       if (__geofence_manager_open_db_handle() != FENCE_ERR_NONE) {
-               LOGI_GEOFENCE("Fail to location_geofence_open_db_handle");
-               return FENCE_ERR_SQLITE_FAIL;
-       }
+       /*
+       geofence_db_file = g_strdup_printf("%s/%s", GEOFENCE_DB_PATH, GEOFENCE_DB_FILE);
+       */
 
-       if (lstat(GEOFENCE_SERVER_DB_PATH, &stat) < 0) {
-               LOGI_GEOFENCE("lstat is ERROR!!!");
-               db_util_close(db_info_s.handle);
-               db_info_s.handle = NULL;
-               return FENCE_ERR_SQLITE_FAIL;
+       if (__check_db_file()) {
+               LOGW_GEOFENCE("db(%s) file doesn't exist.", GEOFENCE_DB_FILE);
+               open_flag = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| SQLITE_OPEN_FULLMUTEX;
+       }
+       else {
+               if (lstat(GEOFENCE_DB_FILE, &stat) < 0) {
+                       LOGE_GEOFENCE("Can't get db(%s) information.", GEOFENCE_DB_FILE);
+                       return FENCE_ERR_SQLITE_FAIL;
+               }
+               open_flag = SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX;
        }
 
-       if (!S_ISREG(stat.st_mode)) {
-               LOGI_GEOFENCE("Invalid file");
-               db_util_close(db_info_s.handle);
-               db_info_s.handle = NULL;
+       if (__geofence_manager_open_db_handle(open_flag) != FENCE_ERR_NONE) {
+               LOGI_GEOFENCE("Fail to create db file(%s).", GEOFENCE_DB_FILE);
                return FENCE_ERR_SQLITE_FAIL;
        }
 
index d294627..298224e 100644 (file)
@@ -1,16 +1,11 @@
 [Unit]
 Description=Geofence server daemon
-After=tizen-runtime.target
-Requires=tizen-runtime.target
+Requires=geofence-server.service
 
 [Service]
-#Type=forking
-#ExecStart=/etc/rc.d/rc5.d/S91geofence-server
+EnvironmentFile=/run/tizen-system-env
+Type=single
 ExecStart=/usr/bin/geofence-server
 MemoryLimit=10M
-User=system
-Group=system
-#SmackProcessLabel=location_fw
-
-[Install]
-WantedBy=multi-user.target
+Restart=always
+RestartSec=1
index 2d87db4..0f91c04 100644 (file)
@@ -1,6 +1,6 @@
 Name:       geofence-server
 Summary:    Geofence Server for Tizen
-Version:    0.4.0
+Version:    0.4.1
 Release:    1
 Group:      Location/Service
 License:    Apache-2.0
@@ -36,6 +36,7 @@ BuildRequires:  pkgconfig(libcore-context-manager)
 #BuildRequires:  pkgconfig(capi-telephony-network-info)
 #BuildRequires:  pkgconfig(capi-context-manager)
 BuildRequires:  pkgconfig(capi-geofence-manager)
+BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  capi-geofence-manager-plugin-devel
 Requires:  sys-assert
 
@@ -62,6 +63,12 @@ make %{?jobs:-j%jobs}
 rm -rf %{buildroot}
 %make_install
 
+#[Workaround] create service file for systemd
+mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants
+install -m 644 %{SOURCE1} %{buildroot}%{_unitdir_user}/geofence-server.service
+ln -s ../geofence-server.service %{buildroot}%{_unitdir_user}/default.target.wants/geofence-server.service
+
+%if 0
 if [ ! -e "$GEOFENCE_SERVER_DB_PATH" ]
 then
 
@@ -74,29 +81,39 @@ sqlite3 %{buildroot}/opt/dbspace/.geofence-server.db 'PRAGMA journal_mode = PERS
        CREATE TABLE FenceGeopointWifi ( fence_id INTEGER, bssid TEXT, ssid TEXT, FOREIGN KEY(fence_id) REFERENCES GeoFence(fence_id) ON DELETE CASCADE);
        CREATE TABLE FenceBssid ( fence_id INTEGER, bssid TEXT, ssid TEXT, FOREIGN KEY(fence_id) REFERENCES Geofence(fence_id) ON DELETE CASCADE);'
 fi
+%endif
 
 %clean
 rm -rf %{buildroot}
 
 %post
+
+%if 0
 GEOFENCE_SERVER_DB_PATH="/opt/dbspace/.geofence-server.db"
 
 # geofence-server db file
 chown system:system /opt/dbspace/.geofence-server.db
 chown system:system /opt/dbspace/.geofence-server.db-journal
-## Change geofence-server db file permissions
+# Change geofence-server db file permissions
 chmod 660 /opt/dbspace/.geofence-server.db
 chmod 660 /opt/dbspace/.geofence-server.db-journal
+%endif
 
 %postun -p /sbin/ldconfig
 
 %files
 %manifest geofence-server.manifest
-%defattr(-,system,system,-)
+%defattr(-,root,root,-)
 /usr/bin/geofence-server
-/usr/share/dbus-1/system-services/org.tizen.lbs.Providers.GeofenceServer.service
-/opt/dbspace/.*.db*
-%config %{_sysconfdir}/dbus-1/system.d/geofence-server.conf
+
+/usr/share/dbus-1/services/org.tizen.lbs.Providers.GeofenceServer.service
+#/opt/dbspace/.*.db*
+%config %{_sysconfdir}/dbus-1/session.d/geofence-server.conf
+
+#[Workaround] create service file for systemd
+%{_unitdir_user}/geofence-server.service
+%{_unitdir_user}/default.target.wants/geofence-server.service
+
 
 %package -n location-geofence-server
 Summary:    Geofence Server for Tizen