Use global mutex variable on __send_result() 61/300061/6
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 16 Oct 2023 08:30:38 +0000 (17:30 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 16 Oct 2023 08:55:08 +0000 (17:55 +0900)
The socket io of aul+ require mutex because read and write can occur at the same time.
This patch uses the global mutex instead of the previously removed channel mutex.

Change-Id: I7189dc4567c2a0150e40877b67f42baf62719b4a
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/aul_launch.c

index b4a555c..e09b9d2 100644 (file)
@@ -49,7 +49,6 @@ typedef struct client_channel_s {
        int fd;
        pid_t pid;
        uid_t uid;
-       GRecMutex mutex;
 } client_channel_t;
 
 struct aul_request_s {
@@ -108,11 +107,6 @@ AUL_DTOR static void __aul_destructor(void)
 static void __destroy_client_channel(gpointer data)
 {
        client_channel_t *channel = data;
-
-       g_rec_mutex_lock(&channel->mutex);
-       g_rec_mutex_unlock(&channel->mutex);
-       g_rec_mutex_clear(&channel->mutex);
-
        free(channel);
 }
 
@@ -126,8 +120,6 @@ static client_channel_t *__create_client_channel(int fd, pid_t pid, uid_t uid)
                return NULL;
        }
 
-       g_rec_mutex_init(&channel->mutex);
-
        channel->fd = fd;
        channel->pid = pid;
        channel->uid = uid;
@@ -404,10 +396,12 @@ static int __send_result(struct aul_request_s *req, int res)
        int ret;
 
        if (req->cmd != WIDGET_GET_CONTENT && req->clifd >= 0) {
+               g_rec_mutex_lock(&__context.mutex);
                if (__find_client_channel(req->clifd) == NULL)
                        _E("Failed to find client channel. fd(%d)", req->clifd);
 
                ret = aul_sock_send_result_v2(req->clifd, res, false);
+               g_rec_mutex_unlock(&__context.mutex);
                if (ret < 0) {
                        _E("Failed to send result. cmd(%s:%d)",
                                        aul_cmd_convert_to_string(req->cmd),
@@ -541,9 +535,11 @@ static bool __received_event_cb(int fd, int condition, void *user_data)
        app_pkt_t *pkt;
        int ret;
 
+       g_rec_mutex_lock(&__context.mutex);
        channel = __find_client_channel(fd);
        if (!channel) {
                _E("Failed to find client channel. fd(%d)", fd);
+               g_rec_mutex_unlock(&__context.mutex);
                return false;
        }
 
@@ -552,12 +548,12 @@ static bool __received_event_cb(int fd, int condition, void *user_data)
                aul_worker_remove_io_job(worker, fd);
                __remove_client_channel(channel);
                __destroy_client_channel(channel);
+               g_rec_mutex_unlock(&__context.mutex);
                return true;
        }
 
-       g_rec_mutex_lock(&channel->mutex);
        ret = aul_sock_recv_reply_pkt_v2(fd, &pkt, false);
-       g_rec_mutex_unlock(&channel->mutex);
+       g_rec_mutex_unlock(&__context.mutex);
        if (ret != 0) {
                _E("Failed to receive the packet. error(%d)", ret);
                return true;