#include <glib-unix.h>
#include "buxton2.h"
+#include "buxton2_internal.h"
#include "common.h"
#include "log.h"
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;
}
break;
default:
free(val);
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
val->type = type;
char *str;
if (!s) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
enum buxton_key_type *type)
{
if (!val || !type) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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;
}
struct buxton_value *_val;
if (!val) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
noticb = l->data;
if (noticb->callback == notify) {
- errno = EEXIST;
+ buxton_errno_set(EEXIST);
pthread_mutex_unlock(¬i->cbs_lock);
return -1;
}
}
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));
assert(rqst);
if (client->fd == -1) {
- errno = ENOTCONN;
+ buxton_errno_set(ENOTCONN);
return -1;
}
struct request rqst;
if (!client || !layer || !key || !*key || !val || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
struct request rqst;
if (!client || !layer || !key || !*key || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
struct response resp;
if (!val) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
struct request rqst;
if (!client || !layer || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
struct response resp;
if (!names) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
struct bxt_req *req;
if (!client || !layer || !key || !*key || !notify || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
struct response resp;
if (!client || !layer || !key || !*key || !notify) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
pthread_mutex_unlock(¬i->cbs_lock);
if (!f) {
- errno = ENOENT;
+ buxton_errno_set(ENOENT);
return -1;
}
int cnt;
if (!client || !layer || !key || !*key || !notify || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
}
if (!noti) {
- errno = ENOENT;
+ buxton_errno_set(ENOENT);
pthread_mutex_unlock(&clients_lock);
return -1;
}
struct response resp;
if (!client || !layer || !key || !*key || !notify) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
}
if (!noti) {
- errno = ENOENT;
+ buxton_errno_set(ENOENT);
pthread_mutex_unlock(&clients_lock);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
if (!client || !layer || !key || !*key || !read_privilege
|| !write_privilege || !val || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
struct request rqst;
if (!client || !layer || !key || !*key || !callback) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
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;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
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;
}
struct response resp;
if (!privilege) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
}
if (resp.res) {
- errno = resp.res;
+ buxton_errno_set(resp.res);
pthread_mutex_unlock(&clients_lock);
return -1;
}
int r;
if (!addr) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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;
}
struct buxton_client *cli;
if (!client) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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;
}
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;
}
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;
+}
#include <dlog.h>
#include "vconf.h"
+#include "buxton2_internal.h"
#ifndef EXPORT
# define EXPORT __attribute__((visibility("default")))
EXPORT char *vconf_keynode_get_name(keynode_t *keynode)
{
if (!keynode || !keynode->keyname) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
EXPORT int vconf_keynode_get_type(keynode_t *keynode)
{
if (!keynode) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
noticb = _vconf_find_noti_cb(noti, cb);
if (noticb) {
if (noticb->active) {
- errno = EEXIST;
+ buxton_errno_set(EEXIST);
return -1;
} else {
noticb->active = true;
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++;
last_result = false;
if (!key || !cb) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
_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 */
struct noti_cb *noticb;
if (!key || !cb) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
if (!noti) {
_vconf_con_close();
pthread_mutex_unlock(&vconf_lock);
- errno = ENOENT;
+ buxton_errno_set(ENOENT);
return -1;
}
if (!noticb || !noticb->active) {
_vconf_con_close();
pthread_mutex_unlock(&vconf_lock);
- errno = ENOENT;
+ buxton_errno_set(ENOENT);
return -1;
}
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();
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);
last_result = false;
if (!key) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
last_result = false;
if (!key) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
last_result = false;
if (!key || !strval) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
last_result = false;
if (!key) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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;
if (t != type) {
buxton_value_free(v);
- errno = ENOTSUP;
+ buxton_errno_set(ENOTSUP);
r = -1;
} else {
*val = v;
last_result = false;
if (!key || !intval) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
if (!key || !boolval) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
last_result = false;
if (!key) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
last_result = false;
if (!key || !dblval) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
if (last_result)
return VCONF_OK;
- switch (errno) {
+ switch (buxton_errno_get()) {
case ENOENT:
ret = VCONF_ERROR_FILE_NO_ENT;
break;
EXPORT int vconf_keylist_free(keylist_t *keylist)
{
if (!keylist) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
struct _keynode_t *keynode;
if (!keylist || !keyname) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
struct _keynode_t *keynode;
if (!keylist || !keyname) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
struct _keynode_t *keynode;
if (!keylist || !keyname) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
char *s;
if (!keylist || !keyname || !value) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
struct _keynode_t *keynode;
if (!keylist || !keyname) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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;
}
GList *next;
if (!keylist) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return NULL;
}
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;
}
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;
}
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;
}
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;
GList *l;
if (!keylist) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
/* LCOV_EXCL_START */
if (!in_key) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}
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);
/* 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;
}
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;
struct _keynode_t *keynode;
if (!keylist || !keyname || !return_node) {
- errno = EINVAL;
+ buxton_errno_set(EINVAL);
return -1;
}