Compare commits

..

209 Commits

Author SHA1 Message Date
Roy Marples
84f6bf4bff Release 0.3 2008-10-02 16:14:13 +00:00
Roy Marples
5f76c1121a Clean stale sockets. 2008-10-01 21:12:54 +00:00
Roy Marples
41c1e170d6 Add an env var so plugins know when leaving single means the end, or start the default level. 2008-10-01 08:46:53 +00:00
Roy Marples
f53197818b Correcly call the right runlevel for plugins when shutting down. 2008-10-01 06:10:34 +00:00
Roy Marples
bb41d2cc80 Use flock to lock PREFIX_LOCK so that multiple processes can cleanly write to the same tty. 2008-09-27 18:50:21 +00:00
Roy Marples
4291b9140e Warn when waiting for a service every few seconds. 2008-09-27 17:17:15 +00:00
Roy Marples
28d7fb9430 When stopping services, check the newlevel if given otherwise the current runlevel. Fixes #100. 2008-09-27 16:56:03 +00:00
Roy Marples
abe94bec6f Load rtc-cmos if needed, Gentoo #235647 thanks to Robin Johnson. 2008-09-27 06:48:21 +00:00
Roy Marples
c3e192a834 Stop ssd from waiting by default - most daemons are good now. 2008-09-26 23:58:57 +00:00
Roy Marples
13d88731b7 We don't check exec when starting, so don't when testing for crashed. 2008-09-22 20:07:14 +00:00
Roy Marples
ffc79a50c2 Style 2008-09-22 19:49:16 +00:00
Roy Marples
6748c0e04e Allow forcefsck instead of gentoo=forcefsck on the kernel command line. 2008-09-22 12:32:35 +00:00
Roy Marples
27805de20a Allow forcefsck on the kernel command line, Gentoo #218431 2008-09-22 12:32:11 +00:00
Roy Marples
53693367df Our match arguments could be different from the exec arguments, as only the kernel should set script arguments. 2008-09-22 12:14:47 +00:00
Roy Marples
554d2fea19 Allow interpreted daemons to detect interperter options. 2008-09-22 10:45:01 +00:00
Roy Marples
a63303971a Document the --verbose option. 2008-09-22 09:37:28 +00:00
Roy Marples
5610c8560c s-s-d now handles interpreted daemons more easily. 2008-09-22 09:34:51 +00:00
Roy Marples
2c62d095c8 Typo. 2008-09-21 09:53:48 +00:00
Roy Marples
a72dc1194a Style. 2008-09-19 11:34:35 +00:00
Roy Marples
dcc4aa131c Document the limitation of symlinking services outside of the service directory, Gentoo #237263. 2008-09-19 11:32:24 +00:00
Roy Marples
6b3d8cf598 Fix stopping wpa_supplicant incorrectly, #107 2008-09-19 11:24:21 +00:00
Roy Marples
600d1f62fb Allow configuration of bond via extra sysfs entries, #105. 2008-09-19 09:32:24 +00:00
Roy Marples
2de401bca1 Enable bonding via sysfs, #104 thanks to Wolfram Schlich 2008-09-18 22:24:58 +00:00
Roy Marples
e368a4b4f8 Add missing profile bits to env, #72. 2008-09-18 19:46:10 +00:00
Roy Marples
354fb96ee9 Use the new rc_stringlist_find function. 2008-09-18 15:36:22 +00:00
Roy Marples
312d6f3e57 Work with NULL lists. 2008-09-18 15:32:57 +00:00
Roy Marples
39ea0cb84d Use the new rc_stringlist_find function. 2008-09-18 15:28:20 +00:00
Roy Marples
17bf78a539 Use the new rc_stringlist_find function. 2008-09-18 15:20:57 +00:00
Roy Marples
072328ff60 rc_nostop now lists services we should not stop on shutdown. 2008-09-18 15:13:53 +00:00
Roy Marples
e0dfa472d1 Add new functions, rc_stringlist_find and rc_stringlist_split. 2008-09-18 15:12:43 +00:00
Roy Marples
ccc24d1086 Add a config file for ipfw, #110 2008-09-18 14:25:23 +00:00
Roy Marples
c4c024fc9d Allow an empty bridge with no options, Gentoo #237485. 2008-09-18 14:13:33 +00:00
Roy Marples
223015920c Warn about parallel still locking the system. 2008-09-18 13:59:05 +00:00
Roy Marples
aa02a5516a Use better CFLAGS - some new warnings will need to be fixed. 2008-09-18 13:49:58 +00:00
Roy Marples
80a17eb596 Clean up some compile warnings. 2008-09-18 13:09:51 +00:00
Roy Marples
39304745d4 Allow interpreted daemons to use s-s-d a little easier. 2008-09-17 16:56:23 +00:00
Roy Marples
93a3b2dd02 Fix iwconfig parsing on Linux, #111 thanks to Andrew Gaffney. 2008-09-04 14:54:56 +00:00
Roy Marples
00d010fbe0 Work without IP6 kernels, #108 2008-08-29 06:43:54 +00:00
Roy Marples
01de348ede Add rpc.lockd to netmount.in for BSD 2008-08-27 16:06:01 +00:00
Roy Marples
fabee4dc2d Actually set the umask. 2008-08-20 10:19:03 +00:00
Roy Marples
1ab1e9328a Add -k,--umask option, Gentoo #232455. 2008-08-20 10:02:11 +00:00
Roy Marples
a9f7d2d5e5 Allow dhcpcd to use global dhcpcd variable for commandline options. 2008-08-19 22:30:59 +00:00
Roy Marples
a3c8706618 Allow OpenVZ to mount /sys and device managers, #102 2008-08-19 15:27:15 +00:00
Roy Marples
1f227d62bf Allow renaming of modules, #103 thanks to Sven. 2008-08-19 15:25:06 +00:00
Roy Marples
cdace75539 OpenVZ can mount NFS shares. 2008-08-19 06:44:47 +00:00
Roy Marples
15678263d5 Add new OpenVZ detection code 2008-08-19 06:36:43 +00:00
Roy Marples
cea206014d Attempt to make s-s-d simpler by not enforcing the need for a full path and maybe working better with interpreted scripts. 2008-07-27 11:30:49 +00:00
Roy Marples
46a74f244e Typo 2008-07-24 19:02:28 +00:00
Roy Marples
c67233f15c Don't set silly defaults that may brake users. 2008-07-09 18:28:45 +00:00
Roy Marples
b15c4758f8 We should unmount / here. 2008-07-09 18:28:14 +00:00
Roy Marples
289889ebf0 Fix unmounting some more. 2008-07-09 17:05:10 +00:00
Roy Marples
7183cb1b18 Fix last commit 2008-07-09 16:20:48 +00:00
Roy Marples
b83108cd2e Add a knob to avoid the unmounting of some points. 2008-07-09 16:08:38 +00:00
Roy Marples
1ca63447c9 Hide mkdir error's 2008-07-09 15:22:15 +00:00
Roy Marples
c2781c209e Really test if we can write to RC_LIBDIR or not. 2008-07-09 15:12:56 +00:00
Roy Marples
5983add0f2 No point in re-mounting ro filesystems that are already ro. 2008-07-09 14:24:48 +00:00
Roy Marples
a566493eb8 Ignore core files 2008-07-09 14:04:40 +00:00
Roy Marples
bdd8b150cd Fix return display. 2008-07-09 13:36:37 +00:00
Roy Marples
53401cd35f STAILQ -> TAILQ 2008-07-08 10:48:21 +00:00
Roy Marples
7a6112d3b0 Punt STAILQ and just use TAILQ so we're a bit more portable. 2008-07-07 14:16:46 +00:00
Roy Marples
157db50df7 Fix is_older_than a little better, and make is_newer_than correct. 2008-07-03 13:30:17 +00:00
Roy Marples
a88a177f99 Add older_than function to complement newer_than function. Also make the userland instance reversed to be compatable with current baselayout, which truely does suck. 2008-07-03 13:11:47 +00:00
Roy Marples
d61f831896 More unit fixes. 2008-07-03 13:09:24 +00:00
Roy Marples
28a65393ca More unit fixes. 2008-07-03 13:09:10 +00:00
Roy Marples
aa57dd1ff6 More unit fixes. 2008-07-03 12:33:42 +00:00
Roy Marples
e0968a1c2e Fix test. 2008-07-03 12:20:32 +00:00
Roy Marples
2f5d2855ba Add an is_older_than unit test, thanks to zzam 2008-07-03 12:07:46 +00:00
Roy Marples
db9bf18587 Fix compile with pcc. 2008-07-02 23:20:04 +00:00
Roy Marples
feac5ea1d5 Ignore ewaitfile. 2008-06-30 13:36:59 +00:00
Roy Marples
64dbae7f61 If filtering fstab, only match additional mounts asked for. 2008-06-30 13:33:42 +00:00
Roy Marples
11e4059b05 Set the default RC_SVCDIR higher up. 2008-06-21 15:31:04 +00:00
Roy Marples
5510451bac We need to replace @LIB@ here. 2008-06-21 14:10:59 +00:00
Roy Marples
11acce3c7d Use CPPFLAGS so we work with -combine in CFLAGS. 2008-06-19 23:12:00 +00:00
Roy Marples
4f2bb5ceaf open should use 3 args when using O_CREAT. 2008-06-17 15:14:33 +00:00
Roy Marples
bf8f0da921 fuzzy dependency ordering should be started, starting, stopped whilst checking runlevel, bootlevel, any at each stage. 2008-06-10 15:19:46 +00:00
Roy Marples
9b1cb4e246 When we have dependant scheduled services, don't error if a need is stopped. 2008-06-10 15:04:29 +00:00
Roy Marples
2adc99a8f5 No need to include this. 2008-06-05 12:26:53 +00:00
Roy Marples
fc747f9894 Remove the macro ;) 2008-06-05 12:19:49 +00:00
Roy Marples
76063daee5 Update style to more BSDish and replace the big macro with a function. 2008-06-05 12:17:41 +00:00
Roy Marples
dc891b0647 Remove broken before dependencies, Gentoo #224171. 2008-06-05 10:14:11 +00:00
Roy Marples
3525e602d6 Use addu instead of another loop. 2008-06-04 19:07:09 +00:00
Roy Marples
79ebd89d19 Only add a backreference if it doesn't already exist. 2008-06-04 19:00:46 +00:00
Roy Marples
ba8008fb05 Include time headers for ewaitfile. 2008-06-04 14:09:25 +00:00
Roy Marples
5e2c3fb5fe Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-06-04 12:58:05 +00:00
Roy Marples
e6aed12328 No need to check type twice like this. 2008-06-04 12:47:06 +00:00
Roy Marples
83ade5b701 Style. 2008-06-04 12:44:45 +00:00
Roy Marples
587051ec67 Add the ewaitfile function so init scripts can wait until sockts are created, Gentoo #175783. 2008-06-03 11:57:15 +00:00
Roy Marples
f2ea7ca514 Let ifdown control all interfaces. 2008-06-03 11:51:36 +00:00
Roy Marples
b41c864fc3 openrc-0.2.5 2008-05-28 13:39:52 +00:00
Roy Marples
c409dd0570 Some ifconfig's output weird inet6 loopback addresses 2008-05-28 13:38:58 +00:00
Roy Marples
aaaa0b50d8 Be quiet when checking at start. 2008-05-27 16:48:47 +00:00
Roy Marples
ca6f289c80 When stopping with a pidfile, only read the pid once incase it vanishes but the process still hangs around. 2008-05-27 16:42:28 +00:00
Roy Marples
f640ecaebb Only check tentative when we have a carrier, Gentoo #223061 2008-05-27 16:41:53 +00:00
Roy Marples
75eff5a86b Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-05-27 13:08:14 +00:00
Roy Marples
eeadc618fb Work with madwifi craptastic drivers. Hopefuly prism54 still works. 2008-05-27 13:07:18 +00:00
Roy Marples
bb069e1618 Use iwconfig defaults and config if available. 2008-05-27 10:46:27 +00:00
Roy Marples
3a592fa31b Trap fsck for SIGINT as well, so user can ctrl-C to abort fsck and continue, Gentoo #223473. 2008-05-27 10:25:29 +00:00
Roy Marples
6b77cc624f Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-05-27 10:05:15 +00:00
Roy Marples
328215e841 Work with new beta5 options to skip hoof files. 2008-05-25 22:57:44 +00:00
Roy Marples
b03282b901 Fix tunnel, #80. Someone should fix iproute2 documentation and help files also :P 2008-05-25 22:34:05 +00:00
Roy Marples
08081f7ef4 Fix passno and IFS, #77 and #85, thanks to Nahor 2008-05-25 22:30:31 +00:00
Roy Marples
8ca8e00a89 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-05-25 22:25:29 +00:00
Roy Marples
1df3ab05b5 realloc -> xrealloc 2008-05-19 13:41:16 +00:00
Roy Marples
775df18a70 Fix a potential segfault, thanks to Fernando J. Pereda. 2008-05-19 13:16:53 +00:00
Roy Marples
148caecc7e Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-05-13 08:41:54 +00:00
Roy Marples
d0f7a63487 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-05-13 08:18:07 +00:00
Roy Marples
b7e598ad91 Install symlinks correctly, thanks to zlin. 2008-05-13 00:03:10 +00:00
Roy Marples
5c114d9430 When testing services to stop, we should trace it. More for #79. 2008-05-12 23:45:17 +00:00
Roy Marples
f13ea77491 The real fix for the last commit is to uncomment some code - d'oh. 2008-05-12 23:33:40 +00:00
Roy Marples
a89171ee9b When stopping, stop services that need our provide as well, #79. 2008-05-12 23:17:45 +00:00
Roy Marples
6d5d655b52 Style. 2008-05-12 23:00:05 +00:00
Roy Marples
0f51f3e863 We should add devdb to boot. 2008-05-12 15:13:35 +00:00
Roy Marples
be8f8d0ac0 Add the devdb init script. 2008-05-12 15:11:04 +00:00
Roy Marples
d667da8e5c Check we have a deptree before using it, Gentoo #220579 2008-05-12 13:20:35 +00:00
Roy Marples
9894669742 Fix help text, #75. 2008-05-12 08:34:42 +00:00
Roy Marples
b732df31ef Don't report fstab passno of 0 when using greater or less than, #76. 2008-05-12 08:32:19 +00:00
Roy Marples
762dc3d197 Work with dhcpcd-4 style options. 2008-05-10 12:29:49 +00:00
Roy Marples
30fe99dead openrc-0.2.4 2008-05-10 12:01:17 +00:00
Roy Marples
2d75eb7976 netmount may use openvpn. 2008-05-10 11:09:52 +00:00
Roy Marples
3663cf1e2a Only launch single user when RUNLEVEL == S, #74. 2008-05-10 10:04:34 +00:00
Roy Marples
766ec96e3d Add ifdown_eth0=NO so that the interface stays up for WakeOnLan, Gentoo #220875 2008-05-09 10:29:06 +00:00
Roy Marples
a854fe6d61 Simplify the wait code. 2008-05-07 09:47:07 +00:00
Roy Marples
619b0b4f37 Fix the EINTR check for waitpid, Gentoo #219929. 2008-05-06 21:53:21 +00:00
Roy Marples
c8248d05a0 Ensure that make dep ordering is correct for install. 2008-05-06 19:52:30 +00:00
Roy Marples
5ae702339e We don't need to handle SIGWINCH in sysinit, so this should fix loading a framebuffer module in init.sh (Gentoo #219929. Ideally someone should tell me why this is happening and if there is a better fix. 2008-05-06 16:21:16 +00:00
Roy Marples
d384502e57 There could be a space between #! and /sbin/runscript, Gentoo #218001. 2008-05-01 15:18:34 +00:00
Roy Marples
bdaca0baf5 Busybox find now works with -exec correctly, so remove our nasty hack. 2008-04-30 16:44:29 +00:00
Roy Marples
5188fd2592 Wups, test compiles before commiting :) 2008-04-30 16:33:54 +00:00
Roy Marples
5b800030f1 Remove redundant checking of /proc/pid/exe 2008-04-30 16:26:05 +00:00
Roy Marples
208443fa0e Save a few bytes and make it easier to read. 2008-04-30 15:26:29 +00:00
Roy Marples
a818eebf7b No need to init this. 2008-04-30 12:26:38 +00:00
Roy Marples
10910876d1 Make the function a little smaller. 2008-04-30 10:55:42 +00:00
Roy Marples
35b4978152 Style 2008-04-30 10:31:06 +00:00
Roy Marples
cedd81801a We should use correct iproute2 commands and fix busybox as it's iproute2 implementation is a little broken. 2008-04-30 09:18:20 +00:00
Roy Marples
e273b4e08e Fix another leak. 2008-04-29 11:08:02 +00:00
Roy Marples
50cff8ebc8 Tweak the last commit and fix a valgrind error. 2008-04-29 10:49:50 +00:00
Roy Marples
aec83494d6 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-04-29 10:26:17 +00:00
Roy Marples
5ba6f0a628 We need to ensure that the init script started is correct, translating symlinks. This has a new rule - multiplexed services must exist in the same dir as the master sript. So we need to ensuret that net.lo(0) is the real script and not a symlink itself. This fixes Gentoo #219526. 2008-04-29 10:25:45 +00:00
Roy Marples
5a59542629 Fix syscons for setting the font correctly. 2008-04-29 08:00:50 +00:00
Roy Marples
52711bdca7 Release openrc-0.2.3 2008-04-28 18:39:51 +00:00
Roy Marples
53902cefb8 Add rc_program function which uses fork and signal masking to try and resolve the waitpid issue, Gentoo #219179. 2008-04-28 16:04:16 +00:00
Roy Marples
75f991068d Fix multi platform a little. 2008-04-28 12:48:20 +00:00
Roy Marples
e499e58310 Don't re-start or re-stop failed services if runlevel is changing. 2008-04-27 21:04:37 +00:00
Roy Marples
b08b6cd91b Always define template start/stop functions so that the real script name isn't hidden when errors are in the real start/stop functions, Gentoo #219179 2008-04-26 19:32:28 +00:00
Roy Marples
3c2b93fc9c Check we have a list before running depends. 2008-04-26 14:59:07 +00:00
Roy Marples
b5d829789f Check we have a list before running depends. 2008-04-26 14:57:39 +00:00
Roy Marples
1e3442f95d Work with aliases on NetBSD. 2008-04-23 13:17:13 +00:00
Roy Marples
2bda1871a1 When fsck_passno is set, show this so output is clearer when fsck is multiplexed, Gentoo #218141. 2008-04-22 13:46:53 +00:00
Roy Marples
d3b111bd58 Our init scripts normally output context in [ .. ] 2008-04-22 08:12:26 +00:00
Roy Marples
dbea63b76d Fix logic for templates. 2008-04-21 21:34:52 +00:00
Roy Marples
6a5287dbb5 Typo 2008-04-21 19:26:56 +00:00
Roy Marples
df8eeba2fb Punt is_function in favour of POSIX shell builtin command, thanks to Harald van Dijk for the idea. 2008-04-21 17:32:17 +00:00
Roy Marples
54fce42c6f Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-04-21 13:07:04 +00:00
Roy Marples
54d7aa39dd If we don't have permission to inspect the pidfile, don't report crashed. Gentoo #218028. 2008-04-21 10:56:28 +00:00
Roy Marples
dc5d63aa97 Add RC_TMPDIR so that there's a writeable location during boot. 2008-04-21 10:29:29 +00:00
Roy Marples
bab5d7767d Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-04-21 10:26:40 +00:00
Roy Marples
799686e40d Fix force_preferred, #60. 2008-04-20 14:24:35 +00:00
Roy Marples
d83ae59cca Add help for mountargs, #63 2008-04-19 17:19:59 +00:00
Mike Frysinger
18b4108755 add support for parsing newer ifconfig output
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2008-04-19 07:22:30 +00:00
Roy Marples
e96347523f We should check type output to ensure that we're really calling a shell function and not some badly named binary like stop from boinc, Gentoo #218063. 2008-04-18 23:00:43 +00:00
Roy Marples
f0aacec02e Cast to unsigned char for ctype calls. 2008-04-17 10:19:58 +00:00
Roy Marples
57e1dd7389 Fix rc-status some more. 2008-04-17 00:25:08 +00:00
Roy Marples
c89b3763fb Respect shutdown -F on Linux to force fsck, #59 2008-04-17 00:09:34 +00:00
Roy Marples
425abe40c5 Only report unassigned services when there are any, Gentoo #218005. 2008-04-16 19:47:19 +00:00
Roy Marples
725b9dc89c Use qlen instead of txqueuelen so we work with busybox iproute2, Gentoo #217948 2008-04-16 15:23:57 +00:00
Roy Marples
22d650c450 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-04-16 15:02:19 +00:00
Roy Marples
809ac86c69 We should only check dependencies in files. 2008-04-16 15:01:52 +00:00
Roy Marples
b3310e8e10 Fix rebooting for OpenVZ systems. 2008-04-15 21:50:08 +00:00
Roy Marples
29369c44c1 Add help text for rc-service --resole. 2008-04-15 16:16:59 +00:00
Roy Marples
292fe3a568 Release 0.2.2 2008-04-15 16:09:02 +00:00
Roy Marples
99d5046a56 Don't assume that we have a list returned. 2008-04-10 08:49:05 +00:00
Roy Marples
0e38dcc4d2 By default, rc-status now shows the statuses of the services in the current runlevel and any unassigned non stopped services, #52. 2008-04-09 22:56:32 +00:00
Roy Marples
9176b77c23 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-04-09 19:02:41 +00:00
Roy Marples
fad61a7c4b Fix windowkeys. 2008-04-09 12:24:34 +00:00
Roy Marples
0e114abf5d Respect shutdown's fastboot. 2008-04-09 00:21:49 +00:00
Roy Marples
bc369085c7 More ltsp fixes. 2008-04-09 00:06:50 +00:00
Roy Marples
6d8b36e09d Fix netmout for nfs 2008-04-08 23:25:48 +00:00
Roy Marples
8759735711 Give an error when running zap as a generic user. 2008-04-08 22:57:42 +00:00
Roy Marples
034b9b7a12 Add a silly rc_runlevel function to appease SpanKY :) 2008-04-08 16:01:40 +00:00
Roy Marples
e82435c2f4 rc_runlevel is now the preferred kernel commandline option for choosing default runlevel. 2008-04-08 15:59:56 +00:00
Roy Marples
71dd280656 Fix rc-service --help output. 2008-04-07 11:48:32 +00:00
Roy Marples
594d98eddc Tests now work on NetBSD. 2008-04-07 09:37:14 +00:00
Roy Marples
dcdfdb442f Some systems are only detectable after /proc is mounted, so re-test if unknown. 2008-04-06 20:06:07 +00:00
Roy Marples
143239e143 Increase pidstr size to 10 chars. 2008-04-06 13:24:10 +00:00
Roy Marples
5d38d4d6e9 p could be null here. 2008-04-06 13:21:42 +00:00
Roy Marples
c18c4fc4cc Check list existance before iterating, Gentoo #216091. 2008-04-04 16:31:56 +00:00
Roy Marples
5ebe7f1349 Push out 0.2.1 to solve a few issues. 2008-04-02 16:35:28 +00:00
Roy Marples
6a227d0c45 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-04-02 16:35:02 +00:00
Roy Marples
403abe73de Fix vlans, #49. 2008-04-01 21:34:31 +00:00
Roy Marples
be82e950d7 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-03-31 16:31:43 +00:00
Roy Marples
3ca8387966 Document SSD_NICELEVEL. 2008-03-29 09:37:59 +00:00
Roy Marples
f5a9b42215 Restore noserver and noopenvz to sysctl. 2008-03-28 19:05:26 +00:00
Roy Marples
d370918f0c Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-03-28 16:21:59 +00:00
Roy Marples
e995404e3b Add XEN support to NetBSD. 2008-03-28 16:10:31 +00:00
Roy Marples
caa4704ce6 Merge branch 'master' of git@git.overlays.gentoo.org:proj/openrc 2008-03-28 16:05:11 +00:00
Roy Marples
17d28fde42 Support XEN on NetBSD 2008-03-28 16:04:48 +00:00
Roy Marples
b418f2e471 Allow our headers to be included by C++ programs easily. 2008-03-28 11:06:47 +00:00
Roy Marples
ee4e861796 Put some dir locations in rc.h so that 3rd party apps can become awware of them. 2008-03-28 10:46:12 +00:00
Roy Marples
11e33e81c8 Remove rc_service_start/stop from librc as they block and unmask signals. The application may not wish this behaviour and should fork/exec the service itself. 2008-03-28 08:42:05 +00:00
Roy Marples
5e8ed2aeca Tweak install of runlevels. 2008-03-27 19:55:03 +00:00
Roy Marples
742310744d We would sanitize $RC_LIBDIR/sbin as well. If it's really needed then rc-functions.sh will add it back. 2008-03-27 18:34:12 +00:00
Roy Marples
4e9b58b07d Sanitize the write rc dir. 2008-03-27 17:09:18 +00:00
Roy Marples
c564043f86 No need for the extra rc. 2008-03-27 16:59:33 +00:00
Roy Marples
b3d1182a2f Fix mulitlib issues. 2008-03-27 16:53:22 +00:00
Roy Marples
f6cb321f9f NetBSD doesn't work with this powerd. 2008-03-27 14:56:50 +00:00
Roy Marples
f85c6ca84c Make our messages similar 2008-03-27 14:03:37 +00:00
Roy Marples
d09f9f47eb Split terminal encoding out. 2008-03-27 13:49:49 +00:00
Roy Marples
b271ac5af5 Fix install of rc and rc.shutdown on the BSD's. 2008-03-27 09:33:20 +00:00
Roy Marples
fccff6a4ed Allow multiple ntp_servers without error, #47 2008-03-26 22:39:27 +00:00
126 changed files with 2387 additions and 1755 deletions

