Compare commits

...

61 Commits

Author SHA1 Message Date
Roy Marples
e9e37ad798 Release openrc-0.5.3 2009-12-02 19:08:02 +00:00
Roy Marples
4df8770a90 Only add metric to dhcpcd if not given.
Fixes Gentoo #294312
2009-11-25 02:07:22 +00:00
Roy Marples
ec38bbbdda If mounting tmpfs fails, try ramfs.
This is because buggy kernels always report tmpfs even when not present.
2009-11-20 00:04:32 +00:00
Roy Marples
509e34d425 Only allow one service to be provided by default.
Fixes Gentoo #293139.
2009-11-14 08:37:05 +00:00
Roy Marples
0de1d18d41 Fix logic 2009-11-13 22:29:01 +00:00
Roy Marples
89a2d76772 Rework around new kbd-1.15.1, Gentoo #289265. 2009-11-13 22:21:50 +00:00
Roy Marples
80d4ce3a11 Add a --warn option to just warn when reference file does not exist.
Fixes Gentoo #291894.
2009-11-13 21:31:09 +00:00
Roy Marples
d21177e5c7 Ensure we have a valid broadcast address. 2009-11-11 00:31:32 +00:00
Roy Marples
d29daf3952 fsck only checks battery when requested, which is not by default.
This fixes having JFS as the root partition on battery power.
For most modern FS's this is a non op, or a very small op by default
so it should be fine.
Fixes Gentoo #291654.
2009-11-10 22:50:48 +00:00
Roy Marples
1d9ce8e9a1 Allow sysctl to read confs from /etc/sysctl.d
Fixes #203.
2009-11-10 22:40:35 +00:00
William Hubbs
bb96dc4e01 Fix iproute2 support.
Fixes Gentoo #289762.
2009-11-10 21:19:17 +00:00
Jan Psota
ebb49805fc Don't punt /var/log/wtmp if it exists, just create if it does not.
Fixes Gentoo #289849.
2009-11-10 20:09:44 +00:00
Nao Nakashima
4a892a23ba Fix ppp options ordering.
Fixes #205.
2009-11-04 19:40:52 +00:00
Roy Marples
95ee39ab1c Add support for Linux Containers, fixes #202.
Patch by bug reporter.
2009-11-04 19:21:24 +00:00
Roy Marples
3c8ea5896a Fix default domain 2009-10-25 00:03:20 +01:00
Roy Marples
7c5047acfc Release OpenRC-0.5.2 2009-10-17 00:32:40 +01:00
Roy Marples
f2f7d0ae6d Add README.net to describe the networking goals for OpenRC. 2009-10-17 00:18:39 +01:00
Roy Marples
d27655c908 Add domainname to the network script 2009-10-16 12:04:20 +01:00
Roy Marples
9f4a7afd83 Add staticroute to the boot runlevel 2009-10-16 09:25:08 +01:00
Roy Marples
ac6808a73e Regenerate version.h if necessary 2009-10-16 08:13:34 +01:00
Roy Marples
baeb59cd2e Add a new staticroute init script so that .... static routes can be configured!
Fixes Gentoo #288421.
2009-10-16 08:08:22 +01:00
Roy Marples
a4b03ead79 Add lustre 2009-10-15 23:48:40 +01:00
William Hubbs
c96a015742 fix wait time for gentoo bug 288495
The wait time was in seconds.  This patch converts it to milliseconds.
2009-10-15 20:25:01 +01:00
Roy Marples
fdca530d4f Address iproute2 mtu. 2009-10-15 20:20:36 +01:00
Roy Marples
da08e3822f Ensure ip brings interface up when adding addresses.
Fixes Gentoo #288889
2009-10-15 20:17:51 +01:00
Roy Marples
ac7af85813 Provide clock 2009-10-13 21:06:35 +01:00
Roy Marples
a8f6a9b654 Add new utility and init script swclock that sets the system time based on
the mtime of a file. It saves the shutdown time to this file also.
This is handy for systems without a working RTC chip.
Based on an idea by Michael A. Smith <michael@smith-li.com>.
Fixes Gentoo #272073.
2009-10-13 08:03:45 +01:00
Semen Maryasin
aaa0498bf8 EeePC 901 has /proc/acpi/ac_adapter/AC0, so check all AC entries. 2009-10-12 08:21:50 +01:00
Roy Marples
0ffe5caf18 Add more net fs's, Gentoo #284327. 2009-10-11 08:18:35 +01:00
Roy Marples
5e8e38b9cf Improve comments, Gentoo #282243. 2009-10-11 08:15:10 +01:00
Roy Marples
454bd460c4 Multihomed rules show not be applied to the interface, Gentoo #273303. 2009-10-11 08:03:30 +01:00
Roy Marples
a7fabeef95 Release OpenRC-0.5.1 2009-10-08 21:27:30 +01:00
Roy Marples
07f9be7b1c Add pkg-config support, fixes #187. 2009-10-08 00:20:43 +01:00
Roy Marples
42ca23b878 Don't quote opts 2009-09-21 19:05:47 +01:00
Roy Marples
3dc712e222 Allow init scripts to show their dependencies easier 2009-09-04 16:00:08 +01:00
Roy Marples
44585fea46 Add -P to start-stop-daemon to display a . for each second elapsed.
Fixes #197.
2009-09-04 15:41:08 +01:00
Roy Marples
6e485bde39 Really fix --signal 0 2009-09-04 13:32:59 +01:00
Roy Marples
2ea1df634e Fix signed error. 2009-09-04 13:24:26 +01:00
Roy Marples
807e5d7250 Timeout for ipv6 addresses being tentative. 2009-09-04 13:23:40 +01:00
Roy Marples
7012630302 Allow any valid numeric signal and not just what we define. 2009-09-01 13:57:45 +01:00
Roy Marples
51907c7368 If there is an error setting the font, abort instead of trying to set
the font for subsequent consoles.
2009-08-19 16:49:35 +01:00
Roy Marples
8da7a49d02 Fix example 2009-08-17 21:45:11 +01:00
Roy Marples
29949a5496 If mtab is write only and a symlink then assume it's linked to /proc/mounts
and don't try and update it. Fixes #185.
2009-07-20 19:47:08 +01:00
Roy Marples
7fbb6ad427 Don't provide ourself, fixes #190 2009-07-20 19:42:15 +01:00
Roy Marples
08b5664668 Only delete /etc/nologin if we can write to it 2009-07-09 13:32:27 +01:00
Roy Marples
7962218dd8 Apply MTU and txqueuelen after creating the tunnel. 2009-07-08 22:38:48 +01:00
Roy Marples
889b317ac6 Fix wpa_supplicant to find wireless interfaces on newer kernels.
Fixes #176.
2009-07-01 00:24:08 +01:00
Roy Marples
9907c90552 Host should configure urandom.
Fixes #179.
2009-07-01 00:13:25 +01:00
Roy Marples
b4104957b1 We should use -feature instead of nofeature.
This matches the ifconfig and Gentoo USE flag syntax and is hopefully
easier to read.
Fixes #178.
2009-07-01 00:07:32 +01:00
Roy Marples
6abeec7430 Use rc_getline instead of assuming a fixed kernel cmdline length.
This is now requires as COMMAND_LINE_SIZE isn't exposed by kernel
headers anymore.
Fixes #177.
2009-06-21 12:20:53 +01:00
Roy Marples
fbb78022f9 Ensure that tmp dirs are +rw as well as +t. 2009-06-13 21:12:50 +01:00
Natanael Copa
79b24f5b79 hwclock now sends help to stderr. 2009-06-12 23:11:16 +01:00
Roy Marples
fc6cdefedb Linux FHS requires /var/lib/misc
Stop fuser from being chatty
2009-06-08 22:18:39 +01:00
Roy Marples
43f6c2196e Release openrc-0.5.0 2009-06-05 09:20:11 +01:00
Roy Marples
c568baf8c8 Ignore more foo 2009-06-05 09:20:10 +01:00
Roy Marples
aaced3face Update copyright 2009-06-05 09:20:10 +01:00
Roy Marples
c3e9a7ec14 Warn about going inactive correctly. 2009-06-01 20:10:42 +01:00
Roy Marples
efec0b5012 nexthop routes don't use metrics 2009-06-01 20:06:56 +01:00
Roy Marples
278e65b24a Ignore termencoding 2009-05-29 22:09:39 +01:00
Roy Marples
1b3a413673 Skip sysctl errors 2009-05-29 22:08:47 +01:00
Roy Marples
a685e4db0a Add FreeBSD support for AC power. 2009-05-29 21:33:44 +01:00
94 changed files with 729 additions and 232 deletions

