bthidd.c (133178) | bthidd.c (137868) |
---|---|
1/* 2 * bthidd.c 3 * 4 * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * | 1/* 2 * bthidd.c 3 * 4 * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * |
28 * $Id: bthidd.c,v 1.4 2004/02/26 21:48:44 max Exp $ 29 * $FreeBSD: head/usr.sbin/bluetooth/bthidd/bthidd.c 133178 2004-08-05 16:32:41Z emax $ | 28 * $Id: bthidd.c,v 1.7 2004/11/17 21:59:42 max Exp $ 29 * $FreeBSD: head/usr.sbin/bluetooth/bthidd/bthidd.c 137868 2004-11-18 18:05:15Z emax $ |
30 */ 31 32#include <sys/time.h> 33#include <sys/queue.h> 34#include <assert.h> 35#include <bluetooth.h> 36#include <err.h> 37#include <errno.h> --- 19 unchanged lines hidden (view full) --- 57 58static int done = 0; /* are we done? */ 59 60int 61main(int argc, char *argv[]) 62{ 63 struct bthid_server srv; 64 struct sigaction sa; | 30 */ 31 32#include <sys/time.h> 33#include <sys/queue.h> 34#include <assert.h> 35#include <bluetooth.h> 36#include <err.h> 37#include <errno.h> --- 19 unchanged lines hidden (view full) --- 57 58static int done = 0; /* are we done? */ 59 60int 61main(int argc, char *argv[]) 62{ 63 struct bthid_server srv; 64 struct sigaction sa; |
65 char const *pid_file = BTHIDD_PIDFILE; | 65 char const *pid_file = BTHIDD_PIDFILE, *ep = NULL; |
66 int opt, detach, tval; 67 | 66 int opt, detach, tval; 67 |
68 memset(&srv, 0, sizeof(srv)); |
|
68 memcpy(&srv.bdaddr, NG_HCI_BDADDR_ANY, sizeof(srv.bdaddr)); | 69 memcpy(&srv.bdaddr, NG_HCI_BDADDR_ANY, sizeof(srv.bdaddr)); |
70 srv.windex = -1; |
|
69 detach = 1; 70 tval = 10; /* sec */ 71 | 71 detach = 1; 72 tval = 10; /* sec */ 73 |
72 while ((opt = getopt(argc, argv, "a:c:dH:hp:t:")) != -1) { | 74 while ((opt = getopt(argc, argv, "a:c:dH:hp:s:t:")) != -1) { |
73 switch (opt) { 74 case 'a': /* BDADDR */ 75 if (!bt_aton(optarg, &srv.bdaddr)) { 76 struct hostent *he = NULL; 77 78 if ((he = bt_gethostbyname(optarg)) == NULL) 79 errx(1, "%s: %s", optarg, hstrerror(h_errno)); 80 --- 12 unchanged lines hidden (view full) --- 93 case 'H': /* hids file */ 94 hids_file = optarg; 95 break; 96 97 case 'p': /* pid file */ 98 pid_file = optarg; 99 break; 100 | 75 switch (opt) { 76 case 'a': /* BDADDR */ 77 if (!bt_aton(optarg, &srv.bdaddr)) { 78 struct hostent *he = NULL; 79 80 if ((he = bt_gethostbyname(optarg)) == NULL) 81 errx(1, "%s: %s", optarg, hstrerror(h_errno)); 82 --- 12 unchanged lines hidden (view full) --- 95 case 'H': /* hids file */ 96 hids_file = optarg; 97 break; 98 99 case 'p': /* pid file */ 100 pid_file = optarg; 101 break; 102 |
101 case 't': { /* rescan interval */ 102 char *ep = NULL; | 103 case 's': /* switch script */ 104 srv.script = optarg; 105 break; |
103 | 106 |
104 tval = strtol(optarg, &ep, 10); | 107 case 't': /* rescan interval */ 108 tval = strtol(optarg, (char **) &ep, 10); |
105 if (*ep != '\0' || tval <= 0) 106 usage(); | 109 if (*ep != '\0' || tval <= 0) 110 usage(); |
107 } break; | 111 break; |
108 | 112 |
113 case 'u': /* wired keyboard index */ 114 srv.windex = strtol(optarg, (char **) &ep, 10); 115 if (*ep != '\0' || srv.windex < 0) 116 usage(); 117 break; 118 |
|
109 case 'h': 110 default: 111 usage(); 112 /* NOT REACHED */ 113 } 114 } 115 116 openlog(BTHIDD_IDENT, LOG_PID|LOG_PERROR|LOG_NDELAY, LOG_USER); --- 19 unchanged lines hidden (view full) --- 136 137 sa.sa_handler = SIG_IGN; 138 if (sigaction(SIGPIPE, &sa, NULL) < 0) { 139 syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", 140 strerror(errno), errno); 141 exit(1); 142 } 143 | 119 case 'h': 120 default: 121 usage(); 122 /* NOT REACHED */ 123 } 124 } 125 126 openlog(BTHIDD_IDENT, LOG_PID|LOG_PERROR|LOG_NDELAY, LOG_USER); --- 19 unchanged lines hidden (view full) --- 146 147 sa.sa_handler = SIG_IGN; 148 if (sigaction(SIGPIPE, &sa, NULL) < 0) { 149 syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", 150 strerror(errno), errno); 151 exit(1); 152 } 153 |
154 sa.sa_handler = SIG_IGN; 155 sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT; 156 if (sigaction(SIGCHLD, &sa, NULL) < 0) { 157 syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", 158 strerror(errno), errno); 159 exit(1); 160 } 161 |
|
144 if (read_config_file() < 0 || read_hids_file() < 0 || 145 server_init(&srv) < 0 || write_pid_file(pid_file) < 0) 146 exit(1); 147 148 for (done = 0; !done; ) { 149 if (elapsed(tval)) 150 client_rescan(&srv); 151 --- 92 unchanged lines hidden (view full) --- 244"Usage: %s [options]\n" \ 245"Where options are:\n" \ 246" -a address specify address to listen on (default ANY)\n" \ 247" -c file specify config file name\n" \ 248" -d run in foreground\n" \ 249" -H file specify known HIDs file name\n" \ 250" -h display this message\n" \ 251" -p file specify PID file name\n" \ | 162 if (read_config_file() < 0 || read_hids_file() < 0 || 163 server_init(&srv) < 0 || write_pid_file(pid_file) < 0) 164 exit(1); 165 166 for (done = 0; !done; ) { 167 if (elapsed(tval)) 168 client_rescan(&srv); 169 --- 92 unchanged lines hidden (view full) --- 262"Usage: %s [options]\n" \ 263"Where options are:\n" \ 264" -a address specify address to listen on (default ANY)\n" \ 265" -c file specify config file name\n" \ 266" -d run in foreground\n" \ 267" -H file specify known HIDs file name\n" \ 268" -h display this message\n" \ 269" -p file specify PID file name\n" \ |
252" -t tval client rescan interval (sec)\n" \ | 270" -s script specify keyboard switching script\n" \ 271" -t tval specify client rescan interval (sec)\n" \ 272" -u unit specify wired keyboard unit\n" \ |
253"", BTHIDD_IDENT); 254 exit(255); 255} 256 | 273"", BTHIDD_IDENT); 274 exit(255); 275} 276 |