View File

@@ -3,7 +3,7 @@
# All rights reserved. Released under the 2-clause BSD license.
NAME= openrc
VERSION= 0.2
VERSION= 0.3.0
PKG= ${NAME}-${VERSION}
SUBDIR= conf.d doc etc init.d man net sh src

View File

@@ -1,5 +1,5 @@
DIR= ${CONFDIR}
CONF= bootmisc fsck hostname local net urandom
CONF= bootmisc fsck hostname local localmount net urandom
MK= ../mk
include ${MK}/os.mk

View File

@@ -1 +1 @@
CONF+= moused powerd rarpd savecore syscons
CONF+= ipfw moused powerd rarpd savecore syscons

View File

@@ -1 +1 @@
CONF+= moused powerd rarpd savecore
CONF+= moused rarpd savecore

14
conf.d/ipfw Normal file
View File

@@ -0,0 +1,14 @@
# ipfw provides a stateful firewall.
# This means we allow everything out, and if we have a connection we allow it
# back in. This is very flexable and quite secure.
# For ease of use, we allow auth and ssh ports through as well.
# To override the list of allowed ports
#ipfw_ports_in="auth ssh"
# You may want to enable logging of denied connections
#ipfw_log_deny="YES"
# This ports not logged
#ipfw_ports_nolog="135-139,445 1026,1027 1433,1434"

3
conf.d/localmount Normal file
View File

@@ -0,0 +1,3 @@
# Stop the unmounting of certain points.
# This could be useful for some NFS related work.
#no_umounts="/dir1:/var/dir2"

View File

@@ -5,6 +5,10 @@
#modules_2_6="tun"
#modules="ohci1394"
# You can give modules a different name when they load - the new name
# will also be used to pick arguments below.
#modules="dummy:dummy1"
# Give the modules some arguments if needed, per version if necessary.
#module_ieee1394_args="debug"
#module_ieee1394_args_2_6_23_gentoo_r5="ieee1394 ohci1394"

View File

@@ -87,6 +87,10 @@
# is how long we wait for carrier. The current default is 3 seconds
#carrier_timeout_eth0=-1
# You may wish to disable the interface being brought down when stopping.
# This is only of use for WakeOnLan.
#ifdown_eth0="NO"
##############################################################################
# OPTIONAL MODULES

View File

@@ -120,6 +120,10 @@
# tables you may have to set a global metric as the due to a simple read of
# the routing table taking over a minute at a time.
# You may wish to disable the interface being brought down when stopping.
# This is only of use for WakeOnLan.
#ifdown_eth0="NO"
##############################################################################
# OPTIONAL MODULES
@@ -565,12 +569,18 @@
#-----------------------------------------------------------------------------
# Bonding
# For link bonding/trunking emerge net-misc/ifenslave
# For link bonding/trunking on 2.4 kernels, or kernels without sysfs
# emerge net-misc/ifenslave
# To bond interfaces together
#slaves_bond0="eth0 eth1 eth2"
#config_bond0="null" # You may not want to assign an IP the the bond
# You can also configure the bond here, which must be done via sysfs on 2.6
# kernels or newer. See the kernel bonding documention for a description of
# these options.
#arp_ip_target_bond0="+26.0.0.0"
# If any of the slaves require extra configuration - for example wireless or
# ppp devices - we need to depend function on the bonded interfaces
#rc_need_bond0="net.eth0 net.eth1"
@@ -1006,7 +1016,7 @@
#postdown() {
# # Enable Wake-On-LAN for every interface except for lo
# # Probably a good idea to set RC_DOWN_INTERFACE="no" in /etc/conf.d/rc
# # Probably a good idea to set ifdown="no" in /etc/conf.d/net
# # as well ;)
# [ "${IFACE}" != "lo" ] && ethtool -s "${IFACE}" wol g

View File

@@ -1,4 +1,4 @@
SED_EXTRA= -e 's:@TERM@:cons25:g'
SRCS+= rc.conf.in rc.in rc.shutdown.in
CONF+= devd.conf
BIN+= rc.devd
BIN+= rc rc.shutdown rc.devd

View File

@@ -1,2 +1,3 @@
SED_EXTRA= -e 's:@TERM@:wsvt25:g'
SRCS+= rc.conf.in rc.in rc.shutdown.in
BIN+= rc rc.shutdown

View File

@@ -4,6 +4,9 @@
# in parallel for a slight speed improvement. When running in parallel we
# prefix the service output with it's name as the output will get
# jumbled up.
# WARNING: whilst we have improved parallel, it can still potentially lock
# the boot process. Don't file bugs about this unless you can supply
# patches that fix it without breaking other things!
rc_parallel="NO"
# Set rc_interactive to "YES" and you'll be able to press the I key during
@@ -49,6 +52,14 @@ rc_logger="NO"
# variables through, add them here. Use a * to allow all variables through.
# rc_env_allow="VAR1 VAR2"
# By default we assume that all daemons will start correctly.
# However, some do not - a classic example is that they fork and return 0 AND
# then child barfs on a configuration error. Or the daemon has a bug and the
# child crashes. You can set the number of milliseconds start-stop-daemon
# waits to check that the daemon is still running after starting here.
# The default is 0 - no checking.
# rc_start_wait=100
##############################################################################
# MISC CONFIGURATION VARIABLES
# There variables are shared between many init scripts

View File

@@ -3,5 +3,8 @@ SRCS= avahi-dnsconfd.in avahid.in dbus.in hald.in named.in ntpd.in \
openvpn.in polkitd.in sshd.in
MK= ../mk
SED_EXTRA+= -e 's:@VARBASE@:/var:g'
include ${MK}/scripts.mk
include Makefile.${OS}

View File

@@ -3,7 +3,7 @@
# All rights reserved. Released under the 2-clause BSD license.
command=@PKG_PREFIX@/bin/dbus-daemon
pidfile=@VARBASE@/run/dbus/dbus.pid
pidfile=@VARBASE@/run/dbus/pid
command_args="${dbusd_args---system}"
name="Message Bus Daemon"

View File

@@ -4,12 +4,22 @@
command=/usr/sbin/named
command_args=${named_args}
pidfile=@VARBASE@/run/named/pid
pidfile=@VARBASE@/run/named.pid
name="Domain Name server"
extra_started_commands="reload"
namedb=/etc/namedb
named_uid=${named_uid:-bind}
uid=named
case "${RC_UNAME}" in
FreeBSD)
uid=bind
pidfile=@VARBASE@/run/named/pid
;;
Linux)
uid=bind
;;
esac
named_uid=${named_uid:-${uid}}
depend()
{

13
init.d/.gitignore vendored
View File

@@ -26,3 +26,16 @@ mixer
nscd
powerd
syscons
net.lo
ttys
swap-blk
wscons
consolefont
hwclock
keymaps
modules
mtab
numlock
procfs
termencoding
devdb

View File

@@ -3,7 +3,14 @@ SRCS= bootmisc.in fsck.in halt.sh.in hostname.in local.in localmount.in \
netmount.in root.in swap.in sysctl.in urandom.in
BIN= ${OBJS}
INSTALLAFTER= _installafter
CLEANFILES+= net.lo
TARGETS+= net.lo
MK= ../mk
include ${MK}/os.mk
include Makefile.${OS}
include ${MK}/scripts.mk
_installafter: realinstall
${INSTALL} -m ${BINMODE} net.lo ${DESTDIR}/${INITDIR}/${NET_LO}

View File

@@ -1,3 +1,5 @@
NET_LO= net.lo0
# Generic BSD scripts
SRCS+= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
rpcbind.in savecore.in syslogd.in

View File

@@ -1,5 +1,7 @@
NET_LO= net.lo
SRCS+= hwclock.in consolefont.in keymaps.in modules.in mtab.in numlock.in \
procfs.in
procfs.in termencoding.in
.SUFFIXES: .Linux.in
.Linux.in:

View File

@@ -1,9 +1,11 @@
NET_LO= net.lo0
# Generic BSD scripts
SRCS+= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
rpcbind.in savecore.in syslogd.in
# These are NetBSD specific
SRCS+= swap-blk.in ttys.in wscons.in
SRCS+= devdb.in swap-blk.in ttys.in wscons.in
.SUFFIXES: .BSD.in
.BSD.in:

View File

@@ -11,21 +11,25 @@ depend()
keyword noprefix
}
dir_writeable()
{
mkdir "$1"/.test.$$ 2>/dev/null && rmdir "$1"/.test.$$
}
cleanup_tmp_dir()
{
local dir=$1
local dir="$1"
mkdir -p "${dir}"
if ! [ -d "${dir}" ]; then
mkdir -p "${dir}" || return $?
fi
dir_writeable "${dir}" || return 1
chmod +t "${dir}"
cd "${dir}"
if yesno ${wipe_tmp:-${WIPE_TMP:-yes}}; then
ebegin "Wiping ${dir} directory"
local startopts="-x . -depth" delete="-exec rm -rf -- {} ;"
if [ "${RC_UNAME}" = "Linux" ]; then
startopts=". -xdev -depth"
# busybox find / rm cannot handle --
delete="-delete"
fi
local startopts="-x . -depth"
[ "${RC_UNAME}" = "Linux" ] && startopts=". -xdev -depth"
# Faster than find
rm -rf -- [b-ikm-pr-zA-Z0-9\.]*
@@ -45,8 +49,7 @@ cleanup_tmp_dir()
! -path "./journal/*" \
! -path "./.private" \
! -path "./.private/*" \
${delete} \
-type d -prune
-exec rm -rf {} \;
eend 0
else
ebegin "Cleaning ${dir} directory"
@@ -60,12 +63,7 @@ cleanup_tmp_dir()
start()
{
if ! mkdir /.test.$$ 2>/dev/null; then
ewarn "Skipping /var and /tmp initialization (ro root?)"
return 0
fi
rmdir /.test.$$
local logw=false
# Ensure that our basic dirs exist
for x in /var/log /var/run /tmp; do
if ! [ -d "${x}" ]; then
@@ -76,51 +74,64 @@ start()
fi
done
ebegin "Creating user login records"
cp /dev/null /var/run/utmp
[ -e /var/log/wtmp ] || cp /dev/null /var/log/wtmp
chmod 0644 /var/run/utmp /var/log/wtmp
eend 0
if dir_writeable /var/run; then
ebegin "Creating user login records"
cp /dev/null /var/run/utmp
if dir_writeable /var/log; then
logw=true
[ -e /var/log/wtmp ] || cp /dev/null /var/log/wtmp
chmod 0644 /var/run/utmp /var/log/wtmp
fi
eend 0
ebegin "Cleaning /var/run"
for x in $(find /var/run ! -type d ! -name utmp ! -name random-seed \
! -name ld-elf.so.hints ! -name ld.so.hints);
do
[ ! -f "${x}" ] && continue
# Do not remove pidfiles of already running daemons
case "${x}" in
*.pid)
start-stop-daemon --test --quiet --stop \
--pidfile "${x}"
[ $? -eq 0 ] && continue
ebegin "Cleaning /var/run"
for x in $(find /var/run ! -type d ! -name utmp \
! -name random-seed ! -name dev.db \
! -name ld-elf.so.hints ! -name ld.so.hints);
do
# Clean stale sockets
if [ -S "${x}" ] && type fuser >/dev/null 2>&1; then
fuser -s "${x}" || rm "${x}"
fi
[ ! -f "${x}" ] && continue
# Do not remove pidfiles of already running daemons
case "${x}" in
*.pid)
start-stop-daemon --test --quiet \
--stop --pidfile "${x}" && continue
;;
esac
rm -f -- "${x}"
done
eend 0
esac
rm -f -- "${x}"
done
eend 0
fi
# Clean up /tmp directories
local tmp=
for tmp in ${wipe_tmp_dirs-/tmp}; do
cleanup_tmp_dir "${tmp}"
done
chmod +t /tmp /var/tmp
# Make sure our X11 stuff have the correct permissions
# Omit the chown as bootmisc is run before network is up
# and users may be using lame LDAP auth #139411
rm -rf /tmp/.ICE-unix /tmp/.X11-unix
mkdir -p /tmp/.ICE-unix /tmp/.X11-unix
chmod 1777 /tmp/.ICE-unix /tmp/.X11-unix
[ -x /sbin/restorecon ] && restorecon /tmp/.ICE-unix /tmp/.X11-unix
if dir_writeable /tmp; then
# Make sure our X11 stuff have the correct permissions
# Omit the chown as bootmisc is run before network is up
# and users may be using lame LDAP auth #139411
rm -rf /tmp/.ICE-unix /tmp/.X11-unix
mkdir -p /tmp/.ICE-unix /tmp/.X11-unix
chmod 1777 /tmp/.ICE-unix /tmp/.X11-unix
[ -x /sbin/restorecon ] && restorecon /tmp/.ICE-unix /tmp/.X11-unix
fi
# Create an 'after-boot' dmesg log
if [ "${RC_SYS}" != "VSERVER" -a "${RC_SYS}" != "OPENVZ" ]; then
dmesg > /var/log/dmesg
chmod 640 /var/log/dmesg
if ${logw} || dir_writeable /var/log; then
# Create an 'after-boot' dmesg log
if [ "${RC_SYS}" != "VSERVER" -a "${RC_SYS}" != "OPENVZ" ]; then
dmesg > /var/log/dmesg
chmod 640 /var/log/dmesg
fi
fi
rm -f /etc/nologin
return 0
}
stop()

