1 /* $NetBSD: bthcid.c,v 1.4 2008/07/21 13:36:57 lukem Exp $ */
4 * Copyright (c) 2006 Itronix Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of Itronix Inc. may not be used to endorse
16 * or promote products derived from this software without specific
17 * prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __COPYRIGHT("@(#) Copyright (c) 2006 Itronix, Inc.\
34 Copyright (c) 2001-2002 Maksim Yevmenkin m_evmenkin@yahoo.com.\
35 All rights reserved.");
36 __RCSID("$NetBSD: bthcid.c,v 1.4 2008/07/21 13:36:57 lukem Exp $");
38 #include <sys/param.h>
40 #include <bluetooth.h>
52 const char *socket_name
= BTHCID_SOCKET_NAME
;
55 static struct event sighup_ev
;
56 static struct event sigint_ev
;
57 static struct event sigterm_ev
;
59 static void process_signal(int, short, void *);
60 static void usage(void);
63 main(int argc
, char *argv
[])
70 mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
;
72 while ((ch
= getopt(argc
, argv
, "d:fm:ns:h")) != -1) {
103 "** ERROR: You should run %s as privileged user!",
107 if (daemon(0, 0) < 0)
108 err(EXIT_FAILURE
, "Could not daemon()ize");
110 openlog(getprogname(), LOG_NDELAY
| LOG_PERROR
| LOG_PID
, LOG_DAEMON
);
114 signal_set(&sigterm_ev
, SIGTERM
, process_signal
, NULL
);
115 if (signal_add(&sigterm_ev
, NULL
) < 0) {
116 syslog(LOG_ERR
, "signal_add(sigterm_ev)");
120 signal_set(&sigint_ev
, SIGINT
, process_signal
, NULL
);
121 if (signal_add(&sigint_ev
, NULL
) < 0) {
122 syslog(LOG_ERR
, "signal_add(sigint_ev)");
126 signal_set(&sighup_ev
, SIGHUP
, process_signal
, NULL
);
127 if (signal_add(&sighup_ev
, NULL
) < 0) {
128 syslog(LOG_ERR
, "signal_add(sighup_ev)");
132 if (init_hci(device
) < 0) {
133 syslog(LOG_ERR
, "init_hci(%s)", device
);
137 if (init_control(socket_name
, mode
) < 0) {
138 syslog(LOG_ERR
, "init_control(%s)", socket_name
);
142 if (detach
&& pidfile(NULL
) < 0) {
143 syslog(LOG_ERR
, "Could not create PID file: %m");
155 process_signal(int s
, short e
, void *arg
)
158 syslog(LOG_DEBUG
, "Exiting on signal %d", s
);
168 /* Display usage and exit */
174 "Usage: %s [-fhn] [-c config] [-d device] [-m mode] [-s path]\n"
176 "\t-c config specify config filename\n"
177 "\t-d device specify device address\n"
178 "\t-f run in foreground\n"
179 "\t-m mode specify socket permissions\n"
180 "\t-n do not listen for clients\n"
181 "\t-s path specify client socket pathname\n"
182 "\t-h display this message\n",