}
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;
}
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
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);
{
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);
static void _ms_log_set_fd(ms_log_t *log)
{
- char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
-
if (!ms_is_log_enabled())
return;
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);