View File

@@ -2,9 +2,7 @@
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
NAME= openrc
VERSION= 0.4.3
PKG= ${NAME}-${VERSION}
include Makefile.inc
SUBDIR= conf.d etc init.d man sh src
@@ -16,6 +14,14 @@ _OLDNET_SH= case "${MKOLDNET}" in \
_OLDNET!= ${_OLDNET_SH}
SUBDIR+= ${_OLDNET}$(shell ${_OLDNET_SH})
# Build pkgconfig or not
_PKGCONFIG_SH= case "${MKPKGCONFIG}" in \
[Yy][Ee][Ss]|"") echo "pkgconfig";; \
*) echo "";; \
esac
_PKGCONFIG!= ${_PKGCONFIG_SH}
SUBDIR+= ${_PKGCONFIG}$(shell ${_PKGCONFIG_SH})
# We need to ensure that runlevels is done last
SUBDIR+= runlevels

3
Makefile.inc Normal file
View File

@@ -0,0 +1,3 @@
NAME= openrc
VERSION= 0.5.3
PKG= ${NAME}-${VERSION}

1
README
View File

@@ -11,6 +11,7 @@ PROGLDFLAGS=-static
LIBNAME=lib64
DESTDIR=/tmp/openrc-image
MKPAM=pam
MKPKGCONFIG=no
MKTERMCAP=ncurses
MKTERMCAP=termcap
MKOLDNET=yes

36
README.net Normal file
View File

@@ -0,0 +1,36 @@
OpenRC Network Ideals
---------------------
The new style networking for OpenRC is very simplistic - provide a basic means
of configuring static interface address and routes whilst allowing the
possibility to run any command at any point.
In a nutshell, init.d/network is a wrapper around ifconfig(8) and
init.d/staticroute is wrapper around route(8).
In the Perfect World (TM) ifconfig should be able to configure everything
about the interface easily * . The BSD family almost get this right and Linux
epically fails.
* Only static confguration, including link setup.
For dynmaic, static, IPv4LL, arping and per ssid IPv4 setup dhcpcd-5.x
provides your needs.
It fails because there are many tools to do the same job and often have
vastly different syntax where they could be similar. In other words, there
is no coherence.
OpenRC-0.4.x and older (inc Gentoo baselayout-1) had a collection of scripts
for each tool and allowed a script per interface. Over the years, this design
has proven very hard to maintain as each user has their own idea of how
things should work. Also, there were (and still are) race conditions.
So where do we go from here?
Well, it's possible to use the new network scripts using the tools
currently available. It's just harder as you have to know them and their
documentation can be lacking at times.
The correct end goal is a BSD style ifconfig tool.
I've started work on it, but the project has stalled somewhat.
It's display only right now and the source is not yet publically available.
If you have the skills and share the vision then contact me privately and
we'll take it from there.

1
conf.d/.gitignore vendored
View File

@@ -1 +1,2 @@
network
staticroute

View File

@@ -1,14 +1,19 @@
DIR= ${CONFDIR}
CONF= bootmisc fsck hostname local localmount network urandom
CONF= bootmisc fsck hostname local localmount network staticroute urandom
TARGETS+= network
CLEANFILES+= network
TARGETS+= network staticroute
CLEANFILES+= network staticroute
MK= ../mk
include ${MK}/os.mk
include Makefile.${OS}
include ${MK}/scripts.mk
SOS?= BSD
network: network.in network.${OS}
cp network.in network
[ -e network.${OS} ] && cat network.${OS} >> network || true
cp $@.in $@
[ -e $@.${OS} ] && cat $@.${OS} >> $@ || true
staticroute: staticroute.${SOS}
cp $@.${SOS} $@

View File

@@ -1 +1,2 @@
CONF+= consolefont dmesg hwclock keymaps modules
SOS= Linux

View File

@@ -13,6 +13,11 @@
#fsck_passno=">1"
#fsck_passno="<2"
# Most modern fs's don't require a full fsck on boot, but for those that do
# it may be adivisable to skip this when running on battery.
# WARNING: Do not turn this off if you have any JFS partitions.
fsck_on_battery="YES"
# fsck_shutdown causes fsck to trigger during shutdown as well as startup.
# The end result of this is that if any periodic non-root filesystem checks are
# scheduled, under normal circumstances the actual check will happen during

View File

@@ -1,11 +1,11 @@
# Set CLOCK to "UTC" if your system clock is set to UTC (also known as
# Greenwich Mean Time). If your clock is set to the local time, then
# Set CLOCK to "UTC" if your Hardware Clock is set to UTC (also known as
# Greenwich Mean Time). If that clock is set to the local time, then
# set CLOCK to "local". Note that if you dual boot with Windows, then
# you should set it to "local".
clock="UTC"
# If you want to set the Hardware Clock to the current System Time
# during shutdown, then say "YES" here.
# (software clock) during shutdown, then say "YES" here.
# You normally don't need to do this if you run a ntp daemon.
clock_systohc="NO"

View File

@@ -3,6 +3,9 @@
# On the other hand, ip (iproute2) is quite powerful and is also supported
#ip_eth0="192.168.0.10/24; 192.168.10.10/24"
# ip doesn't handle MTU like ifconfig, but we can do it like so
#ifup_eth0="ip link set \$int mtu 1500"
# Create a bonded interface
#interfaces="bond0"
#ifup_bond0="modprobe bonding; ifconfig \$int up; ifenslave \$int bge0"

View File

@@ -26,3 +26,5 @@
# If you require DHCP, you should install dhcpcd and it to the boot or
# default runlevel.
# NIS users can set the domain name here
#domainname="foobar"

2
conf.d/staticroute.BSD Normal file
View File

@@ -0,0 +1,2 @@
# Example static route. See route(8) for syntax.
staticroute="net 192.168.0.0 -netmask 255.255.0.0 10.73.1.1"

2
conf.d/staticroute.Linux Normal file
View File

@@ -0,0 +1,2 @@
# Example static route. See route(8) for syntax.
staticroute="net 192.168.0.0 netmask 255.255.0.0 gw 10.73.1.1"

1
doc/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
net.example

View File

@@ -992,7 +992,7 @@
# # 'from 24.80.102.112/32 to 192.168.1.0/24 table localnet priority 100' \
# # 'from 216.113.223.51/32 to 192.168.1.0/24 table localnet priority 100' \
# #"
# eval set -- $\rules_${IFVAR}
# eval set -- \$rules_${IFVAR}
# if [ $# != 0 ]; then
# einfo "Adding IP policy routing rules"
# eindent
@@ -1003,7 +1003,7 @@
# else
# for x; do
# ebegin "${x}"
# ip rule add ${x} dev "${IFACE}"
# ip rule add ${x}
# eend $?
# done
# fi

View File

@@ -76,7 +76,7 @@
#unicode="NO"
# Network fstypes. Below is the default.
net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs"
net_fs_list="afs cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre ncpfs nfs nfs4 ocfs2 shfs smbfs"
##############################################################################
# SERVICE CONFIGURATION VARIABLES

11
init.d.misc/.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
avahi-dnsconfd
avahid
dhcpcd
dbus
hald
named
ntpd
openvpn
polkitd
sshd
wpa_supplicant

View File

@@ -14,7 +14,7 @@ depend()
use logger
after bootmisc modules
before dns dhcpcd net
keyword noshutdown
keyword -shutdown
}
find_wireless()
@@ -24,7 +24,9 @@ find_wireless()
case "$RC_UNAME" in
Linux)
for iface in /sys/class/net/*; do
if [ -e "$iface"/wireless ]; then
if [ -e "$iface"/wireless -o \
-e "$iface"/phy80211 ]
then
echo "${iface##*/}"
return 0
fi

5
init.d/.gitignore vendored
View File

@@ -4,6 +4,8 @@ hostname
local
localmount
moused
net.lo
net.lo0
netmount
network
root
@@ -22,6 +24,7 @@ mount-ro
mtab
numlock
procfs
staticroute
sysfs
devdb
hostid
@@ -32,6 +35,8 @@ rc-enabled
rpcbind
savecore
swap-blk
swclock
syslogd
termencoding
ttys
wscons

View File

