g_pref_dir_path = (char *)malloc(PREFERENCE_KEY_PATH_LEN + 1);
if ((app_data_path = app_get_data_path()) == NULL) {
+ /* LCOV_EXCL_START */
ERR("IO_ERROR(0x%08x) : fail to get data directory", PREFERENCE_ERROR_IO_ERROR);
free(g_pref_dir_path);
g_pref_dir_path = NULL;
return NULL;
+ /* LCOV_EXCL_STOP */
}
snprintf(g_pref_dir_path, PREFERENCE_KEY_PATH_LEN, "%s%s", app_data_path, PREF_DIR);
return fcntl(fd, F_SETLK, &l);
}
+/* LCOV_EXCL_START */
static int _preference_get_pid_of_file_lock_owner(int fd, short type)
{
struct flock l;
else
return l.l_pid;
}
+/* LCOV_EXCL_STOP */
static int _preference_set_read_lock(int fd)
{
return _preference_set_file_lock(fd, F_UNLCK);
}
+/* LCOV_EXCL_START */
static void _preference_log_subject_label(void)
{
int fd;
close(fd);
}
+/* LCOV_EXCL_STOP */
static int _preference_check_retry_err(keynode_t *keynode, int preference_errno, int io_errno, int op_type)
{
if (op_type == PREFERENCE_OP_SET) {
rc = _preference_get_key_path(keynode, path);
if (rc != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("_preference_get_key_path error");
_preference_log_subject_label();
break;
+ /* LCOV_EXCL_STOP */
}
rc = _preference_set_key_check_pref_dir();
if (rc != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("_preference_set_key_check_pref_dir() failed.");
_preference_log_subject_label();
break;
+ /* LCOV_EXCL_STOP */
}
rc = _preference_set_key_creation(path);
if (rc != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("_preference_set_key_creation error : %s", path);
_preference_log_subject_label();
break;
+ /* LCOV_EXCL_STOP */
}
INFO("%s key is created", keynode->keyname);
ret = _preference_set_write_lock(fileno(fp));
if (ret == -1) {
+ /* LCOV_EXCL_START */
func_ret = PREFERENCE_ERROR_FILE_LOCK;
err_no = errno;
ERR("file(%s) lock owner(%d)",
keynode->keyname,
_preference_get_pid_of_file_lock_owner(fileno(fp), F_WRLCK));
goto out_return;
+ /* LCOV_EXCL_STOP */
}
/* write keyname and size */
ret = fwrite((void *)&keyname_len, sizeof(int), 1, fp);
if (ret <= 0) {
+ /* LCOV_EXCL_START */
if (!errno) {
LOGW("number of written items is 0. try again");
errno = EAGAIN;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_WRITE;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
ret = fwrite((void *)keynode->keyname, keyname_len, 1, fp);
if (ret <= 0) {
+ /* LCOV_EXCL_START */
if (!errno) {
LOGW("number of written items is 0. try again");
errno = EAGAIN;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_WRITE;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
/* write key type */
ret = fwrite((void *)&(keynode->type), sizeof(int), 1, fp);
if (ret <= 0) {
+ /* LCOV_EXCL_START */
if (!errno) {
LOGW("number of written items is 0. try again");
errno = EAGAIN;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_WRITE;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
/* write key value */
}
if (is_write_error) {
+ /* LCOV_EXCL_START */
if (!errno) {
LOGW("number of written items is 0. try again");
errno = EAGAIN;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_WRITE;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
fflush(fp);
g_posix_errno = PREFERENCE_ERROR_NONE;
g_preference_errno = PREFERENCE_ERROR_NONE;
} else {
+ /* LCOV_EXCL_START */
strerror_r(io_errno, err_buf, 100);
ERR("_preference_set_key(%s) step(%d) failed(%d / %s)", keynode->keyname, ret, io_errno, err_buf);
g_posix_errno = io_errno;
g_preference_errno = ret;
+ /* LCOV_EXCL_STOP */
}
return ret;
func_ret = _preference_keynode_set_keyname(pKeyNode, key);
if (func_ret != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("set key name error");
_preference_keynode_free(pKeyNode);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
_preference_keynode_set_value_int(pKeyNode, intval);
func_ret = _preference_keynode_set_keyname(pKeyNode, key);
if (func_ret != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("set key name error");
_preference_keynode_free(pKeyNode);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
_preference_keynode_set_value_boolean(pKeyNode, boolval);
func_ret = _preference_keynode_set_keyname(pKeyNode, key);
if (func_ret != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("set key name error");
_preference_keynode_free(pKeyNode);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
_preference_keynode_set_value_double(pKeyNode, dblval);
func_ret = _preference_keynode_set_keyname(pKeyNode, key);
if (func_ret != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("set key name error");
_preference_keynode_free(pKeyNode);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
_preference_keynode_set_value_string(pKeyNode, strval);
ret = _preference_set_read_lock(fileno(fp));
if (ret == -1) {
+ /* LCOV_EXCL_START */
func_ret = PREFERENCE_ERROR_FILE_LOCK;
err_no = errno;
goto out_return;
+ /* LCOV_EXCL_STOP */
}
read_size = fread((void *)&keyname_len, sizeof(int), 1, fp);
if ((read_size <= 0) || (read_size > sizeof(int))) {
+ /* LCOV_EXCL_START */
if (!ferror(fp))
errno = ENODATA;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
ret = fseek(fp, keyname_len, SEEK_CUR);
if (ret) {
+ /* LCOV_EXCL_START */
if (!ferror(fp))
errno = ENODATA;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
read_size = fread((void *)&type, sizeof(int), 1, fp);
if (read_size <= 0) {
+ /* LCOV_EXCL_START */
if (!ferror(fp))
errno = ENODATA;
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
}
/* read data value */
case PREFERENCE_TYPE_INT:
read_size = fread((void *)&value_int, sizeof(int), 1, fp);
if ((read_size <= 0) || (read_size > sizeof(int))) {
+ /* LCOV_EXCL_START */
if (!ferror(fp))
LOGW("number of read items for value is wrong. err : %d", errno);
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
} else {
_preference_keynode_set_value_int(keynode, value_int);
}
case PREFERENCE_TYPE_DOUBLE:
read_size = fread((void *)&value_dbl, sizeof(double), 1, fp);
if ((read_size <= 0) || (read_size > sizeof(double))) {
+ /* LCOV_EXCL_START */
if (!ferror(fp))
LOGW("number of read items for value is wrong. err : %d", errno);
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
} else {
_preference_keynode_set_value_double(keynode, value_dbl);
}
case PREFERENCE_TYPE_BOOLEAN:
read_size = fread((void *)&value_int, sizeof(int), 1, fp);
if ((read_size <= 0) || (read_size > sizeof(int))) {
+ /* LCOV_EXCL_START */
if (!ferror(fp))
LOGW("number of read items for value is wrong. err : %d", errno);
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
+ /* LCOV_EXCL_STOP */
} else {
_preference_keynode_set_value_boolean(keynode, value_int);
}
strerror_r(err_no, err_buf, 100);
if (_preference_check_retry_err(keynode, func_ret, err_no, PREFERENCE_OP_GET)) {
+ /* LCOV_EXCL_START */
if (retry_cnt < PREFERENCE_ERROR_RETRY_CNT) {
retry_cnt++;
usleep((retry_cnt)*PREFERENCE_ERROR_RETRY_SLEEP_UTIME);
ERR("_preference_get_key_filesys(%s) step(%d) faild(%d / %s) over the retry count.",
keynode->keyname, func_ret, err_no, err_buf);
}
+ /* LCOV_EXCL_STOP */
}
}
ret = _preference_get_key_name(path, &keyname);
if (ret != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
ERR("_preference_get_key_name() failed(%d)", ret);
_preference_keynode_free(pKeyNode);
closedir(dir);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
ret = preference_unset_changed_cb(keyname);
if (ret != PREFERENCE_ERROR_NONE) {
+ /* LCOV_EXCL_START */
if (ret == PREFERENCE_ERROR_NO_KEY) {
ERR("can't find %s's cb()", keyname);
} else {
free(keyname);
return PREFERENCE_ERROR_IO_ERROR;
}
+ /* LCOV_EXCL_STOP */
}
do {
ret = remove(path);
if (ret == -1) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("preference_remove_all error: %d(%s)", errno, err_buf);
func_ret = PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
} else {
func_ret = PREFERENCE_ERROR_NONE;
break;
n->keyname = strndup(t->keyname, PREFERENCE_KEY_PATH_LEN);
if (n->keyname == NULL) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("The memory is insufficient, errno: %d (%s)", errno, err_buf);
free(n);
break;
+ /* LCOV_EXCL_STOP */
}
n->wd = t->wd;
n->cb_data = t->cb_data;
pthread_mutex_lock(&_kdb_inoti_fd_mutex);
if (0 < _kdb_inoti_fd) {
+ /* LCOV_EXCL_START */
ERR("Error: invalid _kdb_inoti_fd");
pthread_mutex_unlock(&_kdb_inoti_fd_mutex);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
_kdb_inoti_fd = inotify_init();
if (_kdb_inoti_fd == -1) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("inotify init: %s", err_buf);
pthread_mutex_unlock(&_kdb_inoti_fd_mutex);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
ret = fcntl(_kdb_inoti_fd, F_SETFD, FD_CLOEXEC);
if (ret < 0) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("inotify init: %s", err_buf);
pthread_mutex_unlock(&_kdb_inoti_fd_mutex);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
ret = fcntl(_kdb_inoti_fd, F_SETFL, O_NONBLOCK);
if (ret < 0) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("inotify init: %s", err_buf);
pthread_mutex_unlock(&_kdb_inoti_fd_mutex);
return PREFERENCE_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
}
pthread_mutex_unlock(&_kdb_inoti_fd_mutex);
list = g_list_find_custom(g_notilist, &t, (GCompareFunc)_preference_inoti_comp_with_wd);
if (list) {
+ /* LCOV_EXCL_START */
WARN("_preference_kdb_add_notify : key(%s) change callback(%p)", keyname, cb);
node = list->data;
node->cb = cb;
goto out_func;
+ /* LCOV_EXCL_STOP */
}
n = calloc(1, sizeof(noti_node_s));
if (n == NULL) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("_preference_kdb_add_notify : add noti(%s)", err_buf);
func_ret = PREFERENCE_ERROR_IO_ERROR;
goto out_func;
+ /* LCOV_EXCL_STOP */
}
n->keyname = strndup(keyname, PREFERENCE_KEY_PATH_LEN);
if (n->keyname == NULL) {
+ /* LCOV_EXCL_START */
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("The memory is insufficient, errno: %d (%s)", errno, err_buf);
free(n);
goto out_func;
+ /* LCOV_EXCL_STOP */
}
n->wd = wd;
n->cb_data = data;