View File

@@ -6,8 +6,7 @@ description="Sets a font for the consoles."
depend()
{
need localmount
need keymaps # sets up terminal encoding scheme
need localmount termencoding
after hotplug
keyword noopenvz noprefix nouml novserver noxenu
}
@@ -34,7 +33,7 @@ start()
return 0
fi
local x= param= sf_param= retval=0 ttydev=
local x= param= sf_param= retval=0 ttydev=/dev/tty
# Get additional parameters
if [ -n "${consoletranslation}" ]; then
@@ -45,11 +44,8 @@ start()
fi
# Set the console font
ebegin "Setting user font"
[ -d /dev/vc ] \
&& ttydev=/dev/vc/ \
|| ttydev=/dev/tty
ebegin "Setting console font [${consolefont}]"
[ -d /dev/vc ] && ttydev=/dev/vc/
x=1
while [ ${x} -le ${ttyn} ]; do
setfont ${consolefont} ${param} -C ${ttydev}${x} >/dev/null
@@ -61,17 +57,17 @@ start()
# Store the last font so we can use it ASAP on boot
if [ ${retval} -eq 0 -a -w "${RC_LIBDIR}" ]; then
mkdir -p "${RC_LIBDIR}"/console
for font in /usr/share/consolefonts/"${consolefont}".*; do
:
done
cp "${font}" "${RC_LIBDIR}"/console
echo "${font##*/}" > "${RC_LIBDIR}"/console/font
if yesno ${unicode:-${UNICODE}}; then
cp /dev/null "${RC_LIBDIR}"/console/unicode
echo "" > "${RC_LIBDIR}"/console/unicode
else
rm -f "${RC_LIBDIR}"/console/unicode
fi
fi
return ${retval}

21
init.d/devdb.in Normal file
View File

@@ -0,0 +1,21 @@
#!@PREFIX@/sbin/runscript
# Copyright 2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
description="Creates the dev database"
depend()
{
need localmount
}
start()
{
ebegin "Bulding the dev database"
if [ /var/run/dev.db -nt /dev ]; then
:
else
dev_mkdb
fi
eend $?
}

View File

@@ -3,7 +3,7 @@
# All rights reserved. Released under the 2-clause BSD license.
description="Check and repair filesystems according to /etc/fstab"
_ISF="
_IFS="
"
depend()
@@ -27,20 +27,32 @@ _reboot() {
start()
{
local reboot_opts= fsck_opts= p=
local reboot_opts= fsck_opts= p= check_extra=
ebegin "Checking local filesystems"
if [ -e /fastboot ]; then
ewarn "Skipping fsck due to /fastboot"
return 0
fi
if [ -e /forcefsck ] || get_bootparam forcefsck; then
fsck_opts="${fsck_opts} -f"
check_extra="(check forced)"
fi
if [ -n "${fsck_passno}" ]; then
check_extra="[passno ${fsck_passno}] ${check_extra}"
fi
ebegin "Checking local filesystems ${check_extra}"
for p in ${fsck_passno}; do
local IFS="${_IFS}"
case "${p}" in
[0-9]*) p="=${p}";;
esac
set -- "$@" "$(fstabinfo --passno "${p}")"
set -- "$@" $(fstabinfo --passno "${p}")
unset IFS
done
if [ "${RC_UNAME}" = "Linux" ]; then
fsck_opts="-C0 -T"
fsck_opts="${fsck_opts} -C0 -T"
if [ -z "${fsck_passno}" ]; then
fsck_args=${fsck_args--A -p}
if echo 2>/dev/null >/.test.$$; then
@@ -51,7 +63,7 @@ start()
reboot_opts="-f"
fi
trap : QUIT
trap : INT QUIT
fsck ${fsck_args--p} ${fsck_opts} "$@"
case $? in
0) eend 0; return 0;;

View File