@@ -1,6 +1,7 @@
DIR= ${INITDIR}
SRCS= bootmisc.in fsck.in hostname.in local.in localmount.in netmount.in \
network.in root.in savecache.in swap.in sysctl.in urandom.in
network.in root.in savecache.in staticroute.in swap.in swclock.in \
sysctl.in urandom.in
BIN= ${OBJS}
# Build our old net foo or not

View File

@@ -22,7 +22,7 @@ depend()
[ "$clock" != "UTC" -a ! -e /etc/wall_cmos_clock ]; then
need root
fi
keyword nojail noprefix
keyword -jail -prefix
}
start()

View File

@@ -8,7 +8,7 @@ depend()
need localmount
before logger
after clock sysctl
keyword noprefix
keyword -prefix
}
dir_writeable()
@@ -26,7 +26,7 @@ cleanup_tmp_dir()
mkdir -p "$dir" || return $?
fi
dir_writeable "$dir" || return 1
chmod +t "$dir"
chmod a+rwt "$dir"
cd "$dir"
if yesno $wipe_tmp; then
ebegin "Wiping $dir directory"
@@ -76,9 +76,10 @@ start()
# Remove any added console dirs
rm -rf "$RC_LIBEXECDIR"/console
local logw=false runw=false
local logw=false runw=false extra=
# Ensure that our basic dirs exist
for x in /var/log /var/run /tmp; do
[ "$RC_UNAME" = Linux ] && extra=/var/lib/misc # Satisfy Linux FHS
for x in /var/log /var/run /tmp $extra; do
if ! [ -d $x ]; then
if ! mkdir -p $x; then
eend 1 "failed to create needed directory $x"
@@ -94,7 +95,7 @@ start()
for x in "" $xtra; do
mkutmp /var/run/utmp$x
done
[ -e /var/log/wtmp ] && mkutmp /var/log/wtmp
[ -e /var/log/wtmp ] || mkutmp /var/log/wtmp
eend 0
ebegin "Cleaning /var/run"
@@ -105,7 +106,7 @@ start()
# Clean stale sockets
if [ -S "$x" ]; then
if type fuser >/dev/null 2>&1; then
fuser "$x" 2>/dev/null || rm -- "$x"
fuser "$x" >/dev/null 2>&1 || rm -- "$x"
else
rm -- "$x"
fi
@@ -149,7 +150,7 @@ start()
fi
fi
rm -f /etc/nologin
[ -w /etc/nologin ] && rm -f /etc/nologin
return 0
}

View File

@@ -8,7 +8,7 @@ depend()
{
need localmount termencoding
after hotplug bootmisc
keyword noopenvz noprefix nouml novserver noxenu
keyword -openvz -prefix -uml -vserver -xenu
}
start()
@@ -45,8 +45,10 @@ start()
[ -d /dev/vc ] && ttydev=/dev/vc/
x=1
while [ $x -le $ttyn ]; do
setfont $consolefont $param -C $ttydev$x >/dev/null
retval=$(($retval + $?))
if ! setfont $consolefont $param -C $ttydev$x >/dev/null; then
retval=1
break
fi
x=$(($x + 1))
done
eend $retval

View File

@@ -10,7 +10,7 @@ depend() {
need localmount
after bootmisc
before net.lo0
keyword nojail noprefix
keyword -jail -prefix
}
start_pre() {

View File

@@ -6,7 +6,7 @@ description="Mount system critical filesystems in /dev."
depend() {
use dev
keyword noprefix novserver
keyword -prefix -vserver
}
start() {

View File

@@ -7,7 +7,7 @@ description="Set the dmesg level for a cleaner boot"
depend()
{
before dev modules
keyword novserver
keyword -vserver
}
start()

View File

@@ -6,7 +6,7 @@ description="Configures a specific kernel dump device."
depend() {
need swap
keyword nojail noprefix
keyword -jail -prefix
}
start() {

View File

@@ -9,7 +9,7 @@ _IFS="
depend()
{
use dev clock modules
keyword nojail noopenvz noprefix notimeout novserver
keyword -jail -openvz -prefix -timeout -vserver -lxc
}
_abort() {
@@ -32,8 +32,8 @@ _forcefsck()
_on_ac_power()
{
if [ -f /proc/acpi/ac_adapter/AC/state ]; then
cat /proc/acpi/ac_adapter/AC/state | while read line; do
if [ -f /proc/acpi/ac_adapter/AC*/state ]; then
cat /proc/acpi/ac_adapter/AC*/state | while read line; do
case "$line" in
"state:"*"off-line") return 128;;
esac
@@ -51,6 +51,11 @@ _on_ac_power()
"connected:"*"OFF") return 128;;
esac
done
elif sysctl -q hw.acpi.acline >/dev/null 2>/dev/null; then
case $(sysctl -n hw.acpi.acline) in
0) return 1;;
*) return 0;;
esac
else
return 0
fi
@@ -68,7 +73,7 @@ start()
if _forcefsck; then
fsck_opts="$fsck_opts -f"
check_extra="(check forced)"
elif ! _on_ac_power; then
elif ! yesno ${fsck_on_battery:-YES} && ! _on_ac_power; then
ewarn "Skipping fsck due to not being on AC power"
return 0
fi

View File

@@ -9,7 +9,7 @@ depend()
{
use root
before devd net
keyword nojail noprefix
keyword -jail -prefix
}
_set()

View File

@@ -5,7 +5,7 @@
description="Sets the hostname of the machine."
depend() {
keyword noprefix
keyword -prefix
}
start()

View File

@@ -28,7 +28,7 @@ depend()
else
before *
fi
keyword noopenvz noprefix nouml novserver noxenu
keyword -openvz -prefix -uml -vserver -xenu -lxc
}
setupopts()
@@ -118,7 +118,7 @@ stop()
if ! yesno $clock_adjfile; then
# Some implementations don't handle adjustments
if LC_ALL=C hwclock --help | grep -q "\-\-noadjfile"; then
if LC_ALL=C hwclock --help 2>&1 | grep -q "\-\-noadjfile"; then
utc_cmd="$utc_cmd --noadjfile"
fi
fi

View File

