Use buxton_errno instead of global variable 'errno' 54/200854/1
authorjusung son <jusung07.son@samsung.com>
Tue, 26 Feb 2019 02:34:53 +0000 (11:34 +0900)
committerjusung son <jusung07.son@samsung.com>
Tue, 5 Mar 2019 05:58:08 +0000 (05:58 +0000)
 - The global variable 'errno' can be contaminated by other libraries.

Change-Id: Ie173b0907a8ade50af436c4fd699be1fe1d0033b
Signed-off-by: jusung son <jusung07.son@samsung.com>
(cherry picked from commit 12742d4a6f6b24fd0a24a75ac18b510e1a888cd2)

lib/buxton2.c
lib/include/buxton2_internal.h [new file with mode: 0644]
vconf-compat/vconf.c

index cea766feb64aa3ae0a7679951625e0e7539c7b12..55d6cb9602013a426b9c268a2ee9ae57ef272c2c 100644 (file)
@@ -32,6 +32,7 @@
 #include <glib-unix.h>
 
 #include "buxton2.h"
+#include "buxton2_internal.h"
 
 #include "common.h"
 #include "log.h"
@@ -92,13 +93,14 @@ struct buxton_client {
 static GList *clients; /* data: buxton_client */
 static pthread_mutex_t clients_lock = PTHREAD_MUTEX_INITIALIZER;
 static guint32 client_msgid;
+static int buxton_errno;
 
 static struct buxton_value *value_create(enum buxton_key_type type, void *value)
 {
        struct buxton_value *val;
 
        if (!value) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -130,7 +132,7 @@ static struct buxton_value *value_create(enum buxton_key_type type, void *value)
                break;
        default:
                free(val);
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
        val->type = type;
@@ -144,7 +146,7 @@ EXPORT struct buxton_value *buxton_value_create_string(const char *s)
        char *str;
 
        if (!s) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -195,7 +197,7 @@ EXPORT int buxton_value_get_type(const struct buxton_value *val,
                enum buxton_key_type *type)
 {
        if (!val || !type) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -208,12 +210,12 @@ static int value_get(const struct buxton_value *val, void *dest,
                enum buxton_key_type type)
 {
        if (!val || !dest) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        if (val->type != type) {
-               errno = ENOTSUP;
+               buxton_errno_set(ENOTSUP);
                return -1;
        }
 
@@ -289,7 +291,7 @@ EXPORT struct buxton_value *buxton_value_duplicate(
        struct buxton_value *_val;
 
        if (!val) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -559,7 +561,7 @@ static int add_noticb(struct bxt_noti *noti, buxton_notify_callback notify,
                noticb = l->data;
 
                if (noticb->callback == notify) {
-                       errno = EEXIST;
+                       buxton_errno_set(EEXIST);
                        pthread_mutex_unlock(&noti->cbs_lock);
                        return -1;
                }
@@ -812,7 +814,7 @@ static int wait_msg(struct buxton_client *client, guint32 msgid)
        }
 
        bxt_err("wait response: timeout");
-       errno = ETIMEDOUT;
+       buxton_errno_set(ETIMEDOUT);
 
        pthread_mutex_lock(&client->lock);
        g_hash_table_remove(client->req_cbs, GUINT_TO_POINTER(msgid));
@@ -841,7 +843,7 @@ static int send_req(struct buxton_client *client, const struct request *rqst)
        assert(rqst);
 
        if (client->fd == -1) {
-               errno = ENOTCONN;
+               buxton_errno_set(ENOTCONN);
                return -1;
        }
 
@@ -870,7 +872,7 @@ static struct bxt_req *set_value(struct buxton_client *client,
        struct request rqst;
 
        if (!client || !layer || !key || !*key || !val || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -953,7 +955,7 @@ EXPORT int buxton_set_value_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -971,7 +973,7 @@ static struct bxt_req *get_value(struct buxton_client *client,
        struct request rqst;
 
        if (!client || !layer || !key || !*key || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -1040,7 +1042,7 @@ EXPORT int buxton_get_value_sync(struct buxton_client *client,
        struct response resp;
 
        if (!val) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1060,7 +1062,7 @@ EXPORT int buxton_get_value_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1080,7 +1082,7 @@ static struct bxt_req *list_keys(struct buxton_client *client,
        struct request rqst;
 
        if (!client || !layer || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -1167,7 +1169,7 @@ EXPORT int buxton_list_keys_sync(struct buxton_client *client,
        struct response resp;
 
        if (!names) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1187,7 +1189,7 @@ EXPORT int buxton_list_keys_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1300,7 +1302,7 @@ EXPORT int buxton_register_notification(struct buxton_client *client,
        struct bxt_req *req;
 
        if (!client || !layer || !key || !*key || !notify || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1350,7 +1352,7 @@ EXPORT int buxton_register_notification_sync(struct buxton_client *client,
        struct response resp;
 
        if (!client || !layer || !key || !*key || !notify) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1382,7 +1384,7 @@ EXPORT int buxton_register_notification_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1424,7 +1426,7 @@ static int del_noticb(struct bxt_noti *noti, buxton_notify_callback notify,
        pthread_mutex_unlock(&noti->cbs_lock);
 
        if (!f) {
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                return -1;
        }
 
@@ -1483,7 +1485,7 @@ EXPORT int buxton_unregister_notification(struct buxton_client *client,
        int cnt;
 
        if (!client || !layer || !key || !*key || !notify || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1495,7 +1497,7 @@ EXPORT int buxton_unregister_notification(struct buxton_client *client,
        }
 
        if (!noti) {
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1543,7 +1545,7 @@ EXPORT int buxton_unregister_notification_sync(struct buxton_client *client,
        struct response resp;
 
        if (!client || !layer || !key || !*key || !notify) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1555,7 +1557,7 @@ EXPORT int buxton_unregister_notification_sync(struct buxton_client *client,
        }
 
        if (!noti) {
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1586,7 +1588,7 @@ EXPORT int buxton_unregister_notification_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1607,7 +1609,7 @@ static struct bxt_req *create_value(struct buxton_client *client,
 
        if (!client || !layer || !key || !*key || !read_privilege
                        || !write_privilege || !val || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -1696,7 +1698,7 @@ EXPORT int buxton_create_value_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1714,7 +1716,7 @@ static struct bxt_req *unset_value(struct buxton_client *client,
        struct request rqst;
 
        if (!client || !layer || !key || !*key || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -1794,7 +1796,7 @@ EXPORT int buxton_unset_value_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1815,12 +1817,12 @@ static struct bxt_req *set_priv(struct buxton_client *client,
        struct buxton_value val;
 
        if (!client || !layer || !key || !*key || !privilege || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
        if (type <= BUXTON_PRIV_UNKNOWN || type >= BUXTON_PRIV_MAX) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -1910,7 +1912,7 @@ EXPORT int buxton_set_privilege_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -1929,12 +1931,12 @@ static struct bxt_req *get_priv(struct buxton_client *client,
        struct request rqst;
 
        if (!client || !layer || !key || !*key || !callback) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
        if (type <= BUXTON_PRIV_UNKNOWN || type >= BUXTON_PRIV_MAX) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -2005,7 +2007,7 @@ EXPORT int buxton_get_privilege_sync(struct buxton_client *client,
        struct response resp;
 
        if (!privilege) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -2025,7 +2027,7 @@ EXPORT int buxton_get_privilege_sync(struct buxton_client *client,
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2131,7 +2133,7 @@ EXPORT int buxton_enable_security_sync(struct buxton_client *client)
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2178,7 +2180,7 @@ EXPORT int buxton_disable_security_sync(struct buxton_client *client)
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2276,7 +2278,7 @@ EXPORT int buxton_update_client_label_sync(struct buxton_client *client)
        }
 
        if (resp.res) {
-               errno = resp.res;
+               buxton_errno_set(resp.res);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2388,7 +2390,7 @@ int connect_server(const char *addr)
        int r;
 
        if (!addr) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -2459,14 +2461,14 @@ EXPORT int buxton_close(struct buxton_client *client)
        GList *l;
 
        if (!client) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        pthread_mutex_lock(&clients_lock);
        l = g_list_find(clients, client);
        if (!l) {
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2483,7 +2485,7 @@ EXPORT int buxton_open_full(struct buxton_client **client, bool attach_fd,
        struct buxton_client *cli;
 
        if (!client) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -2505,7 +2507,7 @@ EXPORT int buxton_open_full(struct buxton_client **client, bool attach_fd,
        if (!cli->req_cbs) {
                pthread_mutex_unlock(&cli->lock);
                free_client(cli);
-               errno = ENOMEM;
+               buxton_errno_set(ENOMEM);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2514,7 +2516,7 @@ EXPORT int buxton_open_full(struct buxton_client **client, bool attach_fd,
        if (!cli->noti_cbs) {
                pthread_mutex_unlock(&cli->lock);
                free_client(cli);
-               errno = ENOMEM;
+               buxton_errno_set(ENOMEM);
                pthread_mutex_unlock(&clients_lock);
                return -1;
        }
@@ -2550,3 +2552,13 @@ EXPORT int buxton_open(struct buxton_client **client,
        return buxton_open_full(client, true, callback, user_data);
 }
 
+EXPORT void buxton_errno_set(int err)
+{
+       buxton_errno = err;
+       errno = err;
+}
+
+EXPORT int buxton_errno_get()
+{
+       return buxton_errno;
+}
diff --git a/lib/include/buxton2_internal.h b/lib/include/buxton2_internal.h
new file mode 100644 (file)
index 0000000..3866bd4
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Buxton
+ *
+ * Copyright (C) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __BUXTON_INTERNAL_H__
+#define __BUXTON_INTERNALH__
+
+/**
+ * @file buxton2_internal.h
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void buxton_errno_set(int err);
+int buxton_errno_get();
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __BUXTON_H__ */
index 0fd64dbd228d65afab51431a914d145ab054c4b7..adec99ea10ab7991bcd67bd9104acb2237668d82 100644 (file)
@@ -30,6 +30,7 @@
 #include <dlog.h>
 
 #include "vconf.h"
+#include "buxton2_internal.h"
 
 #ifndef EXPORT
 #  define EXPORT __attribute__((visibility("default")))
@@ -109,7 +110,7 @@ static void _vconf_finish(void)
 EXPORT char *vconf_keynode_get_name(keynode_t *keynode)
 {
        if (!keynode || !keynode->keyname) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -119,7 +120,7 @@ EXPORT char *vconf_keynode_get_name(keynode_t *keynode)
 EXPORT int vconf_keynode_get_type(keynode_t *keynode)
 {
        if (!keynode) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -129,12 +130,12 @@ EXPORT int vconf_keynode_get_type(keynode_t *keynode)
 EXPORT int vconf_keynode_get_int(keynode_t *keynode)
 {
        if (!keynode) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        if (keynode->type != VCONF_TYPE_INT) {
-               errno = ENOTSUP;
+               buxton_errno_set(ENOTSUP);
                return -1;
        }
 
@@ -144,12 +145,12 @@ EXPORT int vconf_keynode_get_int(keynode_t *keynode)
 EXPORT double vconf_keynode_get_dbl(keynode_t *keynode)
 {
        if (!keynode) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        if (keynode->type != VCONF_TYPE_DOUBLE) {
-               errno = ENOTSUP;
+               buxton_errno_set(ENOTSUP);
                return -1;
        }
 
@@ -159,12 +160,12 @@ EXPORT double vconf_keynode_get_dbl(keynode_t *keynode)
 EXPORT int vconf_keynode_get_bool(keynode_t *keynode)
 {
        if (!keynode) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        if (keynode->type != VCONF_TYPE_BOOL) {
-               errno = ENOTSUP;
+               buxton_errno_set(ENOTSUP);
                return -1;
        }
 
@@ -174,12 +175,12 @@ EXPORT int vconf_keynode_get_bool(keynode_t *keynode)
 EXPORT char *vconf_keynode_get_str(keynode_t *keynode)
 {
        if (!keynode) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
        if (keynode->type != VCONF_TYPE_STRING) {
-               errno = ENOTSUP;
+               buxton_errno_set(ENOTSUP);
                return NULL;
        }
 
@@ -255,7 +256,7 @@ static void _vconf_restore_connection(enum buxton_status status,
        r = buxton_open(&client, _vconf_restore_connection, NULL);
        if (r == -1) {
                _refcnt = 0;
-               LOGE("Can't connect to buxton: %d", errno);
+               LOGE("Can't connect to buxton: %d", buxton_errno_get());
                pthread_mutex_unlock(&vconf_lock);
                return;
        }
@@ -276,7 +277,7 @@ static int _vconf_con_open(void)
 
        r = buxton_open(&client, _vconf_restore_connection, NULL);
        if (r == -1) {
-               LOGE("Can't connect to buxton: %d", errno);
+               LOGE("Can't connect to buxton: %d", buxton_errno_get());
                _refcnt--;
                return -1;
        }
@@ -488,7 +489,7 @@ static int _vconf_add_noti(struct noti *noti, vconf_callback_fn cb, void *user_d
        noticb = _vconf_find_noti_cb(noti, cb);
        if (noticb) {
                if (noticb->active) {
-                       errno = EEXIST;
+                       buxton_errno_set(EEXIST);
                        return -1;
                } else {
                        noticb->active = true;
@@ -552,7 +553,7 @@ static void _vconf_restore_noti_cb(gpointer key, gpointer value, gpointer user_d
 
        if (r == -1) {
                LOGE("vconf_notify_key_changed: key '%s' add notify error %d",
-                               _key, errno);
+                               _key, buxton_errno_get());
                g_hash_table_remove(noti_tbl, key);
        } else {
                _refcnt++;
@@ -568,7 +569,7 @@ EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb,
        last_result = false;
 
        if (!key || !cb) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -591,7 +592,7 @@ EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb,
                                _vconf_notify_cb, NULL);
                if (r == -1) {
                        LOGE("vconf_notify_key_changed: key '%s' add notify error %d",
-                                       key, errno);
+                                       key, buxton_errno_get());
                        g_hash_table_remove(noti_tbl, key);
                }
                /* increase reference count */
@@ -636,7 +637,7 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb)
        struct noti_cb *noticb;
 
        if (!key || !cb) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -651,7 +652,7 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb)
        if (!noti) {
                _vconf_con_close();
                pthread_mutex_unlock(&vconf_lock);
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                return -1;
        }
 
@@ -659,7 +660,7 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb)
        if (!noticb || !noticb->active) {
                _vconf_con_close();
                pthread_mutex_unlock(&vconf_lock);
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                return -1;
        }
 
@@ -680,7 +681,7 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb)
        r = buxton_unregister_notification_sync(client, _vconf_get_layer(key),
                        key, _vconf_notify_cb);
        if (r == -1)
-               LOGE("unregister error '%s' %d", noti->key, errno);
+               LOGE("unregister error '%s' %d", noti->key, buxton_errno_get());
        else
                _vconf_con_close();
 
@@ -711,7 +712,7 @@ static int _vconf_set(const char *key, const struct buxton_value *val)
 
        r = buxton_set_value_sync(client, _vconf_get_layer(key), key, val);
        if (r == -1)
-               LOGE("set value: key '%s' errno %d", key, errno);
+               LOGE("set value: key '%s' errno %d", key, buxton_errno_get());
 
        _vconf_con_close();
        pthread_mutex_unlock(&vconf_lock);
@@ -726,7 +727,7 @@ EXPORT int vconf_set_int(const char *key, int intval)
        last_result = false;
 
        if (!key) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -750,7 +751,7 @@ EXPORT int vconf_set_bool(const char *key, int boolval)
        last_result = false;
 
        if (!key) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -774,7 +775,7 @@ EXPORT int vconf_set_str(const char *key, const char *strval)
        last_result = false;
 
        if (!key || !strval) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -798,7 +799,7 @@ EXPORT int vconf_set_dbl(const char *key, double dblval)
        last_result = false;
 
        if (!key) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -833,7 +834,7 @@ static int _vconf_get(const char *key, enum buxton_key_type type,
 
        r = buxton_get_value_sync(client, _vconf_get_layer(key), key, &v);
        if (r == -1) {
-               LOGE("get value: key '%s' errno %d", key, errno);
+               LOGE("get value: key '%s' errno %d", key, buxton_errno_get());
        } else {
                enum buxton_key_type t;
 
@@ -843,7 +844,7 @@ static int _vconf_get(const char *key, enum buxton_key_type type,
 
                if (t != type) {
                        buxton_value_free(v);
-                       errno = ENOTSUP;
+                       buxton_errno_set(ENOTSUP);
                        r = -1;
                } else {
                        *val = v;
@@ -864,7 +865,7 @@ EXPORT int vconf_get_int(const char *key, int *intval)
        last_result = false;
 
        if (!key || !intval) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -894,7 +895,7 @@ EXPORT int vconf_get_bool(const char *key, int *boolval)
 
 
        if (!key || !boolval) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -924,7 +925,7 @@ EXPORT char *vconf_get_str(const char *key)
        last_result = false;
 
        if (!key) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -953,7 +954,7 @@ EXPORT int vconf_get_dbl(const char *key, double *dblval)
        last_result = false;
 
        if (!key || !dblval) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -982,7 +983,7 @@ EXPORT int vconf_get_ext_errno(void)
        if (last_result)
                return VCONF_OK;
 
-       switch (errno) {
+       switch (buxton_errno_get()) {
        case ENOENT:
                ret = VCONF_ERROR_FILE_NO_ENT;
                break;
@@ -1021,7 +1022,7 @@ EXPORT keylist_t *vconf_keylist_new(void)
 EXPORT int vconf_keylist_free(keylist_t *keylist)
 {
        if (!keylist) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1084,7 +1085,7 @@ EXPORT int vconf_keylist_add_int(keylist_t *keylist,
        struct _keynode_t *keynode;
 
        if (!keylist || !keyname) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1107,7 +1108,7 @@ EXPORT int vconf_keylist_add_bool(keylist_t *keylist,
        struct _keynode_t *keynode;
 
        if (!keylist || !keyname) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1130,7 +1131,7 @@ EXPORT int vconf_keylist_add_dbl(keylist_t *keylist,
        struct _keynode_t *keynode;
 
        if (!keylist || !keyname) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1154,7 +1155,7 @@ EXPORT int vconf_keylist_add_str(keylist_t *keylist,
        char *s;
 
        if (!keylist || !keyname || !value) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1182,7 +1183,7 @@ EXPORT int vconf_keylist_add_null(keylist_t *keylist, const char *keyname)
        struct _keynode_t *keynode;
 
        if (!keylist || !keyname) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1199,13 +1200,13 @@ EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname)
        struct _keynode_t *keynode;
 
        if (!keylist || !keyname) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        keynode = _vconf_find_keynode(keylist, keyname);
        if (!keynode) {
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                return -1;
        }
 
@@ -1221,7 +1222,7 @@ EXPORT keynode_t *vconf_keylist_nextnode(keylist_t *keylist)
        GList *next;
 
        if (!keylist) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return NULL;
        }
 
@@ -1243,14 +1244,14 @@ EXPORT int vconf_keylist_rewind(keylist_t *keylist)
        GList *l;
 
        if (!keylist) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        l = g_list_last(keylist->cursor);
 
        if (!l) {
-               errno = ENOENT;
+               buxton_errno_set(ENOENT);
                return -1;
        }
 
@@ -1316,7 +1317,7 @@ static struct _keynode_t *_vconf_alloc_keynode(const char *keyname)
 
        r = buxton_get_value_sync(client, _vconf_get_layer(keyname), keyname, &v);
        if (r == -1) {
-               LOGE("get value: key '%s' errno %d", keyname, errno);
+               LOGE("get value: key '%s' errno %d", keyname, buxton_errno_get());
                return NULL;
        }
 
@@ -1355,13 +1356,13 @@ EXPORT int vconf_get(keylist_t *keylist,
        int dirlen;
 
        if (!keylist || !in_parentDIR) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        dirlen = strlen(in_parentDIR);
        if (dirlen < 2) { /* minimum is "db" */
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1374,7 +1375,7 @@ EXPORT int vconf_get(keylist_t *keylist,
 
        r = buxton_list_keys_sync(client, _vconf_get_layer(in_parentDIR), &names, &len);
        if (r == -1) {
-               LOGE("get key list: errno %d", errno);
+               LOGE("get key list: errno %d", buxton_errno_get());
                _vconf_con_close();
                pthread_mutex_unlock(&vconf_lock);
                return -1;
@@ -1407,7 +1408,7 @@ EXPORT int vconf_set(keylist_t *keylist)
        GList *l;
 
        if (!keylist) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1449,7 +1450,7 @@ EXPORT int vconf_unset(const char *in_key)
 
        /* LCOV_EXCL_START */
        if (!in_key) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1462,7 +1463,7 @@ EXPORT int vconf_unset(const char *in_key)
 
        r = buxton_unset_value_sync(client, _vconf_get_layer(in_key), in_key);
        if (r == -1)
-               LOGE("unset value: key '%s' errno %d", in_key, errno);
+               LOGE("unset value: key '%s' errno %d", in_key, buxton_errno_get());
 
        _vconf_con_close();
        pthread_mutex_unlock(&vconf_lock);
@@ -1484,13 +1485,13 @@ EXPORT int vconf_unset_recursive(const char *in_dir)
 
        /* LCOV_EXCL_START */
        if (!in_dir) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
        dirlen = strlen(in_dir);
        if (dirlen < 2) { /* minimum is "db" */
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }
 
@@ -1503,7 +1504,7 @@ EXPORT int vconf_unset_recursive(const char *in_dir)
 
        r = buxton_list_keys_sync(client, _vconf_get_layer(in_dir), &names, &len);
        if (r == -1) {
-               LOGE("get key list: errno %d", errno);
+               LOGE("get key list: errno %d", buxton_errno_get());
                _vconf_con_close();
                pthread_mutex_unlock(&vconf_lock);
                return -1;
@@ -1565,7 +1566,7 @@ EXPORT int vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
        struct _keynode_t *keynode;
 
        if (!keylist || !keyname || !return_node) {
-               errno = EINVAL;
+               buxton_errno_set(EINVAL);
                return -1;
        }