@@ -4,6 +4,7 @@
. @SYSCONFDIR@/init.d/functions.sh
. "${RC_LIBDIR}"/sh/rc-functions.sh
[ -r @SYSCONFDIR@/conf.d/localmount ] && . @SYSCONFDIR@/conf.d/localmount
[ -r @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
# Support LiveCD foo
@@ -28,6 +29,7 @@ sync; sync
# 1) we don't need (and by default can't) umount anything (VServer) or
# 2) the host utils take care of all umounting stuff (OpenVZ)
if [ "${RC_SYS}" = "VSERVER" -o "${RC_SYS}" = "OPENVZ" ]; then
[ "${RC_SYS}" = "OPENVZ" -a "$1" = "reboot" ] && echo "" > /reboot
if [ -e @SYSCONFDIR@/init.d/"$1".sh ]; then
. @SYSCONFDIR@/init.d/"$1".sh
else
@@ -37,7 +39,11 @@ fi
# If $svcdir is still mounted, preserve it if we can
mnt=$(mountinfo --node "${RC_SVCDIR}")
if [ -n "${mnt}" -a -w "${RC_LIBDIR}" ]; then
if [ -n "${mnt}" ] && \
rm -rf "${RC_LIBDIR}/tmp.$$" && \
mkdir -p "${RC_LIBDIR}/tmp.$$" 2>/dev/null \
; then
rmdir "${RC_LIBDIR}/tmp.$$"
f_opts="-m -c"
[ "${RC_UNAME}" = "Linux" ] && f_opts="-c"
if type fuser >/dev/null 2>&1; then
@@ -74,13 +80,27 @@ if [ "${RC_UNAME}" = "Linux" ]; then
# We need the do_unmount function
. "${RC_LIBDIR}"/sh/rc-mount.sh
eindent
no_umounts_r="/dev|/dev/.*|${RC_SVCDIR}"
# RC_NO_UMOUNTS is an env var that can be set by plugins
OIFS=${IFS} SIFS=${IFS-y}
IFS=$IFS:
for x in ${no_umounts} ${RC_NO_UMOUNTS}; do
no_umounts_r="${no_umounts_r}|${x}"
done
if [ "${SIFS}" = "y" ]; then
IFS=$OIFS
else
unset IFS
fi
no_umounts_r="${no_umounts_r}|/proc|/proc/.*|/sys|/sys/.*"
no_umounts_r="^(${no_umounts_r})$"
fs=
for x in ${net_fs_list}; do
fs="${fs}${fs:+|}${x}"
done
[ -n "${fs}" ] && fs="^(${fs})$"
do_unmount "mount -n -o remount,ro" \
--skip-point-regex "^(/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*)$" \
--skip-point-regex "${no_umounts_r}" \
${fs:+--skip-fstype-regex} ${fs} --nonetdev
eoutdent
eend $?

View File

@@ -74,8 +74,12 @@ start()
fi
ebegin "Setting system clock using the hardware clock [${utc}]"
if [ -e /proc/modules -a ! -e /dev/rtc ]; then
modprobe -q rtc || modprobe -q genrtc
local rtc=
for rtc in /dev/rtc /dev/rtc[0-9]*; do
[ -e "${rtc}" ] && break
done
if [ ! -e "${rtc}" -a -e /proc/modules ]; then
modprobe -q rtc-cmos || modprobe -q rtc || modprobe -q genrtc
fi
if [ -e /etc/adjtime ] && yesno ${clock_adjfile}; then

View File

@@ -20,6 +20,10 @@ ipfw() {
/sbin/ipfw -f -q "$@"
}
have_ip6() {
sysctl net.ipv6 2>/dev/null
}
init() {
# Load the kernel module
if ! sysctl net.inet.ip.fw.enable=1 >/dev/null 2>&1; then
@@ -36,13 +40,15 @@ init() {
ipfw add deny all from any to 127.0.0.0/8
ipfw add deny ip from 127.0.0.0/8 to any
ipfw add pass ip6 from any to any via lo0
ipfw add deny ip6 from any to ::1
ipfw add deny ip6 from ::1 to any
if have_ip6; then
ipfw add pass ip6 from any to any via lo0
ipfw add deny ip6 from any to ::1
ipfw add deny ip6 from ::1 to any
ipfw add pass ip6 from :: to ff02::/16 proto ipv6-icmp
ipfw add pass ip6 from fe80::/10 to fe80::/10 proto ipv6-icmp
ipfw add pass ip6 from fe80::/10 to ff02::/16 proto ipv6-icmp
ipfw add pass ip6 from :: to ff02::/16 proto ipv6-icmp
ipfw add pass ip6 from fe80::/10 to fe80::/10 proto ipv6-icmp
ipfw add pass ip6 from fe80::/10 to ff02::/16 proto ipv6-icmp
fi
}
start() {
@@ -62,9 +68,11 @@ start() {
ipfw add pass udp from me to any keep-state
ipfw add pass icmp from me to any keep-state
ipfw add pass tcp from me6 to any setup keep-state
ipfw add pass udp from me6 to any keep-state
ipfw add pass icmp from me6 to any keep-state
if have_ip6; then
ipfw add pass tcp from me6 to any setup keep-state
ipfw add pass udp from me6 to any keep-state
ipfw add pass icmp from me6 to any keep-state
fi
# Allow DHCP.
ipfw add pass udp from 0.0.0.0 68 to 255.255.255.255 67 out
@@ -77,11 +85,13 @@ start() {
# Allow "mandatory" ICMP in.
ipfw add pass icmp from any to any icmptype 3,4,11
# Allow ICMPv6 destination unreach
ipfw add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
# Allow NS/NA/toobig (don't filter it out)
ipfw add pass ip6 from any to any icmp6types 2,135,136 proto ipv6-icmp
if have_ip6; then
# Allow ICMPv6 destination unreach
ipfw add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
# Allow NS/NA/toobig (don't filter it out)
ipfw add pass ip6 from any to any icmp6types 2,135,136 proto ipv6-icmp
fi
# Add permits for this workstations published services below
# Only IPs and nets in firewall_allowservices is allowed in.

View File

@@ -8,13 +8,13 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
unicode=${unicode:-${UNICODE}}
keymap=${keymap:-${KEYMAP}}
extended_keymaps=${extended_keymaps:-${EXTENDED_KEYMAPS}}
windowskeys=${windowskeys:-${SET_WINDOWSKEYS}}
windowkeys=${windowkeys:-${SET_WINDOWSKEYS}}
fix_euro=${fix_euro:-${FIX_EURO}}
dumpkeys_charset=${dumpkeys_charset:-${DUMPKEYS_CHARSET}}
depend()
{
need localmount
need localmount termencoding
keyword noopenvz noprefix nouml novserver noxenu
}
@@ -25,43 +25,41 @@ start()
return 1
fi
local ttydev= n=
[ -d /dev/vc ] \
&& ttydev=/dev/vc/ \
|| ttydev=/dev/tty
local ttydev=/dev/tty n=
[ -d /dev/vc ] && ttydev=/dev/vc/
# Force linux keycodes for PPC.
if [ -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ]; then
echo 1 > /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes
fi
ebegin "Loading key mappings"
local loadkeys_uni= wkeys=
yesno ${unicode} && loadkeys_uni="--unicode"
yesno ${windowskeys} && wkeys="windowkeys"
ebegin "Loading key mappings [${keymap}]"
local loadkeys_uni= wkeys= kmode="-a" msg="ASCII"
if yesno ${unicode}; then
loadkeys_uni="--unicode"
kmode="-u"
msg="UTF-8"
fi
yesno ${windowkeys} && wkeys="windowkeys"
loadkeys -q ${loadkeys_uni} ${wkeys} ${keymap} ${extended_keymaps}
eend $? "Error loading key mappings" || return $?
if yesno ${fix_euro}; then
ebegin "Fixing font for euro symbol"
# Fix some fonts displaying the Euro, #173528.
echo "altgr keycode 18 = U+20AC" | loadkeys -q
eend $?
fi
# Set terminal encoding to either ASCII or UNICODE.
# See utf-8(7) for more information.
local termencoding="%@" termmsg="ASCII" kmode="-a"
ebegin "Setting keyboard mode [${msg}]"
if yesno ${unicode}; then
dumpkeys ${dumpkeys_charset:+-c} \
${dumpkeys_charset} | loadkeys --unicode
termencoding="%G"
termmsg="UTF-8"
kmode="-u"
fi
ebegin "Setting terminal encoding to" ${termmsg}
n=1
while [ ${n} -le "${ttyn}" ]; do
printf "\033%s" "${termencoding}" >"${ttydev}${n}"
kbd_mode "${kmode}" -C "${ttydev}${n}"
n=$((${n} + 1))
done

View File

@@ -30,13 +30,13 @@ start()
stop()
{
# We never unmount / or /dev or $RC_SVCDIR
local x= no_umounts="/|/dev|/dev/.*|${RC_SVCDIR}"
local x= no_umounts_r="/|/dev|/dev/.*|${RC_SVCDIR}"
# RC_NO_UMOUNTS is an env var that can be set by plugins
OIFS=${IFS} SIFS=${IFS-y}
IFS=$IFS:
for x in ${no_umounts} ${RC_NO_UMOUNTS}; do
no_umounts="${no_umounts}|${x}"
no_umounts_r="${no_umounts_r}|${x}"
done
if [ "${SIFS}" = "y" ]; then
IFS=$OIFS
@@ -45,9 +45,9 @@ stop()
fi
if [ "${RC_UNAME}" = "Linux" ]; then
no_umounts="${no_umounts}|/proc|/proc/.*|/sys|/sys/.*"
no_umounts_r="${no_umounts_r}|/proc|/proc/.*|/sys|/sys/.*"
fi
no_umounts="^(${no_umounts})$"
no_umounts_r="^(${no_umounts_r})$"
# Flush all pending disk writes now
sync; sync
@@ -63,7 +63,7 @@ stop()
# Umount loopback devices
einfo "Unmounting loopback devices"
eindent
do_unmount "umount -d" --skip-point-regex "${no_umounts}" \
do_unmount "umount -d" --skip-point-regex "${no_umounts_r}" \
--node-regex "^/dev/loop"
eoutdent
@@ -76,7 +76,7 @@ stop()
fs="${fs}${fs:+|}${x}"
done
[ -n "${fs}" ] && fs="^(${fs})$"
do_unmount "umount" --skip-point-regex "${no_umounts}" \
do_unmount "umount" --skip-point-regex "${no_umounts_r}" \
${fs:+--skip-fstype-regex} ${fs} --nonetdev
eoutdent

View File

@@ -23,7 +23,7 @@ start()
x=${KV#*.*.}
local KV_MICRO=${x%%-*}
local list= x= xx= y= args= cnt=0
local list= x= xx= y= args= mpargs= cnt=0 a=
for x in "${KV}" \
${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} \
${KV_MAJOR}.${KV_MINOR} \
@@ -34,17 +34,29 @@ start()
[ -z "${list}" ] && list=${modules}
for x in ${list}; do
ebegin "Loading module ${x}"
a=${x#*:}
if [ "${a}" = "${x}" ]; then
unset mpargs
ebegin "Loading module ${x}"
else
x=${x%%:*}
mpargs="-o ${a}"
ebegin "Loading module ${x} as ${a}"
fi
aa=$(shell_var "${a}")
xx=$(shell_var "${x}")
for y in "${KV}" \
${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} \
${KV_MAJOR}.${KV_MINOR} \
; do
eval args=\$module_${aa}_args_$(shell_var "${y}")
[ -n "${args}" ] && break
eval args=\$module_${xx}_args_$(shell_var "${y}")
[ -n "${args}" ] && break
done
[ -z "${args}" ] && eval args=\$module_${aa}_args
[ -z "${args}" ] && eval args=\$module_${xx}_args
eval modprobe -q "${x}" "${args}"
eval modprobe -q "${mpargs}" "${x}" "${args}"
eend $? "Failed to load ${x}" && cnt=$((${cnt} + 1))
done
einfo "Autoloaded ${cnt} module(s)"

View File

@@ -28,7 +28,7 @@ depend()
*) after net.lo net.lo0;;
esac
if type depend_${IFVAR} >/dev/null 2>&1; then
if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then
depend_${IFVAR}
fi
@@ -344,7 +344,7 @@ _load_modules()
# Wrap our provides
local f=
for f in pre_start start post_start; do
eval "${provides}_${f}() { type ${mod}_${f} >/dev/null 2>&1 || return 0; ${mod}_${f} \"\$@\"; }"
eval "${provides}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }"
done
eval module_${mod}_provides="${provides}"
@@ -358,7 +358,7 @@ _load_modules()
eval x=\$module_${mod}_provides
[ -z "${x}" ] && continue
for f in pre_start start post_start; do
eval "${x}_${f}() { type ${mod}_${f} >/dev/null 2>&1 || return 0; ${mod}_${f} \"\$@\"; }"
eval "${x}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }"
done
eval module_${x}_providedby="${mod}"
;;
@@ -462,7 +462,7 @@ start()
# We up the iface twice if we have a preup to ensure it's up if
# available in preup and afterwards incase the user inadvertently
# brings it down
if type preup >/dev/null 2>&1; then
if [ "$(command -v preup)" = "preup" ]; then
_up 2>/dev/null
ebegin "Running preup"
eindent
@@ -473,7 +473,7 @@ start()
_up 2>/dev/null
for module in ${MODULES}; do
if type "${module}_pre_start" >/dev/null 2>&1; then
if [ "$(command -v "${module}_pre_start")" = "${module}_pre_start" ]; then
${module}_pre_start || exit $?
fi
done
@@ -522,7 +522,7 @@ start()
null) :;;
[0-9]*|*:*) _add_address ${config};;
*)
if type "${config}_start" >/dev/null 2>&1; then
if [ "$(command -v "${config}_start")" = "${config}_start" ]; then
"${config}"_start
else
eerror "nothing provides \`${config}'"
@@ -547,7 +547,7 @@ start()
done
if ! ${oneworked}; then
if type failup >/dev/null 2>&1; then
if [ "$(command -v failup)" = "failup" ]; then
ebegin "Running failup"
eindent
failup
@@ -600,12 +600,12 @@ ${routes}"
fi
for module in ${MODULES}; do
if type "${module}_post_start" >/dev/null 2>&1; then
if [ "$(command -v "${module}_post_start")" = "${module}_post_start" ]; then
${module}_post_start || exit $?
fi
done
if type postup >/dev/null 2>&1; then
if [ "$(command -v postup)" = "postup" ]; then
ebegin "Running postup"
eindent
postup
@@ -628,7 +628,7 @@ stop()
_load_modules false
fi
if type predown >/dev/null 2>&1; then
if [ "$(command -v predown)" = "predown" ]; then
ebegin "Running predown"
eindent
predown || return 1
@@ -641,35 +641,40 @@ stop()
fi
for module in ${MODULES}; do
if type "${module}_pre_stop" >/dev/null 2>&1; then
if [ "$(command -v "${module}_pre_stop")" = "${module}_pre_stop" ]; then
${module}_pre_stop || exit $?
fi
done
for module in ${MODULES}; do
if type "${module}_stop" >/dev/null 2>&1; then
if [ "$(command -v "${module}_stop")" = "${module}_stop" ]; then
${module}_stop
fi
done
# Only delete addresses for non PPP interfaces
if ! type is_ppp >/dev/null 2>&1 || ! is_ppp; then
if ! [ "$(command -v is_ppp)" = "is_ppp" ] || ! is_ppp; then
_delete_addresses "${IFACE}"
fi
for module in ${MODULES}; do
if type "${module}_post_stop" >/dev/null 2>&1; then
if [ "$(command -v "${module}_post_stop")" = "${module}_post_stop" ]; then
${module}_post_stop
fi
done
! yesno ${IN_BACKGROUND} && \
[ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] && \
_down 2>/dev/null
# If not in background, and not loopback then bring the interface down
# unless overridden.
if ! yesno ${IN_BACKGROUND} && \
[ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
eval module=\$ifdown_${IFVAR}
module=${module:-${ifdown:-YES}}
yesno ${module} && _down 2>/dev/null
fi
type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null
if type postdown >/dev/null 2>&1; then
if [ "$(command -v "postdown")" = "postdown" ]; then
ebegin "Running postdown"
eindent
postdown

View File

@@ -23,18 +23,19 @@ depend()
{
# Only have portmap as a dependency if there is a nfs mount in fstab
# that is set to mount at boot
local pmap=""
local pmap=
if need_portmap; then
pmap="${pmap} rpc.statd"
pmap="rpc.statd"
[ -x @SYSCONFDIR@/init.d/rpcbind ] \
&& pmap="rpcbind" \
|| pmap="portmap"
&& pmap="${pmap} rpcbind" \
|| pmap="${pmap} portmap"
fi
config /etc/fstab
need net ${pmap}
use afc-client amd autofs dns nfs nfsmount portmap rpcbind rpc.statd
keyword nojail noopenvz noprefix novserver
use afc-client amd autofs openvpn
use dns nfs nfsmount portmap rpcbind rpc.statd rpc.lockd
keyword nojail noprefix novserver
}
start()

View File

@@ -26,7 +26,7 @@ start()
local usbfs=$(grep -Fow usbfs /proc/filesystems ||
grep -Fow usbdevfs /proc/filesystems)
if [ -n "${usbfs}" ]; then
ebegin "Mounting USB device filesystem (${usbfs})"
ebegin "Mounting USB device filesystem [${usbfs}]"
local usbgid="$(getent group usb | \
sed -e 's/.*:.*:\(.*\):.*/\1/')"
mount -t ${usbfs} \

View File

@@ -13,7 +13,7 @@ depend()
start()
{
if echo 2>/dev/null >/.test.$$; then
rm -f /.test.$$
rm -f /.test.$$ /fastboot /forcefsck
return 0
fi
@@ -22,5 +22,7 @@ start()
Linux) mount -n -o remount,rw /;;
*) mount -u -o rw /;;
esac
eend $? "Root filesystem could not be mounted read/write"
if eend $? "Root filesystem could not be mounted read/write"; then
rm -f /fastboot /forcefsck
fi
}

View File

@@ -49,10 +49,10 @@ start() {
local v= f=
for v in font8x16 font8x14 font8x8; do
f=$(eval \$"${v}")
eval f=\$${v}
if [ -n "${f}" ]; then
ebegin "Setting font ${f}"
vidcontrol -f ${v##FONT} ${f}
vidcontrol -f ${v##font} ${f}
eend $?
fi
done

View File

@@ -6,7 +6,7 @@ depend()
{
use hostname
before bootmisc logger
keyword noprefix
keyword noopenvz noprefix novserver
}
start()

35
init.d/termencoding.in Normal file
View File

@@ -0,0 +1,35 @@
#!@PREFIX@/sbin/runscript
# Copyright 2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
description="Configures terminal encoding."
ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
unicode=${unicode:-${UNICODE}}
depend()
{
keyword noopenvz noprefix nouml novserver noxenu
}
start()
{
local ttydev=/dev/tty n=
[ -d /dev/vc ] && ttydev=/dev/vc/
# Set terminal encoding to either ASCII or UNICODE.
# See utf-8(7) for more information.
local termencoding="%@" termmsg="ASCII"
if yesno ${unicode}; then
termencoding="%G"
termmsg="UTF-8"
fi
ebegin "Setting terminal encoding [${termmsg}]"
n=1
while [ ${n} -le "${ttyn}" ]; do
printf "\033%s" "${termencoding}" >"${ttydev}${n}"
n=$((${n} + 1))
done
eend 0
}

View File

@@ -202,4 +202,4 @@ Rinse and repeat for the other verbose functions.
.Sh SEE ALSO
.Xr printf 3 ,
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples <roy@marples.name>

View File

@@ -61,4 +61,4 @@ does the same and also prints the full path of the service to stdout.
.Xr rc 8 ,
.Xr stdout 3
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Feb 22, 2008
.Dd Arp 9, 2008
.Dt RC-STATUS 8 SMM
.Os OpenRC
.Sh NAME
@@ -36,7 +36,8 @@
.Nm
gathers and displays information about the status of services
in different runlevels. The default behavior is to show information
about the current runlevel, but any runlevel can be quickly examined.
about the current runlevel and any unassgined services that are not stopped,
but any runlevel can be quickly examined.
.Pp
The options are as follows:
.Bl -tag -width ".Fl test , test string"
@@ -60,4 +61,4 @@ Show information only for the named
.Xr rc 8 ,
.Xr rc-update 8
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -77,4 +77,4 @@ Show all services.
.Xr rc 8 ,
.Xr rc-status 8
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -74,4 +74,4 @@ Changes to the single runlevel and then halts the host.
.Xr rc-status 8 ,
.Xr rc-update 8
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples <roy@marples.name>

View File

@@ -70,4 +70,4 @@ is set to
.Xr rc_stringlist_free 3 ,
.Xr sh 1
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -110,4 +110,4 @@ when done.
.Xr rc_stringlist_free 3 ,
.Xr runscript 8
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -67,4 +67,4 @@ Each RC_PID should be freed in the list as well as the list itself when done.
.Xr free 3 ,
.Xr queue 3
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -48,4 +48,4 @@ Plugins can affect the parent environemnt by writing NULL separated strings to
.Xr rc 8 ,
.Xr runscript 8
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -63,4 +63,4 @@ Rinse and repeat for the other verbose functions.
.Xr free 3
.Xr rc_stringlist_free 3
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -31,11 +31,10 @@
.Nm rc_service_mark , rc_service_extra_commands , rc_service_plugable ,
.Nm rc_service_resolve , rc_service_schedule_start , rc_services_scheduled_by ,
.Nm rc_service_schedule_clear , rc_service_state ,
.Nm rc_service_start , rc_service_stop ,
.Nm rc_service_started_daemon , rc_service_value_get , rc_service_value_set ,
.Nm rc_services_in_runlevel , rc_services_in_state , rc_services_scheduled ,
.Nm rc_service_daemons_crashed
.Nd functions to start, stop and query OpenRC services
.Nd functions to query OpenRC services
.Sh LIBRARY
Run Command library (librc, -lrc)
.Sh SYNOPSIS
@@ -66,8 +65,6 @@ Run Command library (librc, -lrc)
.Ft "RC_STRINGLIST *" Fn rc_services_scheduled_by "const char *service"
.Ft bool Fn rc_service_schedule_clear "const char *service"
.Ft RC_SERVICE Fn rc_service_state "const char *service"
.Ft pid_t Fn rc_service_start "const char *service"
.Ft pid_t Fn rc_service_stop "const char *service"
.Ft bool Fo rc_service_started_daemon
.Fa "const char *service"
.Fa "const char *exec"
@@ -176,16 +173,6 @@ clears these scheduled services for
.Fa service .
The return value is a bitmask, where more than one state can apply.
.Pp
.Fn rc_service_start
starts
.Fa service ,
returning the pid of new process.
.Pp
.Fn rc_service_stop
stops
.Fa service ,
returning the pid of new process.
.Pp
.Fn rc_service_started_daemon
checks to see if
.Fa service
@@ -240,4 +227,4 @@ normally holds the volatile state data for services on a RAM backed disk.
.Xr rc_stringlist_free 3 ,
.Xr start-stop-daemon 8
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -85,4 +85,4 @@ itself.
.Xr queue 3 ,
.Xr strcmp 3
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Mar 19, 2008
.Dd September 19, 2008
.Dt RUNSCRIPT 8 SMM
.Os OpenRC
.Sh NAME
@@ -173,8 +173,9 @@ If
does not equal 0 then output the string using
.Ic eerror
and !! in square brackets
at the end of the line. Otherwise output ok in square brackets at the end of
the line. The value of
at the end of the line.
Otherwise output ok in square brackets at the end of the line.
The value of
.Ar retval
is returned.
.It Ic ewend Ar retval Op Ar string
@@ -193,6 +194,14 @@ output when the environment variable
.Va EINFO_VERBOSE
is true.
.Bl -tag -width indent
.It Ic ewaitfile Ar timeout Ar file1 Ar file2 ...
Wait for
.Ar timeout
seconds until all files exist.
Returns 0 if all files exist, otherwise non zero.
If
.Ar timeout
is less then 1 then we wait indefinitely.
.It Ic is_newer_than Ar file1 Ar file2 ...
If
.Ar file1
@@ -205,7 +214,7 @@ is a directory, then check all it's contents too.
.It Ic is_older_than Ar file1 Ar file2 ...
If
.Ar file1
is older than
is newer than
.Ar file2
return 0, otherwise 1.
If
@@ -432,6 +441,16 @@ show()
}
.Ed
.Sh BUGS
Because of the way we load our configuration files and the need to handle
more than one service directory, you can only use symlinks in service
directories to other services in the same directory.
You cannot symlink to a service in a different directory even if it is
another service directory.
.Pp
is_older_than should return 0 on success.
Instead we return 1 to be compliant with Gentoo baselayout.
Users are encouraged to use the is_newer_than function which returns correctly.
.Sh SEE ALSO
.Xr einfo 3 ,
.Xr rc 8 ,
@@ -442,4 +461,4 @@ show()
.Xr start-stop-daemon 8 ,
.Xr uname 1
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Feb 24, 2008
.Dd September 27, 2008
.Dt START-STOP-DAEMON 8 SMM
.Os OpenRC
.Sh NAME
@@ -44,6 +44,11 @@
.Sh DESCRIPTION
.Nm
provides a consistent method of starting, stopping and signalling daemons.
If neither
.Fl K , -stop
nor
.Fl s , -signal
are provided, then we assume we are starting the daemon.
If a daemon cannot background by itself, nor create a pidfile,
.Nm
can do it for the daemon in a secure fashion.
@@ -67,16 +72,8 @@ Here are the options to specify the daemon and how it should start or stop:
The
.Ar daemon
we start or stop.
If the
.Ar daemon
is a script and you are not using the pidfile or process name options,
then you should replace
.Ar daemon
with the interpreter and pass
.Ar daemon
as an argument. Below is an example:
.Pp
start-stop-daemon -Sx /usr/bin/perl -- /usr/bin/daemon.pl
If this option is not specified, then the first non option argument
is used.
.It Fl p , -pidfile Ar pidfile
When starting, we expect the daemon to create a valid
.Ar pidfile
@@ -97,10 +94,17 @@ name here also.
.It Fl t , -test
Print the action(s) that would be taken, but don't actually do anything.
The return value is set as if the command was taken and worked.
.It Fl v , -verbose
P
Print the action(s) that are taken just before doing them.
.El
.Pp
These options are only used for starting daemons:
.Bl -tag -width indent
.It Fl a , -startas Ar name
Change the process name of the daemon to
.Ar name .
This just changes the first argument passed to the daemon.
.It Fl b , -background
Force the daemon into the background. Some daemons don't create pidfiles, so a
good trick is to get the daemon to run in the foreground, and use the this
@@ -116,6 +120,8 @@ as the path to the daemon, chdir and pidfile, should be relative to the chroot.
Set the environment variable VAR to VALUE.
.It Fl g , -group Ar group
Start the daemon as in the group.
.It Fl k , -umask Ar mode
Set the umask of the daemon.
.It Fl m , -make-pidfile
Saves the pid of the daemon in the file specified by the
.Fl p , -pidfile
@@ -145,6 +151,16 @@ stopping schedule.
If not specified then a default value of SIGTERM/5 is
assumed.
.El
.Sh ENVIRONMENT
.Va SSD_NICELEVEL
can also set the scheduling priority of the daemon, but the command line
option takes precedence.
.Pp
.Va SSD_STARTWAIT
overrides the number of milliseconds set in
.Pa /etc/rc.conf
.Nm
waits for to check the daemon is still running.
.Sh NOTE
.Nm
uses
@@ -159,6 +175,9 @@ to stop or signal.
.Xr getopt 3 ,
.Xr nice 2 ,
.Xr rc_find_pids 3
.Sh BUGS
.Nm
cannot stop an interperted daemon that no longer exists without a pidfile.
.Sh HISTORY
.Nm
first appeared in Debian.
@@ -166,4 +185,4 @@ first appeared in Debian.
This is a complete re-implementation with the process finding code in the
OpenRC library (librc, -lrc) so other programs can make use of it.
.Sh AUTHORS
.An "Roy Marples" Aq roy@marples.name
.An Roy Marples" <roy@marples.name>

View File

@@ -1,5 +1,4 @@
# Copyright 2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
# Setup some good default CFLAGS
CFLAGS?= -O2
@@ -10,15 +9,25 @@ _CSTD_SH= if test -n "${CSTD}"; then echo "-std=${CSTD}"; else echo ""; fi
_CSTD!= ${_CSTD_SH}
CFLAGS+= ${_CSTD}$(shell ${_CSTD_SH})
# Try and use some good cc flags
_CC_FLAGS= -pedantic -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
-Wbad-function-cast -Wnested-externs -Wcomment -Winline \
-Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
-Wdeclaration-after-statement -Wsequence-point -Wextra
_CC_FLAGS_SH= for f in ${_CC_FLAGS}; do \
if ${CC} $$f -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
# Try and use some good cc flags if we're building from git
# We don't use -pedantic as it will warn about our perfectly valid
# use of %m in our logger.
_CCFLAGS= -Wall -Wextra -Wimplicit -Wshadow -Wformat=2 \
-Wmissing-prototypes -Wmissing-declarations \
-Wmissing-noreturn -Wmissing-format-attribute \
-Wnested-externs \
-Winline -Wwrite-strings -Wcast-align -Wcast-qual \
-Wpointer-arith \
-Wdeclaration-after-statement -Wsequence-point
# We should be using -Wredundant-decls, but our library hidden proto stuff
# gives loads of warnings. I don't fully understand it (the hidden proto,
# not the warning) so we just silence the warning.
_CC_FLAGS_SH= for f in ${_CCFLAGS}; do \
if echo "int main(void) { return 0;} " | \
${CC} $$f -S -xc -o /dev/null - ; \
then printf "%s" "$$f "; fi \
done
done;
_CC_FLAGS!= ${_CC_FLAGS_SH}
CFLAGS+= ${_CC_FLAGS}$(shell ${CC_FLAGS_SH})
CFLAGS+= ${_CC_FLAGS}$(shell ${_CC_FLAGS_SH})

View File

@@ -4,7 +4,7 @@
_RC_DEBUG_SH= case "${DEBUG}" in "") echo "";; *) echo "-DRC_DEBUG";; esac
_RC_DEBUG!= ${_RC_DEBUG_SH}
CFLAGS+= ${_RC_DEBUG}$(shell ${_RC_DEBUG_SH})
CPPFLAGS+= ${_RC_DEBUG}$(shell ${_RC_DEBUG_SH})
# Should we enable this with a different flag?
_LD_DEBUG_SH= case "${DEBUG}" in "") echo "";; *) echo "-Wl,--rpath=../librc -Wl,--rpath=../libeinfo";; esac

View File

@@ -8,6 +8,6 @@ CLEANFILES+= .depend
IGNOREFILES+= .depend
.depend: ${SRCS}
${CC} ${CFLAGS} -MM ${SRCS} > .depend
${CC} ${CPPFLAGS} -MM ${SRCS} > .depend
depend: .depend

View File

@@ -17,7 +17,7 @@ CLEANFILES+= ${OBJS} ${SOBJS} ${_LIBS} ${SHLIB_LINK}
.SUFFIXES: .So
.c.So:
${CC} ${PICFLAG} -DPIC ${CFLAGS} -c $< -o $@
${CC} ${PICFLAG} -DPIC ${CPPFLAGS} ${CFLAGS} -c $< -o $@
all: depend ${_LIBS}

View File

@@ -1,3 +1,3 @@
LIBTERMCAP?= -lncurses
CFLAGS+= -DHAVE_TERMCAP
CPPFLAGS+= -DHAVE_TERMCAP
LDADD+= ${LIBTERMCAP}

View File

@@ -1,5 +1,5 @@
# Copyright 2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
CFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=600
CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=600
LIBDL= -Wl,-Bdynamic -ldl

View File

@@ -10,14 +10,3 @@ include ${MK}/os-${OS}.mk
RC_LIB= /$(LIBNAME)/rc
_PREFIX_SH= if test -n "${PREFIX}" && test "${PREFIX}" != "/"; then echo "-DPREFIX=\\\"${PREFIX}\\\""; else echo ""; fi
_PREFIX!= ${_PREFIX_SH}
CFLAGS+= ${_PREFIX}$(shell ${_PREFIX_SH})
_PKG_PREFIX_SH= if test -n "${PKG_PREFIX}" && test "${PKG_PREFIX}" != "/" && test "${PKG_PREFIX}" != "${PREFIX}"; then echo "-DPKG_PREFIX=\\\"${PKG_PREFIX}\\\""; else echo ""; fi
_PKG_PREFIX!= ${_PKG_PREFIX_SH}
CFLAGS+= ${_PKG_PREFIX}$(shell ${_PKG_PREFIX_SH})
_LCL_PREFIX_SH= if test -n "${LOCAL_PREFIX}" && test "${LOCAL_PREFIX}" != "/" && test "${LOCAL_PREFIX}" != "${PREFIX}"; then echo "-DLOCAL_PREFIX=\\\"${LOCAL_PREFIX}\\\""; else echo ""; fi
_LCL_PREFIX!= ${_LCL_PREFIX_SH}
CFLAGS+= ${_LCL_PREFIX}$(shell ${_LCL_PREFIX_SH})

View File

@@ -1,5 +1,5 @@
LIBPAM?= -lpam
CFLAGS+= -DHAVE_PAM
CPPFLAGS+= -DHAVE_PAM
LDADD+= ${LIBPAM}
PAMDIR?= /etc/pam.d

View File

@@ -24,6 +24,9 @@ CLEANFILES+= ${OBJS} ${PROG}
all: depend ${PROG}
.c.o:
${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
${PROG}: ${SCRIPTS} ${OBJS}
${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}

View File

@@ -22,9 +22,9 @@ SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR
.in:
${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
all: ${OBJS}
all: ${OBJS} ${TARGETS}
realinstall: ${BIN} ${CONF} ${CONF_APPEND}
realinstall: ${BIN} ${CONF} ${INC}
@if test -n "${DIR}"; then \
${ECHO} ${INSTALL} -d ${DESTDIR}/${DIR}; \
${INSTALL} -d ${DESTDIR}/${DIR} || exit $$?; \

View File

@@ -1,3 +1,3 @@
LIBTERMCAP?= -ltermcap
CFLAGS+= -DHAVE_TERMCAP
CPPFLAGS+= -DHAVE_TERMCAP
LDADD+= ${LIBTERMCAP}

View File

@@ -4,7 +4,6 @@
bonding_depend()
{
before interface macchanger
program /sbin/ifenslave
}
_config_vars="$_config_vars slaves"
@@ -16,7 +15,7 @@ _is_bond()
bonding_pre_start()
{
local s= slaves="$(_get_array "slaves_${IFVAR}")"
local x= s= slaves="$(_get_array "slaves_${IFVAR}")"
[ -z "${slaves}" ] && return 0
@@ -40,6 +39,16 @@ bonding_pre_start()
return 1
fi
# Configure the bond.
# Nice and dynamic :)
for x in /sys/class/net/"${IFACE}"/bonding/*; do
[ -f "${x}" ] || continue
eval s=\$${x##*/}_${IFVAR}
if [ -n "${s}" ]; then
echo "${s}" >"${x}"
fi
done
ebegin "Adding slaves to ${IFACE}"
eindent
einfo "${slaves}"
@@ -53,7 +62,7 @@ bonding_pre_start()
# Must force the slaves to a particular state before adding them
for IFACE in ${slaves}; do
_delete_addresses
_up
_down
done
)
@@ -62,7 +71,13 @@ bonding_pre_start()
# finally add in slaves
eoutdent
/sbin/ifenslave "${IFACE}" ${slaves} >/dev/null
if [ -d /sys/class/net ]; then
for s in ${slaves}; do
echo "+${s}" >/sys/class/net/"${IFACE}"/bonding/slaves
done
else
/sbin/ifenslave "${IFACE}" ${slaves} >/dev/null
fi
eend $?
return 0 #important
@@ -84,7 +99,13 @@ bonding_stop()
eindent
einfo "${slaves}"
eoutdent
/sbin/ifenslave -d "${IFACE}" ${slaves}
if [ -d /sys/class/net ]; then
for s in ${slaves}; do
echo -"${s}" > /sys/class/net/"${IFACE}"/bonding/slaves
done
else
/sbin/ifenslave -d "${IFACE}" ${slaves}
fi
# reset all slaves
(

View File

@@ -16,12 +16,15 @@ _is_bridge()
bridge_pre_start()
{
local ports= brif= iface="${IFACE}" e= x=
local brif= iface="${IFACE}" e= x=
local ports="$(_get_array "bridge_${IFVAR}")"
local opts="$(_get_array "brctl_${IFVAR}")"
eval brif=\$bridge_add_${IFVAR}
[ -z "${ports}" -a -z "${brif}" -a -z "${opts}" ] && return 0
eval x=\${bridge_${IFVAR}-y\}
if [ -z "${brif}" -a -z "${opts}" ]; then
[ -n "${ports}" -o "${x}" != "y" ] || return 0
fi
[ -n "${ports}" ] && bridge_post_stop

View File

@@ -15,20 +15,42 @@ _config_vars="$_config_vars dhcp dhcpcd"
dhcpcd_start()
{
local args= opt= opts= pidfile="/var/run/dhcpcd-${IFACE}.pid"
local args= opt= opts= pidfile="/var/run/dhcpcd-${IFACE}.pid" new=true
eval args=\$dhcpcd_${IFVAR}
[ -z "${args}" ] && args=${dhcpcd}
# Get our options
eval opts=\$dhcp_${IFVAR}
[ -z "${opts}" ] && opts=${dhcp}
case "$(dhcpcd --version)" in
"dhcpcd "[123]*) new=false;;
esac
# Map some generic options to dhcpcd
for opt in ${opts}; do
case "${opt}" in
nodns) args="${args} -R";;
nontp) args="${args} -N";;
nonis) args="${args} -Y";;
nodns)
if ${new}; then
args="${args} -C resolv.conf"
else
args="${args} -R"
fi
;;
nontp)
if ${new}; then
args="${args} -C ntp.conf"
else
args="${args} -N"
fi
;;
nonis)
if ${new}; then
args="${args} -C yp.conf"
else
args="${args} -Y"
fi
;;
nogateway) args="${args} -G";;
nosendhost) args="${args} -h ''";
esac