@@ -13,7 +13,7 @@ opts="panic showstatus"
depend() {
before net
provide firewall
keyword nojail
keyword -jail
}
ipfw() {

View File

@@ -8,14 +8,14 @@ depend()
{
need localmount termencoding
after bootmisc
keyword noopenvz noprefix nouml novserver noxenu
keyword -openvz -prefix -uml -vserver -xenu
}
start()
{
ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
: ${unicode:=$UNICODE}
: =${keymap:=$KEYMAP}
: ${keymap:=$KEYMAP}
: ${extended_keymaps:=$EXTENDED_KEYMAPS}
: ${windowkeys:=$SET_WINDOWSKEYS}
: ${fix_euro:=$FIX_EURO}
@@ -34,15 +34,25 @@ start()
echo 1 > /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes
fi
ebegin "Loading key mappings [$keymap]"
local loadkeys_uni= wkeys= kmode="-a" msg="ASCII"
local 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
# Set terminal encoding to either ASCII or UNICODE.
# See utf-8(7) for more information.
ebegin "Setting keyboard mode [$msg]"
n=1
while [ $n -le $ttyn ]; do
kbd_mode $kmode -C $ttydev$n
n=$(($n + 1))
done
eend 0
ebegin "Loading key mappings [$keymap]"
loadkeys -q $wkeys $keymap $extended_keymaps
eend $? "Error loading key mappings" || return $?
if yesno $fix_euro; then
@@ -52,20 +62,6 @@ start()
eend $?
fi
# Set terminal encoding to either ASCII or UNICODE.
# See utf-8(7) for more information.
ebegin "Setting keyboard mode [$msg]"
if yesno $unicode; then
dumpkeys ${dumpkeys_charset:+-c} \
$dumpkeys_charset | loadkeys --unicode
fi
n=1
while [ $n -le $ttyn ]; do
kbd_mode $kmode -C $ttydev$n
n=$(($n + 1))
done
eend 0
# Save the keymapping for use immediately at boot
if [ -w "$RC_LIBEXECDIR" ]; then
mkdir -p "$RC_LIBEXECDIR"/console

View File

@@ -6,7 +6,7 @@ description="Kill all processes so we can unmount disks cleanly."
depend()
{
keyword noprefix
keyword -prefix
}
start()

View File

@@ -7,7 +7,7 @@ description="Executes user commands in /etc/conf.d/local"
depend()
{
after *
keyword notimeout
keyword -timeout
}
start()

View File

@@ -8,7 +8,7 @@ depend()
{
need fsck
use lvm modules mtab
keyword nojail noopenvz noprefix novserver
keyword -jail -openvz -prefix -vserver -lxc
}
start()

View File

@@ -7,7 +7,7 @@ extra_commands="restore"
depend()
{
need localmount
keyword nojail noprefix
keyword -jail -prefix
}
restore()

View File

@@ -7,7 +7,7 @@ description="Loads a user defined list of kernel modules."
depend()
{
use isapnp
keyword noopenvz noprefix novserver
keyword -openvz -prefix -vserver -lxc
}
start()

View File

@@ -7,7 +7,7 @@ description="Re-mount filesytems read-only for a clean reboot."
depend()
{
need killprocs savecache
keyword noprefix noopenvz novserver
keyword -prefix -openvz -vserver -lxc
}
start()

View File

@@ -16,7 +16,7 @@ depend()
{
need localmount
after bootmisc
keyword nojail noprefix
keyword -jail -prefix
}
start()

View File

@@ -7,11 +7,17 @@ description="Update /etc/mtab to match what the kernel knows about"
depend()
{
need root
keyword noprefix
keyword -prefix
}
start()
{
# /etc/mtab could be a symlink to /proc/mounts
if [ ! -w /etc/mtab -a -L /etc/mtab ]; then
eeinfo "Skipping mtab update (non writeable symlink)"
return 0
fi
ebegin "Updating /etc/mtab"
if ! echo 2>/dev/null >/etc/mtab; then
ewend 1 "/etc/mtab is not updateable"

View File

@@ -1,5 +1,5 @@
#!@PREFIX@/sbin/runscript
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
MODULESDIR="${RC_LIBEXECDIR}/net"
@@ -21,7 +21,7 @@ depend()
need localmount
after bootmisc
provide net
keyword nojail noprefix novserver
keyword -jail -prefix -vserver
case "${IFACE}" in
lo|lo0);;

View File

@@ -35,7 +35,7 @@ depend()
need net $pmap
use afc-client amd autofs openvpn
use dns nfs nfsmount portmap rpcbind rpc.statd rpc.lockd
keyword nojail noprefix novserver
keyword -jail -prefix -vserver
}
start()

View File

@@ -13,7 +13,7 @@ depend()
need localmount
after bootmisc
provide net
keyword nojail noprefix novserver
keyword -jail -prefix -vserver
}
uniqify()
@@ -103,13 +103,27 @@ dumpargs()
esac
}
intup=false
runip()
{
local int="$1" err=
shift
# Ensure we have a valid broadcast address
case "$@" in
*" broadcast "*|*" brd "*) ;;
*) set -- "$@" brd +;;
esac
err=$(LC_ALL=C ip address add "$@" dev "$int" 2>&1)
[ -z "$err" ] && return 0
if [ -z "$err" ]; then
# ip does not bring up the interface when adding addresses
if ! $intup; then
ip link set "$int" up
intup=true
fi
return 0
fi
if [ "$err" = "RTNETLINK answers: File exists" ]; then
ip address del "$@" dev "$int" 2>/dev/null
fi
@@ -165,6 +179,16 @@ runargs()
start()
{
local cr=0 r= int= intv= cmd= args= upcmd=
if [ -z "$domainname" -a -s /etc/defaultdomain ]; then
domainname=$(cat /etc/defaultdomain)
fi
if [ -n "$domainname" ]; then
ebegin "Setting NIS domainname: $domainname"
domainname "$domainname"
eend $?
fi
einfo "Starting network"
routeflush
if [ "$RC_UNAME" = "Linux" ]; then
@@ -194,7 +218,7 @@ start()
-f /etc/ifup."$int" -o -f "$cf" ] || continue
veinfo "$int"
case "$func" in
ip) func=runip;;
ip) func=runip; intup=false;;
esac
eindent
runargs /etc/ifup."$int" "$upcmd"

View File

@@ -7,7 +7,7 @@ required_files="/etc/newsyslog.conf"
depend()
{
need localmount
keyword noprefix
keyword -prefix
}
start()

View File

@@ -9,7 +9,7 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
depend()
{
need localmount
keyword noopenvz noprefix novserver
keyword -openvz -prefix -vserver -lxc
}
_setleds()

View File

@@ -11,7 +11,7 @@ extra_started_commands="reload"
depend() {
need localmount
keyword nojail noprefix
keyword -jail -prefix
}
start()

View File

@@ -12,7 +12,7 @@ depend()
need localmount
use logger
after bootmisc
keyword nojail noprefix
keyword -jail -prefix
}
start_pre()

View File

@@ -8,7 +8,7 @@ depend()
{
use modules devfs
need localmount
keyword noopenvz noprefix novserver
keyword -openvz -prefix -vserver -lxc
}
start()

View File

@@ -7,7 +7,7 @@ depend()
need localmount net
after *
before local
keyword noprefix
keyword -prefix
}
start()

View File

@@ -7,7 +7,7 @@ description="Mount the root fs read/write"
depend()
{
need fsck
keyword nojail noopenvz noprefix novserver
keyword -jail -openvz -prefix -vserver -lxc
}
start()

View File

@@ -22,7 +22,7 @@ start()
fi
fi
local save=
for x in deptree depconfig softlevel nettree rc.log; do
for x in deptree depconfig shutdowntime softlevel nettree rc.log; do
[ -e "$RC_SVCDIR/$x" ] && save="$save $RC_SVCDIR/$x"
done
if [ -n "$save" ]; then

View File

@@ -7,7 +7,7 @@ description="Saves a kernel dump."
depend()
{
need localmount
keyword nojail noprefix
keyword -jail -prefix
}
start()

73
init.d/staticroute.in Normal file
View File

@@ -0,0 +1,73 @@
#!@PREFIX@/sbin/runscript
# Copyright (c) 2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
# This script was inspired by the equivalent rc.d staticroute from NetBSD.
description="Configures static routes."
__nl="
"
depend()
{
provide net
use network
keyword -jail -prefix -vserver
}
dump_args()
{
if [ -s /etc/route.conf ]; then
cat /etc/route.conf
else
case "$staticroute" in
*"$__nl"*)
echo "$staticroute"
;;
*)
(
set -o noglob
IFS=';'; set -- $staticroute
IFS="$__nl"; echo "$*"
)
;;
esac
fi
}
do_routes()
{
local xtra=
[ "$RC_UNAME" != Linux ] && xtra=-q
ebegin "$1 static routes"
dump_args | while read args; do
[ -z "$args" ] && continue
case "$args" in
"#"*)
;;
"+"*)
[ $2 = "add" ] && eval ${args#*+}
;;
"-"*)
[ $2 = "del" -o $2 = "delete" ] && eval ${args#*-}
;;
*)
route $xtra $2 -$args
;;
esac
done
eend 0
}
start()
{
do_routes "Adding" "add"
}
stop()
{
local cmd="delete"
[ "$RC_UNAME" = Linux ] && cmd="del"
do_routes "Deleting" "$cmd"
}

View File

@@ -5,7 +5,7 @@
depend()
{
before fsck
keyword nojail noprefix
keyword -jail -prefix
}
start()

View File

@@ -5,7 +5,7 @@
depend()
{
need localmount
keyword nojail noopenvz noprefix novserver
keyword -jail -openvz -prefix -vserver -lxc
}
start()

28
init.d/swclock.in Normal file
View File

@@ -0,0 +1,28 @@
#!@PREFIX@/sbin/runscript
# Copyright (c) 2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
description="Sets the local clock to the mtime of a given file."
depend()
{
before *
provide clock
keyword -openvz -prefix -uml -vserver -xenu -lxc
}
# swclock is an OpenRC built in
start()
{
ebegin "Setting the local clock based on last shutdown time"
swclock --warn
eend $?
}
stop()
{
ebegin "Saving the shutdown time"
swclock --save
eend $?
}

View File

@@ -4,7 +4,7 @@
depend() {
need localmount
keyword nojail noprefix
keyword -jail -prefix
}
start() {

View File

@@ -6,19 +6,27 @@ depend()
{
use hostname
before bootmisc logger
keyword noprefix
keyword -prefix
}
start()
{
[ -e /etc/sysctl.conf ] || return 0
local retval=0 var= comments=
local retval=0 var= comments= conf=
ebegin "Configuring kernel parameters"
while read var comments; do
case "$var" in
""|"#"*) continue;;
esac
sysctl -w "$var" >/dev/null || retval=1
done < /etc/sysctl.conf
eindent
for conf in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
if [ -r "$conf" ]; then
vebegin "applying $conf"
while read var comments; do
case "$var" in
""|"#"*) continue;;
esac
sysctl -w "$var" >/dev/null || retval=1
done < "$conf"
veend $retval
fi
done
eoutdent
eend $retval "Some errors were encountered"
}

