diff options
Diffstat (limited to 'usr.sbin/bluetooth/bthidd/bthidd.c')
-rw-r--r-- | usr.sbin/bluetooth/bthidd/bthidd.c | 90 |
1 files changed, 28 insertions, 62 deletions
diff --git a/usr.sbin/bluetooth/bthidd/bthidd.c b/usr.sbin/bluetooth/bthidd/bthidd.c index a0f1463..b93fd3d 100644 --- a/usr.sbin/bluetooth/bthidd/bthidd.c +++ b/usr.sbin/bluetooth/bthidd/bthidd.c @@ -1,7 +1,9 @@ /* * bthidd.c - * - * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com> + */ + +/*- + * Copyright (c) 2006 Maksim Yevmenkin <m_evmenkin@yahoo.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bthidd.c,v 1.7 2004/11/17 21:59:42 max Exp $ + * $Id: bthidd.c,v 1.8 2006/09/07 21:06:53 max Exp $ * $FreeBSD$ */ @@ -42,42 +44,40 @@ #include <syslog.h> #include <unistd.h> #include <usbhid.h> -#include "bthidd.h" #include "bthid_config.h" +#include "bthidd.h" -static int write_pid_file (char const *file); -static int remove_pid_file (char const *file); -static int elapsed (int tval); -static void sighandler (int s); -static void sighup (int s); +static int32_t write_pid_file (char const *file); +static int32_t remove_pid_file (char const *file); +static int32_t elapsed (int32_t tval); +static void sighandler (int32_t s); static void usage (void); /* * bthidd */ -static int done = 0; /* are we done? */ -static int reload = 0; /* reload config file */ +static int32_t done = 0; /* are we done? */ -int -main(int argc, char *argv[]) +int32_t +main(int32_t argc, char *argv[]) { struct bthid_server srv; struct sigaction sa; - char const *pid_file = BTHIDD_PIDFILE, *ep = NULL; - int opt, detach, tval; + char const *pid_file = BTHIDD_PIDFILE; + char *ep; + int32_t opt, detach, tval; memset(&srv, 0, sizeof(srv)); - memcpy(&srv.bdaddr, NG_HCI_BDADDR_ANY, sizeof(srv.bdaddr)); - srv.windex = -1; + memset(&srv.bdaddr, 0, sizeof(srv.bdaddr)); detach = 1; tval = 10; /* sec */ - while ((opt = getopt(argc, argv, "a:c:dH:hp:s:t:")) != -1) { + while ((opt = getopt(argc, argv, "a:c:dH:hp:t:")) != -1) { switch (opt) { case 'a': /* BDADDR */ if (!bt_aton(optarg, &srv.bdaddr)) { - struct hostent *he = NULL; + struct hostent *he; if ((he = bt_gethostbyname(optarg)) == NULL) errx(1, "%s: %s", optarg, hstrerror(h_errno)); @@ -102,22 +102,12 @@ main(int argc, char *argv[]) pid_file = optarg; break; - case 's': /* switch script */ - srv.script = optarg; - break; - case 't': /* rescan interval */ tval = strtol(optarg, (char **) &ep, 10); if (*ep != '\0' || tval <= 0) usage(); break; - case 'u': /* wired keyboard index */ - srv.windex = strtol(optarg, (char **) &ep, 10); - if (*ep != '\0' || srv.windex < 0) - usage(); - break; - case 'h': default: usage(); @@ -139,19 +129,13 @@ main(int argc, char *argv[]) sa.sa_handler = sighandler; if (sigaction(SIGTERM, &sa, NULL) < 0 || + sigaction(SIGHUP, &sa, NULL) < 0 || sigaction(SIGINT, &sa, NULL) < 0) { syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", strerror(errno), errno); exit(1); } - sa.sa_handler = sighup; - if (sigaction(SIGHUP, &sa, NULL) < 0) { - syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", - strerror(errno), errno); - exit(1); - } - sa.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &sa, NULL) < 0) { syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", @@ -177,15 +161,6 @@ main(int argc, char *argv[]) if (server_do(&srv) < 0) break; - - if (reload) { - if (write_hids_file() < 0 || - read_config_file() < 0 || - read_hids_file() < 0) - break; - - reload = 0; - } } server_shutdown(&srv); @@ -200,10 +175,10 @@ main(int argc, char *argv[]) * Write pid file */ -static int +static int32_t write_pid_file(char const *file) { - FILE *pid = NULL; + FILE *pid; assert(file != NULL); @@ -223,7 +198,7 @@ write_pid_file(char const *file) * Remote pid file */ -static int +static int32_t remove_pid_file(char const *file) { assert(file != NULL); @@ -241,10 +216,10 @@ remove_pid_file(char const *file) * Returns true if desired time interval has elapsed */ -static int -elapsed(int tval) +static int32_t +elapsed(int32_t tval) { - static struct timeval last = { 0, }; + static struct timeval last = { 0, 0 }; struct timeval now; gettimeofday(&now, NULL); @@ -258,23 +233,16 @@ elapsed(int tval) } /* - * Signal handlers + * Signal handler */ static void -sighandler(int s) +sighandler(int32_t s) { syslog(LOG_NOTICE, "Got signal %d, total number of signals %d", s, ++ done); } -static void -sighup(int s) -{ - syslog(LOG_NOTICE, "Got SIGHUP: reload config"); - reload = 1; -} - /* * Display usage and exit */ @@ -291,9 +259,7 @@ usage(void) " -H file specify known HIDs file name\n" \ " -h display this message\n" \ " -p file specify PID file name\n" \ -" -s script specify keyboard switching script\n" \ " -t tval specify client rescan interval (sec)\n" \ -" -u unit specify wired keyboard unit\n" \ "", BTHIDD_IDENT); exit(255); } |