[-]
[+]
|
Changed |
_service:tar_git:bluebinder.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:bluebinder.spec
^
|
|
[-]
[+]
|
Added |
_service:tar_git:bluebinder-1.0.12.tar.bz2/.gitignore
^
|
@@ -0,0 +1 @@
+bluebinder
|
[-]
[+]
|
Changed |
_service:tar_git:bluebinder-1.0.12.tar.bz2/Makefile
^
|
@@ -1,9 +1,16 @@
# TODO: this is a bit minimalistic isn't it?
-DESTDIR ?= /
+USE_SYSTEMD ?= 1
-build:
- gcc -Wall -O3 -flto bluebinder.c `pkg-config --cflags libgbinder` `pkg-config --libs libgbinder` -lsystemd -o bluebinder
+DEPEND_LIBS = libgbinder glib-2.0
+ifeq ($(USE_SYSTEMD),1)
+DEPEND_LIBS += libsystemd
+endif
+
+build: bluebinder
+
+bluebinder: bluebinder.c
+ gcc $(CFLAGS) -Wall -flto $^ `pkg-config --cflags --libs $(DEPEND_LIBS)` -DUSE_SYSTEMD=$(USE_SYSTEMD) -o $@
install:
mkdir -p $(DESTDIR)/usr/sbin
|
[-]
[+]
|
Changed |
_service:tar_git:bluebinder-1.0.12.tar.bz2/bluebinder.c
^
|
@@ -39,7 +39,9 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
+#if USE_SYSTEMD
#include <systemd/sd-daemon.h>
+#endif
#include <gbinder.h>
@@ -72,6 +74,7 @@
int gio_channel_event_id;
int binder_replies_pending;
+ gboolean init_failed;
};
void
@@ -223,7 +226,7 @@
if (proxy->host_len < 1)
return true;
- switch (proxy->host_buf[0]) {
+ switch ((guint8)proxy->host_buf[0]) {
case HCI_COMMAND_PKT:
if (proxy->host_len < 1 + sizeof(*cmd_hdr))
return true;
@@ -348,6 +351,30 @@
}
static
+gboolean
+binder_init_complete(
+ struct proxy* proxy)
+{
+ fprintf(stderr, "Binder interface initialized, opening virtual device\n");
+
+ proxy->host_fd = open_vhci(HCI_PRIMARY);
+ if (proxy->host_fd < 0) {
+ fprintf(stderr, "Unable to open virtual device\n");
+ return FALSE;
+ }
+
+ if (!setup_watch(proxy)) {
+ fprintf(stderr, "Unable to setup watch\n");
+ return FALSE;
+ }
+
+ if (proxy->init_failed && proxy->loop)
+ g_main_loop_quit(proxy->loop);
+
+ return TRUE;
+}
+
+static
GBinderLocalReply*
bluebinder_callbacks_transact(
GBinderLocalObject* obj,
@@ -373,35 +400,27 @@
if (result != 0) {
fprintf(stderr, "Bluetooth binder service failed\n");
- g_main_loop_quit(proxy->loop);
- *status = GBINDER_STATUS_FAILED;
- return NULL;
- }
-
- fprintf(stderr, "Binder interface initialized, opening virtual device\n");
-
- proxy->host_fd = open_vhci(HCI_PRIMARY);
- if (proxy->host_fd < 0) {
- fprintf(stderr, "Unable to open virtual device\n");
- g_main_loop_quit(proxy->loop);
- *status = GBINDER_STATUS_FAILED;
- return NULL;
+ /* we need to tell BT service that we properly handled Status::INITIALIZATION_ERROR */
+ *status = GBINDER_STATUS_OK;
+ proxy->init_failed = TRUE;
+ return gbinder_local_reply_append_int32(gbinder_local_object_new_reply(obj), 0);
}
- if (!setup_watch(proxy)) {
- fprintf(stderr, "Unable to setup watch\n");
- g_main_loop_quit(proxy->loop);
+ if (binder_init_complete(proxy)) {
+ proxy->init_failed = FALSE;
+#if USE_SYSTEMD
+ sd_notify(0, "READY=1");
+#endif
+ *status = GBINDER_STATUS_OK;
+ return gbinder_local_reply_append_int32(gbinder_local_object_new_reply(obj), 0);
+ } else {
+ proxy->init_failed = TRUE;
*status = GBINDER_STATUS_FAILED;
return NULL;
}
- sd_notify(0, "READY=1");
-
- *status = GBINDER_STATUS_OK;
-
- return gbinder_local_reply_append_int32(gbinder_local_object_new_reply(obj), 0);
} else if (code == 2 || code == 3 || code == 4) {
- unsigned int count, elemsize;
+ gsize count, elemsize;
GBinderReader reader;
const uint8_t *vec;
uint8_t *packet;
@@ -514,7 +533,8 @@
death_id = gbinder_remote_object_add_death_handler
(remote, binder_remote_died, &proxy);
- g_main_loop_run(proxy.loop);
+ if (!proxy.init_failed)
+ g_main_loop_run(proxy.loop);
g_main_loop_unref(proxy.loop);
@@ -558,9 +578,11 @@
close(proxy.host_fd);
+#if USE_SYSTEMD
sd_notify(0,
"STATUS=Exiting.\n"
"ERRNO=19");
+#endif
return err;
}
|