From 9dcb91a1ea13aa84dbc5ea6d8bbc865721f7fd94 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 28 Nov 2018 16:39:38 +0900 Subject: [PATCH] Fix exceptions about checking errno Before calling dlog_print function, the result value should be set. While calling dlog_print function, the errno value can be changed. If the error is occurred after calling inotify_rm_watch function, the errno value is EBADF or EINVAL. Change-Id: Ic0773c09db18235d9db3c3f2ceb901c17e3b525f Signed-off-by: Hwankyu Jhun --- src/preference_inoti.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/preference_inoti.c b/src/preference_inoti.c index 9e553ed..5512629 100644 --- a/src/preference_inoti.c +++ b/src/preference_inoti.c @@ -386,11 +386,13 @@ int _preference_kdb_del_notify(keynode_t *keynode) /* get wd */ wd = inotify_add_watch(_kdb_inoti_fd, path, INOTY_EVENT_MASK); if (wd == -1) { + if (errno == ENOENT) + func_ret = PREFERENCE_ERROR_NO_KEY; + else + func_ret = PREFERENCE_ERROR_IO_ERROR; strerror_r(errno, err_buf, sizeof(err_buf)); ERR("Error: inotify_add_watch() [%s]: %s", path, err_buf); - if (errno == ENOENT) - return PREFERENCE_ERROR_NO_KEY; - return PREFERENCE_ERROR_IO_ERROR; + return func_ret; } pthread_mutex_lock(&_kdb_g_ns_mutex); @@ -410,10 +412,7 @@ int _preference_kdb_del_notify(keynode_t *keynode) if (r == -1) { strerror_r(errno, err_buf, sizeof(err_buf)); ERR("Error: inotify_rm_watch [%s]: %s", keyname, err_buf); - if (errno == ENOENT) - func_ret = PREFERENCE_ERROR_NO_KEY; - else - func_ret = PREFERENCE_ERROR_IO_ERROR; + func_ret = PREFERENCE_ERROR_IO_ERROR; } INFO("key(%s) cb is removed. remained noti list total length(%d)", -- 2.34.1