View File

@@ -6,13 +6,21 @@ depend()
{
use hostname
before bootmisc logger
keyword noopenvz noprefix novserver
keyword -openvz -prefix -vserver
}
start()
{
[ -e /etc/sysctl.conf ] || return 0
local conf= retval=0
ebegin "Configuring kernel parameters"
sysctl -p >/dev/null
eend $? "Some errors were encountered"
eindent
for conf in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
if [ -r "$conf" ]; then
vebegin "applying $conf"
sysctl -p "$conf" >/dev/null
veend $? || retval=1
fi
done
eoutdent
eend $retval "Some errors were encountered"
}

View File

@@ -6,7 +6,7 @@ description="Mount the sys filesystem."
depend()
{
keyword noprefix novserver
keyword -prefix -vserver
}
mount_sys()

View File

@@ -16,5 +16,5 @@ depend()
use net newsyslog
need localmount
after bootmisc
keyword noprefix
keyword -prefix
}

View File

@@ -9,7 +9,7 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
depend()
{
keyword noopenvz noprefix nouml novserver noxenu
keyword -openvz -prefix -uml -vserver -xenu
}
start()

View File

@@ -5,7 +5,7 @@
depend()
{
after fsck
keyword noprefix
keyword -prefix
}
start()

View File

@@ -8,7 +8,7 @@ description="Initializes the random number generator."
depend()
{
need localmount
keyword nojail noprefix
keyword -jail -openvz -prefix
}
save_seed()

View File

@@ -5,7 +5,7 @@
depend()
{
need localmount
keyword noprefix
keyword -prefix
}
start()

View File

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 30, 2009
.Dd November 4, 2009
.Dt RUNSCRIPT 8 SMM
.Os OpenRC
.Sh NAME
@@ -138,30 +138,32 @@ We should recalculate our dependencies if the listed files have changed.
.It Ic keyword
Tags a service with a keyword. Here's the keywords we currently understand:-
.Bl -tag -width indent
.It Dv nojail
.It Dv -jail
When in a jail, exclude this service from any dependencies. The service can
still be run directly.
.It Dv noopenvz
Same as nojail, but for OpenVZ systems.
.It Dv noshutdown
.It Dv -openvz
Same as -jail, but for OpenVZ systems.
.It Dv -lxc
Same as -jail, but for Linux Resource Containers (LXC).
.It Dv -shutdown
Don't stop this service when shutting the system down.
This normally quite safe as remaining daemons will be sent a SIGTERM just
before final shutdown.
Network related services such as the network and dhcpcd init scripts normally
have this keyword.
.It Dv nostop
.It Dv -stop
Don't stop this service when changing runlevels, even if not present.
This includes shutting the system down.
.It Dv notimeout
.It Dv -timeout
Do not time out waiting for that service.
.It Dv nouml
Same as nojail, but for UML systems.
.It Dv novserver
Same as nojail, but for VServer systems.
.It Dv noxen0
Same as nojail, but for Xen DOM0 systems.
.It Dv noxenu
Same as nojail, but for Xen DOMU systems.
.It Dv -uml
Same as -jail, but for UML systems.
.It Dv -vserver
Same as -jail, but for VServer systems.
.It Dv -xen0
Same as -jail, but for Xen DOM0 systems.
.It Dv -xenu
Same as -jail, but for Xen DOMU systems.
.El
.El
.Pp

View File

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 22, 2009
.Dd October 14, 2009
.Dt START-STOP-DAEMON 8 SMM
.Os OpenRC
.Sh NAME
@@ -98,6 +98,8 @@ 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
Print the action(s) that are taken just before doing them.
.It Fl P , -progress
Echo a . to the console for each second elapsed whilst waiting.
.El
.Pp
These options are only used for starting daemons:
@@ -142,9 +144,9 @@ Redirect the standard output of the process to logfile when started with
Must be an absolute pathname, but relative to the path optionally given with
.Fl r , -chroot .
The logfile can also be a named pipe.
.It Fl w , -wait Ar seconds
.It Fl w , -wait Ar milliseconds
Wait
.Ar seconds
.Ar milliseconds
after starting and check that daemon is still running.
Useful for daemons that check configuration after forking or stopping race
conditions where the pidfile is written out after forking.

View File

@@ -56,8 +56,11 @@ dhcpcd_start()
esac
done
# Add our route metric
[ "${metric:-0}" != "0" ] && args="${args} -m ${metric}"
# Add our route metric if not given
case " $args " in
*" -m "*) ;;
*) [ "${metric:-0}" != 0 ] && args="$args -m $metric";;
esac
# Bring up DHCP for this interface
ebegin "Running dhcpcd"

View File

@@ -261,6 +261,17 @@ _tunnel()
ifconfig_pre_start()
{
local tunnel=
eval tunnel=\$iptunnel_${IFVAR}
if [ -n "${tunnel}" ]; then
# Set our base metric to 1000
metric=1000
ebegin "Creating tunnel ${IFVAR}"
iptunnel add ${tunnel}
eend $? || return 1
_up
fi
# MTU support
local mtu=
eval mtu=\$mtu_${IFVAR}
@@ -271,17 +282,7 @@ ifconfig_pre_start()
eval len=\$txqueuelen_${IFVAR}
[ -n "${len}" ] && ifconfig "${IFACE}" txqueuelen "${len}"
local tunnel=
eval tunnel=\$iptunnel_${IFVAR}
[ -z "${tunnel}" ] && return 0
# Set our base metric to 1000
metric=1000
ebegin "Creating tunnel ${IFVAR}"
iptunnel add ${tunnel}
eend $?
return 0
}
ifconfig_post_stop()

View File

@@ -157,7 +157,10 @@ _add_route()
shift
done
if ! ${have_metric} && [ -n "${metric}" ]; then
# We cannot use a metric if we're using a nexthop
if ! ${have_metric} && \
[ -n "${metric}" -a -z "${cmd##* nexthop }" ]
then
cmd="${cmd} metric ${metric}"
fi
@@ -187,16 +190,6 @@ _tunnel()
iproute2_pre_start()
{
# MTU support
local mtu=
eval mtu=\$mtu_${IFVAR}
[ -n "${mtu}" ] && ip link set "${IFACE}" mtu "${mtu}"
# TX Queue Length support
local len=
eval len=\$txqueuelen_${IFVAR}
[ -n "${len}" ] && ip link set "${IFACE}" txqueuelen "${len}"
local tunnel=
eval tunnel=\$iptunnel_${IFVAR}
if [ -n "${tunnel}" ]; then
@@ -209,6 +202,16 @@ iproute2_pre_start()
_up
fi
# MTU support
local mtu=
eval mtu=\$mtu_${IFVAR}
[ -n "${mtu}" ] && ip link set "${IFACE}" mtu "${mtu}"
# TX Queue Length support
local len=
eval len=\$txqueuelen_${IFVAR}
[ -n "${len}" ] && ip link set "${IFACE}" txqueuelen "${len}"
return 0
}
@@ -222,6 +225,8 @@ _iproute2_ipv6_tentative()
iproute2_post_start()
{
local n=5
# Kernel may not have IP built in
if [ -e /proc/net/route ]; then
ip route flush table cache dev "${IFACE}"
@@ -229,11 +234,16 @@ iproute2_post_start()
if _iproute2_ipv6_tentative; then
ebegin "Waiting for IPv6 addresses"
while true; do
while [ $n -ge 0 ]; do
_iproute2_ipv6_tentative || break
sleep 1
n=$(($n - 1))
done
eend 0
[ $n -ge 0 ]
eend $?
fi
return 0
}
iproute2_post_stop()

View File

@@ -90,7 +90,7 @@ pppd_pre_start()
eval passwordset=\$\{password_${IFVAR}-x\}
if [ -n "${username}" ] \
&& [ -n "${password}" -o -z "${passwordset}" ]; then
opts="${opts} plugin passwordfd.so passwordfd 0"
opts="plugin passwordfd.so ${opts} passwordfd 0"
fi
if ! ${hasdefaultmetric}; then
@@ -155,7 +155,7 @@ pppd_pre_start()
opts="${opts} connect true"
set -- "$@" "${link}"
fi
opts="${opts} plugin $1.so"
opts="plugin $1.so ${opts}"
shift
opts="${opts} $@"
done

