Add muse_core_set_close_on_exec for FD_CLOEXEC flag 31/275131/5 accepted/tizen/unified/20220525.010115 submit/tizen/20220524.050409
authorYoungHun Kim <yh8004.kim@samsung.com>
Tue, 17 May 2022 05:52:34 +0000 (14:52 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Wed, 18 May 2022 01:19:55 +0000 (10:19 +0900)
Change-Id: I31b83574c2fbd4119334ff7124eef8321f803f05

client/src/muse_client.c
core/include/muse_core_internal.h
core/src/muse_core.c
packaging/mused.spec
server/src/muse_server_log.c

index 030ff1e..f06c17f 100644 (file)
@@ -155,9 +155,8 @@ static int _mc_new(muse_channel_e channel)
        }
        LOGI("sockfd: %d", sock_fd);
 
-       if (fcntl(sock_fd, F_SETFD, FD_CLOEXEC) < 0) {
-               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
-               LOGE("unable to set on ctrl socket fd %d: %s", sock_fd, err_msg);
+       if (!muse_core_set_close_on_exec(sock_fd)) {
+               LOGE("unable to set on ctrl socket fd %d", sock_fd);
                close(sock_fd);
                return ret;
        }
index b82faf9..1fa5dac 100644 (file)
@@ -201,6 +201,7 @@ void muse_core_setenv(const char *name, const char *value, int replace);
 
 bool muse_core_msg_recv_len(int fd, char *buf, int msg_len);
 void muse_core_update_fd_state(int fd);
+gboolean muse_core_set_close_on_exec(int fd);
 void muse_core_get_cur_time(struct timespec *time, char *time_buf);
 
 #ifdef __cplusplus
index afab4a6..1d8e979 100644 (file)
@@ -740,6 +740,19 @@ void muse_core_update_fd_state(int fd)
        g_mutex_unlock(&fd_state_lock);
 }
 
+gboolean muse_core_set_close_on_exec(int fd)
+{
+       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
+
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
+               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
+               LOGE("unable to set FD_CLOEXEC on fd %d: %s", fd, err_msg);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 void muse_core_create_fd_table(void)
 {
        g_mutex_lock(&fd_state_lock);
index 370861c..5533a27 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.148
+Version:    0.3.149
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 17a8eb7..c1cf539 100644 (file)
@@ -197,11 +197,16 @@ static int _ms_fd_set_block(int fd)
 {
        int flags;
        int ret;
+       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
 
        muse_return_val_if_fail(ms_is_log_enabled(), MM_ERROR_NOT_SUPPORT_API);
 
        flags = fcntl(fd, F_GETFL);
        ret = fcntl(fd, F_SETFL, flags & (U32BITS ^ O_NONBLOCK));
+       if (ret < 0) {
+               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
+               LOGE("failed to set block fd %d : %s", fd, err_msg);
+       }
 
        muse_core_update_fd_state(fd);
 
@@ -258,8 +263,6 @@ static void _ms_log_create_fd(ms_log_t *log)
 
 static void _ms_log_set_fd(ms_log_t *log)
 {
-       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
-
        if (!ms_is_log_enabled())
                return;
 
@@ -269,10 +272,8 @@ static void _ms_log_set_fd(ms_log_t *log)
 
        muse_return_if_fail(muse_core_fd_is_valid(log->fd));
 
-       if (fcntl(log->fd, F_SETFD, FD_CLOEXEC) < 0) {
-               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
-               LOGE("unable to set CLO_EXEC on log fd %d: %s", log->fd, err_msg);
-       }
+       if (!muse_core_set_close_on_exec(log->fd))
+               LOGE("[%d] muse_core_set_close_on_exec is failed", log->fd);
 
        if (_ms_fd_set_block(log->fd) != 0)
                LOGE("[%d] _ms_fd_set_block is failed", log->fd);