Deleted Added
full compact
devd.cc (259362) devd.cc (262914)
1/*-
2 * Copyright (c) 2002-2010 M. Warner Losh.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 49 unchanged lines hidden (view full) ---

58 */
59
60// TODO list:
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.
64
65#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002-2010 M. Warner Losh.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 49 unchanged lines hidden (view full) ---

58 */
59
60// TODO list:
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.
64
65#include <sys/cdefs.h>
66__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 259362 2013-12-13 22:58:57Z asomers $");
66__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 262914 2014-03-07 23:30:48Z asomers $");
67
68#include <sys/param.h>
69#include <sys/socket.h>
70#include <sys/stat.h>
71#include <sys/sysctl.h>
72#include <sys/types.h>
73#include <sys/wait.h>
74#include <sys/un.h>

--- 49 unchanged lines hidden (view full) ---

124
125static const char notify = '!';
126static const char nomatch = '?';
127static const char attach = '+';
128static const char detach = '-';
129
130static struct pidfh *pfh;
131
67
68#include <sys/param.h>
69#include <sys/socket.h>
70#include <sys/stat.h>
71#include <sys/sysctl.h>
72#include <sys/types.h>
73#include <sys/wait.h>
74#include <sys/un.h>

--- 49 unchanged lines hidden (view full) ---

124
125static const char notify = '!';
126static const char nomatch = '?';
127static const char attach = '+';
128static const char detach = '-';
129
130static struct pidfh *pfh;
131
132int dflag;
133int nflag;
132static int no_daemon = 0;
133static int daemonize_quick = 0;
134static int quiet_mode = 0;
134static unsigned total_events = 0;
135static volatile sig_atomic_t got_siginfo = 0;
136static volatile sig_atomic_t romeo_must_die = 0;
137
138static const char *configfile = CF;
139
140static void devdlog(int priority, const char* message, ...)
141 __printflike(2, 3);

--- 144 unchanged lines hidden (view full) ---

286 bool retval;
287
288 /*
289 * This function gets called WAY too often to justify calling syslog()
290 * each time, even at LOG_DEBUG. Because if syslogd isn't running, it
291 * can consume excessive amounts of systime inside of connect(). Only
292 * log when we're in -d mode.
293 */
135static unsigned total_events = 0;
136static volatile sig_atomic_t got_siginfo = 0;
137static volatile sig_atomic_t romeo_must_die = 0;
138
139static const char *configfile = CF;
140
141static void devdlog(int priority, const char* message, ...)
142 __printflike(2, 3);

--- 144 unchanged lines hidden (view full) ---

287 bool retval;
288
289 /*
290 * This function gets called WAY too often to justify calling syslog()
291 * each time, even at LOG_DEBUG. Because if syslogd isn't running, it
292 * can consume excessive amounts of systime inside of connect(). Only
293 * log when we're in -d mode.
294 */
294 if (dflag) {
295 if (no_daemon) {
295 devdlog(LOG_DEBUG, "Testing %s=%s against %s, invert=%d\n",
296 _var.c_str(), value.c_str(), _re.c_str(), _inv);
297 }
298
299 retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0);
300 if (_inv == 1)
301 retval = (retval == 0) ? 1 : 0;
302

--- 93 unchanged lines hidden (view full) ---

396var_list::set_variable(const string &var, const string &val)
397{
398 /*
399 * This function gets called WAY too often to justify calling syslog()
400 * each time, even at LOG_DEBUG. Because if syslogd isn't running, it
401 * can consume excessive amounts of systime inside of connect(). Only
402 * log when we're in -d mode.
403 */
296 devdlog(LOG_DEBUG, "Testing %s=%s against %s, invert=%d\n",
297 _var.c_str(), value.c_str(), _re.c_str(), _inv);
298 }
299
300 retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0);
301 if (_inv == 1)
302 retval = (retval == 0) ? 1 : 0;
303

--- 93 unchanged lines hidden (view full) ---