2
pkgconfig/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
einfo.pc
openrc.pc

11
pkgconfig/Makefile Normal file
View File

@@ -0,0 +1,11 @@
DIR= ${LIBDIR}/pkgconfig
SRCS= einfo.pc.in openrc.pc.in
INC= einfo.pc openrc.pc
sed -n -e 's/^VERSION=[[:space:]]*\([^[:space:]]*\).*/#define VERSION "\1${GITVER}\"/p' ../../Makefile > version.h
SED_EXTRA= -e 's:@VERSION@:${VERSION}:g'
MK= ../mk
include ../Makefile.inc
include ${MK}/scripts.mk

9
pkgconfig/einfo.pc.in Normal file
View File

@@ -0,0 +1,9 @@
prefix=@PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@LIB@
includedir=/usr/include
Name: einfo
Description: Pretty console informational display
Version: @VERSION@
Libs: -L${libdir} -leinfo

10
pkgconfig/openrc.pc.in Normal file
View File

@@ -0,0 +1,10 @@
prefix=@PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@LIB@
includedir=/usr/include
Name: OpenRC
Description: Universal init system
Version: @VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -lrc

View File

@@ -1,5 +1,5 @@
BOOT= bootmisc fsck hostname localmount network \
root swap sysctl urandom
root staticroute swap sysctl urandom
DEFAULT= local netmount
SHUTDOWN= savecache

View File

@@ -8,14 +8,19 @@
# tmpfs and ramfs are easy, so force one or the other.
mount_svcdir()
{
# mount from fstab if we can
fstabinfo --mount "$RC_SVCDIR" && return 0
local fs= fsopts="-o rw,noexec,nodev,nosuid"
local devdir="rc-svcdir" x=
local svcsize=${rc_svcsize:-1024}
# Some buggy kernels report tmpfs even when not present :(
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
fs="tmpfs"
fsopts="$fsopts,mode=0755,size=${svcsize}k"
elif grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
mount -n -t tmpfs $fsopts,mode=755,size=${svcsize}k \
rc-svcdir "$RC_SVCDIR" && return 0
fi
if grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
fs="ramfs"
# ramfs has no special options
elif [ -e /dev/ram0 ] \
@@ -32,10 +37,7 @@ mount_svcdir()
return 1
fi
# If we have no entry in fstab for $RC_SVCDIR, provide our own
if ! fstabinfo --mount "$RC_SVCDIR"; then
mount -n -t "$fs" $fsopts "$devdir" "$RC_SVCDIR"
fi
mount -n -t "$fs" $fsopts rc-svcdir "$RC_SVCDIR"
}
. "$RC_LIBEXECDIR"/sh/functions.sh

View File