View File

@@ -151,9 +151,12 @@ _delete_addresses()
{
einfo "Removing addresses"
eindent
LC_ALL=C ifconfig "${IFACE}" | while read inet address rest; do
LC_ALL=C ifconfig "${IFACE}" | while read inet address ali rest; do
case "${inet}" in
inet|inet6)
if [ "${address}" = "alias" ]; then
address="${ali}"
fi
case "${address}" in
*"%${IFACE}"|::1) continue;;
127.0.0.1) [ "${IFACE}" = "lo0" ] && continue;;

View File

@@ -56,7 +56,7 @@ _set_flag()
_get_mac_address()
{
local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
sed -n -e 's/.* HWaddr \(..:..:..:..:..:..\).*/\1/p')
sed -n -e 's/.* \(HWaddr\|ether\) \(..:..:..:..:..:..\).*/\2/p')
case "${mac}" in
00:00:00:00:00:00);;
@@ -77,7 +77,7 @@ _set_mac_address()
_get_inet_address()
{
set -- $(LC_ALL=C ifconfig "${IFACE}" |
sed -n -e 's/.*inet addr:\([^ ]*\).*Mask:\([^ ]*\).*/\1 \2/p')
sed -n -e 's/.*\(inet addr:\|inet \)\([^ ]*\).*\(Mask:\|netmask \)\([^ ]*\).*/\2 \4/p')
[ -z "$1" ] && return 1
echo -n "$1"
@@ -145,7 +145,7 @@ _add_address()
# IPv4 is tricky - ifconfig requires an aliased device
# for multiple addresses
local iface="${IFACE}"
if LC_ALL=C ifconfig "${iface}" | grep -Eq "\<inet addr:.*"; then
if LC_ALL=C ifconfig "${iface}" | grep -Eq '\<inet (addr:)?.*'; then
# Get the last alias made for the interface and add 1 to it
i=$(ifconfig | sed '1!G;h;$!d' | grep -m 1 -o "^${iface}:[0-9]*" \
| sed -n -e 's/'"${iface}"'://p')
@@ -234,8 +234,12 @@ _delete_addresses()
# Remove IPv6 addresses
local addr=
for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
sed -n -e 's/^.*inet6 addr: \([^ ]*\) Scope:[^L].*/\1/p'); do
[ "${addr}" = "::1/128" -a "${IFACE}" = "lo" ] && continue
sed -n -e 's/^.*\(inet6 addr:\|inet6\) \([^ ]*\) .*\(Scope:[^L]\|scopeid [^<]*<[^l]\).*/\2/p'); do
if [ "${IFACE}" = "lo" ]; then
case "${addr}" in
"::1/128"|"/128") continue;;
esac
fi
einfo "${addr}"
ifconfig "${IFACE}" inet6 del "${addr}"
done

View File

@@ -54,7 +54,6 @@ ifwatchd_stop()
ebegin "Stopping ifwatchd on" "${IFACE}"
start-stop-daemon --stop --exec /usr/sbin/ifwatchd \
-- -c "${RC_LIBDIR}/sh/ifwatchd-carrier.sh" \
-n "${RC_LIBDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" \
&& return 0
-n "${RC_LIBDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}"
eend $?
}

View File

@@ -10,12 +10,12 @@ iproute2_depend()
_up()
{
ip link set up dev "${IFACE}"
ip link set "${IFACE}" up
}
_down()
{
ip link set down dev "${IFACE}"
ip link set "${IFACE}" down
}
_exists()
@@ -78,7 +78,7 @@ _get_mac_address()
_set_mac_address()
{
ip link set address "$1" dev "${IFACE}"
ip link set "${IFACE}" address "$1"
}
_get_inet_addresses()
@@ -126,7 +126,7 @@ _add_address()
;;
esac
ip addr add dev "${IFACE}" "$@"
ip addr add "$@" dev "${IFACE}"
}
_add_route()
@@ -184,12 +184,12 @@ iproute2_pre_start()
# MTU support
local mtu=
eval mtu=\$mtu_${IFVAR}
[ -n "${mtu}" ] && ip link set mtu "${mtu}" dev "${IFACE}"
[ -n "${mtu}" ] && ip link set "${IFACE}" mtu "${mtu}"
# TX Queue Length support
local len=
eval len=\$txqueuelen_${IFVAR}
[ -n "${len}" ] && ip link set txqueuelen "${len}" dev "${IFACE}"
[ -n "${len}" ] && ip link set "${IFACE}" txqueuelen "${len}"
local tunnel=
eval tunnel=\$iptunnel_${IFVAR}
@@ -208,6 +208,8 @@ iproute2_pre_start()
_iproute2_ipv6_tentative()
{
# Only check tentative when we have a carrier.
LC_ALL=C ip link show dev "${IFACE}" | grep -q "NO-CARRIER" && return 1
LC_ALL=C ip addr show dev "${IFACE}" | \
grep -q "^[[:space:]]*inet6 .* tentative"
}

View File

@@ -414,8 +414,9 @@ iwconfig_connect_preferred()
[ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
[ $# = 0 ] && return 1
local ssid= i=0 mode= mac= caps= freq= chan=
local ssid= i= mode= mac= caps= freq= chan=
for ssid; do
i=0
while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i}
if [ "${e}" = "${ssid}" ] ; then
@@ -484,7 +485,7 @@ iwconfig_defaults()
iwconfig_configure()
{
local x APS
local x= APS=-1
eval SSID=\$ssid_${IFVAR}
# Setup ad-hoc mode?

View File

@@ -206,9 +206,13 @@ iwconfig_wait_for_association()
# Use sysfs if we can
if [ -e /sys/class/net/"${IFACE}"/carrier ]; then
if [ "$(cat /sys/class/net/"${IFACE}"/carrier)" = "1" ]; then
# Double check we have an ssid. This is mainly for buggy
# prism54 drivers that always set their carrier on :/
[ -n "$(iwgetid --raw "${IFACE}")" ] && return 0
# Double check we have an ssid and a non-zero
# mac address. This is mainly for buggy
# prism54 drivers that always set their
# carrier on or buggy madwifi drivers that
# sometimes have carrier on and ssid set
# without being associated. :/
[ -n "$(iwgetid --raw "${IFACE}")" ] && [ "$(iwgetid --ap --raw "${IFACE}")" != "00:00:00:00:00:00" ] && return 0
fi
else
local atest=
@@ -429,7 +433,7 @@ iwconfig_scan()
[ -z "${a}" ] && break
eval b=\$QUALITY_${k}
if [ -n "${b}" -a "${a}" -lt "${b}" ]; then
for x in MAC SSID CHAN QUALITY ENC; do
for x in MAC SSID MODE CHAN QUALITY ENC; do
eval t=\$${x}_${i}
eval ${x}_${i}=\$${x}_${k}
eval ${x}_${k}=\$t
@@ -453,7 +457,7 @@ iwconfig_scan()
local u=${k}
# We need to split this into two tests, otherwise bash errors
[ -n "${a}" -a -n "${b}" ] && [ "${a}" -lt "${b}" ] && u=${i}
unset MAC_${u} SSID_${u} CHAN_${u} QUALITY_${u} ENC_${u}
unset MAC_${u} SSID_${u} MODE_${u} CHAN_${u} QUALITY_${u} ENC_${u}
fi
k=$((${k} + 1))
done
@@ -499,7 +503,7 @@ iwconfig_scan()
for x; do
if [ "${x}" = "${s}" ]; then
ewarn "${s} has been blacklisted - not connecting"
unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} ENC_${i}
unset SSID_${i} MAC_${i} ${MODE}_${i} CHAN_${i} QUALITY_${i} ENC_${i}
fi
done
i=$((${i} + 1))
@@ -525,7 +529,7 @@ iwconfig_force_preferred()
i=$((${i} + 1))
done
if ! ${found_AP}; then
SSID=${e}
SSID=${ssid}
iwconfig_associate && return 0
fi
done
@@ -597,10 +601,8 @@ iwconfig_connect_not_preferred()
iwconfig_defaults()
{
local x=
for x in txpower rate rts frag; do
iwconfig "${IFACE}" "${x}" auto 2>/dev/null
done
# Turn on the radio
iwconfig "${IFACE}" txpower on 2>/dev/null
# Release the AP forced
# Must do ap and then ssid otherwise scanning borks
@@ -610,7 +612,7 @@ iwconfig_defaults()
iwconfig_configure()
{
local x= APS=
local x= APS=-1
eval SSID=\$ssid_${IFVAR}
# Support old variable
@@ -735,7 +737,7 @@ iwconfig_pre_start()
# which reports NOT READY!
x="$(iwconfig_get_type)"
if [ "${x}" = "NOT READY!" ]; then
eerror "Looks like there was a probem loading the firmware for ${IFACE}"
eerror "Looks like there was a problem loading the firmware for ${IFACE}"
return 1
fi

View File

@@ -58,8 +58,8 @@ _system_ntp()
local servers= buffer= x=
eval servers=\$ntp_servers_${IFVAR}
[ -z ${servers} ] && servers=${ntp_servers}
[ -z ${servers} ] && return 0
[ -z "${servers}" ] && servers=${ntp_servers}
[ -z "${servers}" ] && return 0
buffer="# Generated by net-scripts for interface ${IFACE}\n"
buffer="${buffer}restrict default noquery notrust nomodify\n"

View File

@@ -66,7 +66,7 @@ vlan_pre_start()
vlan_post_start()
{
local vlans=
eval vlans=\$vlans_${IFACE}
eval vlans=\$vlans_${IFVAR}
[ -z "${vlans}" ] && return 0
_check_vlan || return 1
@@ -86,13 +86,13 @@ vlan_post_start()
yesno ${s:-yes} || continue
# We need to work out the interface name of our new vlan id
local ifname="$( \
sed -n -e 's/^\([^[:space:]]*\) *| '"${vlan}"' *| .*'"${iface}"'$/\1/p' \
local ifname="$(sed -n -e \
's/^\([^[:space:]]*\) *| '"${vlan}"' *| .*'"${iface}"'$/\1/p' \
/proc/net/vlan/config )"
mark_service_started "net.${ifname}"
(
export RC_SVCNAME="net.${ifname}"
start
start
) || mark_service_stopped "net.${ifname}"
done

View File

@@ -78,11 +78,9 @@ wpa_supplicant_pre_start()
service_set_value "SSID" ""
ebegin "Starting wpa_supplicant on ${IFVAR}"
if [ -x /sbin/iwconfig ]; then
local x=
for x in txpower rate rts frag; do
iwconfig "${IFACE}" "${x}" auto 2>/dev/null
done
if type iwconfig_defaults >/dev/null 2>&1; then
iwconfig_defaults
iwconfig_user_config
fi
cfgfile=${opts##* -c}

View File

@@ -6,6 +6,8 @@ LEVELDIR= ${DESTDIR}/${SYSCONFDIR}/runlevels
BOOTDIR= ${LEVELDIR}/boot
DEFAULTDIR= ${LEVELDIR}/default
INITDIR= ../init.d
MK= ../mk
include ${MK}/sys.mk
include ${MK}/os.mk
@@ -19,7 +21,8 @@ install:
${INSTALL} -d ${BOOTDIR} || exit $$?; \
for x in ${BOOT}; do \
if test -n "${PREFIX}"; then \
grep -q "keyword .*noprefix" ${SYSCONFDIR}/init.d/"$$x" && continue; \
test "$$x" = "net.lo" -o "$$x" = "net.lo0" && continue; \
grep -q "keyword .*noprefix" ${INITDIR}/"$$x" && continue; \
fi; \
ln -snf ${PREFIX}/etc/init.d/"$$x" ${BOOTDIR}/"$$x" || exit $$?; \
done \
@@ -28,7 +31,7 @@ install:
${INSTALL} -d ${DEFAULTDIR} || exit $$?; \
for x in ${DEFAULT}; do \
if test -n "${PREFIX}"; then \
grep -q "keyword .*noprefix" ${SYSCONFDIR}/init.d/"$$x" && continue; \
grep -q "keyword .*noprefix" ${INITDIR}/"$$x" && continue; \
fi; \
ln -snf ${PREFIX}/etc/init.d/"$$x" ${DEFAULTDIR}/"$$x" || exit $$?; done \
fi

View File

@@ -1,2 +1,2 @@
BOOT+= hwclock consolefont keymaps modules mtab net.lo procfs
DEFAULT+= hdparm
BOOT+= hwclock consolefont keymaps modules mtab net.lo procfs \
termencoding

View File

@@ -2,4 +2,4 @@
BOOT+= hostid net.lo0 newsyslog savecore syslogd
# NetBSD specific stuff
BOOT+= swap-blk ttys wscons
BOOT+= devdb swap-blk ttys wscons

4
sh/.gitignore vendored
View File

@@ -3,4 +3,8 @@ gendepends.sh
net.sh
rc-functions.sh
runscript.sh
init-common-post.sh
init-early.sh
init.sh
ifwatchd-carrier.sh
ifwatchd-nocarrier.sh

View File

@@ -1,8 +1,8 @@
DIR= ${PREFIX}/${RC_LIB}/sh
SRCS= functions.sh.in gendepends.sh.in net.sh.in \
SRCS= functions.sh.in gendepends.sh.in init-common-post.sh.in \
rc-functions.sh.in runscript.sh.in
INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh
BIN= gendepends.sh init.sh net.sh runscript.sh
BIN= gendepends.sh init.sh runscript.sh
INSTALLAFTER= _installafter
@@ -13,8 +13,6 @@ include ${MK}/scripts.mk
_installafter:
${INSTALL} -d ${DESTDIR}/${INITDIR}
@# Provide an init script for the loopback interface
ln -snf ${PREFIX}/${RC_LIB}/sh/net.sh ${DESTDIR}/${INITDIR}/${NET_LO} || exit $$?
@# Put functions.sh into the init.d dir so 3rd party apps don't have to
@# be multilib aware
ln -snf ${PREFIX}/${RC_LIB}/sh/functions.sh ${DESTDIR}/${INITDIR} || exit $$?

View File

@@ -1,7 +1,5 @@
SRCS+= init.sh.in
NET_LO= net.lo0
.SUFFIXES: .sh.BSD.in
.sh.BSD.in.sh:
${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@

View File

@@ -1,4 +1,3 @@
NET_LO= net.lo
SRCS+= init.sh.in init-early.sh.in
BIN+= init-early.sh

View File

@@ -1,6 +1,5 @@
SRCS+= init.sh.in
NET_LO= net.lo0
SRCS+= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
BIN+= ifwatchd-carrier.sh ifwatchd-nocarrier.sh

View File

@@ -38,12 +38,17 @@ yesno()
esac
}
rc_runlevel() {
rc-status --runlevel
}
_sanitize_path()
{
local IFS=":" p= path=
for p in ${PATH}; do
case "${p}" in
@PREFIX@/lib/rc/sbin|@PREFIX@/bin|@PREFIX@/sbin|/usr/bin|/usr/sbin);;
@PREFIX@/@LIB@/rc/bin|@PREFIX@/@LIB@/rc/sbin);;
@PREFIX@/bin|@PREFIX@/sbin|/usr/bin|/usr/sbin);;
@PKG_PREFIX@/bin|@PKG_PREFIX@/sbin);;
@LOCAL_PREFIX@/bin|@LOCAL_PREFIX@/sbin);;
*) path="${path}${path:+:}${p}";;
@@ -66,7 +71,7 @@ _PREFIX=@PREFIX@
_PKG_PREFIX=@PKG_PREFIX@
_LOCAL_PREFIX=@LOCAL_PREFIX@
_LOCAL_PREFIX=${_LOCAL_PREFIX:-/usr/local}
_PATH=@PREFIX@/lib/rc/bin
_PATH=@PREFIX@/@LIB@/rc/bin
case "${_PREFIX}" in
"${_PKG_PREFIX}"|"${_LOCAL_PREFIX}") ;;
*) _PATH="${_PATH}:${_PREFIX}/bin:${_PREFIX}/sbin";;
@@ -79,8 +84,9 @@ fi
if [ -n "${_LOCAL_PREFIX}" ]; then
_PATH="${_PATH}:${_LOCAL_PREFIX}/bin:${_LOCAL_PREFIX}/sbin"
fi
export PATH="${_PATH}:$(_sanitize_path "${PATH}")"
unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH
_path="$(_sanitize_path "${PATH}")"
export PATH="${_PATH}${_path:+:}${_path}"
unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH _path
for arg; do
case "${arg}" in
@@ -99,7 +105,7 @@ else
# the last ecmd
for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \
vebegin veend veinfo vewarn vewend; do
eval "${_e}() { local _r; @PREFIX@/lib/rc/bin/${_e} \"\$@\"; _r=$?; \
eval "${_e}() { local _r; @PREFIX@/@LIB@/rc/bin/${_e} \"\$@\"; _r=$?; \
export EINFO_LASTCMD=${_e}; return \$_r; }"
done
unset _e

View File

@@ -48,12 +48,14 @@ do
cd "${_dir}"
for RC_SERVICE in *; do
[ -x "${RC_SERVICE}" ] || continue
[ -x "${RC_SERVICE}" -a -f "${RC_SERVICE}" ] || continue
# Only generate dependencies for runscripts
read one two < "${RC_SERVICE}"
[ "${one}" = "#!@PREFIX@/sbin/runscript" ] || continue
unset one two
read one two three < "${RC_SERVICE}"
[ "${one}" = "#!@PREFIX@/sbin/runscript" ] || \
[ "${one}" = "#!" -a "${two}" = "@PREFIX@/sbin/runscript" ] || \
continue
unset one two three
export RC_SVCNAME=${RC_SERVICE##*/}

View File

@@ -6,9 +6,10 @@ retval=0
# mount $svcdir as something we can write to if it's not rw
# On vservers, / is always rw at this point, so we need to clean out
# the old service state data
RC_SVCDIR=${RC_SVCDIR:-/@LIB@/rc/init.d}
if [ "${RC_SVCDIR}" != "/" ] && mkdir "${RC_SVCDIR}/.test.$$" 2>/dev/null; then
rmdir "${RC_SVCDIR}/.test.$$"
for x in ${RC_SVCDIR:-/lib/rc/init.d}/*; do
for x in ${RC_SVCDIR}/*; do
[ -e "${x}" ] || continue
case ${x##*/} in
depconfig|deptree|ksoftlevel|rc.log);;

