2 * Copyright (c) 2002-2010 M. Warner Losh.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * my_system is a variation on lib/libc/stdlib/system.c:
28 * Copyright (c) 1988, 1993
29 * The Regents of the University of California. All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * DEVD control daemon.
61 // o devd.conf and devd man pages need a lot of help:
62 // - devd needs to document the unix domain socket
63 // - devd.conf needs more details on the supported statements.
65 #include <sys/cdefs.h>
66 __FBSDID("$FreeBSD$");
68 #include <sys/param.h>
69 #include <sys/socket.h>
71 #include <sys/sysctl.h>
72 #include <sys/types.h>
100 #include "devd.h" /* C compatible definitions */
101 #include "devd.hh" /* C++ class definitions */
103 #define STREAMPIPE "/var/run/devd.pipe"
104 #define SEQPACKETPIPE "/var/run/devd.seqpacket.pipe"
105 #define CF "/etc/devd.conf"
106 #define SYSCTL "hw.bus.devctl_queue"
109 * Since the client socket is nonblocking, we must increase its send buffer to
110 * handle brief event storms. On FreeBSD, AF_UNIX sockets don't have a receive
111 * buffer, so the client can't increase the buffersize by itself.
113 * For example, when creating a ZFS pool, devd emits one 165 character
114 * resource.fs.zfs.statechange message for each vdev in the pool. The kernel
115 * allocates a 4608B mbuf for each message. Modern technology places a limit of
116 * roughly 450 drives/rack, and it's unlikely that a zpool will ever be larger
119 * 450 drives * 165 bytes / drive = 74250B of data in the sockbuf
120 * 450 drives * 4608B / drive = 2073600B of mbufs in the sockbuf
122 * We can't directly set the sockbuf's mbuf limit, but we can do it indirectly.
123 * The kernel sets it to the minimum of a hard-coded maximum value and sbcc *
124 * kern.ipc.sockbuf_waste_factor, where sbcc is the socket buffer size set by
125 * the user. The default value of kern.ipc.sockbuf_waste_factor is 8. If we
126 * set the bufsize to 256k and use the kern.ipc.sockbuf_waste_factor, then the
127 * kernel will set the mbuf limit to 2MB, which is just large enough for 450
128 * drives. It also happens to be the same as the hardcoded maximum value.
130 #define CLIENT_BUFSIZE 262144
134 typedef struct client {
142 static const char notify = '!';
143 static const char nomatch = '?';
144 static const char attach = '+';
145 static const char detach = '-';
147 static struct pidfh *pfh;
149 static int no_daemon = 0;
150 static int daemonize_quick = 0;
151 static int quiet_mode = 0;
152 static unsigned total_events = 0;
153 static volatile sig_atomic_t got_siginfo = 0;
154 static volatile sig_atomic_t romeo_must_die = 0;
156 static const char *configfile = CF;
158 static void devdlog(int priority, const char* message, ...)
160 static void event_loop(void);
161 static void usage(void);
163 template <class T> void
164 delete_and_clear(vector<T *> &v)
166 typename vector<T *>::const_iterator i;
168 for (i = v.begin(); i != v.end(); ++i)
175 event_proc::event_proc() : _prio(-1)
180 event_proc::~event_proc()
182 delete_and_clear(_epsvec);
186 event_proc::add(eps *eps)
188 _epsvec.push_back(eps);
192 event_proc::matches(config &c) const
194 vector<eps *>::const_iterator i;
196 for (i = _epsvec.begin(); i != _epsvec.end(); ++i)
197 if (!(*i)->do_match(c))
203 event_proc::run(config &c) const
205 vector<eps *>::const_iterator i;
207 for (i = _epsvec.begin(); i != _epsvec.end(); ++i)
208 if (!(*i)->do_action(c))
213 action::action(const char *cmd)
225 my_system(const char *command)
229 struct sigaction ign, intact, quitact;
230 sigset_t newsigblock, oldsigblock;
232 if (!command) /* just checking... */
236 * Ignore SIGINT and SIGQUIT, block SIGCHLD. Remember to save
237 * existing signal dispositions.
239 ign.sa_handler = SIG_IGN;
240 ::sigemptyset(&ign.sa_mask);
242 ::sigaction(SIGINT, &ign, &intact);
243 ::sigaction(SIGQUIT, &ign, &quitact);
244 ::sigemptyset(&newsigblock);
245 ::sigaddset(&newsigblock, SIGCHLD);
246 ::sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
247 switch (pid = ::fork()) {
252 * Restore original signal dispositions and exec the command.
254 ::sigaction(SIGINT, &intact, NULL);
255 ::sigaction(SIGQUIT, &quitact, NULL);
256 ::sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
258 * Close the PID file, and all other open descriptors.
259 * Inherit std{in,out,err} only.
263 ::execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL);
265 default: /* parent */
268 pid = ::wait4(savedpid, &pstat, 0, (struct rusage *)0);
269 } while (pid == -1 && errno == EINTR);
272 ::sigaction(SIGINT, &intact, NULL);
273 ::sigaction(SIGQUIT, &quitact, NULL);
274 ::sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
275 return (pid == -1 ? -1 : pstat);
279 action::do_action(config &c)
281 string s = c.expand_string(_cmd.c_str());
282 devdlog(LOG_NOTICE, "Executing '%s'\n", s.c_str());
283 my_system(s.c_str());
287 match::match(config &c, const char *var, const char *re) :
290 _re(c.expand_string(_inv ? re + 1 : re, "^", "$"))
292 regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE);
301 match::do_match(config &c)
303 const string &value = c.get_variable(_var);
307 * This function gets called WAY too often to justify calling syslog()
308 * each time, even at LOG_DEBUG. Because if syslogd isn't running, it
309 * can consume excessive amounts of systime inside of connect(). Only
310 * log when we're in -d mode.
313 devdlog(LOG_DEBUG, "Testing %s=%s against %s, invert=%d\n",
314 _var.c_str(), value.c_str(), _re.c_str(), _inv);
317 retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0);
319 retval = (retval == 0) ? 1 : 0;
324 #include <sys/sockio.h>
326 #include <net/if_media.h>
328 media::media(config &, const char *var, const char *type)
329 : _var(var), _type(-1)
331 static struct ifmedia_description media_types[] = {
332 { IFM_ETHER, "Ethernet" },
333 { IFM_TOKEN, "Tokenring" },
334 { IFM_FDDI, "FDDI" },
335 { IFM_IEEE80211, "802.11" },
340 for (int i = 0; media_types[i].ifmt_string != NULL; ++i)
341 if (strcasecmp(type, media_types[i].ifmt_string) == 0) {
342 _type = media_types[i].ifmt_word;
352 media::do_match(config &c)
355 struct ifmediareq ifmr;
359 // Since we can be called from both a device attach/detach
360 // context where device-name is defined and what we want,
361 // as well as from a link status context, where subsystem is
362 // the name of interest, first try device-name and fall back
363 // to subsystem if none exists.
364 value = c.get_variable("device-name");
366 value = c.get_variable("subsystem");
367 devdlog(LOG_DEBUG, "Testing media type of %s against 0x%x\n",
368 value.c_str(), _type);
372 s = socket(PF_INET, SOCK_DGRAM, 0);
374 memset(&ifmr, 0, sizeof(ifmr));
375 strncpy(ifmr.ifm_name, value.c_str(), sizeof(ifmr.ifm_name));
377 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0 &&
378 ifmr.ifm_status & IFM_AVALID) {
379 devdlog(LOG_DEBUG, "%s has media type 0x%x\n",
380 value.c_str(), IFM_TYPE(ifmr.ifm_active));
381 retval = (IFM_TYPE(ifmr.ifm_active) == _type);
382 } else if (_type == -1) {
383 devdlog(LOG_DEBUG, "%s has unknown media type\n",
393 const string var_list::bogus = "_$_$_$_$_B_O_G_U_S_$_$_$_$_";
394 const string var_list::nothing = "";
397 var_list::get_variable(const string &var) const
399 map<string, string>::const_iterator i;
402 if (i == _vars.end())
403 return (var_list::bogus);
408 var_list::is_set(const string &var) const
410 return (_vars.find(var) != _vars.end());
414 var_list::set_variable(const string &var, const string &val)
417 * This function gets called WAY too often to justify calling syslog()
418 * each time, even at LOG_DEBUG. Because if syslogd isn't running, it
419 * can consume excessive amounts of systime inside of connect(). Only
420 * log when we're in -d mode.
423 devdlog(LOG_DEBUG, "setting %s=%s\n", var.c_str(), val.c_str());
431 delete_and_clear(_var_list_table);
432 delete_and_clear(_attach_list);
433 delete_and_clear(_detach_list);
434 delete_and_clear(_nomatch_list);
435 delete_and_clear(_notify_list);
439 config::parse_one_file(const char *fn)
441 devdlog(LOG_DEBUG, "Parsing %s\n", fn);
442 yyin = fopen(fn, "r");
444 err(1, "Cannot open config file %s", fn);
447 errx(1, "Cannot parse %s at line %d", fn, lineno);
452 config::parse_files_in_dir(const char *dirname)
458 devdlog(LOG_DEBUG, "Parsing files in %s\n", dirname);
459 dirp = opendir(dirname);
462 readdir(dirp); /* Skip . */
463 readdir(dirp); /* Skip .. */
464 while ((dp = readdir(dirp)) != NULL) {
465 if (strcmp(dp->d_name + dp->d_namlen - 5, ".conf") == 0) {
466 snprintf(path, sizeof(path), "%s/%s",
467 dirname, dp->d_name);
468 parse_one_file(path);
476 int operator()(event_proc *const&l1, event_proc *const&l2) const
478 return (l1->get_priority() > l2->get_priority());
483 config::sort_vector(vector<event_proc *> &v)
485 stable_sort(v.begin(), v.end(), epv_greater());
491 vector<string>::const_iterator i;
493 parse_one_file(configfile);
494 for (i = _dir_list.begin(); i != _dir_list.end(); ++i)
495 parse_files_in_dir((*i).c_str());
496 sort_vector(_attach_list);
497 sort_vector(_detach_list);
498 sort_vector(_nomatch_list);
499 sort_vector(_notify_list);
503 config::open_pidfile()
507 if (_pidfile.empty())
509 pfh = pidfile_open(_pidfile.c_str(), 0600, &otherpid);
512 errx(1, "devd already running, pid: %d", (int)otherpid);
513 warn("cannot open pid file");
518 config::write_pidfile()
525 config::close_pidfile()
532 config::remove_pidfile()
539 config::add_attach(int prio, event_proc *p)
541 p->set_priority(prio);
542 _attach_list.push_back(p);
546 config::add_detach(int prio, event_proc *p)
548 p->set_priority(prio);
549 _detach_list.push_back(p);
553 config::add_directory(const char *dir)
555 _dir_list.push_back(string(dir));
559 config::add_nomatch(int prio, event_proc *p)
561 p->set_priority(prio);
562 _nomatch_list.push_back(p);
566 config::add_notify(int prio, event_proc *p)
568 p->set_priority(prio);
569 _notify_list.push_back(p);
573 config::set_pidfile(const char *fn)
579 config::push_var_table()
584 _var_list_table.push_back(vl);
585 devdlog(LOG_DEBUG, "Pushing table\n");
589 config::pop_var_table()
591 delete _var_list_table.back();
592 _var_list_table.pop_back();
593 devdlog(LOG_DEBUG, "Popping table\n");
597 config::set_variable(const char *var, const char *val)
599 _var_list_table.back()->set_variable(var, val);
603 config::get_variable(const string &var)
605 vector<var_list *>::reverse_iterator i;
607 for (i = _var_list_table.rbegin(); i != _var_list_table.rend(); ++i) {
608 if ((*i)->is_set(var))
609 return ((*i)->get_variable(var));
611 return (var_list::nothing);
615 config::is_id_char(char ch) const
617 return (ch != '\0' && (isalpha(ch) || isdigit(ch) || ch == '_' ||
622 config::expand_one(const char *&src, string &dst)
635 // Not sure if I want to support this or not, so for now we just pass
640 /* If the string ends before ) is matched , return. */
641 while (count > 0 && *src) {
644 else if (*src == '(')
652 if (!isalpha(*src)) {
658 // $var -> replace with value
661 } while (is_id_char(*src));
662 dst.append(get_variable(buffer));
666 config::expand_string(const char *src, const char *prepend, const char *append)
672 * 128 bytes is enough for 2427 of 2438 expansions that happen
673 * while parsing config files, as tested on 2013-01-30.
681 var_at = strchr(src, '$');
682 if (var_at == NULL) {
686 dst.append(src, var_at - src);
688 expand_one(src, dst);
698 config::chop_var(char *&buffer, char *&lhs, char *&rhs) const
704 walker = lhs = buffer;
705 while (is_id_char(*walker))
710 if (*walker == '"') {
713 while (*walker && *walker != '"')
721 while (*walker && !isspace(*walker))
727 while (isspace(*walker))
735 config::set_vars(char *buffer)
741 if (!chop_var(buffer, lhs, rhs))
743 set_variable(lhs, rhs);
749 config::find_and_execute(char type)
751 vector<event_proc *> *l;
752 vector<event_proc *>::const_iterator i;
775 devdlog(LOG_DEBUG, "Processing %s event\n", s);
776 for (i = l->begin(); i != l->end(); ++i) {
777 if ((*i)->matches(*this)) {
787 process_event(char *buffer)
793 devdlog(LOG_INFO, "Processing event '%s'\n", buffer);
795 cfg.push_var_table();
796 // No match doesn't have a device, and the format is a little
797 // different, so handle it separately.
800 sp = cfg.set_vars(sp);
803 //? at location pnp-info on bus
804 sp = strchr(sp, ' ');
806 return; /* Can't happen? */
810 if (strncmp(sp, "at ", 3) == 0)
812 sp = cfg.set_vars(sp);
815 if (strncmp(sp, "on ", 3) == 0)
816 cfg.set_variable("bus", sp + 3);
818 case attach: /*FALLTHROUGH*/
820 sp = strchr(sp, ' ');
822 return; /* Can't happen? */
824 cfg.set_variable("device-name", buffer);
827 if (strncmp(sp, "at ", 3) == 0)
829 sp = cfg.set_vars(sp);
832 if (strncmp(sp, "on ", 3) == 0)
833 cfg.set_variable("bus", sp + 3);
837 cfg.find_and_execute(type);
842 create_socket(const char *name, int socktype)
845 struct sockaddr_un sun;
847 if ((fd = socket(PF_LOCAL, socktype, 0)) < 0)
849 bzero(&sun, sizeof(sun));
850 sun.sun_family = AF_UNIX;
851 strlcpy(sun.sun_path, name, sizeof(sun.sun_path));
852 slen = SUN_LEN(&sun);
854 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
856 if (::bind(fd, (struct sockaddr *) & sun, slen) < 0)
859 chown(name, 0, 0); /* XXX - root.wheel */
864 unsigned int max_clients = 10; /* Default, can be overridden on cmdline. */
865 unsigned int num_clients;
867 list<client_t> clients;
870 notify_clients(const char *data, int len)
872 list<client_t>::iterator i;
875 * Deliver the data to all clients. Throw clients overboard at the
876 * first sign of trouble. This reaps clients who've died or closed
877 * their sockets, and also clients who are alive but failing to keep up
878 * (or who are maliciously not reading, to consume buffer space in
879 * kernel memory or tie up the limited number of available connections).
881 for (i = clients.begin(); i != clients.end(); ) {
883 if (i->socktype == SOCK_SEQPACKET)
888 if (send(i->fd, data, len, flags) != len) {
891 i = clients.erase(i);
892 devdlog(LOG_WARNING, "notify_clients: send() failed; "
893 "dropping unresponsive client\n");
904 list<client_t>::iterator i;
907 * Check all existing clients to see if any of them have disappeared.
908 * Normally we reap clients when we get an error trying to send them an
909 * event. This check eliminates the problem of an ever-growing list of
910 * zombie clients because we're never writing to them on a system
911 * without frequent device-change activity.
914 for (i = clients.begin(); i != clients.end(); ) {
916 s = poll(&pfd, 1, 0);
917 if ((s < 0 && s != EINTR ) ||
918 (s > 0 && (pfd.revents & POLLHUP))) {
921 i = clients.erase(i);
922 devdlog(LOG_NOTICE, "check_clients: "
923 "dropping disconnected client\n");
930 new_client(int fd, int socktype)
936 * First go reap any zombie clients, then accept the connection, and
937 * shut down the read side to stop clients from consuming kernel memory
938 * by sending large buffers full of data we'll never read.
941 s.socktype = socktype;
942 s.fd = accept(fd, NULL, NULL);
944 sndbuf_size = CLIENT_BUFSIZE;
945 if (setsockopt(s.fd, SOL_SOCKET, SO_SNDBUF, &sndbuf_size,
946 sizeof(sndbuf_size)))
947 err(1, "setsockopt");
948 shutdown(s.fd, SHUT_RD);
949 clients.push_back(s);
960 char buffer[DEVCTL_MAXBUF];
962 int stream_fd, seqpacket_fd, max_fd;
967 fd = open(PATH_DEVCTL, O_RDONLY | O_CLOEXEC);
969 err(1, "Can't open devctl device %s", PATH_DEVCTL);
970 stream_fd = create_socket(STREAMPIPE, SOCK_STREAM);
971 seqpacket_fd = create_socket(SEQPACKETPIPE, SOCK_SEQPACKET);
973 max_fd = max(fd, max(stream_fd, seqpacket_fd)) + 1;
974 while (!romeo_must_die) {
975 if (!once && !no_daemon && !daemonize_quick) {
976 // Check to see if we have any events pending.
981 rv = select(fd + 1, &fds, &fds, &fds, &tv);
982 // No events -> we've processed all pending events
984 devdlog(LOG_DEBUG, "Calling daemon\n");
985 cfg.remove_pidfile();
993 * When we've already got the max number of clients, stop
994 * accepting new connections (don't put the listening sockets in
995 * the set), shrink the accept() queue to reject connections
996 * quickly, and poll the existing clients more often, so that we
997 * notice more quickly when any of them disappear to free up
1002 if (num_clients < max_clients) {
1004 listen(stream_fd, max_clients);
1005 listen(seqpacket_fd, max_clients);
1008 FD_SET(stream_fd, &fds);
1009 FD_SET(seqpacket_fd, &fds);
1014 listen(stream_fd, 0);
1015 listen(seqpacket_fd, 0);
1021 rv = select(max_fd, &fds, NULL, NULL, &tv);
1023 devdlog(LOG_NOTICE, "Events received so far=%u\n",
1033 if (FD_ISSET(fd, &fds)) {
1034 rv = read(fd, buffer, sizeof(buffer) - 1);
1037 if (rv == sizeof(buffer) - 1) {
1038 devdlog(LOG_WARNING, "Warning: "
1039 "available event data exceeded "
1042 notify_clients(buffer, rv);
1044 while (buffer[--rv] == '\n')
1046 process_event(buffer);
1047 } else if (rv < 0) {
1055 if (FD_ISSET(stream_fd, &fds))
1056 new_client(stream_fd, SOCK_STREAM);
1058 * Aside from the socket type, both sockets use the same
1059 * protocol, so we can process clients the same way.
1061 if (FD_ISSET(seqpacket_fd, &fds))
1062 new_client(seqpacket_fd, SOCK_SEQPACKET);
1068 * functions that the parser uses.
1071 add_attach(int prio, event_proc *p)
1073 cfg.add_attach(prio, p);
1077 add_detach(int prio, event_proc *p)
1079 cfg.add_detach(prio, p);
1083 add_directory(const char *dir)
1085 cfg.add_directory(dir);
1086 free(const_cast<char *>(dir));
1090 add_nomatch(int prio, event_proc *p)
1092 cfg.add_nomatch(prio, p);
1096 add_notify(int prio, event_proc *p)
1098 cfg.add_notify(prio, p);
1102 add_to_event_proc(event_proc *ep, eps *eps)
1105 ep = new event_proc();
1111 new_action(const char *cmd)
1113 eps *e = new action(cmd);
1114 free(const_cast<char *>(cmd));
1119 new_match(const char *var, const char *re)
1121 eps *e = new match(cfg, var, re);
1122 free(const_cast<char *>(var));
1123 free(const_cast<char *>(re));
1128 new_media(const char *var, const char *re)
1130 eps *e = new media(cfg, var, re);
1131 free(const_cast<char *>(var));
1132 free(const_cast<char *>(re));
1137 set_pidfile(const char *name)
1139 cfg.set_pidfile(name);
1140 free(const_cast<char *>(name));
1144 set_variable(const char *var, const char *val)
1146 cfg.set_variable(var, val);
1147 free(const_cast<char *>(var));
1148 free(const_cast<char *>(val));
1160 * SIGINFO handler. Will print useful statistics to the syslog or stderr
1170 * Local logging function. Prints to syslog if we're daemonized; syslog
1174 devdlog(int priority, const char* fmt, ...)
1178 va_start(argp, fmt);
1180 vfprintf(stderr, fmt, argp);
1181 else if ((! quiet_mode) || (priority <= LOG_WARNING))
1182 vsyslog(priority, fmt, argp);
1189 fprintf(stderr, "usage: %s [-dnq] [-l connlimit] [-f file]\n",
1195 check_devd_enabled()
1201 if (sysctlbyname(SYSCTL, &val, &len, NULL, 0) != 0)
1202 errx(1, "devctl sysctl missing from kernel!");
1204 warnx("Setting " SYSCTL " to 1000");
1206 sysctlbyname(SYSCTL, NULL, NULL, &val, sizeof(val));
1214 main(int argc, char **argv)
1218 check_devd_enabled();
1219 while ((ch = getopt(argc, argv, "df:l:nq")) != -1) {
1225 configfile = optarg;
1228 max_clients = MAX(1, strtoul(optarg, NULL, 0));
1231 daemonize_quick = 1;
1242 if (!no_daemon && daemonize_quick) {
1245 cfg.write_pidfile();
1247 signal(SIGPIPE, SIG_IGN);
1248 signal(SIGHUP, gensighand);
1249 signal(SIGINT, gensighand);
1250 signal(SIGTERM, gensighand);
1251 signal(SIGINFO, siginfohand);