@@ -25,6 +25,29 @@ shift
# Compat
export SVCNAME=$RC_SVCNAME
# Dependency function
config() {
[ -n "$*" ] && echo "config $*"
}
need() {
[ -n "$*" ] && echo "need $*"
}
use() {
[ -n "$*" ] && echo "use $*"
}
before() {
[ -n "$*" ] && echo "before $*"
}
after() {
[ -n "$*" ] && echo "after $*"
}
provide() {
[ -n "$*" ] && echo "provide $*"
}
keyword() {
[ -n "$*" ] && echo "keyword $*"
}
# Descript the init script to the user
describe()
{
@@ -165,7 +188,7 @@ unset _f
while [ -n "$1" ]; do
# See if we have the required function and run it
for _cmd in describe start stop status ${extra_commands:-$opts} \
for _cmd in describe start stop status depend ${extra_commands:-$opts} \
$extra_started_commands
do
if [ "$_cmd" = "$1" ]; then

View File

@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define RC_LEVEL_BOOT "boot"

View File

@@ -346,8 +346,9 @@ get_provided(const RC_DEPINFO *depinfo, const char *runlevel, int options)
get_provided1(runlevel, providers, dt, bootlevel, false, RC_SERVICE_STOPPED))
return providers;
/* Still nothing? OK, list all services */
TAILQ_FOREACH(service, dt->services, entries)
/* Still nothing? OK, list our first provided service. */
service = TAILQ_FIRST(dt->services);
if (service != NULL)
rc_stringlist_add(providers, service->value);
return providers;
@@ -738,7 +739,7 @@ rc_deptree_update(void)
RC_STRING *s, *s2, *s2_np, *s3, *s4;
char *line = NULL;
size_t len = 0;
char *depend, *depends, *service, *type, *nosys;
char *depend, *depends, *service, *type, *nosys, *onosys;
size_t i, k, l;
bool retval = true;
const char *sys = rc_sys();
@@ -802,6 +803,11 @@ rc_deptree_update(void)
continue;
}
/* Don't provide ourself */
if (strcmp(type, "iprovide") == 0 &&
strcmp(depend, service) == 0)
continue;
/* .sh files are not init scripts */
l = strlen(depend);
if (l > 2 &&
@@ -841,17 +847,25 @@ rc_deptree_update(void)
* work for them. This doesn't stop them from being run directly. */
if (sys) {
len = strlen(sys);
nosys = xmalloc(len + 3);
nosys[0] = 'n';
nosys[1] = 'o';
nosys = xmalloc(len + 1);
nosys[0] = '-';
for (i = 0; i < len; i++)
nosys[i + 2] = (char)tolower((unsigned char)sys[i]);
nosys[i + 2] = '\0';
nosys[i + 1] = (char)tolower((unsigned char)sys[i]);
nosys[i + 1] = '\0';
onosys = xmalloc(len + 3);
onosys[0] = 'n';
onosys[1] = 'o';
for (i = 0; i < len; i++)
onosys[i + 2] = (char)tolower((unsigned char)sys[i]);
onosys[i + 2] = '\0';
TAILQ_FOREACH_SAFE(depinfo, deptree, entries, depinfo_np)
if ((deptype = get_deptype(depinfo, "keyword")))
TAILQ_FOREACH(s, deptype->services, entries)
if (strcmp(s->value, nosys) == 0) {
if (strcmp(s->value, nosys) == 0 ||
strcmp(s->value, onosys) == 0)
{
provide = get_deptype(depinfo, "iprovide");
TAILQ_REMOVE(deptree, depinfo, entries);
TAILQ_FOREACH(di, deptree, entries) {
@@ -870,6 +884,7 @@ rc_deptree_update(void)
}
}
free(nosys);
free(onosys);
}
/* Phase 3 - add our providers to the tree */

View File

@@ -233,6 +233,8 @@ rc_sys(void)
return RC_SYS_VSERVER;
else if (exists("/proc/vz/veinfo") && !exists("/proc/vz/version"))
return RC_SYS_OPENVZ;
else if (file_regex("/proc/self/cgroup", ":/.+$"))
return RC_SYS_LXC;
else if (file_regex("/proc/self/status",
"envID:[[:space:]]*[1-9]"))
return RC_SYS_OPENVZ; /* old test */
@@ -468,7 +470,7 @@ rc_service_exists(const char *service)
}
librc_hidden_def(rc_service_exists)
#define OPTSTR ". '%s'; echo \"${opts}\""
#define OPTSTR ". '%s'; echo $opts"
RC_STRINGLIST *
rc_service_extra_commands(const char *service)
{

View File

@@ -72,8 +72,6 @@
#define librc_hidden_proto(x) hidden_proto(x)
#define librc_hidden_def(x) hidden_def(x)
ssize_t rc_getline(char **, size_t *, FILE *);
librc_hidden_proto(rc_config_list)
librc_hidden_proto(rc_config_load)
librc_hidden_proto(rc_config_value)

View File

@@ -268,6 +268,7 @@ bool rc_service_daemons_crashed(const char *);
* Some services cannot work in these systems, or we do something else. */
#define RC_SYS_JAIL "JAIL"
#define RC_SYS_OPENVZ "OPENVZ"
#define RC_SYS_LXC "LXC"
#define RC_SYS_PREFIX "PREFIX"
#define RC_SYS_UML "UML"
#define RC_SYS_VSERVER "VSERVER"
@@ -517,5 +518,9 @@ typedef LIST_HEAD(rc_pidlist, rc_pid) RC_PIDLIST;
* @return NULL terminated list of pids */
RC_PIDLIST *rc_find_pids(const char *, const char *const *, uid_t, pid_t);
/* getline is a handy glibc function that not all libcs have, so
* we have our own */
ssize_t rc_getline(char **, size_t *, FILE *);
__END_DECLS
#endif

View File

@@ -12,6 +12,7 @@ global:
rc_deptree_update_needed;
rc_environ_fd;
rc_find_pids;
rc_getline;
rc_newer_than;
rc_older_than;
rc_runlevel_exists;

2
src/rc/.gitignore vendored
View File

@@ -38,6 +38,7 @@ service_crashed
checkpath
fstabinfo
mountinfo
swclock
rc-depend
service_get_value
service_set_value
@@ -59,6 +60,7 @@ checkpath.o
fstabinfo.o
mountinfo.o
start-stop-daemon.o
swclock.o
rc-applets.o
rc-depend.o
rc-logger.o

View File

@@ -2,7 +2,7 @@ PROG= rc
SRCS= checkpath.c fstabinfo.c mountinfo.c start-stop-daemon.c \
rc-applets.c rc-depend.c rc-logger.c \
rc-misc.c rc-plugin.c rc-service.c rc-status.c rc-update.c \
runscript.c rc.c
runscript.c rc.c swclock.c
CLEANFILES= version.h
@@ -26,7 +26,7 @@ RC_SBINLINKS= mark_service_starting mark_service_started \
mark_service_stopping mark_service_stopped \
mark_service_inactive mark_service_wasinactive \
mark_service_hotplugged mark_service_failed \
rc-abort
rc-abort swclock
ALL_LINKS= ${BINLINKS} ${SBINLINKS} ${RC_BINLINKS} ${RC_SBINLINKS}
CLEANFILES+= ${ALL_LINKS}
@@ -34,6 +34,7 @@ CPPFLAGS+= -I../includes -I../librc -I../libeinfo
LDFLAGS+= -L../librc -L../libeinfo
LDADD+= -lutil -lrc -leinfo
include ../../Makefile.inc
MK= ../../mk
include ${MK}/debug.mk
include ${MK}/prog.mk
@@ -45,12 +46,17 @@ LDADD+= ${LIBDL} ${LIBKVM}
include ${MK}/${MKPAM}.mk
${SRCS}: version.h
version.h:
sed -n -e 's/^VERSION=[[:space:]]*\([^[:space:]]*\).*/#define VERSION "\1${GITVER}\"/p' ../../Makefile > version.h
.PHONY: version.h.tmp
version.h.tmp:
echo "#define VERSION \"${VERSION}${GITVER}\"" >$@
if test -n "${BRANDING}"; then \
echo "#define BRANDING \"${BRANDING}\"" >> version.h; \
echo "#define BRANDING \"${BRANDING}\"" >> $@; \
fi
version.h: version.h.tmp
cmp -s $@.tmp $@ && rm $@.tmp || mv $@.tmp $@
install: all
${INSTALL} -d ${DESTDIR}${SBINDIR}
${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${SBINDIR}

View File

@@ -35,6 +35,7 @@ int rc_status(int, char **);
int rc_update(int, char **);
int runscript(int, char **);
int start_stop_daemon(int, char **);
int swclock(int, char **);
void run_applets(int, char **);

View File

@@ -449,6 +449,8 @@ run_applets(int argc, char **argv)
exit(start_stop_daemon(argc, argv));
else if (strcmp (applet, "checkpath") == 0)
exit(checkpath(argc, argv));
else if (strcmp(applet, "swclock") == 0)
exit(swclock(argc, argv));
/* These could also be applications in their own right */
if (strcmp(applet, "shell_var") == 0)

View File

@@ -43,10 +43,6 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#include <sys/utsname.h>
#include <sys/wait.h>
#ifdef __linux__
# include <asm/setup.h> /* for COMMAND_LINE_SIZE */
#endif
#include <errno.h>
#include <dirent.h>
#include <ctype.h>
@@ -177,10 +173,8 @@ static char *
proc_getent(const char *ent)
{
FILE *fp;
char proc[COMMAND_LINE_SIZE];
char *p;
char *value = NULL;
int i;
char *proc, *p, *value = NULL;
size_t i;
if (!exists("/proc/cmdline"))
return NULL;
@@ -190,11 +184,11 @@ proc_getent(const char *ent)
return NULL;
}
memset(proc, 0, sizeof(proc));
p = fgets(proc, sizeof(proc), fp);
if (p == NULL)
eerror("fgets: %s", strerror(errno));
else if (*proc && (p = strstr(proc, ent))) {
proc = NULL;
i = 0;
if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
eerror("rc_getline: %s", strerror(errno));
if (*proc && (p = strstr(proc, ent))) {
i = p - proc;
if (i == '\0' || proc[i - 1] == ' ') {
p += strlen(ent);
@@ -205,6 +199,7 @@ proc_getent(const char *ent)
} else
errno = ENOENT;
fclose(fp);
free(proc);
return value;
}
@@ -605,8 +600,11 @@ do_stop_services(const char *newlevel, bool parallel, bool going_down)
continue;
}
kwords = rc_deptree_depend(deptree, service->value, "keyword");
if (rc_stringlist_find(kwords, "nostop") ||
(going_down && rc_stringlist_find(kwords, "noshutdown")))
if (rc_stringlist_find(kwords, "-stop") ||
rc_stringlist_find(kwords, "nostop") ||
(going_down &&
(rc_stringlist_find(kwords, "-shutdown") ||
rc_stringlist_find(kwords, "noshutdown"))))
nstop = true;
else
nstop = false;

View File

@@ -471,7 +471,8 @@ svc_wait(const char *svc)
/* Some services don't have a timeout, like fsck */
keywords = rc_deptree_depend(deptree, svc, "keyword");
if (rc_stringlist_find(keywords, "notimeout"))
if (rc_stringlist_find(keywords, "-timeout") ||
rc_stringlist_find(keywords, "notimeout"))
forever = true;
rc_stringlist_free(keywords);
@@ -755,13 +756,10 @@ static void svc_start_real()
if (ibsave)
unsetenv("IN_BACKGROUND");
if (!started)
if (rc_service_state(service) & RC_SERVICE_INACTIVE)
ewarnx("WARNING: %s has started, but is inactive", applet);
else if (!started)
eerrorx("ERROR: %s failed to start", applet);
else {
if (rc_service_state(service) & RC_SERVICE_INACTIVE)
ewarnx("WARNING: %s has started, but is inactive",
applet);
}
rc_service_mark(service, RC_SERVICE_STARTED);
exclusive_fd = svc_unlock(applet, exclusive_fd);
@@ -1275,7 +1273,8 @@ runscript(int argc, char **argv)
doneone = true;
if (strcmp(optarg, "describe") == 0 ||
strcmp(optarg, "help") == 0)
strcmp(optarg, "help") == 0 ||
strcmp(optarg, "depend") == 0)
{
save = prefix;
eprefix(NULL);

View File

@@ -37,6 +37,7 @@
#define POLL_INTERVAL 20000000
#define WAIT_PIDFILE 500000000
#define ONE_SECOND 1000000000
#define ONE_MS 1000000
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -155,7 +156,8 @@ parse_signal(const char *sig)
{ "STOP", SIGSTOP },
{ "TSTP", SIGTSTP },
{ "TTIN", SIGTTIN },
{ "TTOU", SIGTTOU }
{ "TTOU", SIGTTOU },
{ "NULL", 0 },
};
unsigned int i = 0;
@@ -165,7 +167,7 @@ parse_signal(const char *sig)
return -1;
if (sscanf(sig, "%u", &i) == 1) {
if (i > 0 && i < sizeof(signallist) / sizeof(signallist[0]))
if (i < NSIG)
return i;
eerrorx("%s: `%s' is not a valid signal", applet, sig);
}
@@ -369,16 +371,17 @@ do_stop(const char *exec, const char *const *argv,
static int
run_stop_schedule(const char *exec, const char *const *argv,
const char *pidfile, uid_t uid,
bool quiet, bool verbose, bool test)
bool quiet, bool verbose, bool test, bool progress)
{
SCHEDULEITEM *item = TAILQ_FIRST(&schedule);
int nkilled = 0;
int tkilled = 0;
int nrunning = 0;
long nloops;
long nloops, nsecs;
struct timespec ts;
pid_t pid = 0;
const char *const *p;
bool progressed = false;
if (verbose) {
if (exec)
@@ -416,6 +419,8 @@ run_stop_schedule(const char *exec, const char *const *argv,
quiet, verbose, test);
if (nkilled == 0) {
if (tkilled == 0) {
if (progressed)
printf("\n");
if (! quiet)
eerror("%s: no matching "
"processes found", applet);
@@ -433,30 +438,47 @@ run_stop_schedule(const char *exec, const char *const *argv,
break;
}
nloops = (ONE_SECOND / POLL_INTERVAL) * item->value;
ts.tv_sec = 0;
ts.tv_nsec = POLL_INTERVAL;
while (nloops) {
if ((nrunning = do_stop(exec, argv, pid,
uid, 0, true, false, true)) == 0)
return 0;
if (nanosleep(&ts, NULL) == -1) {
if (errno == EINTR)
eerror("%s: caught an"
" interrupt", applet);
else {
eerror("%s: nanosleep: %s",
applet, strerror(errno));
for (nsecs = 0; nsecs < item->value; nsecs++) {
for (nloops = 0;
nloops < ONE_SECOND / POLL_INTERVAL;
nloops++)
{
if ((nrunning = do_stop(exec, argv,
pid, uid, 0, true, false,
true)) == 0)
return 0;
if (nanosleep(&ts, NULL) == -1) {
if (progressed) {
printf("\n");
progressed = false;
}
if (errno == EINTR)
eerror("%s: caught an"
" interrupt", applet);
else {
eerror("%s: nanosleep: %s",
applet, strerror(errno));
return 0;
}
}
}
nloops --;
if (progress) {
printf(".");
fflush(stdout);
progressed = true;
}
}
break;
default:
if (progressed) {
printf("\n");
progressed = false;
}
eerror("%s: invalid schedule item `%d'",
applet, item->type);
return 0;
@@ -469,6 +491,8 @@ run_stop_schedule(const char *exec, const char *const *argv,
if (test || (tkilled > 0 && nrunning == 0))
return nkilled;
if (progressed)
printf("\n");
if (! quiet) {
if (nrunning == 1)
eerror("%s: %d process refused to stop",
@@ -549,7 +573,7 @@ expand_home(const char *home, const char *path)
ppath++;
if (!home) {
free(opath);
free(opath);
return xstrdup(path);
}
if (!ppath) {
@@ -565,7 +589,7 @@ expand_home(const char *home, const char *path)
}
#include "_usage.h"
#define getoptstring "KN:R:Sbc:d:e:g:ik:mn:op:s:tu:r:w:x:1:2:" getoptstring_COMMON
#define getoptstring "KN:PR:Sbc:d:e:g:ik:mn:op:s:tu:r:w:x:1:2:" getoptstring_COMMON
static const struct option longopts[] = {
{ "stop", 0, NULL, 'K'},
{ "nicelevel", 1, NULL, 'N'},
@@ -591,6 +615,7 @@ static const struct option longopts[] = {
{ "exec", 1, NULL, 'x'},
{ "stdout", 1, NULL, '1'},
{ "stderr", 1, NULL, '2'},
{ "progress", 0, NULL, 'P'},
longopts_COMMON
};
static const char * const longopts_help[] = {
@@ -614,10 +639,11 @@ static const char * const longopts_help[] = {
"Test actions, don't do them",
"Change the process user",
"Chroot to this directory",
"Seconds to wait for daemon start",
"Milliseconds to wait for daemon start",
"Binary to start/stop",
"Redirect stdout to file",
"Redirect stderr to file",
"Print dots each second while waiting",
longopts_help_COMMON
};
#include "_usage.c"
@@ -648,11 +674,12 @@ start_stop_daemon(int argc, char **argv)
char *name = NULL;
char *pidfile = NULL;
char *retry = NULL;
int sig = 0;
int sig = -1;
int nicelevel = 0;
bool background = false;
bool makepidfile = false;
bool interpreted = false;
bool progress = false;
uid_t uid = 0;
gid_t gid = 0;
char *home = NULL;
@@ -714,12 +741,17 @@ start_stop_daemon(int argc, char **argv)
case 'K': /* --stop */
stop = true;
break;
case 'N': /* --nice */
if (sscanf(optarg, "%d", &nicelevel) != 1)
eerrorx("%s: invalid nice level `%s'",
applet, optarg);
break;
case 'P': /* --progress */
progress = true;
break;
case 'R': /* --retry <schedule>|<timeout> */
retry = optarg;
break;
@@ -885,8 +917,8 @@ start_stop_daemon(int argc, char **argv)
else if (exec)
*--argv = exec;
if (stop || sig != 0) {
if (sig == 0)
if (stop || sig != -1) {
if (sig == -1)
sig = SIGTERM;
if (!*argv && !pidfile && !name && !uid)
eerrorx("%s: --stop needs --exec, --pidfile,"
@@ -989,8 +1021,8 @@ start_stop_daemon(int argc, char **argv)
}
margv = nav ? nav : argv;
if (stop || sig) {
if (sig == 0)
if (stop || sig != -1) {
if (sig == -1)
sig = SIGTERM;
if (!stop)
oknodo = true;
@@ -1001,7 +1033,7 @@ start_stop_daemon(int argc, char **argv)
else
parse_schedule(NULL, sig);
i = run_stop_schedule(exec, (const char *const *)margv,
pidfile, uid, quiet, verbose, test);
pidfile, uid, quiet, verbose, test, progress);
if (i < 0)
/* We failed to stop something */
@@ -1280,8 +1312,8 @@ start_stop_daemon(int argc, char **argv)
struct timespec ts;
bool alive = false;
ts.tv_sec = start_wait;
ts.tv_nsec = 0;
ts.tv_sec = start_wait / 1000;
ts.tv_nsec = (start_wait % 1000) * ONE_MS;
if (nanosleep(&ts, NULL) == -1) {
if (errno == EINTR)
eerror("%s: caught an interrupt", applet);

120
src/rc/swclock.c Normal file
View File

@@ -0,0 +1,120 @@
/*
swclock.c
Sets the system time from the mtime of the given file.
This is useful for systems who do not have a working RTC and rely on ntp.
OpenRC relies on the correct system time for a lot of operations so this is needed
quite early.
*/
/*
* Copyright (c) 2009 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <unistd.h>
#include <utime.h>
#include "builtins.h"
#include "einfo.h"
#include "rc-misc.h"
#define RC_SHUTDOWNTIME RC_SVCDIR "/shutdowntime"
extern const char *applet;
#include "_usage.h"
#define extraopts "file"
#define getoptstring "sw" getoptstring_COMMON
static const struct option longopts[] = {
{ "save", 0, NULL, 's' },
{ "warn", 0, NULL, 'w' },
longopts_COMMON
};
static const char * const longopts_help[] = {
"saves the time",
"no error if no reference file",
longopts_help_COMMON
};
#include "_usage.c"
int
swclock(int argc, char **argv)
{
int opt, sflag = 0, wflag = 0;
const char *file = RC_SHUTDOWNTIME;
struct stat sb;
struct timeval tv;
while ((opt = getopt_long(argc, argv, getoptstring,
longopts, (int *) 0)) != -1)
{
switch (opt) {
case 's':
sflag = 1;
break;
case 'w':
wflag = 1;
break;
case_RC_COMMON_GETOPT;
}
}
if (optind < argc)
file = argv[optind++];
if (sflag) {
if (stat(file, &sb) == -1) {
opt = open(file, O_WRONLY | O_CREAT, 0644);
if (opt == -1)
eerrorx("swclock: open: %s", strerror(errno));
close(opt);
} else
if (utime(file, NULL) == -1)
eerrorx("swclock: utime: %s", strerror(errno));
return 0;
}
if (stat(file, &sb) == -1) {
if (wflag != 0 && errno == ENOENT)
ewarn("swclock: `%s': %s", file, strerror(errno));
else
eerrorx("swclock: `%s': %s", file, strerror(errno));
return 0;
}
tv.tv_sec = sb.st_mtime;
tv.tv_usec = 0;
if (settimeofday(&tv, NULL) == -1)
eerrorx("swclock: settimeofday: %s", strerror(errno));
return 0;
}

View File

@@ -20,6 +20,8 @@ rc_deptree_update_needed
rc_deptree_update_needed@@RC_1.0
rc_find_pids
rc_find_pids@@RC_1.0
rc_getline
rc_getline@@RC_1.0
rc_newer_than
rc_newer_than@@RC_1.0
rc_older_than