Compare commits

...

31 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
49 changed files with 436 additions and 85 deletions

View File

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

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"

View File

@@ -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

2
init.d/.gitignore vendored
View File

@@ -24,6 +24,7 @@ mount-ro
mtab
numlock
procfs
staticroute
sysfs
devdb
hostid
@@ -34,6 +35,7 @@ rc-enabled
rpcbind
savecore
swap-blk
swclock
syslogd
termencoding
ttys

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

@@ -95,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"

View File

@@ -9,7 +9,7 @@ _IFS="
depend()
{
use dev clock modules
keyword -jail -openvz -prefix -timeout -vserver
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
@@ -73,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

@@ -28,7 +28,7 @@ depend()
else
before *
fi
keyword -openvz -prefix -uml -vserver -xenu
keyword -openvz -prefix -uml -vserver -xenu -lxc
}
setupopts()

View File

@@ -15,7 +15,7 @@ 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

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

View File

@@ -7,7 +7,7 @@ description="Loads a user defined list of kernel modules."
depend()
{
use isapnp
keyword -openvz -prefix -vserver
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 -prefix -openvz -vserver
keyword -prefix -openvz -vserver -lxc
}
start()

View File

@@ -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

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

View File

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

View File

@@ -7,7 +7,7 @@ description="Mount the root fs read/write"
depend()
{
need fsck
keyword -jail -openvz -prefix -vserver
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

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()
{
need localmount
keyword -jail -openvz -prefix -vserver
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

@@ -12,13 +12,21 @@ depend()
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

@@ -11,8 +11,16 @@ depend()
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

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd July 1, 2009
.Dd November 4, 2009
.Dt RUNSCRIPT 8 SMM
.Os OpenRC
.Sh NAME
@@ -143,6 +143,8 @@ When in a jail, exclude this service from any dependencies. The service can
still be run directly.
.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

View File

@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 4, 2009
.Dd October 14, 2009
.Dt START-STOP-DAEMON 8 SMM
.Os OpenRC
.Sh NAME
@@ -144,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

@@ -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

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

@@ -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;

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 */

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"

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}
@@ -46,12 +46,17 @@ LDADD+= ${LIBDL} ${LIBKVM}
include ${MK}/${MKPAM}.mk
${SRCS}: version.h
version.h:
echo "#define VERSION \"${VERSION}${GITVER}\"" >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

@@ -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>
@@ -638,7 +639,7 @@ 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",
@@ -1311,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;
}