View File

@@ -96,6 +96,9 @@ if ${mountproc}; then
fi
unset mountproc
# Re-load RC_SYS if empty now we have /proc mounted
[ -z "${RC_SYS}" ] && export RC_SYS="$(rc --sys)"
# Read off the kernel commandline to see if there's any special settings
# especially check to see if we need to set the CDBOOT environment variable
# Note: /proc MUST be mounted
@@ -105,8 +108,7 @@ if [ -r /sbin/livecd-functions.sh ]; then
fi
if [ "${RC_UNAME}" != "GNU/kFreeBSD" \
-a "${RC_SYS}" != "VSERVER" \
-a "${RC_SYS}" != "OPENVZ" ]
-a "${RC_SYS}" != "VSERVER" ];
then
if grep -Eq "[[:space:]]+sysfs$" /proc/filesystems; then
if [ -d /sys ]; then
@@ -123,10 +125,14 @@ then
fi
fi
# Default OpenVZ to static devices
if [ "${RC_SYS}" = "OPENVZ" ]; then
rc_devices=${rc_devices:-static}
fi
# Try to figure out how the user wants /dev handled
if [ "${rc_devices}" = "static" \
-o "${RC_SYS}" = "VSERVER" \
-o "${RC_SYS}" = "OPENVZ" \
-o "${RC_UNAME}" = "GNU/kFreeBSD" ]
then
ebegin "Using existing device nodes in /dev"

View File

@@ -4,15 +4,15 @@
has_addon()
{
[ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ]
[ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /@LIB@/rcscripts/addons/"$1".sh ]
}
import_addon()
{
if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then
. "${RC_LIBDIR}/addons/$1.sh"
elif [ -e /lib/rcscripts/addons/"$1".sh ]; then
. /lib/rcscripts/addons/"$1".sh
elif [ -e /@LIB@/rcscripts/addons/"$1".sh ]; then
. /@LIB@/rcscripts/addons/"$1".sh
else
return 1
fi
@@ -58,6 +58,7 @@ get_bootparam()
set -- $(cat /proc/cmdline)
while [ -n "$1" ]; do
[ "$1" = "${match}" ] && return 0
case "$1" in
gentoo=*)
local params="${1##*=}"
@@ -75,6 +76,6 @@ get_bootparam()
# Add our sbin to $PATH
case "${PATH}" in
@PREFIX@/lib/rc/sbin|@PREFIX@/lib/rc/sbin:*);;
*) export PATH="@PREFIX@/lib/rc/sbin:${PATH}";;
"${RC_LIBDIR}"/sbin|"${RC_LIBDIR}"/sbin:*);;
*) export PATH="${RC_LIBDIR}/sbin:${PATH}";;
esac

View File

@@ -20,6 +20,7 @@ fi
# So daemons know where to recall us if needed
export RC_SERVICE="$1"
shift
# Compat
export SVCNAME=${RC_SVCNAME}
@@ -44,9 +45,49 @@ describe()
done
}
# Template start / stop functions
start()
{
[ -n "${command}" ] || return 0
local _background=
ebegin "Starting ${name:-${RC_SVCNAME}}"
if yesno "${command_background}"; then
_background="--background --pidfile"
fi
if yesno "${start_inactive}"; then
local _inactive=false
service_inactive && _inactive=true
mark_service_inactive
fi
start-stop-daemon --start \
--exec ${command} \
${procname:+--name} ${procname} \
${pidfile:+--pidfile} ${pidfile} \
${_background} ${start_stop_daemon_args} \
-- ${command_args}
eend $? "Failed to start ${RC_SVCNAME}" && return 0
if yesno "${start_inactive}"; then
if ! ${_inactive}; then
mark_service_stopped
fi
fi
return 1
}
stop()
{
[ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ] || return 0
ebegin "Stopping ${name:-${RC_SVCNAME}}"
start-stop-daemon --stop \
${command:+--exec} ${command} \
${procname:+--name} ${procname} \
${pidfile:+--pidfile} ${pidfile}
eend $? "Failed to stop ${RC_SVCNAME}"
}
yesno ${RC_DEBUG} && set -x
_conf_d=${1%/*}/../conf.d
_conf_d=${RC_SERVICE%/*}/../conf.d
# If we're net.eth0 or openvpn.work then load net or openvpn config
_c=${RC_SVCNAME%%.*}
if [ -n "${_c}" -a "${_c}" != "${RC_SVCNAME}" ]; then
@@ -73,8 +114,7 @@ unset _conf_d
[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}}
# Load our script
. $1
shift
. "${RC_SERVICE}"
for _d in ${required_dirs}; do
if [ ! -d ${_d} ]; then
@@ -92,58 +132,12 @@ for _f in ${required_files}; do
done
unset _f
# If we have a default command then supply a default start function
if [ -n "${command}" ]; then
if ! type start >/dev/null 2>&1; then
start() {
local _background=
ebegin "Starting ${name:-${RC_SVCNAME}}"
if yesno "${command_background}"; then
_background="--background --pidfile"
fi
if yesno "${start_inactive}"; then
local _inactive=false
service_inactive && _inactive=true
mark_service_inactive
fi
start-stop-daemon --start \
--exec ${command} \
${procname:+--name} ${procname} \
${pidfile:+--pidfile} ${pidfile} \
${_background} ${start_stop_daemon_args} \
-- ${command_args}
eend $? "Failed to start ${RC_SVCNAME}" && return 0
if yesno "${start_inactive}"; then
if ! ${_inactive}; then
mark_service_stopped
fi
fi
return 1
}
fi
fi
# If we have a default command, procname or pidfile then supply a default stop
# function
if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then
if ! type stop >/dev/null 2>&1; then
stop() {
ebegin "Stopping ${name:-${RC_SVCNAME}}"
start-stop-daemon --stop \
${command:+--exec} ${command} \
${procname:+--name} ${procname} \
${pidfile:+--pidfile} ${pidfile}
eend $? "Failed to stop ${RC_SVCNAME}"
}
fi
fi
while [ -n "$1" ]; do
# See if we have the required function and run it
for _cmd in describe start stop ${extra_commands:-${opts}} \
${extra_started_commands}; do
if [ "${_cmd}" = "$1" ]; then
if type "$1" >/dev/null 2>&1; then
if [ "$(command -v "$1")" = "$1" ]; then
# If we're in the background, we may wish to
# fake some commands. We do this so we can
# "start" ourselves from inactive which then
@@ -168,11 +162,11 @@ while [ -n "$1" ]; do
fi
done
unset _cmd
if type "$1"_pre >/dev/null 2>&1; then
if [ "$(command -v "$1_pre")" = "$1_pre" ]; then
"$1"_pre || exit $?
fi
"$1" || exit $?
if type "$1"_post >/dev/null 2>&1; then
if [ "$(command -v "$1_post")" = "$1_post" ]; then
"$1"_post || exit $?
fi
shift

View File

@@ -9,17 +9,17 @@ tret=0
ebegin "Testing yesno()"
for f in yes YES Yes true TRUE True 1 ; do
if ! yesno ${f} ; then
((tret+=1))
tret=$((${tret} + 1))
echo "!${f}!"
fi
done
for f in no NO No false FALSE False 0 ; do
if yesno ${f} ; then
((tret+=1))
tret=$(({$tret} + 1))
echo "!${f}!"
fi
done
eend ${tret}
((ret+=tret))
ret=$((${ret} + ${tret}))
exit ${ret}

View File

@@ -37,45 +37,10 @@
#include <stdbool.h>
#include <string.h>
#ifndef LIB
# define LIB "lib"
#endif
#ifdef PREFIX
# define RC_PREFIX PREFIX
#else
# define RC_PREFIX
#endif
#ifndef SYSCONFDIR
# define SYSCONFDIR RC_PREFIX "/etc"
#endif
#define RC_LEVEL_BOOT "boot"
#define RC_LEVEL_DEFAULT "default"
#define RC_LIBDIR RC_PREFIX "/" LIB "/rc"
#define RC_SVCDIR RC_LIBDIR "/init.d"
#define RC_DEPTREE_CACHE RC_SVCDIR "/deptree"
#define RC_RUNLEVELDIR SYSCONFDIR "/runlevels"
#define RC_INITDIR SYSCONFDIR "/init.d"
#define RC_CONFDIR SYSCONFDIR "/conf.d"
/* PKG_PREFIX is where packages are installed if different from the base OS
* On Gentoo this is normally unset, on FreeBSD /usr/local and on NetBSD
* /usr/pkg. */
#ifdef PKG_PREFIX
# define RC_PKG_INITDIR PKG_PREFIX "/etc/init.d"
# define RC_PKG_CONFDIR PKG_PREFIX "/etc/conf.d"
#endif
/* LOCAL_PREFIX is for user written stuff, which the base OS and package
* manger don't touch. */
#ifdef LOCAL_PREFIX
# define RC_LOCAL_INITDIR LOCAL_PREFIX "/etc/init.d"
# define RC_LOCAL_CONFDIR LOCAL_PREFIX "/etc/conf.d"
#endif
#define RC_KRUNLEVEL RC_SVCDIR "/krunlevel"
#define RC_STARTING RC_SVCDIR "/rc.starting"
#define RC_STOPPING RC_SVCDIR "/rc.stopping"
@@ -85,31 +50,22 @@
#define RC_SVCDIR_STARTED RC_SVCDIR "/started"
#define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "/coldplugged"
#define RC_PLUGINDIR RC_LIBDIR "/plugins"
#define ERRX fprintf (stderr, "out of memory\n"); exit (1)
#define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#ifdef lint
# define _unused
#endif
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
# define _dead __attribute__((__noreturn__))
# define _unused __attribute__((__unused__))
#else
# define _dead
# define _unused
#endif
/* Some libc implemntations don't have these */
#ifndef STAILQ_CONCAT
#define STAILQ_CONCAT(head1, head2) do { \
if (!STAILQ_EMPTY((head2))) { \
*(head1)->stqh_last = (head2)->stqh_first; \
(head1)->stqh_last = (head2)->stqh_last; \
STAILQ_INIT((head2)); \
} \
} while (0)
#endif
#ifndef TAILQ_CONCAT
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
@@ -121,13 +77,6 @@
} while (0)
#endif
#ifndef STAILQ_FOREACH_SAFE
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = STAILQ_FIRST((head)); \
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#endif
#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
@@ -196,6 +145,10 @@ void env_filter(void);
void env_config(void);
bool service_plugable(const char *service);
int signal_setup(int sig, void (*handler)(int));
pid_t exec_service(const char *, const char *);
#define service_start(service) exec_service(service, "start");
#define service_stop(service) exec_service(service, "stop");
/* basename_c never modifies the argument. As such, if there is a trailing
* slash then an empty string is returned. */
@@ -208,4 +161,5 @@ _unused static const char *basename_c(const char *path)
return (path);
}
int parse_mode(mode_t *, char *);
#endif

View File

@@ -4,7 +4,7 @@ SRCS= libeinfo.c
INCS= einfo.h
VERSION_MAP= einfo.map
CFLAGS+= -I../includes
CPPFLAGS+= -I../includes
MK= ../../mk
include ${MK}/lib.mk

View File