397var_list::set_variable(const string &var, const string &val)
398{
399 /*
400 * This function gets called WAY too often to justify calling syslog()
401 * each time, even at LOG_DEBUG. Because if syslogd isn't running, it
402 * can consume excessive amounts of systime inside of connect(). Only
403 * log when we're in -d mode.
404 */
404 if (dflag)
405 if (no_daemon)
405 devdlog(LOG_DEBUG, "setting %s=%s\n", var.c_str(), val.c_str());
406 _vars[var] = val;
407}
408
409void
410config::reset(void)
411{
412 _dir_list.clear();

--- 527 unchanged lines hidden (view full) ---

940
941 fd = open(PATH_DEVCTL, O_RDONLY | O_CLOEXEC);
942 if (fd == -1)
943 err(1, "Can't open devctl device %s", PATH_DEVCTL);
944 server_fd = create_socket(PIPE);
945 accepting = 1;
946 max_fd = max(fd, server_fd) + 1;
947 while (!romeo_must_die) {
406 devdlog(LOG_DEBUG, "setting %s=%s\n", var.c_str(), val.c_str());
407 _vars[var] = val;
408}
409
410void
411config::reset(void)
412{
413 _dir_list.clear();

--- 527 unchanged lines hidden (view full) ---

941
942 fd = open(PATH_DEVCTL, O_RDONLY | O_CLOEXEC);
943 if (fd == -1)
944 err(1, "Can't open devctl device %s", PATH_DEVCTL);
945 server_fd = create_socket(PIPE);
946 accepting = 1;
947 max_fd = max(fd, server_fd) + 1;
948 while (!romeo_must_die) {
948 if (!once && !dflag && !nflag) {
949 if (!once && !no_daemon && !daemonize_quick) {
949 // Check to see if we have any events pending.
950 tv.tv_sec = 0;
951 tv.tv_usec = 0;
952 FD_ZERO(&fds);
953 FD_SET(fd, &fds);
954 rv = select(fd + 1, &fds, &fds, &fds, &tv);
955 // No events -> we've processed all pending events
956 if (rv == 0) {

--- 177 unchanged lines hidden (view full) ---

1134 * otherwise.
1135 */
1136static void
1137devdlog(int priority, const char* fmt, ...)
1138{
1139 va_list argp;
1140
1141 va_start(argp, fmt);
950 // Check to see if we have any events pending.
951 tv.tv_sec = 0;
952 tv.tv_usec = 0;
953 FD_ZERO(&fds);
954 FD_SET(fd, &fds);
955 rv = select(fd + 1, &fds, &fds, &fds, &tv);
956 // No events -> we've processed all pending events
957 if (rv == 0) {

--- 177 unchanged lines hidden (view full) ---

1135 * otherwise.
1136 */
1137static void
1138devdlog(int priority, const char* fmt, ...)
1139{
1140 va_list argp;
1141
1142 va_start(argp, fmt);
1142 if (dflag)
1143 if (no_daemon)
1143 vfprintf(stderr, fmt, argp);
1144 vfprintf(stderr, fmt, argp);
1144 else
1145 else if ((! quiet_mode) || (priority <= LOG_WARNING))
1145 vsyslog(priority, fmt, argp);
1146 va_end(argp);
1147}
1148
1149static void
1150usage()
1151{
1146 vsyslog(priority, fmt, argp);
1147 va_end(argp);
1148}
1149
1150static void
1151usage()
1152{
1152 fprintf(stderr, "usage: %s [-dn] [-l connlimit] [-f file]\n",
1153 fprintf(stderr, "usage: %s [-dnq] [-l connlimit] [-f file]\n",
1153 getprogname());
1154 exit(1);
1155}
1156
1157static void
1158check_devd_enabled()
1159{
1160 int val = 0;

--- 13 unchanged lines hidden (view full) ---

1174 * main
1175 */
1176int
1177main(int argc, char **argv)
1178{
1179 int ch;
1180
1181 check_devd_enabled();
1154 getprogname());
1155 exit(1);
1156}
1157
1158static void
1159check_devd_enabled()
1160{
1161 int val = 0;

--- 13 unchanged lines hidden (view full) ---

1175 * main
1176 */
1177int
1178main(int argc, char **argv)
1179{
1180 int ch;
1181
1182 check_devd_enabled();
1182 while ((ch = getopt(argc, argv, "df:l:n")) != -1) {
1183 while ((ch = getopt(argc, argv, "df:l:nq")) != -1) {
1183 switch (ch) {
1184 case 'd':
1184 switch (ch) {
1185 case 'd':
1185 dflag++;
1186 no_daemon = 1;
1186 break;
1187 case 'f':
1188 configfile = optarg;
1189 break;
1190 case 'l':
1191 max_clients = MAX(1, strtoul(optarg, NULL, 0));
1192 break;
1193 case 'n':
1187 break;
1188 case 'f':
1189 configfile = optarg;
1190 break;
1191 case 'l':
1192 max_clients = MAX(1, strtoul(optarg, NULL, 0));
1193 break;
1194 case 'n':
1194 nflag++;
1195 daemonize_quick = 1;
1195 break;
1196 break;
1197 case 'q':
1198 quiet_mode = 1;
1199 break;
1196 default:
1197 usage();
1198 }
1199 }
1200
1201 cfg.parse();
1200 default:
1201 usage();
1202 }
1203 }
1204
1205 cfg.parse();
1202 if (!dflag && nflag) {
1206 if (!no_daemon && daemonize_quick) {
1203 cfg.open_pidfile();
1204 daemon(0, 0);
1205 cfg.write_pidfile();
1206 }
1207 signal(SIGPIPE, SIG_IGN);
1208 signal(SIGHUP, gensighand);
1209 signal(SIGINT, gensighand);
1210 signal(SIGTERM, gensighand);
1211 signal(SIGINFO, siginfohand);
1212 event_loop();
1213 return (0);
1214}
1207 cfg.open_pidfile();
1208 daemon(0, 0);
1209 cfg.write_pidfile();
1210 }
1211 signal(SIGPIPE, SIG_IGN);
1212 signal(SIGHUP, gensighand);
1213 signal(SIGINT, gensighand);
1214 signal(SIGTERM, gensighand);
1215 signal(SIGINFO, siginfohand);
1216 event_loop();
1217 return (0);
1218}