summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-08-16 10:54:06 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-08-16 10:54:06 +0000
commita1bc48d15a5d6e78efe744eb7b27b6421cb7222f (patch)
treea7880f87c2585311975e4087d36255c9f1f0b7ec
parenta23442be507d9384175898a28fb72c35f790fbd1 (diff)
Convert to using ppoll() and pselect()
-rw-r--r--acinclude.m44
-rw-r--r--common/ppoll.h5
-rw-r--r--configure.in2
-rw-r--r--dund/dun.c1
-rw-r--r--dund/main.c1
-rw-r--r--hidd/fakehid.c10
-rw-r--r--hidd/main.c11
-rw-r--r--pand/Makefile.am2
-rw-r--r--pand/main.c34
-rw-r--r--rfcomm/Makefile.am2
-rw-r--r--rfcomm/main.c15
-rw-r--r--sdpd/Makefile.am2
-rw-r--r--sdpd/main.c5
-rw-r--r--tools/ciptool.c10
14 files changed, 76 insertions, 28 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index bbf6bc85..73d4e505 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -10,6 +10,10 @@ AC_DEFUN([AC_PROG_CC_PIE], [
])
])
+AC_DEFUN([AC_FUNC_PPOLL], [
+ AC_CHECK_FUNC(ppoll, dummy=yes, AC_DEFINE(NEED_PPOLL, 1, [Define to 1 if you need the ppoll() function.]))
+])
+
AC_DEFUN([AC_INIT_BLUEZ], [
AC_PREFIX_DEFAULT(/usr/local)
diff --git a/common/ppoll.h b/common/ppoll.h
new file mode 100644
index 00000000..6d84a2e8
--- /dev/null
+++ b/common/ppoll.h
@@ -0,0 +1,5 @@
+static inline int ppoll(struct pollfd *fds, nfds_t nfds,
+ const struct timespec *timeout, const sigset_t *sigmask)
+{
+ return poll(fds, nfds, timeout ? timeout->tv_sec * 1000 : 500);
+}
diff --git a/configure.in b/configure.in
index ded5f1ee..2436e0ce 100644
--- a/configure.in
+++ b/configure.in
@@ -22,6 +22,8 @@ m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])])
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
+AC_FUNC_PPOLL
+
AC_PATH_BLUEZ
AC_PATH_DBUS
AC_PATH_OPENOBEX
diff --git a/dund/dun.c b/dund/dun.c
index 718da7ec..fdc1e287 100644
--- a/dund/dun.c
+++ b/dund/dun.c
@@ -37,7 +37,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/poll.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/ioctl.h>
diff --git a/dund/main.c b/dund/main.c
index bb96d639..868f57fe 100644
--- a/dund/main.c
+++ b/dund/main.c
@@ -37,7 +37,6 @@
#include <getopt.h>
#include <sys/socket.h>
-#include <sys/poll.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
diff --git a/hidd/fakehid.c b/hidd/fakehid.c
index 91a62fb3..70eba3b4 100644
--- a/hidd/fakehid.c
+++ b/hidd/fakehid.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
@@ -44,6 +45,10 @@
#include <math.h>
+#ifdef NEED_PPOLL
+#include "ppoll.h"
+#endif
+
static void event(int fd, uint16_t type, uint16_t code, int32_t value)
{
struct uinput_event event;
@@ -282,6 +287,7 @@ int epox_presenter(const bdaddr_t *src, const bdaddr_t *dst, uint8_t channel)
unsigned char buf[16];
struct sigaction sa;
struct pollfd p;
+ sigset_t sigs;
char addr[18];
int i, fd, sk, len;
@@ -313,12 +319,14 @@ int epox_presenter(const bdaddr_t *src, const bdaddr_t *dst, uint8_t channel)
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
+ sigfillset(&sigs);
+
p.fd = sk;
p.events = POLLIN | POLLERR | POLLHUP;
while (!__io_canceled) {
p.revents = 0;
- if (poll(&p, 1, 500) < 1)
+ if (ppoll(&p, 1, NULL, &sigs) < 1)
continue;
len = read(sk, buf, sizeof(buf));
diff --git a/hidd/main.c b/hidd/main.c
index 77f80c3f..cd1dceb9 100644
--- a/hidd/main.c
+++ b/hidd/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
@@ -47,6 +48,10 @@
#include "hidd.h"
+#ifdef NEED_PPOLL
+#include "ppoll.h"
+#endif
+
enum {
NONE,
SHOW,
@@ -327,9 +332,12 @@ error:
static void run_server(int ctl, int csk, int isk, uint8_t subclass, int nosdp, int nocheck, int bootonly, int encrypt, int timeout)
{
struct pollfd p[2];
+ sigset_t sigs;
short events;
int err, ncsk, nisk;
+ sigfillset(&sigs);
+
p[0].fd = csk;
p[0].events = POLLIN | POLLERR | POLLHUP;
@@ -340,8 +348,7 @@ static void run_server(int ctl, int csk, int isk, uint8_t subclass, int nosdp, i
p[0].revents = 0;
p[1].revents = 0;
- err = poll(p, 2, 500);
- if (err <= 0)
+ if (ppoll(p, 2, NULL, &sigs) < 1)
continue;
events = p[0].revents | p[1].revents;
diff --git a/pand/Makefile.am b/pand/Makefile.am
index 3d92aa85..342b2244 100644
--- a/pand/Makefile.am
+++ b/pand/Makefile.am
@@ -6,6 +6,8 @@ pand_LDADD = @BLUEZ_LIBS@
AM_CFLAGS = @BLUEZ_CFLAGS@
+INCLUDES = -I$(top_srcdir)/common
+
man_MANS = pand.1
EXTRA_DIST = $(man_MANS)
diff --git a/pand/main.c b/pand/main.c
index fd77e4ab..026a879d 100644
--- a/pand/main.c
+++ b/pand/main.c
@@ -26,6 +26,7 @@
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
@@ -48,6 +49,10 @@
#include "pand.h"
+#ifdef NEED_PPOLL
+#include "ppoll.h"
+#endif
+
static uint16_t role = BNEP_SVC_PANU; /* Local role (ie service) */
static uint16_t service = BNEP_SVC_NAP; /* Remote service */
@@ -55,10 +60,7 @@ static int detach = 1;
static int persist;
static int use_sdp = 1;
static int use_cache;
-static int auth;
-static int encrypt;
-static int secure;
-static int master;
+static int link_mode = 0;
static int cleanup;
static int search_duration = 10;
@@ -168,16 +170,7 @@ static int do_listen(void)
}
/* Set link mode */
- lm = 0;
- if (master)
- lm |= L2CAP_LM_MASTER;
- if (auth)
- lm |= L2CAP_LM_AUTH;
- if (encrypt)
- lm |= L2CAP_LM_ENCRYPT;
- if (secure)
- lm |= L2CAP_LM_SECURE;
-
+ lm = link_mode;
if (lm && setsockopt(sk, SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm)) < 0) {
syslog(LOG_ERR, "Failed to set link mode. %s(%d)",
strerror(errno), errno);
@@ -238,12 +231,15 @@ static int do_listen(void)
static int w4_hup(int sk)
{
struct pollfd pf;
+ sigset_t sigs;
int n;
+ sigfillset(&sigs);
+
while (!terminate) {
pf.fd = sk;
pf.events = POLLERR | POLLHUP;
- n = poll(&pf, 1, -1);
+ n = ppoll(&pf, 1, NULL, &sigs);
if (n < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
@@ -614,19 +610,19 @@ int main(int argc, char *argv[])
break;
case 'A':
- auth = 1;
+ link_mode |= L2CAP_LM_AUTH;
break;
case 'E':
- encrypt = 1;
+ link_mode |= L2CAP_LM_ENCRYPT;
break;
case 'S':
- secure = 1;
+ link_mode |= L2CAP_LM_SECURE;
break;
case 'M':
- master = 1;
+ link_mode |= L2CAP_LM_MASTER;
break;
case 'e':
diff --git a/rfcomm/Makefile.am b/rfcomm/Makefile.am
index bda4a13f..8e883540 100644
--- a/rfcomm/Makefile.am
+++ b/rfcomm/Makefile.am
@@ -10,6 +10,8 @@ rfcomm_LDADD = @BLUEZ_LIBS@
AM_CFLAGS = @BLUEZ_CFLAGS@
+INCLUDES = -I$(top_srcdir)/common
+
man_MANS = rfcomm.1
AM_YFLAGS = -d
diff --git a/rfcomm/main.c b/rfcomm/main.c
index 43d52e61..5167d497 100644
--- a/rfcomm/main.c
+++ b/rfcomm/main.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
@@ -47,6 +48,10 @@
#include "kword.h"
+#ifdef NEED_PPOLL
+#include "ppoll.h"
+#endif
+
static char *rfcomm_config_file = NULL;
static int rfcomm_raw_tty = 0;
@@ -259,6 +264,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg
struct termios ti;
struct sigaction sa;
struct pollfd p;
+ sigset_t sigs;
socklen_t alen;
char dst[18], devname[MAXPATHLEN];
int sk, fd, try = 30;
@@ -378,12 +384,14 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
+ sigfillset(&sigs);
+
p.fd = fd;
p.events = POLLERR | POLLHUP;
while (!__io_canceled) {
p.revents = 0;
- if (poll(&p, 1, 500))
+ if (ppoll(&p, 1, NULL, &sigs) > 0)
break;
}
@@ -399,6 +407,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
struct termios ti;
struct sigaction sa;
struct pollfd p;
+ sigset_t sigs;
socklen_t alen;
char dst[18], devname[MAXPATHLEN];
int sk, nsk, fd, try = 30;
@@ -496,12 +505,14 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
+ sigfillset(&sigs);
+
p.fd = fd;
p.events = POLLERR | POLLHUP;
while (!__io_canceled) {
p.revents = 0;
- if (poll(&p, 1, 500))
+ if (ppoll(&p, 1, NULL, &sigs) > 0)
break;
}
diff --git a/sdpd/Makefile.am b/sdpd/Makefile.am
index 018a66f1..a82c2756 100644
--- a/sdpd/Makefile.am
+++ b/sdpd/Makefile.am
@@ -6,6 +6,8 @@ sdpd_LDADD = @BLUEZ_LIBS@
AM_CFLAGS = @BLUEZ_CFLAGS@
+INCLUDES = -I$(top_srcdir)/common
+
man_MANS = sdpd.8
EXTRA_DIST = $(man_MANS)
diff --git a/sdpd/main.c b/sdpd/main.c
index 269d5af8..fbc7f5e6 100644
--- a/sdpd/main.c
+++ b/sdpd/main.c
@@ -409,6 +409,7 @@ static struct option main_options[] = {
int main(int argc, char *argv[])
{
+ sigset_t sigs;
uint16_t mtu = 0;
int daemonize = 1, public = 0, master = 0;
int opt;
@@ -455,6 +456,8 @@ int main(int argc, char *argv[])
signal(SIGQUIT, sig_term);
signal(SIGPIPE, SIG_IGN);
+ sigfillset(&sigs);
+
for (;;) {
int num, nfd;
fd_set mask;
@@ -462,7 +465,7 @@ int main(int argc, char *argv[])
FD_ZERO(&mask);
mask = active_fdset;
- num = select(active_maxfd + 1, &mask, NULL, NULL, NULL);
+ num = pselect(active_maxfd + 1, &mask, NULL, NULL, NULL, &sigs);
if (num <= 0) {
SDPDBG("Select error:%s", strerror(errno));
goto exit;
diff --git a/tools/ciptool.c b/tools/ciptool.c
index 97dcb62d..3f4b113f 100644
--- a/tools/ciptool.c
+++ b/tools/ciptool.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@@ -44,6 +45,10 @@
#include <bluetooth/sdp_lib.h>
#include <bluetooth/cmtp.h>
+#ifdef NEED_PPOLL
+#include "ppoll.h"
+#endif
+
static volatile sig_atomic_t __io_canceled = 0;
static void sig_hup(int sig)
@@ -331,6 +336,7 @@ static void cmd_loopback(int ctl, bdaddr_t *bdaddr, int argc, char **argv)
struct cmtp_conndel_req req;
struct sigaction sa;
struct pollfd p;
+ sigset_t sigs;
bdaddr_t src, dst;
unsigned short psm;
int dev_id, sk;
@@ -375,12 +381,14 @@ static void cmd_loopback(int ctl, bdaddr_t *bdaddr, int argc, char **argv)
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
+ sigfillset(&sigs);
+
p.fd = sk;
p.events = POLLERR | POLLHUP;
while (!__io_canceled) {
p.revents = 0;
- if (poll(&p, 1, 500))
+ if (ppoll(&p, 1, NULL, &sigs) > 0)
break;
}