Use libsyscommon for list and ini-parser 02/251002/1 accepted/tizen/unified/20210111.125512 submit/tizen/20210108.041937
authorYunmi Ha <yunmi.ha@samsung.com>
Wed, 6 Jan 2021 11:58:19 +0000 (20:58 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Wed, 6 Jan 2021 11:58:19 +0000 (20:58 +0900)
Change-Id: I87a0550c6fd536d24dba6de634c559a3146945a4
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/auto-test/test.c
src/auto-test/test.h
src/block/CMakeLists.txt
src/block/block.c
src/shared/config-parser.c [deleted file]
src/shared/config-parser.h [deleted file]
src/shared/list.h [deleted file]
src/shared/udev.c
src/storage/CMakeLists.txt
src/storage/storage.c

index 70fbf12..59bf9dc 100644 (file)
  * limitations under the License.
  */
 
+#include <libsyscommon/list.h>
 #include "test.h"
 
-static dd_list *dd_head;
+static GList *dd_head;
 
 void add_test(const struct test_ops *d)
 {
        if (d->priority == TEST_PRIORITY_HIGH)
-               DD_LIST_PREPEND(dd_head, d);
+               SYS_G_LIST_PREPEND(dd_head, d);
        else
-               DD_LIST_APPEND(dd_head, d);
+               SYS_G_LIST_APPEND(dd_head, d);
 }
 
 void remove_test(const struct test_ops *d)
 {
-       DD_LIST_REMOVE(dd_head, d);
+       SYS_G_LIST_REMOVE(dd_head, d);
 }
 
 const struct test_ops *find_test(const char *name)
 {
-       dd_list *elem;
+       GList *elem;
        const struct test_ops *d;
 
-       DD_LIST_FOREACH(dd_head, elem, d) {
+       SYS_G_LIST_FOREACH(dd_head, elem, d) {
                if (!strcasecmp(d->name, name))
                        return d;
        }
@@ -47,11 +48,11 @@ const struct test_ops *find_test(const char *name)
 
 void test_init(void *data)
 {
-       dd_list *elem;
+       GList *elem;
        const struct test_ops *d;
 
-       _D("Test module count(%d).", DD_LIST_LENGTH(dd_head));
-       DD_LIST_FOREACH(dd_head, elem, d) {
+       _D("Test module count(%d).", SYS_G_LIST_LENGTH(dd_head));
+       SYS_G_LIST_FOREACH(dd_head, elem, d) {
                _D("%s initialize.", d->name);
                if (d->init)
                        d->init(data);
@@ -60,10 +61,10 @@ void test_init(void *data)
 
 void test_exit(void *data)
 {
-       dd_list *elem;
+       GList *elem;
        const struct test_ops *d;
 
-       DD_LIST_FOREACH(dd_head, elem, d) {
+       SYS_G_LIST_FOREACH(dd_head, elem, d) {
                _D("%s deinitialize.", d->name);
                if (d->exit)
                        d->exit(data);
index b82c876..90aab94 100644 (file)
@@ -23,7 +23,6 @@
 #include <errno.h>
 #include <libsyscommon/dbus-system.h>
 
-#include "list.h"
 #include "log.h"
 #include "storaged_common.h"
 
index c6ad5c2..8346018 100644 (file)
@@ -46,7 +46,6 @@ FILE(GLOB ALL_SRCS "*.c")
 SET(SRCS ${ALL_SRCS})
 SET(SHARED_SRCS
        ../shared/common.c
-       ../shared/config-parser.c
        ../shared/apps.c
        ../shared/fd_handler.c
        ../shared/udev.c
index 357a64f..340ccf1 100644 (file)
 #include <glib/gstdio.h>
 #include <gio/gio.h>
 #include <libsyscommon/dbus-system.h>
+#include <libsyscommon/ini-parser.h>
+#include <libsyscommon/list.h>
 #ifdef EXTENDED_STORAGE
 #include <ode/luks.h>
 #endif
 
 #include "log.h"
-#include "config-parser.h"
 #include "module-intf.h"
 #include "udev.h"
-#include "list.h"
 #include "block.h"
 #include "fd_handler.h"
 #include "utils.h"
@@ -162,7 +162,7 @@ struct operation_queue {
 
 struct block_device {
        struct block_data *data;
-       dd_list *op_queue;
+       GList *op_queue;
        int thread_id;          /* Current thread ID */
        bool removed;           /* True when device is physically removed but operation is not precessed yet */
        enum private_operation_state on_private_op;
@@ -188,8 +188,8 @@ static struct block_conf {
 } block_conf[BLOCK_EXTENDEDSD_DEV + 1];
 
 static struct manage_thread {
-       dd_list *th_node_list;  /* List of devnode which thread dealt with. Only main thread access */
-       dd_list *block_dev_list; /* Use thread mutex */
+       GList *th_node_list;    /* List of devnode which thread dealt with. Only main thread access */
+       GList *block_dev_list; /* Use thread mutex */
        pthread_t th;
        pthread_mutex_t mutex;
        pthread_cond_t cond;
@@ -208,8 +208,8 @@ char mmc_default_path[][FILE_NAME_LEN_MAX + 1] = {
 
 #define DIR_NUM ((int)(sizeof(mmc_default_path)/sizeof(mmc_default_path[0])))
 
-static dd_list *fs_head;
-static dd_list *block_ops_list;
+static GList *fs_head;
+static GList *block_ops_list;
 static bool smack;
 static int pfds[2];
 static fd_handler_h phandler;
@@ -230,8 +230,8 @@ static int add_operation(struct block_device *bdev,
                enum block_dev_operation operation,
                GDBusMethodInvocation *invocation, void *data);
 static void remove_operation(struct block_device *bdev);
-static void check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op);
-static bool check_unmount(struct block_device *bdev, dd_list **queue, struct operation_queue **op);
+static void check_removed(struct block_device *bdev, GList **queue, struct operation_queue **op);
+static bool check_unmount(struct block_device *bdev, GList **queue, struct operation_queue **op);
 static int change_mount_point(struct block_device *bdev, const char *mount_point);
 static void terminate_threads(void);
 
@@ -267,20 +267,20 @@ static void __CONSTRUCTOR__ smack_check(void)
 
 void add_fs(const struct block_fs_ops *fs)
 {
-       DD_LIST_APPEND(fs_head, (void *)fs);
+       SYS_G_LIST_APPEND(fs_head, (void *)fs);
 }
 
 void remove_fs(const struct block_fs_ops *fs)
 {
-       DD_LIST_REMOVE(fs_head, (void *)fs);
+       SYS_G_LIST_REMOVE(fs_head, (void *)fs);
 }
 
 const struct block_fs_ops *find_fs(enum block_fs_type type)
 {
        struct block_fs_ops *fs;
-       dd_list *elem;
+       GList *elem;
 
-       DD_LIST_FOREACH(fs_head, elem, fs) {
+       SYS_G_LIST_FOREACH(fs_head, elem, fs) {
                if (fs->type == type)
                        return fs;
        }
@@ -289,24 +289,24 @@ const struct block_fs_ops *find_fs(enum block_fs_type type)
 
 void add_block_dev(const struct block_dev_ops *ops)
 {
-       DD_LIST_APPEND(block_ops_list, (void *)ops);
+       SYS_G_LIST_APPEND(block_ops_list, (void *)ops);
 }
 
 void remove_block_dev(const struct block_dev_ops *ops)
 {
-       DD_LIST_REMOVE(block_ops_list, (void *)ops);
+       SYS_G_LIST_REMOVE(block_ops_list, (void *)ops);
 }
 
 static void broadcast_block_info(enum block_dev_operation op,
                struct block_data *data, int result)
 {
        struct block_dev_ops *ops;
-       dd_list *elem;
+       GList *elem;
 
        if (data->primary != true)
                return;
 
-       DD_LIST_FOREACH(block_ops_list, elem, ops) {
+       SYS_G_LIST_FOREACH(block_ops_list, elem, ops) {
                int data_block_type = (data->block_type == BLOCK_EXTENDEDSD_DEV)
                                      ? BLOCK_MMC_DEV : data->block_type;
 
@@ -331,7 +331,7 @@ static int block_get_new_id(void)
 {
        static int id = BLOCK_ID_MIN;
        struct block_device *bdev;
-       dd_list *elem;
+       GList *elem;
        bool found;
        int i, j;
 
@@ -339,7 +339,7 @@ static int block_get_new_id(void)
                found = false;
                for (j = 0; j < THREAD_MAX; j++) {
                        pthread_mutex_lock(&(th_manager[j].mutex));
-                       DD_LIST_FOREACH(th_manager[j].block_dev_list, elem, bdev) {
+                       SYS_G_LIST_FOREACH(th_manager[j].block_dev_list, elem, bdev) {
                                if (bdev->data->id == id) {
                                        found = true;
                                        break;
@@ -571,7 +571,7 @@ static bool check_primary_partition(const char *devnode)
 {
        struct block_fs_ops *fs;
        blkid_probe probe;
-       dd_list *elem;
+       GList *elem;
        const char *filesystem = NULL;
        char *temp;
        char str[PATH_MAX];
@@ -624,7 +624,7 @@ static bool check_primary_partition(const char *devnode)
                        blkid_free_probe(probe);
                        continue;
                }
-               DD_LIST_FOREACH(fs_head, elem, fs) {
+               SYS_G_LIST_FOREACH(fs_head, elem, fs) {
                        if (!strncmp(fs->name, filesystem, fs_len)) {
                                found = true;
                                break;
@@ -792,7 +792,7 @@ static struct block_device *make_block_device(struct block_data *data)
 // Called by MainThread - Remove DevNode
 static void free_block_device(struct block_device *bdev)
 {
-       dd_list *l, *next;
+       GList *l, *next;
        struct operation_queue *op;
        int thread_id;
 
@@ -806,13 +806,13 @@ static void free_block_device(struct block_device *bdev)
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
 
        th_manager[thread_id].num_dev--;
-       DD_LIST_REMOVE(th_manager[thread_id].block_dev_list, bdev);
+       SYS_G_LIST_REMOVE(th_manager[thread_id].block_dev_list, bdev);
        free_block_data(bdev->data);
 
-       DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
+       SYS_G_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
                if (!op->done)
                        th_manager[thread_id].op_len--;
-               DD_LIST_REMOVE(bdev->op_queue, op);
+               SYS_G_LIST_REMOVE(bdev->op_queue, op);
                free(op);
        }
        pthread_mutex_unlock(&(th_manager[thread_id].mutex));
@@ -824,14 +824,14 @@ static void free_block_device(struct block_device *bdev)
 static struct block_device *find_block_device(const char *devnode)
 {
        struct block_device *bdev;
-       dd_list *elem;
+       GList *elem;
        int len;
        int i;
 
        len = strlen(devnode) + 1;
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        if (bdev->data && !bdev->removed &&
                            !strncmp(bdev->data->devnode, devnode, len)) {
                                pthread_mutex_unlock(&(th_manager[i].mutex));
@@ -848,14 +848,14 @@ static struct block_device *find_block_device(const char *devnode)
 static struct block_device *find_block_device_path(const char *mount_point)
 {
        struct block_device *bdev;
-       dd_list *elem;
+       GList *elem;
        int len;
        int i;
 
        len = strlen(mount_point) + 1;
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        if (bdev->data && !bdev->removed &&
                           (bdev->data->mount_point != NULL && !strncmp(bdev->data->mount_point, mount_point, len))) {
                                pthread_mutex_unlock(&(th_manager[i].mutex));
@@ -872,12 +872,12 @@ static struct block_device *find_block_device_path(const char *mount_point)
 static struct block_device *find_block_device_by_id(int id)
 {
        struct block_device *bdev;
-       dd_list *elem;
+       GList *elem;
        int i;
 
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        if (!bdev->data)
                                continue;
                        if (bdev->removed)
@@ -1199,7 +1199,7 @@ static int retrieve_udev_device(struct block_data *data, bool mount_point_update
 static int block_mount(struct block_data *data)
 {
        struct block_fs_ops *fs;
-       dd_list *elem;
+       GList *elem;
        int r;
        int len;
 
@@ -1233,7 +1233,7 @@ static int block_mount(struct block_data *data)
 
        fs = NULL;
        len = strlen(data->fs_type) + 1;
-       DD_LIST_FOREACH(fs_head, elem, fs) {
+       SYS_G_LIST_FOREACH(fs_head, elem, fs) {
                if (!strncmp(fs->name, data->fs_type, len))
                        break;
        }
@@ -1483,7 +1483,7 @@ static int block_format(struct block_data *data,
                const char *fs_type, bool mount_point_updated)
 {
        const struct block_fs_ops *fs;
-       dd_list *elem;
+       GList *elem;
        const char *fstype;
        int len;
        int r;
@@ -1506,7 +1506,7 @@ static int block_format(struct block_data *data,
 
        fs = NULL;
        len = strlen(fstype);
-       DD_LIST_FOREACH(fs_head, elem, fs) {
+       SYS_G_LIST_FOREACH(fs_head, elem, fs) {
                if (!strncmp(fs->name, fstype, len))
                        break;
        }
@@ -1600,7 +1600,7 @@ static void release_format_data(struct format_data *data)
 // Called by BlockThread - Real Mount Op
 static int block_mount_device(struct block_device *bdev, void *data)
 {
-       dd_list *l;
+       GList *l;
        int ret;
        int thread_id;
 
@@ -1611,7 +1611,7 @@ static int block_mount_device(struct block_device *bdev, void *data)
        if (thread_id < 0 || thread_id >= THREAD_MAX)
                return -EINVAL;
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
-       l = DD_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
+       l = SYS_G_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
        pthread_mutex_unlock(&(th_manager[thread_id].mutex));
        if (!l) {
                _E("'%s' does not exist in the device list.", bdev->data->devnode);
@@ -1629,7 +1629,7 @@ static int block_mount_device(struct block_device *bdev, void *data)
 // Called by BlockThread - Real Format Op
 static int block_format_device(struct block_device *bdev, void *data)
 {
-       dd_list *l;
+       GList *l;
        int ret;
        int thread_id;
        struct format_data *fdata = (struct format_data *)data;
@@ -1643,7 +1643,7 @@ static int block_format_device(struct block_device *bdev, void *data)
        if (thread_id < 0 || thread_id >= THREAD_MAX)
                return -EINVAL;
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
-       l = DD_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
+       l = SYS_G_LIST_FIND(th_manager[thread_id].block_dev_list, bdev);
        pthread_mutex_unlock(&(th_manager[thread_id].mutex));
        if (!l) {
                _E("'%s' does not exist in the device list.", bdev->data->devnode);
@@ -1687,7 +1687,7 @@ static int block_unmount_device(struct block_device *bdev, void *data)
 static void remove_operation(struct block_device *bdev)
 {
        struct operation_queue *op;
-       dd_list *l, *next;
+       GList *l, *next;
        int thread_id;
 
        assert(bdev);
@@ -1696,23 +1696,23 @@ static void remove_operation(struct block_device *bdev)
        if (thread_id < 0 || thread_id >= THREAD_MAX)
                return;
 
-       DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
+       SYS_G_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) {
                if (op->done) {
                        _D("Remove operation(%s, %s).",
                                        get_operation_char(op->op),
                                        bdev->data->devnode);
 
-                       DD_LIST_REMOVE(bdev->op_queue, op);
+                       SYS_G_LIST_REMOVE(bdev->op_queue, op);
                        free(op);
                }
        }
 }
 
 // Called by BlockThread
-static void check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op)
+static void check_removed(struct block_device *bdev, GList **queue, struct operation_queue **op)
 {
        struct operation_queue *temp;
-       dd_list *l;
+       GList *l;
        int thread_id;
 
        if (!bdev)
@@ -1730,7 +1730,7 @@ static void check_removed(struct block_device *bdev, dd_list **queue, struct ope
 
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
 
-       DD_LIST_FOREACH(*queue, l, temp) {
+       SYS_G_LIST_FOREACH(*queue, l, temp) {
                if (temp->op == BLOCK_DEV_REMOVE) {
                        *op = temp;
                        break;
@@ -1745,10 +1745,10 @@ static void check_removed(struct block_device *bdev, dd_list **queue, struct ope
 }
 
 // Called by BlockThread
-static bool check_unmount(struct block_device *bdev, dd_list **queue, struct operation_queue **op)
+static bool check_unmount(struct block_device *bdev, GList **queue, struct operation_queue **op)
 {
        struct operation_queue *temp;
-       dd_list *l;
+       GList *l;
        int thread_id;
        bool unmounted = false;
 
@@ -1766,7 +1766,7 @@ static bool check_unmount(struct block_device *bdev, dd_list **queue, struct ope
                return false;
 
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
-       DD_LIST_FOREACH(*queue, l, temp) {
+       SYS_G_LIST_FOREACH(*queue, l, temp) {
                if (temp->op == BLOCK_DEV_UNMOUNT) {
                        unmounted = true;
                        _D("Operation queue has unmount operation.");
@@ -1780,7 +1780,7 @@ static bool check_unmount(struct block_device *bdev, dd_list **queue, struct ope
 
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
 
-       DD_LIST_FOREACH(*queue, l, temp) {
+       SYS_G_LIST_FOREACH(*queue, l, temp) {
                if (temp->op == BLOCK_DEV_UNMOUNT) {
                        *op = temp;
                        break;
@@ -1797,7 +1797,7 @@ static bool check_unmount(struct block_device *bdev, dd_list **queue, struct ope
 }
 
 // Called by BlockThread
-static void trigger_operation(struct block_device *bdev, dd_list *queue, struct operation_queue *op)
+static void trigger_operation(struct block_device *bdev, GList *queue, struct operation_queue *op)
 {
        int ret = 0;
        int thread_id;
@@ -1885,9 +1885,9 @@ static void trigger_operation(struct block_device *bdev, dd_list *queue, struct
 
                queue = bdev->op_queue;
                if (queue != NULL) {
-                       queue = DD_LIST_NEXT(queue);
+                       queue = SYS_G_LIST_NEXT(queue);
                        if (queue != NULL)
-                               op = DD_LIST_NTH(queue, 0);
+                               op = SYS_G_LIST_NTH(queue, 0);
                        else
                                op = NULL;
                } else
@@ -1913,8 +1913,8 @@ static void *block_th_start(void *arg)
        struct block_device *temp;
        struct manage_thread *th = (struct manage_thread *)arg;
        struct operation_queue *op = NULL;
-       dd_list *elem;
-       dd_list *queue = NULL;
+       GList *elem;
+       GList *queue = NULL;
        int thread_id;
 
        assert(th);
@@ -1933,16 +1933,16 @@ static void *block_th_start(void *arg)
                        _D("Wake up thread=%d.", thread_id);
                }
 
-               DD_LIST_FOREACH(th_manager[thread_id].block_dev_list, elem, temp) {
+               SYS_G_LIST_FOREACH(th_manager[thread_id].block_dev_list, elem, temp) {
                        queue = temp->op_queue;
                        do {
-                               op = DD_LIST_NTH(queue, 0);
+                               op = SYS_G_LIST_NTH(queue, 0);
                                if (!op) {
                                        _D("Operation queue for device %s is Empty.", temp->data->devnode);
                                        break;
                                }
                                if (op->done) {
-                                       queue = DD_LIST_NEXT(queue);
+                                       queue = SYS_G_LIST_NEXT(queue);
                                        continue;
                                }
                                break;
@@ -1962,7 +1962,7 @@ static void *block_th_start(void *arg)
 // Especially, we don't need to keep th_node_list.
 static int find_thread(char *devnode)
 {
-       dd_list *elem;
+       GList *elem;
        char str[PATH_MAX];
        char *th_node;
        char *temp;
@@ -1992,7 +1992,7 @@ static int find_thread(char *devnode)
        min_num = 1000;
        min = -1;
        for (i = 0; i < THREAD_MAX; i++) {
-               DD_LIST_FOREACH(th_manager[i].th_node_list, elem, temp) {
+               SYS_G_LIST_FOREACH(th_manager[i].th_node_list, elem, temp) {
                        if (!strncmp(temp, th_node, len)) {
                                free(th_node);
                                return i;
@@ -2005,12 +2005,12 @@ static int find_thread(char *devnode)
        }
 
        if (min >= 0 && min < THREAD_MAX) {
-               DD_LIST_APPEND(th_manager[min].th_node_list, th_node);
+               SYS_G_LIST_APPEND(th_manager[min].th_node_list, th_node);
                return min;
        }
 
        _E("Failed to find thread.");
-       DD_LIST_APPEND(th_manager[0].th_node_list, th_node);
+       SYS_G_LIST_APPEND(th_manager[0].th_node_list, th_node);
        return 0;
 }
 
@@ -2066,7 +2066,7 @@ static int add_operation(struct block_device *bdev,
        op->done = false;
 
        start_th = th_manager[thread_id].start_th;
-       DD_LIST_APPEND(bdev->op_queue, op);
+       SYS_G_LIST_APPEND(bdev->op_queue, op);
        th_manager[thread_id].op_len++;
 
        if (th_manager[thread_id].op_len == 1 && start_th)
@@ -2245,7 +2245,7 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m
 
        pthread_mutex_lock(&(th_manager[thread_id].mutex));
        th_manager[thread_id].num_dev++;
-       DD_LIST_APPEND(th_manager[thread_id].block_dev_list, bdev);
+       SYS_G_LIST_APPEND(th_manager[thread_id].block_dev_list, bdev);
        pthread_mutex_unlock(&(th_manager[thread_id].mutex));
 
        if (need_format) {
@@ -2492,12 +2492,12 @@ static int check_already_handled(const char* devnode)
 {
        struct block_device *bdev;
        struct block_data *data;
-       dd_list *elem;
+       GList *elem;
        int i;
 
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        data = bdev->data;
                        if (!data)
                                continue;
@@ -2610,12 +2610,12 @@ static void show_block_device_list(void)
 {
        struct block_device *bdev;
        struct block_data *data;
-       dd_list *elem;
+       GList *elem;
        int i;
 
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        data = bdev->data;
                        if (!data)
                                continue;
@@ -2646,15 +2646,15 @@ static void show_block_device_list(void)
 static void remove_whole_block_device(void)
 {
        struct block_device *bdev;
-       dd_list *elem;
-       dd_list *next;
+       GList *elem;
+       GList *next;
        int r;
        int i;
 
        for (i = 0; i < THREAD_MAX; i++) {
                do {
                        pthread_mutex_lock(&(th_manager[i].mutex));
-                       DD_LIST_FOREACH_SAFE(th_manager[i].block_dev_list, elem, next, bdev) {
+                       SYS_G_LIST_FOREACH_SAFE(th_manager[i].block_dev_list, elem, next, bdev) {
                                if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
                                    !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME)))
                                        continue;
@@ -3294,7 +3294,7 @@ static GVariant *request_get_device_list(GDBusConnection *conn,
        GVariant *reply = NULL;
        struct block_device *bdev;
        struct block_data *data;
-       dd_list *elem;
+       GList *elem;
        char *type = NULL;
        enum block_device_type block_type;
        int i;
@@ -3316,7 +3316,7 @@ static GVariant *request_get_device_list(GDBusConnection *conn,
 
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        if (!bdev->data || bdev->removed)
                                continue;
 
@@ -3367,7 +3367,7 @@ static GVariant *request_get_device_list_2(GDBusConnection *conn,
        GVariant *reply = NULL;
        struct block_device *bdev;
        struct block_data *data;
-       dd_list *elem;
+       GList *elem;
        char *type = NULL;
        enum block_device_type block_type;
        int i;
@@ -3394,7 +3394,7 @@ static GVariant *request_get_device_list_2(GDBusConnection *conn,
 
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        if (!bdev->data || bdev->removed)
                                continue;
 
@@ -3442,13 +3442,13 @@ static GVariant *request_get_mmc_primary(GDBusConnection *conn,
 {
        struct block_device *bdev;
        struct block_data *data = NULL, nodata = {0,};
-       dd_list *elem;
+       GList *elem;
        bool found = false;
        int i;
 
        for (i = 0; i < THREAD_MAX; i++) {
                pthread_mutex_lock(&(th_manager[i].mutex));
-               DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
+               SYS_G_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) {
                        data = bdev->data;
                        if (!data)
                                continue;
@@ -3744,7 +3744,7 @@ static void block_init(void *data)
 }
 static void terminate_threads(void)
 {
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        char *temp;
        int i, count;
        const int WAIT_TIME = 10;
@@ -3760,8 +3760,8 @@ static void terminate_threads(void)
                        pthread_cancel(th_manager[i].th);
                        pthread_join(th_manager[i].th, NULL);
                }
-               DD_LIST_FOREACH_SAFE(th_manager[i].th_node_list, elem, elem_next, temp) {
-                       DD_LIST_REMOVE(th_manager[i].th_node_list, temp);
+               SYS_G_LIST_FOREACH_SAFE(th_manager[i].th_node_list, elem, elem_next, temp) {
+                       SYS_G_LIST_REMOVE(th_manager[i].th_node_list, temp);
                        free(temp);
                }
        }
diff --git a/src/shared/config-parser.c b/src/shared/config-parser.c
deleted file mode 100644 (file)
index 0cfd9fd..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * storaged
- *
- * Copyright (c) 2013 - 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "log.h"
-#include "config-parser.h"
-
-#define MAX_LINE       512
-#define MAX_SECTION    64
-#define WHITESPACE     " \t"
-#define NEWLINE                "\n\r"
-#define COMMENT                '#'
-
-static inline char *trim_str(char *s)
-{
-       char *t;
-       /* left trim */
-       s += strspn(s, WHITESPACE);
-
-       /* right trim */
-       for (t = strchr(s, 0); t > s; t--)
-               if (!strchr(WHITESPACE, t[-1]))
-                       break;
-       *t = 0;
-       return s;
-}
-
-int config_parse(const char *file_name, int cb(struct parse_result *result,
-                       void *user_data), void *user_data)
-{
-       FILE *f = NULL;
-       struct parse_result result;
-       /* use stack for parsing */
-       char line[MAX_LINE];
-       char section[MAX_SECTION];
-       char *start, *end, *name, *value;
-       int lineno = 0, ret = 0;
-
-       if (!file_name || !cb) {
-               ret = -EINVAL;
-               goto error;
-       }
-
-       /* open conf file */
-       f = fopen(file_name, "r");
-       if (!f) {
-               _E("Failed to open file '%s'.", file_name);
-               ret = -EIO;
-               goto error;
-       }
-
-       /* parsing line by line */
-       while (fgets(line, MAX_LINE, f) != NULL) {
-               lineno++;
-
-               start = line;
-               start[strcspn(start, NEWLINE)] = '\0';
-               start = trim_str(start);
-
-               if (*start == COMMENT) {
-                       continue;
-               } else if (*start == '[') {
-                       /* parse section */
-                       end = strchr(start, ']');
-                       if (!end || *end != ']') {
-                               ret = -EBADMSG;
-                               goto error;
-                       }
-
-                       *end = '\0';
-                       strncpy(section, start + 1, sizeof(section)-1);
-                       section[MAX_SECTION-1] = '\0';
-               } else if (*start) {
-                       /* parse name & value */
-                       end = strchr(start, '=');
-                       if (!end || *end != '=') {
-                               ret = -EBADMSG;
-                               goto error;
-                       }
-                       *end = '\0';
-                       name = trim_str(start);
-                       value = trim_str(end + 1);
-                       end = strchr(value, COMMENT);
-                       if (end && *end == COMMENT) {
-                               *end = '\0';
-                               value = trim_str(value);
-                       }
-
-                       result.section = section;
-                       result.name = name;
-                       result.value = value;
-                       /* callback with parse result */
-                       ret = cb(&result, user_data);
-                       if (ret < 0) {
-                               ret = -EBADMSG;
-                               goto error;
-                       }
-               }
-       }
-       _D("Success to load '%s'.", file_name);
-       fclose(f);
-       return 0;
-
-error:
-       if (f)
-               fclose(f);
-       _E("Failed to read '%s': %d", file_name, lineno);
-       return ret;
-}
-
diff --git a/src/shared/config-parser.h b/src/shared/config-parser.h
deleted file mode 100644 (file)
index 4263727..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * storaged
- *
- * Copyright (c) 2013 - 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __CONFIG_PARSER_H__
-#define __CONFIG_PARSER_H__
-
-#define MATCH(a, b)            (!strncmp(a, b, strlen(a)))
-#define SET_CONF(a, b)         (a = (b > 0.0 ? b : a))
-
-struct parse_result {
-       char *section;
-       char *name;
-       char *value;
-};
-
-/**
- * @brief Parse config file and call callback\n
- * @param[in] file_name conf file.
- * @param[in] cb cb is called when conf file is parsed line by line.
- * @param[in] user_data user data is passed to cb.
- * @return 0 on success, negative if failed
- */
-int config_parse(const char *file_name, int cb(struct parse_result *result,
-       void *user_data), void *user_data);
-
-#endif
-
diff --git a/src/shared/list.h b/src/shared/list.h
deleted file mode 100644 (file)
index c355a0a..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * storaged
- *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LIST_H__
-#define __LIST_H__
-
-#include <glib.h>
-typedef GList dd_list;
-
-#define DD_LIST_PREPEND(a, b)          \
-       a = g_list_prepend(a, (gpointer)b)
-#define DD_LIST_APPEND(a, b)           \
-       a = g_list_append(a, (gpointer)b)
-#define DD_LIST_REMOVE(a, b)           \
-       a = g_list_remove(a, (gpointer)b)
-#define DD_LIST_REMOVE_LIST(a, b) \
-       a = g_list_delete_link(a, b)
-#define DD_LIST_LENGTH(a)                      \
-       g_list_length(a)
-#define DD_LIST_NTH(a, b)                      \
-       g_list_nth_data(a, b)
-#define DD_LIST_FIND(a, b)             \
-       g_list_find(a, (gpointer)b)
-#define DD_LIST_FREE_LIST(a)        \
-       g_list_free(a)
-#define DD_LIST_SORT(a, func)       \
-       a = g_list_sort(a, func)
-#define DD_LIST_FOREACH(head, elem, node)      \
-       for (elem = head, node = NULL; \
-                       elem && ((node = elem->data) != NULL); \
-                       elem = elem->next, node = NULL)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
-       for (elem = head, elem_next = g_list_next(elem), node = NULL; \
-                       elem && ((node = elem->data) != NULL); \
-                       elem = elem_next, elem_next = g_list_next(elem), node = NULL)
-#define DD_LIST_REVERSE_FOREACH(head, elem, node) \
-       for (elem = g_list_last(head), node = NULL; \
-                       elem && ((node = elem->data) != NULL); \
-                       elem = g_list_previous(elem), node = NULL)
-#define DD_LIST_REVERSE_FOREACH_SAFE(head, elem, elem_next, node) \
-       for (elem = g_list_last(head), elem_next = g_list_previous(elem), node = NULL; \
-                       elem && ((node = elem->data) != NULL); \
-                       elem = elem_next, elem_next = g_list_previous(elem), node = NULL)
-#define DD_LIST_NEXT(a)                \
-       g_list_next(a)
-
-#endif
index 28d0467..196bda0 100644 (file)
 #include <errno.h>
 #include <assert.h>
 #include <libsyscommon/dbus-system.h>
+#include <libsyscommon/list.h>
 
 #include "log.h"
 #include "fd_handler.h"
 #include "udev.h"
-#include "list.h"
 
 #define KERNEL          "kernel"
 #define UDEV            "udev"
@@ -37,7 +37,7 @@
 struct uevent_info {
        struct udev_monitor *mon;
        fd_handler_h handler;
-       dd_list *event_list;
+       GList *event_list;
 };
 
 /* Uevent */
@@ -53,7 +53,7 @@ static bool uevent_control_cb(int fd, void *data)
        struct uevent_info *info = data;
        struct udev_device *dev;
        struct uevent_handler *l;
-       dd_list *elem;
+       GList *elem;
        const char *subsystem;
        int len;
 
@@ -68,7 +68,7 @@ static bool uevent_control_cb(int fd, void *data)
                goto out;
 
        len = strlen(subsystem);
-       DD_LIST_FOREACH(info->event_list, elem, l) {
+       SYS_G_LIST_FOREACH(info->event_list, elem, l) {
                if (!strncmp(l->subsystem, subsystem, len) &&
                    l->uevent_func)
                        l->uevent_func(dev);
@@ -106,7 +106,7 @@ static int uevent_control_start(const char *type,
                struct uevent_info *info)
 {
        struct uevent_handler *l;
-       dd_list *elem;
+       GList *elem;
        int fd;
        int ret;
 
@@ -141,7 +141,7 @@ static int uevent_control_start(const char *type,
                goto stop;
        }
 
-       DD_LIST_FOREACH(info->event_list, elem, l) {
+       SYS_G_LIST_FOREACH(info->event_list, elem, l) {
                ret = udev_monitor_filter_add_match_subsystem_devtype(
                                info->mon,
                                l->subsystem, NULL);
@@ -182,7 +182,7 @@ static int register_uevent_control(struct uevent_info *info,
                const struct uevent_handler *uh)
 {
        struct uevent_handler *l;
-       dd_list *elem;
+       GList *elem;
        int r;
        bool matched = false;
        int len;
@@ -192,11 +192,11 @@ static int register_uevent_control(struct uevent_info *info,
 
        /* if udev is not initialized, it just will be added list */
        if (!udev || !info->mon)
-               goto add_list;
+               goto aGList;
 
        len = strlen(uh->subsystem);
        /* check if the same subsystem is already added */
-       DD_LIST_FOREACH(info->event_list, elem, l) {
+       SYS_G_LIST_FOREACH(info->event_list, elem, l) {
                if (!strncmp(l->subsystem, uh->subsystem, len)) {
                        matched = true;
                        break;
@@ -217,8 +217,8 @@ static int register_uevent_control(struct uevent_info *info,
        if (r < 0)
                _E("Failed to update udev monitor filter: %d", r);
 
-add_list:
-       DD_LIST_APPEND(info->event_list, uh);
+aGList:
+       SYS_G_LIST_APPEND(info->event_list, uh);
        return 0;
 }
 
@@ -226,17 +226,17 @@ static int unregister_uevent_control(struct uevent_info *info,
                const struct uevent_handler *uh)
 {
        struct uevent_handler *l;
-       dd_list *n, *next;
+       GList *n, *next;
        int len;
 
        if (!info || !uh || !uh->subsystem)
                return -EINVAL;
 
        len = strlen(uh->subsystem);
-       DD_LIST_FOREACH_SAFE(info->event_list, n, next, l) {
+       SYS_G_LIST_FOREACH_SAFE(info->event_list, n, next, l) {
                if (!strncmp(l->subsystem, uh->subsystem, len) &&
                    l->uevent_func == uh->uevent_func) {
-                       DD_LIST_REMOVE(info->event_list, l);
+                       SYS_G_LIST_REMOVE(info->event_list, l);
                        return 0;
                }
        }
index 0b62347..60674c5 100644 (file)
@@ -27,7 +27,6 @@ FILE(GLOB ALL_SRCS "*.c")
 SET(SRCS ${ALL_SRCS})
 SET(SHARED_SRCS
        ../shared/common.c
-       ../shared/config-parser.c
        ../shared/fd_handler.c
 )
 
index cc83755..8a20081 100644 (file)
@@ -33,9 +33,9 @@
 #include <tzplatform_config.h>
 #include <glib.h>
 #include <libsyscommon/dbus-system.h>
+#include <libsyscommon/ini-parser.h>
 
 #include "log.h"
-#include "config-parser.h"
 #include "module-intf.h"
 #include "storaged_common.h"
 #include "cleanup.h"