assert(client);
- pthread_mutex_unlock(&clients_lock);
-
switch (type) {
case MSG_NOTI:
proc_msg_noti(client, data, len);
bxt_err("proc msg: unknown message type %d", type);
break;
}
-
- pthread_mutex_lock(&clients_lock);
}
static int proc_msg(struct buxton_client *client)
assert(client);
- pthread_mutex_lock(&clients_lock);
f = g_list_find(clients, client);
if (!f) {
bxt_dbg("recv msg: cli %p removed\n", client);
- pthread_mutex_unlock(&clients_lock);
return 0;
}
r = proto_recv_async(client->fd, proc_msg_cb, client);
- pthread_mutex_unlock(&clients_lock);
if (r == -1) {
bxt_err("recv msg: fd %d errno %d", client->fd, errno);
return -1;
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = set_value(client, layer, key, val, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = set_value(client, layer, key, val, set_value_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = get_value(client, layer, key, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = get_value(client, layer, key, get_value_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
*val = resp.val;
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = list_keys(client, layer, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = list_keys(client, layer, list_keys_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
if (len)
*len = resp.nmlen;
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
return -1;
}
+ pthread_mutex_lock(&clients_lock);
r = find_noti(client, layer, key, ¬i);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (noti && noti->reg == TRUE) {
r = add_noticb(noti, notify, notify_data);
+ pthread_mutex_unlock(&clients_lock);
return call_resp(r == -1 ? errno : 0, layer, key,
callback, user_data);
}
req = register_noti(client, layer, key, notify, notify_data, callback,
user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
return -1;
}
+ pthread_mutex_lock(&clients_lock);
r = find_noti(client, layer, key, ¬i);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
- if (noti && noti->reg == TRUE)
+ if (noti && noti->reg == TRUE) {
+ pthread_mutex_unlock(&clients_lock);
return add_noticb(noti, notify, notify_data);
+ }
memset(&resp, 0, sizeof(resp));
req = register_noti(client, layer, key, notify, notify_data,
reg_noti_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
return -1;
}
+ pthread_mutex_lock(&clients_lock);
r = find_noti(client, layer, key, ¬i);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (!noti) {
errno = ENOENT;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
r = del_noticb(noti, notify, &cnt);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return call_resp(errno, layer, key, callback, user_data);
+ }
- if (cnt || noti->reg == FALSE)
+ if (cnt || noti->reg == FALSE) {
+ pthread_mutex_unlock(&clients_lock);
return call_resp(0, layer, key, callback, user_data);
+ }
req = unregister_noti(client, layer, key, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
return -1;
}
+ pthread_mutex_lock(&clients_lock);
r = find_noti(client, layer, key, ¬i);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (!noti) {
errno = ENOENT;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
r = del_noticb(noti, notify, &cnt);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
- if (cnt || noti->reg == FALSE)
+ if (cnt || noti->reg == FALSE) {
+ pthread_mutex_unlock(&clients_lock);
return 0;
+ }
memset(&resp, 0, sizeof(resp));
req = unregister_noti(client, layer, key, unreg_noti_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = create_value(client, layer, key, read_privilege, write_privilege,
val, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = create_value(client, layer, key, read_privilege, write_privilege,
val, create_value_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = unset_value(client, layer, key, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = unset_value(client, layer, key, unset_value_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = set_priv(client, layer, key, type, privilege,
callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = set_priv(client, layer, key, type, privilege,
set_priv_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = get_priv(client, layer, key, type, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
memset(&resp, 0, sizeof(resp));
+ pthread_mutex_lock(&clients_lock);
req = get_priv(client, layer, key, type, get_priv_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
resp.val->value.s = NULL;
buxton_value_free(resp.val);
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = security_control(client, TRUE, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
struct bxt_req *req;
struct response resp;
+ pthread_mutex_lock(&clients_lock);
req = security_control(client, TRUE, security_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
{
struct bxt_req *req;
+ pthread_mutex_lock(&clients_lock);
req = security_control(client, FALSE, callback, user_data);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
struct bxt_req *req;
struct response resp;
+ pthread_mutex_lock(&clients_lock);
req = security_control(client, FALSE, security_sync_cb, &resp);
- if (!req)
+ if (!req) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
r = wait_msg(client, req->msgid);
- if (r == -1)
+ if (r == -1) {
+ pthread_mutex_unlock(&clients_lock);
return -1;
+ }
if (resp.res) {
errno = resp.res;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
static void free_client(struct buxton_client *cli)
{
+ GList *f;
+
if (!cli)
return;
- close_conn(cli);
+ f = g_list_find(clients, cli);
+ if (f) {
+ if (cli->fd != -1) {
+ close(cli->fd);
+ cli->fd = -1;
+ }
+
+ if (cli->fd_id) {
+ g_source_remove(cli->fd_id);
+ cli->fd_id = 0;
+ }
+
+ if (cli->st_callback)
+ cli->st_callback(BUXTON_STATUS_DISCONNECTED, cli->st_data);
+ }
- pthread_mutex_lock(&clients_lock);
clients = g_list_remove(clients, cli);
pthread_mutex_lock(&cli->lock);
pthread_mutex_unlock(&cli->lock);
free(cli);
- pthread_mutex_unlock(&clients_lock);
}
int connect_server(const char *addr)
pthread_mutex_unlock(&clients_lock);
return G_SOURCE_REMOVE;
}
- pthread_mutex_unlock(&clients_lock);
r = proc_msg(cli);
if (r == -1) {
cli->fd_id = 0;
g_idle_add(close_conn, cli);
+ pthread_mutex_unlock(&clients_lock);
return G_SOURCE_REMOVE;
}
+ pthread_mutex_unlock(&clients_lock);
return G_SOURCE_CONTINUE;
}
return -1;
}
+ pthread_mutex_lock(&clients_lock);
l = g_list_find(clients, client);
if (!l) {
errno = ENOENT;
+ pthread_mutex_unlock(&clients_lock);
return -1;
}
free_client(client);
+ pthread_mutex_unlock(&clients_lock);
return 0;
}
GList *l;
GList *n;
+ pthread_mutex_lock(&clients_lock);
for (l = clients, n = g_list_next(l); l; l = n, n = g_list_next(n))
free_client(l->data);
clients = NULL;
+ pthread_mutex_unlock(&clients_lock);
}