@@ -51,6 +51,8 @@
# endif
#endif
__BEGIN_DECLS
/*! @brief Color types to use */
typedef enum
{
@@ -141,4 +143,5 @@ void eoutdentv(void);
/*! @brief Prefix each einfo line with something */
void eprefix(const char * __EINFO_RESTRICT);
__END_DECLS
#endif

View File

@@ -199,7 +199,8 @@ static const char *const color_terms[] = {
/* strlcat and strlcpy are nice, shame glibc does not define them */
#ifdef __GLIBC__
# if ! defined (__UCLIBC__) && ! defined (__dietlibc__)
static size_t strlcat(char *dst, const char *src, size_t size)
static size_t
strlcat(char *dst, const char *src, size_t size)
{
char *d = dst;
const char *s = src;
@@ -226,18 +227,19 @@ static size_t strlcat(char *dst, const char *src, size_t size)
return dst_n + (s - src);
}
static size_t strlcpy(char *dst, const char *src, size_t size)
static size_t
strlcpy(char *dst, const char *src, size_t size)
{
const char *s = src;
size_t n = size;
if (n && --n)
do {
if (! (*dst++ = *src++))
if (!(*dst++ = *src++))
break;
} while (--n);
if (! n) {
if (!n) {
if (size)
*dst = '\0';
while (*src++);
@@ -248,9 +250,10 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
# endif
#endif
static bool yesno(const char *value)
static bool
yesno(const char *value)
{
if (! value) {
if (!value) {
errno = ENOENT;
return false;
}
@@ -272,7 +275,8 @@ static bool yesno(const char *value)
return false;
}
static bool noyes(const char *value)
static bool
noyes(const char *value)
{
int serrno = errno;
bool retval;
@@ -280,26 +284,29 @@ static bool noyes(const char *value)
errno = 0;
retval = yesno(value);
if (errno == 0) {
retval = ! retval;
retval = !retval;
errno = serrno;
}
return retval;
}
static bool is_quiet(void)
static bool
is_quiet(void)
{
return yesno(getenv("EINFO_QUIET"));
}
static bool is_verbose(void)
static bool
is_verbose(void)
{
return yesno(getenv ("EINFO_VERBOSE"));
}
/* Fake tgoto call - very crapy, but works for our needs */
#ifndef HAVE_TERMCAP
static char *tgoto(const char *cap, int a, int b)
static char *
tgoto(const char *cap, int a, int b)
{
static char buf[20];
@@ -308,22 +315,22 @@ static char *tgoto(const char *cap, int a, int b)
}
#endif
static bool colour_terminal(FILE * __EINFO_RESTRICT f)
static bool
colour_terminal(FILE * __EINFO_RESTRICT f)
{
static int in_colour = -1;
char *e;
char *e, *ee, *end, *d, *p;
int c;
const char *_af = NULL;
const char *_ce = NULL;
const char *_ch = NULL;
const char *_md = NULL;
const char *_me = NULL;
const char *_up = NULL;
const char *_af = NULL, *_ce = NULL, *_ch = NULL;
const char *_md = NULL, *_me = NULL, *_up = NULL;
const char *bold;
char tmp[100];
char *p;
unsigned int i = 0;
#ifdef HAVE_TERMCAP
char *bp;
#endif
if (f && ! isatty(fileno(f)))
if (f && !isatty(fileno(f)))
return false;
if (noyes(getenv("EINFO_COLOR")))
@@ -335,26 +342,23 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
return true;
term_is_cons25 = false;
if (! term) {
if (!term) {
term = getenv("TERM");
if (! term)
if (!term)
return false;
}
if (strcmp(term, "cons25") == 0)
term_is_cons25 = true;
#ifdef HAVE_TERMCAP
/* Check termcap to see if we can do colour or not */
if (tgetent(termcapbuf, term) == 1) {
char *bp = tcapbuf;
bp = tcapbuf;
_af = tgetstr("AF", &bp);
_ce = tgetstr("ce", &bp);
_ch = tgetstr("ch", &bp);
/* Our ch use also works with RI .... for now */
if (! _ch)
if (!_ch)
_ch = tgetstr("RI", &bp);
_md = tgetstr("md", &bp);
_me = tgetstr("me", &bp);
@@ -377,29 +381,29 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
return false;
}
#endif
if (! _af)
if (!_af)
_af = AF;
if (! _ce)
if (!_ce)
_ce = CE;
if (! _ch)
if (!_ch)
_ch = CH;
if (! _md)
if (!_md)
_md = MD;
if (! _me)
if (!_me)
_me = ME;
if (! _up)
if (!_up)
_up = UP;
#ifdef HAVE_TERMCAP
}
if (! _af || ! _ce || ! _me || !_md || ! _up) {
if (!_af || !_ce || !_me || !_md || !_up) {
in_colour = 0;
return false;
}
/* Many termcap databases don't have ch or RI even though they
* do work */
if (! _ch)
if (!_ch)
_ch = CH;
#endif
@@ -407,33 +411,28 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
p = ebuffer;
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) {
tmp[0] = '\0';
if (ecolors[i].name) {
const char *bold = _md;
bold = _md;
c = ecolors[i].def;
/* See if the user wants to override the colour
* We use a :col;bold: format like 2;1: for bold green
* and 1;0: for a normal red */
if ((e = getenv("EINFO_COLOR"))) {
char *ee = strstr(e, ecolors[i].name);
ee = strstr(e, ecolors[i].name);
if (ee)
ee += strlen(ecolors[i].name);
if (ee && *ee == '=') {
char *d = strdup(ee + 1);
d = strdup(ee + 1);
if (d) {
char *end = strchr(d, ':');
end = strchr(d, ':');
if (end)
*end = '\0';
c = atoi(d);
end = strchr(d, ';');
if (end && *++end == '0')
bold = _me;
free(d);
}
}
@@ -460,7 +459,8 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
return true;
}
static int get_term_columns(FILE * __EINFO_RESTRICT stream)
static int
get_term_columns(FILE * __EINFO_RESTRICT stream)
{
struct winsize ws;
char *env = getenv("COLUMNS");
@@ -469,7 +469,7 @@ static int get_term_columns(FILE * __EINFO_RESTRICT stream)
if (env) {
i = strtoimax(env, &p, 10);
if (! *p)
if (!*p)
return i;
}
@@ -479,13 +479,15 @@ static int get_term_columns(FILE * __EINFO_RESTRICT stream)
return DEFAULT_COLS;
}
void eprefix(const char *__EINFO_RESTRICT prefix)
void
eprefix(const char *__EINFO_RESTRICT prefix)
{
_eprefix = prefix;
}
hidden_def(eprefix)
static void elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap)
static void
elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap)
{
char *e = getenv("EINFO_LOG");
va_list apc;
@@ -500,7 +502,8 @@ static void elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap)
}
}
void elog(int level, const char *__EINFO_RESTRICT fmt, ...)
void
elog(int level, const char *__EINFO_RESTRICT fmt, ...)
{
va_list ap;
@@ -510,7 +513,8 @@ void elog(int level, const char *__EINFO_RESTRICT fmt, ...)
}
hidden_def(elog)
static int _eindent(FILE * __EINFO_RESTRICT stream)
static int
_eindent(FILE * __EINFO_RESTRICT stream)
{
char *env = getenv("EINFO_INDENT");
int amount = 0;
@@ -525,7 +529,7 @@ static int _eindent(FILE * __EINFO_RESTRICT stream)
amount = INDENT_MAX;
if (amount > 0)
memset(indent, ' ', (size_t) amount);
memset(indent, ' ', (size_t)amount);
}
/* Terminate it */
@@ -533,32 +537,32 @@ static int _eindent(FILE * __EINFO_RESTRICT stream)
return fprintf(stream, "%s", indent);
}
static const char *_ecolor(FILE * __EINFO_RESTRICT f, ECOLOR color)
static const char *
_ecolor(FILE * __EINFO_RESTRICT f, ECOLOR color)
{
unsigned int i;
if (! colour_terminal(f))
if (!colour_terminal(f))
return "";
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) {
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++)
if (ecolors[i].color == color)
return ecolors_str[i];
}
return "";
}
hidden_def(ecolor)
const char *ecolor(ECOLOR color)
const char *
ecolor(ECOLOR color)
{
FILE *f = stdout;
/* Try and guess a valid tty */
if (! isatty(fileno(f))) {
if (!isatty(fileno(f))) {
f = stderr;
if (! isatty(fileno(f))) {
if (!isatty(fileno(f))) {
f = stdin;
if (! isatty(fileno(f)))
if (!isatty(fileno(f)))
f = NULL;
}
}
@@ -571,87 +575,69 @@ const char *ecolor(ECOLOR color)
setenv("EINFO_LASTCMD", _cmd, 1); \
}
#define EINFOVN(_file, _color) \
{ \
char *_e = getenv("EINFO_LASTCMD"); \
if (_e && ! colour_terminal(_file) && strcmp(_e, "ewarn") != 0 && \
_e[strlen (_e) - 1] == 'n') \
fprintf(_file, "\n"); \
if (_eprefix) \
fprintf(_file, "%s%s%s|", _ecolor(_file, _color), _eprefix, _ecolor(_file, ECOLOR_NORMAL)); \
fprintf(_file, " %s*%s ", _ecolor(_file, _color), _ecolor(_file, ECOLOR_NORMAL)); \
retval += _eindent(_file); \
{ \
va_list _ap; \
va_copy(_ap, ap); \
retval += vfprintf(_file, fmt, _ap) + 3; \
va_end(_ap); \
} \
if (colour_terminal(_file)) \
fprintf(_file, "%s", flush); \
}
static int
_einfo(FILE *f, ECOLOR color, const char *__EINFO_RESTRICT fmt, va_list va)
static int _einfovn(const char *__EINFO_RESTRICT fmt, va_list ap)
{
int retval = 0;
char *last = getenv("EINFO_LASTCMD");
va_list ap;
EINFOVN(stdout, ECOLOR_GOOD);
if (last &&
!colour_terminal(f) &&
strcmp(last, "ewarn") != 0 &&
last[strlen(last) - 1] == 'n')
fprintf(f, "\n");
if (_eprefix)
fprintf(f, "%s%s%s|", _ecolor(f, color), _eprefix, _ecolor(f, ECOLOR_NORMAL));
fprintf(f, " %s*%s ", _ecolor(f, color), _ecolor(f, ECOLOR_NORMAL));
retval += _eindent(f);
va_copy(ap, va);
retval += vfprintf(f, fmt, ap) + 3;
va_end(ap); \
if (colour_terminal(f))
fprintf(f, "%s", flush);
return retval;
}
static int _ewarnvn(const char *__EINFO_RESTRICT fmt, va_list ap)
{
int retval = 0;
#define _einfovn(fmt, ap) _einfo(stdout, ECOLOR_GOOD, fmt, ap)
#define _ewarnvn(fmt, ap) _einfo(stderr, ECOLOR_WARN, fmt, ap)
#define _eerrorvn(fmt, ap) _einfo(stderr, ECOLOR_BAD, fmt, ap)
EINFOVN(stderr, ECOLOR_WARN);
return retval;
}
static int _eerrorvn(const char *__EINFO_RESTRICT fmt, va_list ap)
{
int retval = 0;
EINFOVN(stderr, ECOLOR_BAD);
return retval;
}
int einfon(const char *__EINFO_RESTRICT fmt, ...)
int
einfon(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || is_quiet())
if (!fmt || is_quiet())
return 0;
va_start(ap, fmt);
retval = _einfovn(fmt, ap);
va_end(ap);
LASTCMD("einfon");
return retval;
}
hidden_def(einfon)
int ewarnn(const char *__EINFO_RESTRICT fmt, ...)
int
ewarnn(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || is_quiet())
if (!fmt || is_quiet())
return 0;
va_start(ap, fmt);
retval = _ewarnvn(fmt, ap);
va_end(ap);
LASTCMD("ewarnn");
return retval;
}
hidden_def(ewarnn)
int eerrorn(const char *__EINFO_RESTRICT fmt, ...)
int
eerrorn(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
@@ -659,58 +645,53 @@ int eerrorn(const char *__EINFO_RESTRICT fmt, ...)
va_start(ap, fmt);
retval = _eerrorvn(fmt, ap);
va_end(ap);
LASTCMD("errorn");
return retval;
}
hidden_def(eerrorn)
int einfo(const char *__EINFO_RESTRICT fmt, ...)
int
einfo(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || is_quiet())
if (!fmt || is_quiet())
return 0;
va_start(ap, fmt);
retval = _einfovn(fmt, ap);
retval += printf("\n");
va_end(ap);
LASTCMD("einfo");
return retval;
}
hidden_def(einfo)
int ewarn(const char *__EINFO_RESTRICT fmt, ...)
int
ewarn(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || is_quiet())
if (!fmt || is_quiet())
return 0;
va_start(ap, fmt);
elogv(LOG_WARNING, fmt, ap);
retval = _ewarnvn(fmt, ap);
retval += fprintf(stderr, "\n");
va_end(ap);
LASTCMD("ewarn");
return retval;
}
hidden_def(ewarn)
void ewarnx(const char *__EINFO_RESTRICT fmt, ...)
void
ewarnx(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (fmt && ! is_quiet()) {
if (fmt && !is_quiet()) {
va_start(ap, fmt);
elogv(LOG_WARNING, fmt, ap);
retval = _ewarnvn(fmt, ap);
@@ -721,27 +702,26 @@ void ewarnx(const char *__EINFO_RESTRICT fmt, ...)
}
hidden_def(ewarnx)
int eerror(const char *__EINFO_RESTRICT fmt, ...)
int
eerror(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt)
if (!fmt)
return 0;
va_start(ap, fmt);
elogv(LOG_ERR, fmt, ap);
retval = _eerrorvn(fmt, ap);
va_end(ap);
retval += fprintf(stderr, "\n");
LASTCMD("eerror");
return retval;
}
hidden_def(eerror)
void eerrorx(const char *__EINFO_RESTRICT fmt, ...)
void
eerrorx(const char *__EINFO_RESTRICT fmt, ...)
{
va_list ap;
@@ -752,46 +732,43 @@ void eerrorx(const char *__EINFO_RESTRICT fmt, ...)
va_end(ap);
fprintf(stderr, "\n");
}
exit(EXIT_FAILURE);
}
hidden_def(eerrorx)
int ebegin(const char *__EINFO_RESTRICT fmt, ...)
int
ebegin(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || is_quiet())
if (!fmt || is_quiet())
return 0;
va_start(ap, fmt);
retval = _einfovn(fmt, ap);
va_end(ap);
retval += printf(" ...");
if (colour_terminal(stdout))
retval += printf("\n");
LASTCMD("ebegin");
return retval;
}
hidden_def(ebegin)
static void _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color,
const char *msg)
static void
_eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color, const char *msg)
{
int i;
int cols;
if (! msg)
if (!msg)
return;
cols = get_term_columns(fp) - (strlen(msg) + 3);
/* cons25 is special - we need to remove one char, otherwise things
* do not align properly at all. */
if (! term) {
if (!term) {
term = getenv("TERM");
if (term && strcmp(term, "cons25") == 0)
term_is_cons25 = true;
@@ -816,7 +793,8 @@ static void _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color,
}
}
static int _do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fmt, va_list ap)
static int
_do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fmt, va_list ap)
{
int col = 0;
FILE *fp = stdout;
@@ -832,54 +810,51 @@ static int _do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fm
col += fprintf(fp, "\n");
va_end(apc);
}
_eend(fp, col,
retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD,
retval == 0 ? OK : NOT_OK);
return retval;
}
int eend(int retval, const char *__EINFO_RESTRICT fmt, ...)
int
eend(int retval, const char *__EINFO_RESTRICT fmt, ...)
{
va_list ap;
if (is_quiet())
return retval;
va_start(ap, fmt);
_do_eend("eend", retval, fmt, ap);
va_end(ap);
LASTCMD("eend");
return retval;
}
hidden_def(eend)
int ewend(int retval, const char *__EINFO_RESTRICT fmt, ...)
int
ewend(int retval, const char *__EINFO_RESTRICT fmt, ...)
{
va_list ap;
if (is_quiet())
return retval;
va_start(ap, fmt);
_do_eend("ewend", retval, fmt, ap);
va_end(ap);
LASTCMD("ewend");
return retval;
}
hidden_def(ewend)
void ebracket(int col, ECOLOR color, const char *msg)
void
ebracket(int col, ECOLOR color, const char *msg)
{
_eend(stdout, col, color, msg);
}
hidden_def(ebracket)
void eindent(void)
void
eindent(void)
{
char *env = getenv("EINFO_INDENT");
int amount = 0;
@@ -891,11 +866,9 @@ void eindent(void)
if (errno != 0)
amount = 0;
}
amount += INDENT_WIDTH;
if (amount > INDENT_MAX)
amount = INDENT_MAX;
snprintf(num, 10, "%08d", amount);
setenv("EINFO_INDENT", num, 1);
}
@@ -908,16 +881,14 @@ void eoutdent(void)
char num[10];
int serrno = errno;
if (! env)
if (!env)
return;
errno = 0;
amount = strtoimax(env, NULL, 0);
if (errno != 0)
amount = 0;
else
amount -= INDENT_WIDTH;
if (amount <= 0)
unsetenv("EINFO_INDENT");
else {
@@ -928,86 +899,79 @@ void eoutdent(void)
}
hidden_def(eoutdent)
int einfovn(const char *__EINFO_RESTRICT fmt, ...)
int
einfovn(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || ! is_verbose())
if (!fmt || !is_verbose())
return 0;
va_start(ap, fmt);
retval = _einfovn(fmt, ap);
va_end(ap);
LASTCMD("einfovn");
return retval;
}
hidden_def(einfovn)
int ewarnvn(const char *__EINFO_RESTRICT fmt, ...)
int
ewarnvn(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || ! is_verbose())
if (!fmt || !is_verbose())
return 0;
va_start(ap, fmt);
retval = _ewarnvn(fmt, ap);
va_end(ap);
LASTCMD("ewarnvn");
return retval;
}
hidden_def(ewarnvn)
int einfov(const char *__EINFO_RESTRICT fmt, ...)
int
einfov(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || ! is_verbose())
if (!fmt || !is_verbose())
return 0;
va_start(ap, fmt);
retval = _einfovn(fmt, ap);
retval += printf("\n");
va_end(ap);
LASTCMD("einfov");
return retval;
}
hidden_def(einfov)
int ewarnv(const char *__EINFO_RESTRICT fmt, ...)
int
ewarnv(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || ! is_verbose())
if (!fmt || !is_verbose())
return 0;
va_start(ap, fmt);
retval = _ewarnvn(fmt, ap);
retval += printf("\n");
va_end(ap);
LASTCMD("ewarnv");
return retval;
}
hidden_def(ewarnv)
int ebeginv(const char *__EINFO_RESTRICT fmt, ...)
int
ebeginv(const char *__EINFO_RESTRICT fmt, ...)
{
int retval;
va_list ap;
if (! fmt || ! is_verbose())
if (!fmt || !is_verbose())
return 0;
va_start(ap, fmt);
@@ -1016,55 +980,51 @@ int ebeginv(const char *__EINFO_RESTRICT fmt, ...)
if (colour_terminal(stdout))
retval += printf("\n");
va_end(ap);
LASTCMD("ebeginv");
return retval;
}
hidden_def(ebeginv)
int eendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
int
eendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
{
va_list ap;
if (! is_verbose())
if (!is_verbose())
return 0;
va_start(ap, fmt);
_do_eend("eendv", retval, fmt, ap);
va_end(ap);
LASTCMD("eendv");
return retval;
}
hidden_def(eendv)
int ewendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
int
ewendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
{
va_list ap;
if (! is_verbose())
if (!is_verbose())
return 0;
va_start(ap, fmt);
_do_eend("ewendv", retval, fmt, ap);
va_end(ap);
LASTCMD("ewendv");
return retval;
}
hidden_def(ewendv)
void eindentv(void)
void
eindentv(void)
{
if (is_verbose())
eindent ();
eindent();
}
hidden_def(eindentv)
void eoutdentv(void)
void
eoutdentv(void)
{
if (is_verbose())
eoutdent();

View File

@@ -13,3 +13,4 @@ librc.a
librc.so.1
librc.so
.depend
rc.h

View File

@@ -5,13 +5,38 @@ SRCS= librc.c librc-daemon.c librc-depend.c librc-misc.c \
INCS= rc.h
VERSION_MAP= rc.map
CFLAGS+= -DLIB=\"${LIBNAME}\"
CFLAGS+= -DSYSCONFDIR=\"${SYSCONFDIR}\"
LDADD+= ${LIBKVM}
CFLAGS+= -I../includes
CPPFLAGS+= -I../includes
MK= ../../mk
include ${MK}/lib.mk
include ${MK}/cc.mk
include ${MK}/debug.mk
# Massage our header file for our dirs
SED_CMD= -e 's:@PREFIX@:${PREFIX}:g'
SED_CMD+= -e 's:@LIB@:${LIBNAME}:g'
SED_CMD+= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
_PKG_PREFIX_SH= if test -n "${PKG_PREFIX}" && test "${PKG_PREFIX}" != "/" && test "${PKG_PREFIX}" != "${PREFIX}"; then \
echo "-e 's:@PKG_PREFIX@:${PKG_PREFIX}:g'"; \
else \
echo "-e 's:.*@PKG_PREFIX@.*:\#undef RC_PKG_PREFIX:g'"; \
fi
_PKG_PREFIX!= ${_PKG_PREFIX_SH}
SED_CMD+= ${_PKG_PREFIX}$(shell ${_PKG_PREFIX_SH})
_LCL_PREFIX_SH= if test -n "${LOCAL_PREFIX}" && test "${LOCAL_PREFIX}" != "/" && test "${LOCAL_PREFIX}" != "${PREFIX}"; then \
echo "-e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'"; \
else \
echo "-e 's:@LOCAL_PREFIX@::g'"; \
fi
_LCL_PREFIX!= ${_LCL_PREFIX_SH}
SED_CMD+= ${_LCL_PREFIX}$(shell ${_LCL_PREFIX_SH})
.SUFFIXES: .h.in .h
.h.in.h:
${SED} ${SED_CMD} $< > $@
${SRCS}: rc.h
CLEANFILES+= rc.h

View File

@@ -40,11 +40,11 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
if (n && --n)
do {
if (! (*dst++ = *src++))
if (!(*dst++ = *src++))
break;
} while (--n);
if (! n) {
if (!n) {
if (size)
*dst = '\0';
while (*src++);
@@ -56,82 +56,60 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
#endif
#if defined(__linux__)
static bool pid_is_cmd(pid_t pid, const char *cmd)
static bool pid_is_exec(pid_t pid, const char *exec)
{
char buffer[32];
FILE *fp;
int c;
bool retval = false;
exec = basename_c(exec);
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
if ((fp = fopen(buffer, "r")) == NULL)
return false;
while ((c = getc(fp)) != EOF && c != '(')
;
if (c != '(') {
if ((fp = fopen(buffer, "r"))) {
while ((c = getc(fp)) != EOF && c != '(')
;
if (c == '(') {
while ((c = getc(fp)) != EOF && c == *exec)
exec++;
if (c == ')' && *exec == '\0')
retval = true;
}
fclose(fp);
return false;
}
while ((c = getc(fp)) != EOF && c == *cmd)
cmd++;
fclose(fp);
return (c == ')' && *cmd == '\0') ? true : false;
return retval;
}
static bool pid_is_exec(pid_t pid, const char *const *argv)
static bool pid_is_argv(pid_t pid, const char *const *argv)
{
char cmdline[32];
int fd;
char buffer[PATH_MAX];
char *p;
int fd = -1;
int r;
/* Check it's the right binary */
snprintf (cmdline, sizeof (cmdline), "/proc/%u/exe", pid);
memset (buffer, 0, sizeof (buffer));
if (readlink(cmdline, buffer, sizeof(buffer)) != -1) {
if (strcmp(*argv, buffer) == 0)
return true;
/* We should cater for deleted binaries too */
if (strlen(buffer) > 10) {
p = buffer + (strlen(buffer) - 10);
if (strcmp(p, " (deleted)") == 0) {
*p = 0;
if (strcmp(buffer, *argv) == 0)
return true;
}
}
}
ssize_t bytes;
snprintf(cmdline, sizeof(cmdline), "/proc/%u/cmdline", pid);
if ((fd = open(cmdline, O_RDONLY)) < 0)
return false;
r = read(fd, buffer, sizeof(buffer));
bytes = read(fd, buffer, sizeof(buffer));
close(fd);
if (bytes == -1)
return false;
if (r == -1)
return 0;
buffer[r] = 0;
buffer[bytes] = '\0';
p = buffer;
while (*argv) {
if (strcmp(*argv, p) != 0)
return false;
argv++;
p += strlen(p) + 1;
if ((unsigned) (p - buffer) > sizeof (buffer))
if ((unsigned)(p - buffer) > sizeof(buffer))
return false;
}
return true;
}
RC_PIDLIST *rc_find_pids(const char *const *argv, const char *cmd,
RC_PIDLIST *rc_find_pids(const char *exec, const char *const *argv,
uid_t uid, pid_t pid)
{
DIR *procdir;
@@ -166,27 +144,21 @@ RC_PIDLIST *rc_find_pids(const char *const *argv, const char *cmd,
while ((entry = readdir(procdir)) != NULL) {
if (sscanf(entry->d_name, "%d", &p) != 1)
continue;
if (runscript_pid != 0 && runscript_pid == p)
continue;
if (pid != 0 && pid != p)
continue;
if (uid) {
snprintf(buffer, sizeof(buffer), "/proc/%d", p);
if (stat(buffer, &sb) != 0 || sb.st_uid != uid)
continue;
}
if (cmd && ! pid_is_cmd(p, cmd))
if (exec && !pid_is_exec(p, exec))
continue;
if (argv && ! cmd && !
pid_is_exec(p, (const char *const *)argv))
if (argv &&
!pid_is_argv(p, (const char *const *)argv))
continue;
if (! pids) {
if (!pids) {
pids = xmalloc(sizeof(*pids));
LIST_INIT(pids);
}
@@ -195,7 +167,6 @@ RC_PIDLIST *rc_find_pids(const char *const *argv, const char *cmd,
LIST_INSERT_HEAD(pids, pi, entries);
}
closedir(procdir);
return pids;
}
librc_hidden_def(rc_find_pids)
@@ -224,7 +195,7 @@ librc_hidden_def(rc_find_pids)
# define _KVM_FLAGS O_RDONLY
# endif
RC_PIDLIST *rc_find_pids(const char *const *argv, const char *cmd,
RC_PIDLIST *rc_find_pids(const char *exec, const char *const *argv,
uid_t uid, pid_t pid)
{
static kvm_t *kd = NULL;
@@ -258,39 +229,34 @@ RC_PIDLIST *rc_find_pids(const char *const *argv, const char *cmd,
return NULL;
}
if (exec)
exec = basename_c(exec);
for (i = 0; i < processes; i++) {
p = _GET_KINFO_PID(kp[i]);
if (pid != 0 && pid != p)
continue;
if (uid != 0 && uid != _GET_KINFO_UID(kp[i]))
continue;
if (cmd) {
if (! _GET_KINFO_COMM(kp[i]) ||
strcmp(cmd, _GET_KINFO_COMM(kp[i])) != 0)
if (exec) {
if (!_GET_KINFO_COMM(kp[i]) ||
strcmp(exec, _GET_KINFO_COMM(kp[i])) != 0)
continue;
}
if (argv && *argv && ! cmd) {
if (argv && *argv) {
pargv = _KVM_GETARGV(kd, &kp[i], pargc);
if (! pargv || ! *pargv)
if (!pargv || !*pargv)
continue;
arg = argv;
match = 1;
while (*arg && *pargv)
if (strcmp(*arg++, *pargv++) != 0) {
match = 0;
break;
}
if (! match)
if (!match)
continue;
}
if (! pids) {
if (!pids) {
pids = xmalloc(sizeof(*pids));
LIST_INIT(pids);
}
@@ -320,7 +286,7 @@ static bool _match_daemon(const char *path, const char *file,
snprintf(ffile, sizeof(ffile), "%s/%s", path, file);
fp = fopen(ffile, "r");
if (! fp)
if (!fp)
return false;
while ((rc_getline(&line, &len, fp))) {
@@ -329,7 +295,7 @@ static bool _match_daemon(const char *path, const char *file,
TAILQ_REMOVE(match, m, entries);
break;
}
if (! TAILQ_FIRST(match))
if (!TAILQ_FIRST(match))
break;
}
fclose(fp);
@@ -339,14 +305,22 @@ static bool _match_daemon(const char *path, const char *file,
return true;
}
static RC_STRINGLIST *_match_list(const char* const* argv,
const char *name, const char *pidfile)
static RC_STRINGLIST *_match_list(const char *exec, const char* const* argv,
const char *pidfile)
{
RC_STRINGLIST *match = rc_stringlist_new();
int i = 0;
size_t l;
char *m;
if (exec) {
l = strlen(exec) + 6;
m = xmalloc(sizeof(char) * l);
snprintf(m, l, "exec=%s", exec);
rc_stringlist_add(match, m);
free(m);
}
while (argv && argv[i]) {
l = strlen(*argv) + strlen("argv_=") + 16;
m = xmalloc(sizeof(char) * l);
@@ -355,14 +329,6 @@ static RC_STRINGLIST *_match_list(const char* const* argv,
free(m);
}
if (name) {
l = strlen(name) + 6;
m = xmalloc(sizeof (char) * l);
snprintf(m, l, "name=%s", name);
rc_stringlist_add(match, m);
free(m);
}
if (pidfile) {
l = strlen(pidfile) + 9;
m = xmalloc(sizeof (char) * l);
@@ -374,8 +340,9 @@ static RC_STRINGLIST *_match_list(const char* const* argv,
return match;
}
bool rc_service_daemon_set(const char *service, const char *const *argv,
const char *name, const char *pidfile, bool started)
bool rc_service_daemon_set(const char *service, const char *exec,
const char *const *argv,
const char *pidfile, bool started)
{
char dirpath[PATH_MAX];
char file[PATH_MAX];
@@ -388,7 +355,7 @@ bool rc_service_daemon_set(const char *service, const char *const *argv,
int i = 0;
FILE *fp;
if (!(argv && *argv) && ! name && ! pidfile) {
if (!exec && !pidfile) {
errno = EINVAL;
return false;
}
@@ -398,7 +365,7 @@ bool rc_service_daemon_set(const char *service, const char *const *argv,
/* Regardless, erase any existing daemon info */
if ((dp = opendir(dirpath))) {
match = _match_list(argv, name, pidfile);
match = _match_list(exec, argv, pidfile);
while ((d = readdir(dp))) {
if (d->d_name[0] == '.')
continue;
@@ -407,7 +374,7 @@ bool rc_service_daemon_set(const char *service, const char *const *argv,
dirpath, d->d_name);
nfiles++;
if (! *oldfile) {
if (!*oldfile) {
if (_match_daemon(dirpath, d->d_name, match)) {
unlink(file);
strlcpy(oldfile, file, sizeof(oldfile));
@@ -428,13 +395,13 @@ bool rc_service_daemon_set(const char *service, const char *const *argv,
snprintf(file, sizeof(file), "%s/%03d",
dirpath, nfiles + 1);
if ((fp = fopen(file, "w"))) {
fprintf(fp, "exec=");
if (exec)
fprintf(fp, "%s", exec);
while (argv && argv[i]) {
fprintf(fp, "argv_%d=%s\n", i, argv[i]);
fprintf(fp, "\nargv_%d=%s", i, argv[i]);
i++;
}
fprintf(fp, "name=");
if (name)
fprintf(fp, "%s", name);
fprintf(fp, "\npidfile=");
if (pidfile)
fprintf(fp, "%s", pidfile);
@@ -450,7 +417,8 @@ bool rc_service_daemon_set(const char *service, const char *const *argv,
}
librc_hidden_def(rc_service_daemon_set)
bool rc_service_started_daemon(const char *service, const char *const *argv,
bool rc_service_started_daemon(const char *service,
const char *exec, const char *const *argv,
int indx)
{
char dirpath[PATH_MAX];
@@ -460,12 +428,12 @@ bool rc_service_started_daemon(const char *service, const char *const *argv,
DIR *dp;
struct dirent *d;
if (!service || !(argv && *argv))
if (!service || !exec)
return false;
snprintf(dirpath, sizeof(dirpath), RC_SVCDIR "/daemons/%s",
basename_c(service));
match = _match_list(argv, NULL, NULL);
match = _match_list(exec, argv, NULL);
if (indx > 0) {
snprintf(file, sizeof(file), "%03d", indx);
@@ -515,7 +483,7 @@ bool rc_service_daemons_crashed(const char *service)
path += snprintf(dirpath, sizeof(dirpath), RC_SVCDIR "/daemons/%s",
basename_c(service));
if (! (dp = opendir(dirpath)))
if (!(dp = opendir(dirpath)))
return false;
while ((d = readdir(dp))) {
@@ -525,25 +493,25 @@ bool rc_service_daemons_crashed(const char *service)
snprintf(path, sizeof(dirpath) - (path - dirpath), "/%s",
d->d_name);
fp = fopen(dirpath, "r");
if (! fp)
if (!fp)
break;
while ((rc_getline(&line, &len, fp))) {
p = line;
if ((token = strsep(&p, "=")) == NULL || ! p)
if ((token = strsep(&p, "=")) == NULL || !p)
continue;
if (! *p)
if (!*p)
continue;
if (strncmp(token, "argv_", 5) == 0) {
if (! list)
list = rc_stringlist_new();
rc_stringlist_add(list, p);
} else if (strcmp(token, "exec") == 0) {
if (strcmp(token, "exec") == 0) {
if (exec)
free(exec);
exec = xstrdup(p);
} else if (strncmp(token, "argv_", 5) == 0) {
if (!list)
list = rc_stringlist_new();
rc_stringlist_add(list, p);
} else if (strcmp(token, "name") == 0) {
if (name)
free(name);
@@ -561,20 +529,21 @@ bool rc_service_daemons_crashed(const char *service)
if ((fp = fopen(pidfile, "r"))) {
if (fscanf(fp, "%d", &pid) == 1)
retval = false;
fclose (fp);
}
free(pidfile);
pidfile = NULL;
/* We have the pid, so no need to match on name */
free (name);
/* We have the pid, so no need to match on exec or name */
free(exec);
exec = NULL;
free(name);
name = NULL;
} else {
if (exec) {
if (! list)
if (!list)
list = rc_stringlist_new();
if (! TAILQ_FIRST(list))
if (!TAILQ_FIRST(list))
rc_stringlist_add(list, exec);
free(exec);
@@ -594,9 +563,10 @@ bool rc_service_daemons_crashed(const char *service)
}
}
if (! retval) {
if ((pids = rc_find_pids((const char *const *)argv,
name, 0, pid)))
if (!retval) {
if ((pids = rc_find_pids(exec,
(const char *const *)argv,
0, pid)))
{
p1 = LIST_FIRST(pids);
while (p1) {

File diff suppressed because it is too large Load Diff

View File

@@ -31,38 +31,35 @@
#include "librc.h"
bool rc_yesno (const char *value)
bool rc_yesno(const char *value)
{
if (! value) {
if (!value) {
errno = ENOENT;
return false;
}
if (strcasecmp (value, "yes") == 0 ||
strcasecmp (value, "y") == 0 ||
strcasecmp (value, "true") == 0 ||
strcasecmp (value, "1") == 0)
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "y") == 0 ||
strcasecmp(value, "true") == 0 ||
strcasecmp(value, "1") == 0)
return true;
if (strcasecmp (value, "no") != 0 &&
strcasecmp (value, "n") != 0 &&
strcasecmp (value, "false") != 0 &&
strcasecmp (value, "0") != 0)
if (strcasecmp(value, "no") != 0 &&
strcasecmp(value, "n") != 0 &&
strcasecmp(value, "false") != 0 &&
strcasecmp(value, "0") != 0)
errno = EINVAL;
return false;
}
librc_hidden_def(rc_yesno)
ssize_t rc_getline (char **line, size_t *len, FILE *fp)
ssize_t rc_getline(char **line, size_t *len, FILE *fp)
{
char *p;
size_t last = 0;
if (feof(fp))
return 0;
do {
while(!feof(fp)) {
if (*line == NULL || last != 0) {
*len += BUFSIZ;
*line = xrealloc(*line, *len);
@@ -71,12 +68,11 @@ ssize_t rc_getline (char **line, size_t *len, FILE *fp)
memset(p, 0, BUFSIZ);
fgets(p, BUFSIZ, fp);
last += strlen(p);
} while (! feof(fp) && (*line)[last - 1] != '\n');
/* Trim the trailing newline */
if (**line && (*line)[last - 1] == '\n')
(*line)[last - 1] = '\0';
if (last && (*line)[last - 1] == '\n') {
(*line)[last - 1] = '\0';
break;
}
}
return last;
}
librc_hidden_def(rc_getline)
@@ -108,7 +104,7 @@ RC_STRINGLIST *rc_config_list(const char *file)
if (token[strlen(token) - 1] == '\n')
token[strlen(token) - 1] = 0;
if (! list)
if (!list)
list = rc_stringlist_new();
rc_stringlist_add(list, token);
}
@@ -135,17 +131,21 @@ RC_STRINGLIST *rc_config_load(const char *file)
char *p;
list = rc_config_list(file);
if (! list)
if (!list)
return NULL;
config = rc_stringlist_new();
TAILQ_FOREACH(line, list, entries) {
/* Get entry */
p = line->value;
if (! p)
continue;
if (strncmp(p, "export ", 7) == 0)
p += 7;
if (! (token = strsep(&p, "=")))
continue;
entry = xstrdup (token);
entry = xstrdup(token);
/* Preserve shell coloring */
if (*p == '$')
token = line->value;
@@ -157,15 +157,15 @@ RC_STRINGLIST *rc_config_load(const char *file)
/* Drop a newline if that's all we have */
if (token) {
i = strlen (token) - 1;
i = strlen(token) - 1;
if (token[i] == '\n')
token[i] = 0;
i = strlen (entry) + strlen (token) + 2;
i = strlen(entry) + strlen(token) + 2;
newline = xmalloc(sizeof(char) * i);
snprintf(newline, i, "%s=%s", entry, token);
} else {
i = strlen (entry) + 2;
i = strlen(entry) + 2;
newline = xmalloc(sizeof(char) * i);
snprintf(newline, i, "%s=", entry);
}
@@ -176,7 +176,7 @@ RC_STRINGLIST *rc_config_load(const char *file)
TAILQ_FOREACH(cline, config, entries) {
p = strchr(cline->value, '=');
if (p && strncmp(entry, cline->value,
(size_t) (p - cline->value)) == 0)
(size_t)(p - cline->value)) == 0)
{
/* We have a match now - to save time we directly replace it */
free(cline->value);
@@ -186,7 +186,7 @@ RC_STRINGLIST *rc_config_load(const char *file)
}
}
if (! replaced) {
if (!replaced) {
rc_stringlist_add(config, newline);
free(newline);
}

View File

@@ -80,6 +80,33 @@ bool rc_stringlist_delete(RC_STRINGLIST *list, const char *value)
}
librc_hidden_def(rc_stringlist_delete)
RC_STRING *rc_stringlist_find(RC_STRINGLIST *list, const char *value)
{
RC_STRING *s;
if (list) {
TAILQ_FOREACH(s, list, entries)
if (strcmp(s->value, value) == 0)
return s;
}
return NULL;
}
librc_hidden_def(rc_stringlist_find)
RC_STRINGLIST *rc_stringlist_split(const char *value, const char *sep)
{
RC_STRINGLIST *list = rc_stringlist_new();
char *d = xstrdup(value);
char *p = d, *token;
while ((token = strsep(&p, sep)))
rc_stringlist_add(list, token);
free(d);
return list;
}
librc_hidden_def(rc_stringlist_split)
void rc_stringlist_sort(RC_STRINGLIST **list)
{
RC_STRINGLIST *l = *list;

View File

@@ -35,7 +35,6 @@ const char librc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#ifdef __FreeBSD__
#include <sys/sysctl.h>
#endif
#include <signal.h>
#define RC_RUNLEVEL RC_SVCDIR "/softlevel"
@@ -214,6 +213,13 @@ const char *rc_sys(void)
return RC_SYS_JAIL;
#endif
#ifdef __NetBSD__
if (exists("/kern/xen/privcmd"))
return RC_SYS_XEN0;
if (exists("/kern/xen"))
return RC_SYS_XENU;
#endif
#ifdef __linux__
if (exists("/proc/xen")) {
if (file_regex("/proc/xen/capabilities", "control_d"))
@@ -224,9 +230,11 @@ const char *rc_sys(void)
else if (file_regex("/proc/self/status",
"(s_context|VxID):[[:space:]]*[1-9]"))
return RC_SYS_VSERVER;
else if (exists("/proc/vz/veinfo") && !exists("/proc/vz/version"))
return RC_SYS_OPENVZ;
else if (file_regex("/proc/self/status",
"envID:[[:space:]]*[1-9]"))
return RC_SYS_OPENVZ;
return RC_SYS_OPENVZ; /* old test */
#endif
return NULL;
@@ -494,7 +502,7 @@ bool rc_service_mark(const char *service, const RC_SERVICE state)
base = basename_c(service);
if (state != RC_SERVICE_STOPPED) {
if (! exists(init)) {
if (!exists(init)) {
free(init);
return false;
}
@@ -540,7 +548,10 @@ bool rc_service_mark(const char *service, const RC_SERVICE state)
symlink(init, was);
skip_wasinactive = true;
}
unlink(file);
if (unlink(file) == -1) {
free(init);
return false;
}
}
}
}
@@ -673,95 +684,6 @@ bool rc_service_value_set(const char *service, const char *option,
}
librc_hidden_def(rc_service_value_set)
static pid_t _exec_service(const char *service, const char *arg)
{
char *file;
char fifo[PATH_MAX];
pid_t pid = -1;
sigset_t full;
sigset_t old;
struct sigaction sa;
file = rc_service_resolve(service);
if (! exists(file)) {
rc_service_mark(service, RC_SERVICE_STOPPED);
free(file);
return 0;
}
/* We create a fifo so that other services can wait until we complete */
snprintf(fifo, sizeof(fifo), RC_SVCDIR "/exclusive/%s",
basename_c(service));
if (mkfifo(fifo, 0600) != 0 && errno != EEXIST) {
free(file);
return -1;
}
/* We need to block signals until we have forked */
memset(&sa, 0, sizeof (sa));
sa.sa_handler = SIG_DFL;
sigemptyset(&sa.sa_mask);
sigfillset(&full);
sigprocmask(SIG_SETMASK, &full, &old);
if ((pid = fork()) == 0) {
/* Restore default handlers */
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGWINCH, &sa, NULL);
/* Unmask signals */
sigprocmask(SIG_SETMASK, &old, NULL);
/* Safe to run now */
execl(file, file, arg, (char *) NULL);
fprintf(stderr, "unable to exec `%s': %s\n",
file, strerror(errno));
unlink(fifo);
_exit(EXIT_FAILURE);
}
if (pid == -1)
fprintf(stderr, "fork: %s\n",strerror (errno));
sigprocmask(SIG_SETMASK, &old, NULL);
free(file);
return pid;
}
pid_t rc_service_stop(const char *service)
{
RC_SERVICE state = rc_service_state(service);
if (state & RC_SERVICE_FAILED)
return -1;
if (state & RC_SERVICE_STOPPED)
return 0;
return _exec_service(service, "stop");
}
librc_hidden_def(rc_service_stop)
pid_t rc_service_start(const char *service)
{
RC_SERVICE state = rc_service_state(service);
if (state & RC_SERVICE_FAILED)
return -1;
if (! state & RC_SERVICE_STOPPED)
return 0;
return _exec_service(service, "start");
}
librc_hidden_def(rc_service_start)
bool rc_service_schedule_start(const char *service,
const char *service_to_start)

Some files were not shown because too many files have changed in this diff Show More