summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dund/dun.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/dund/dun.c b/dund/dun.c
index 1486d515..6611ad86 100644
--- a/dund/dun.c
+++ b/dund/dun.c
@@ -182,7 +182,7 @@ static int dun_create_tty(int sk, char *tty, int size)
{
struct sockaddr_rc sa;
struct stat st;
- int id, alen;
+ int id, alen, try = 3;
struct rfcomm_dev_req req = {
flags: (1 << RFCOMM_REUSE_DLC) | (1 << RFCOMM_RELEASE_ONHUP),
@@ -205,10 +205,19 @@ static int dun_create_tty(int sk, char *tty, int size)
return id;
snprintf(tty, size, "/dev/rfcomm%d", id);
- if (stat(tty, &st) < 0) {
+ while (stat(tty, &st) < 0) {
snprintf(tty, size, "/dev/bluetooth/rfcomm/%d", id);
if (stat(tty, &st) < 0) {
snprintf(tty, size, "/dev/rfcomm%d", id);
+ if (try--) {
+ sleep(1);
+ continue;
+ }
+
+ memset(&req, 0, sizeof(req));
+ req.dev_id = id;
+ ioctl(sk, RFCOMMRELEASEDEV, &req);
+
return -1;
}
}