Move fd-stat-dump function to muse-core for debugging purpose 87/165187/1 accepted/tizen/4.0/unified/20171227.224340 submit/tizen_4.0/20171227.043010
authorYoungHun Kim <yh8004.kim@samsung.com>
Tue, 26 Dec 2017 05:28:44 +0000 (14:28 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Wed, 27 Dec 2017 03:19:21 +0000 (03:19 +0000)
  - Sometimes unexpected fd was returned from socket() on client side (eg. STDIN_FILENO, STDOUT_FILNO or STERR_FILENO)

Change-Id: I3ef8ae49fa29403307e739584a0ac5242e926dcc

client/src/muse_client.c
core/include/muse_core.h
core/src/muse_core.c
packaging/mused.spec
server/include/muse_server.h
server/src/muse_server.c
server/src/muse_server_private.c

index 0ad6861..5937235 100644 (file)
@@ -145,6 +145,7 @@ static int _mc_new(muse_channel_e channel)
        if (!muse_core_fd_is_valid(sock_fd)) {
                strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
                LOGE("[socket failure] %d sock: %s", errno, err_msg);
+               muse_core_fd_state_dump(sock_fd);
                return ret;
        }
        LOGI("sockfd: %d", sock_fd);
index c2e7b3a..5b6a284 100644 (file)
@@ -113,6 +113,8 @@ void *muse_core_msg_object_new(char *str, int *parse_len, muse_core_msg_parse_er
 bool muse_core_msg_object_get_value(const char *key, void *jobj, muse_core_msg_type_e m_type, void *data);
 void muse_core_msg_object_free(void *msg_obj);
 
+void muse_core_fd_state_dump(int fd);
+
 #ifdef __cplusplus
 }
 #endif
index b893eb7..6fd2b65 100644 (file)
@@ -566,3 +566,20 @@ void muse_core_msg_object_free(void *jobj)
 
        g_mutex_unlock(&msg_lock);
 }
+
+void muse_core_fd_state_dump(int fd)
+{
+       struct stat sb = { 0, };
+       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
+
+       if (fstat(fd, &sb) < 0) {
+               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
+               LOGE("[%d] failed to get file status %d %s", fd, errno, err_msg);
+               return;
+       }
+
+       LOGI("[Last file access %d] %s", fd, ctime(&sb.st_atime));
+       LOGI("[Last status change] %s", ctime(&sb.st_ctime));
+       LOGI("[Last file modification] %s", ctime(&sb.st_mtime));
+}
+
index 17abc8c..2f1cbe6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.23
+Version:    0.3.24
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 6ce64f7..3e115e4 100644 (file)
@@ -63,8 +63,6 @@ int muse_server_get_platform_info(const char *key, bool *value);
 unsigned int muse_server_get_atomic_uint(void);
 int muse_server_get_module_instance_count(int idx);
 
-void muse_server_check_fd_state(int fd);
-
 #ifdef __cplusplus
 }
 #endif
index 1a4b450..560b5fa 100644 (file)
@@ -405,20 +405,6 @@ int muse_server_get_module_instance_count(int idx)
        return connection->instance_count[idx];
 }
 
-void muse_server_check_fd_state(int fd)
-{
-       struct stat sb = { 0, };
-
-       if (fstat(fd, &sb) < 0) {
-               LOGE("failed to get file status");
-               return;
-       }
-
-       LOGI("[Last file access %d] %s", fd, ctime(&sb.st_atime));
-       LOGI("[Last status change] %s", ctime(&sb.st_ctime));
-       LOGI("[Last file modification] %s", ctime(&sb.st_mtime));
-}
-
 int main(int argc, char **argv)
 {
        pid_t pid;
index 6a1751f..f222590 100644 (file)
@@ -269,7 +269,7 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
        if (!muse_core_fd_is_valid(server_sockfd)) {
                LOGE("Critical Error : server %d is invalid", server_sockfd);
                _ms_unlock_state();
-               muse_server_check_fd_state(STDIN_FILENO);
+               muse_core_fd_state_dump(server_sockfd);
                ms_respawn(SIGABRT);
                return FALSE;
        }
@@ -278,7 +278,7 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
        client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
        if (!muse_core_fd_is_valid(client_sockfd)) {
                LOGE("Critical Error : accept %d is invalid", client_sockfd);
-               muse_server_check_fd_state(STDIN_FILENO);
+               muse_core_fd_state_dump(client_sockfd);
                close(server_sockfd);
                _ms_unlock_state();
                ms_respawn(SIGABRT);