Deleted Added
full compact
devd.cc (186078) devd.cc (209583)
1/*-
1/*-
2 * Copyright (c) 2002-2003 M. Warner Losh.
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

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

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
24 * SUCH DAMAGE.
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

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

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
24 * SUCH DAMAGE.
25 *
26 * my_system is a variation on lib/libc/stdlib/system.c:
27 *
28 * Copyright (c) 1988, 1993
29 * The Regents of the University of California. All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
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.
42 *
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
53 * SUCH DAMAGE.
25 */
26
27/*
28 * DEVD control daemon.
29 */
30
31// TODO list:
32// o devd.conf and devd man pages need a lot of help:
33// - devd needs to document the unix domain socket
34// - devd.conf needs more details on the supported statements.
35
36#include <sys/cdefs.h>
54 */
55
56/*
57 * DEVD control daemon.
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>
37__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 186078 2008-12-14 11:48:51Z phk $");
66__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 209583 2010-06-29 03:52:12Z imp $");
38
39#include <sys/param.h>
40#include <sys/socket.h>
41#include <sys/stat.h>
42#include <sys/sysctl.h>
43#include <sys/types.h>
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>
44#include <sys/un.h>
45
46#include <ctype.h>
47#include <dirent.h>
48#include <errno.h>
49#include <err.h>
50#include <fcntl.h>
51#include <libutil.h>
74#include <sys/un.h>
75
76#include <ctype.h>
77#include <dirent.h>
78#include <errno.h>
79#include <err.h>
80#include <fcntl.h>
81#include <libutil.h>
82#include <paths.h>
52#include <regex.h>
53#include <signal.h>
54#include <stdlib.h>
55#include <stdio.h>
56#include <string.h>
57#include <unistd.h>
58
59#include <algorithm>

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

147 // nothing
148}
149
150action::~action()
151{
152 // nothing
153}
154
83#include <regex.h>
84#include <signal.h>
85#include <stdlib.h>
86#include <stdio.h>
87#include <string.h>
88#include <unistd.h>
89
90#include <algorithm>

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

178 // nothing
179}
180
181action::~action()
182{
183 // nothing
184}
185
186static int
187my_system(const char *command)
188{
189 pid_t pid, savedpid;
190 int pstat;
191 struct sigaction ign, intact, quitact;
192 sigset_t newsigblock, oldsigblock;
193
194 if (!command) /* just checking... */
195 return(1);
196
197 /*
198 * Ignore SIGINT and SIGQUIT, block SIGCHLD. Remember to save
199 * existing signal dispositions.
200 */
201 ign.sa_handler = SIG_IGN;
202 ::sigemptyset(&ign.sa_mask);
203 ign.sa_flags = 0;
204 ::sigaction(SIGINT, &ign, &intact);
205 ::sigaction(SIGQUIT, &ign, &quitact);
206 ::sigemptyset(&newsigblock);
207 ::sigaddset(&newsigblock, SIGCHLD);
208 ::sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
209 switch (pid = ::fork()) {
210 case -1: /* error */
211 break;
212 case 0: /* child */
213 /*
214 * Restore original signal dispositions and exec the command.
215 */
216 ::sigaction(SIGINT, &intact, NULL);
217 ::sigaction(SIGQUIT, &quitact, NULL);
218 ::sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
219 /*
220 * Close the PID file, and all other open descriptors.
221 * Inherit std{in,out,err} only.
222 */
223 cfg.close_pidfile();
224 ::closefrom(3);
225 ::execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL);
226 ::_exit(127);
227 default: /* parent */
228 savedpid = pid;
229 do {
230 pid = ::wait4(savedpid, &pstat, 0, (struct rusage *)0);
231 } while (pid == -1 && errno == EINTR);
232 break;
233 }
234 ::sigaction(SIGINT, &intact, NULL);
235 ::sigaction(SIGQUIT, &quitact, NULL);
236 ::sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
237 return (pid == -1 ? -1 : pstat);
238}
239
155bool
156action::do_action(config &c)
157{
158 string s = c.expand_string(_cmd);
159 if (Dflag)
160 fprintf(stderr, "Executing '%s'\n", s.c_str());
240bool
241action::do_action(config &c)
242{
243 string s = c.expand_string(_cmd);
244 if (Dflag)
245 fprintf(stderr, "Executing '%s'\n", s.c_str());
161 ::system(s.c_str());
246 my_system(s.c_str());
162 return (true);
163}
164
165match::match(config &c, const char *var, const char *re)
166 : _var(var)
167{
168 string pattern = re;
169 _re = "^";

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

386void
387config::write_pidfile()
388{
389
390 pidfile_write(pfh);
391}
392
393void
247 return (true);
248}
249
250match::match(config &c, const char *var, const char *re)
251 : _var(var)
252{
253 string pattern = re;
254 _re = "^";

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

471void
472config::write_pidfile()
473{
474
475 pidfile_write(pfh);
476}
477
478void
479config::close_pidfile()
480{
481
482 pidfile_close(pfh);
483}
484
485void
394config::remove_pidfile()
395{
396
397 pidfile_remove(pfh);
398}
399
400void
401config::add_attach(int prio, event_proc *p)

--- 564 unchanged lines hidden ---
486config::remove_pidfile()
487{
488
489 pidfile_remove(pfh);
490}
491
492void
493config::add_attach(int prio, event_proc *p)

--- 564 unchanged lines hidden ---