From 8fd59243c314dc931b4a48b1f5295b1dca346a5c Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 28 Dec 2018 11:25:11 +0900 Subject: [PATCH] Remove check_storage in mediadb-update. check_storage was added to fix the timing issue. if media-service miss the "MMC mount" event, media-server didn't scan it. so media-server did check_storage to check MMC by itself. (just update storage table) but the problem seems to be no longer happening. Change-Id: I26148e1a854b052339ad986e5d40159011e5003a Signed-off-by: Minje Ahn --- configure.ac | 2 +- packaging/media-server-user.service | 2 +- src/mediadb-update.c | 240 ------------------------------------ 3 files changed, 2 insertions(+), 242 deletions(-) diff --git a/configure.ac b/configure.ac index 675fc30..6fc6b0f 100755 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ - +# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) diff --git a/packaging/media-server-user.service b/packaging/media-server-user.service index 39e428e..bafd27c 100644 --- a/packaging/media-server-user.service +++ b/packaging/media-server-user.service @@ -6,7 +6,7 @@ DefaultDependencies=no Type=idle CPUAccounting=true CPUQuota=10% -ExecStart=/usr/bin/sh -c "/usr/bin/mediadb-update check_db;/usr/bin/mediadb-update -r `/usr/bin/tzplatform-get TZ_USER_CONTENT | /usr/bin/sed -e 's/^.*=//g'`;/usr/bin/mediadb-update check_storage" +ExecStart=/usr/bin/sh -c "/usr/bin/mediadb-update check_db;/usr/bin/mediadb-update -r `/usr/bin/tzplatform-get TZ_USER_CONTENT | /usr/bin/sed -e 's/^.*=//g'`" [Install] WantedBy=default.target diff --git a/src/mediadb-update.c b/src/mediadb-update.c index e36e472..6d0a063 100755 --- a/src/mediadb-update.c +++ b/src/mediadb-update.c @@ -23,44 +23,17 @@ #include #include #include -#include -#include #include #include #include "media-util.h" -#define BUS_NAME "org.tizen.system.storage" -#define OBJECT_PATH "/Org/Tizen/System/Storage" -#define INTERFACE_NAME BUS_NAME -#define DBUS_REPLY_TIMEOUT (-1) - -#define PATH_BLOCK OBJECT_PATH"/Block" -#define PATH_BLOCK_MANAGER PATH_BLOCK"/Manager" -#define INTERFACE_BLOCK_MANAGER INTERFACE_NAME".BlockManager" #define PATH_PLUGIN_LIB PATH_LIBDIR"/libmedia-content-plugin.so" -#define DEVICE_METHOD "GetDeviceList" -#define DEVICE_ALL "all" - -#define MU_SAFE_FREE(src) { if (src) {free(src); src = NULL; } } - - GMainLoop * mainloop = NULL; -typedef struct block_info_s { - char *mount_path; - int state; - int block_type; - char *mount_uuid; -} block_info_s; - int (*svc_check_db) (sqlite3 * handle, uid_t uid); int (*svc_get_storage_id) (sqlite3 * handle, const char *path, char *storage_id, uid_t uid); -int (*svc_insert_storage) (sqlite3 *handle, const char *storage_id, int storage_type, const char *storage_path, uid_t uid); -int (*svc_update_storage) (sqlite3 *handle, const char *storage_id, const char *storage_path, uid_t uid); -int (*svc_set_storage_validity) (sqlite3 * handle, const char *storage_id, int validity, uid_t uid); -int (*svc_check_storage) (sqlite3 * handle, const char *storage_id, char **storage_path, int *validity, uid_t uid); void callback(media_request_result_s * result, void *user_data) { @@ -87,210 +60,6 @@ void print_help() printf("=======================================================================================\n"); } -int __get_device_list(GArray **dev_list) -{ - GDBusConnection *g_bus = NULL; - GError *error = NULL; - GDBusMessage *message = NULL; - GDBusMessage *reply = NULL; - GVariant *reply_var = NULL; - GVariantIter *iter = NULL; - char *type_str = NULL; - int val_int[5] = {0, }; - char *val_str[7] = {NULL, }; - gboolean val_bool = FALSE; - - g_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!g_bus) { - g_error_free(error); - return -1; - } - - message = g_dbus_message_new_method_call(BUS_NAME, PATH_BLOCK_MANAGER, INTERFACE_BLOCK_MANAGER, DEVICE_METHOD); - if (!message) { - g_object_unref(g_bus); - return -1; - } - - g_dbus_message_set_body(message, g_variant_new("(s)", (gchar*)DEVICE_ALL)); - - reply = g_dbus_connection_send_message_with_reply_sync(g_bus, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, NULL, &error); - g_object_unref(message); - if (!reply) { - g_error_free(error); - g_object_unref(message); - g_object_unref(g_bus); - return -1; - } - - reply_var = g_dbus_message_get_body(reply); - if (!reply_var) { - g_object_unref(reply); - g_object_unref(g_bus); - return -1; - } - - type_str = strdup((char*)g_variant_get_type_string(reply_var)); - if (!type_str) { - g_variant_unref(reply_var); - g_object_unref(reply); - g_object_unref(g_bus); - return -1; - } - - g_variant_get(reply_var, type_str, &iter); - - while (g_variant_iter_loop(iter, "(issssssisibii)", &val_int[0], &val_str[0], &val_str[1], &val_str[2] - , &val_str[3], &val_str[4], &val_str[5], &val_int[1], &val_str[6], &val_int[2], &val_bool, &val_int[3], &val_int[4])) { - int i = 0; - block_info_s *data = NULL; - - if (val_int[2] == 0) { - /* Do nothing */ - } else { - data = malloc(sizeof(block_info_s)); - if (data == NULL) { - printf("Failed to allocate memory"); - } else { - data->block_type = val_int[0]; - data->mount_path = strdup(val_str[6]); - data->state = val_int[2]; - data->mount_uuid = strdup(val_str[5]); - - if (*dev_list == NULL) - *dev_list = g_array_new(FALSE, FALSE, sizeof(block_info_s*)); - g_array_append_val(*dev_list, data); - } - } - - for (i = 0; i < 7; i++) - MU_SAFE_FREE(val_str[i]); - } - - g_variant_iter_free(iter); - - g_variant_unref(reply_var); - g_object_unref(reply); - g_object_unref(g_bus); - MU_SAFE_FREE(type_str); - - return 0; -} - -void __release_device_list(GArray **dev_list) -{ - if (*dev_list) { - while ((*dev_list)->len != 0) { - block_info_s *data = NULL; - data = g_array_index(*dev_list , block_info_s*, 0); - g_array_remove_index(*dev_list, 0); - if (data != NULL) { - MU_SAFE_FREE(data->mount_path); - MU_SAFE_FREE(data->mount_uuid); - MU_SAFE_FREE(data); - } - } - g_array_free(*dev_list, FALSE); - *dev_list = NULL; - } -} - -static bool __check_storage(void) -{ - int ret = 0; - GArray *dev_list = NULL; - void *funcHandle = NULL; - sqlite3 *db_handle = NULL; - char *storage_path = NULL; - int validity = 0; - bool need_scan = false; - - funcHandle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY); - if (funcHandle == NULL) { - printf("Error when open plug-in\n"); - return false; - } - - svc_insert_storage = dlsym(funcHandle, "insert_storage"); - svc_update_storage = dlsym(funcHandle, "update_storage"); - svc_set_storage_validity = dlsym(funcHandle, "set_storage_validity"); - svc_check_storage = dlsym(funcHandle, "check_storage"); - - ret = __get_device_list(&dev_list); - if (ret == 0) { - /* Set validity to 0 */ - ret = media_db_connect(&db_handle, tzplatform_getuid(TZ_USER_NAME), false); - if (ret < 0) { - printf("Error svc_connect\n"); - __release_device_list(&dev_list); - dlclose(funcHandle); - return false; - } - - if (dev_list != NULL) { - int i = 0 ; - int dev_num = dev_list->len; - block_info_s *block_info = NULL; - - for (i = 0; i < dev_num; i++) { - block_info = (block_info_s *)g_array_index(dev_list, int *, i); - /* Check exists */ - ret = svc_check_storage(db_handle, block_info->mount_uuid, &storage_path, &validity, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) - printf("Error svc_check_storage\n"); - - if (storage_path != NULL) { - /* check storage_path and update validity and path */ - /* Mount point can be changed */ - if (strcmp(block_info->mount_path, storage_path) != 0) { - ret = svc_update_storage(db_handle, block_info->mount_uuid, block_info->mount_path, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) - printf("Error svc_update_storage\n"); - } - - if (validity == 0) { - ret = svc_set_storage_validity(db_handle, block_info->mount_uuid, 1, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) - printf("Error svc_set_storage_validity\n"); - - /* Need to scan */ - ret = media_directory_scanning_async(block_info->mount_path, block_info->mount_uuid, true, callback, NULL, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) - printf("Error media_directory_scanning_async\n"); - else - need_scan = true; - } - } else { - /* insert new storage */ - ret = svc_insert_storage(db_handle, block_info->mount_uuid, 1, block_info->mount_path, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) - printf("Error svc_insert_storage\n"); - - /* Need to scan */ - ret = media_directory_scanning_async(block_info->mount_path, block_info->mount_uuid, true, callback, NULL, tzplatform_getuid(TZ_USER_NAME)); - if (ret < 0) - printf("Error media_directory_scanning_async\n"); - else - need_scan = true; - } - } - __release_device_list(&dev_list); - } - - ret = media_db_disconnect(db_handle); - if (ret < 0) - printf("Error svc_disconnect\n"); - } else { - printf("__get_device_list failed\n"); - } - - printf("Check external storage done\n"); - - dlclose(funcHandle); - - return need_scan; -} - static void __check_media_db(void) { void *funcHandle = NULL; @@ -412,15 +181,6 @@ int main(int argc, char **argv) exit(0); } - if (strcmp(argv1 , "check_storage") == 0) { - /* If true, waiting for directory scanning */ - if (__check_storage()) { - g_main_loop_run(mainloop); - } - - exit(0); - } - if (g_file_test(argv1, G_FILE_TEST_IS_DIR)) { len = strlen(argv1); if (len < sizeof(req_path)) { -- 2.7.4