Compare commits

..

2 Commits

Author SHA1 Message Date
William Hubbs
d670dbddf7 Release openrc-0.9.9.1 2012-02-24 11:13:27 -06:00
William Hubbs
f1a19aed78 Skip pam if running as root
Reported-by: Piotr Karbowski <piotr.karbowski@gmail.com>
X-Gentoo-Bug: 386623
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=386623
2012-02-24 09:06:51 -06:00
39 changed files with 407 additions and 906 deletions

View File

@@ -25,8 +25,6 @@ include ${MK}/dist.mk
include ${MK}/git.mk
_installafter:
ifneq ($(OS),Linux)
${INSTALL} -d ${DESTDIR}/${LIBEXECDIR}/init.d
endif
${INSTALL} -d ${DESTDIR}/${LIBEXECDIR}/tmp
${ECHO} "${VERSION}${GITVER}" > ${DESTDIR}/${LIBEXECDIR}/version

View File

@@ -1,3 +1,3 @@
NAME= openrc
VERSION= 0.10
VERSION= 0.9.9.1
PKG= ${NAME}-${VERSION}

14
TODO
View File

@@ -5,17 +5,3 @@
- oldnet[bridging]: Review setting of bridge configuration on dynamic interface add
- Document rc-depend binary.
- _ifindex is not a reliable means of calculating metrics:
_ifindex is used for calculating metrics for new devices but has a major
problem: Since it's only the nth entry in /proc/net/dev
And devices may be removed from that file, and reordered, you won't always
get the same result.
If you do:
- add eth0 - _ifindex (eth0=0)
- add vlan1 - _ifindex (eth0=0,vlan1=1)
- add vlan2 - _ifindex (eth0=0,vlan1=1,vlan2=2)
- rem vlan1 - _ifindex (eth0=0,vlan2=1)
- add vlan3 - _ifindex (eth0=0,vlan2=1,vlan3=2)
Now your routing table has entries for both vlan2 and vlan3 with a metric of 2.

View File

@@ -1,10 +1,9 @@
# The consolefont service is not activated by default. If you need to
# use it, you should run "rc-update add consolefont boot" as root.
#
# consolefont specifies the default font that you'd like Linux to use on the
# console. You can find a good selection of fonts in /usr/share/consolefonts;
# you shouldn't specify the trailing ".psf.gz", just the font name below.
# To use the default console font, comment out the CONSOLEFONT setting below.
# This setting is used by the /etc/init.d/consolefont script (NOTE: if you do
# not want to use it, run "rc-update del consolefont boot" as root).
consolefont="default8x16"
# consoletranslation is the charset map file to use. Leave commented to use

View File

@@ -4,11 +4,9 @@
# you should set it to "local".
clock="UTC"
# If you want the hwclock script to set the system time (software clock)
# to match the current hardware clock during bootup, leave this
# commented out.
# However, you can set this to "NO" ifyou are running a modern kernel
# with CONFIG_RTC_HCTOSYS set to y and your hardware clock set to UTC.
# If you want to set the system time to the current hardware clock
# during bootup, then say "YES" here. You do not need this if you are
# running a modern kernel with CONFIG_RTC_HCTOSYS set to y.
#clock_hctosys="YES"
# If you do not want to set the hardware clock to the current system

View File

@@ -34,7 +34,7 @@
# In other words, you probably should DO NOTHING HERE...
# Prefer ifconfig over iproute2
#modules="!iproute2"
#modules="ifconfig"
# You can also specify other modules for an interface
# In this case we prefer udhcpc over dhcpcd
@@ -57,7 +57,7 @@
# If you don't specify an interface then we prefer iproute2 if it's installed
# To prefer ifconfig over iproute2
#modules="!iproute2"
#modules="ifconfig"
# For a static configuration, use something like this
# (They all do exactly the same thing btw)
@@ -616,22 +616,9 @@
#slaves_bond0="eth0 eth1 eth2"
#config_bond0="null" # You may not want to assign an IP the the bond
# Please note, that you should generally NOT try to change the MAC addresses of
# a bond interface yourself. If you do so, the kernel and your network switches
# may not work quite right. It is permissible to set the MAC addresses of bond
# slaves BEFORE the bond comes up, but not after the bond is up (it will change
# MAC addresses of the slaves on it's own).
# You can also configure the parameters of the bond here, which must be done
# via sysfs on 2.6 kernels or newer. The description of all the options can be
# found in the kernel: /usr/src/linux-*/Documentation/networking/bonding.txt
# You will probably want the 'mode' option at the least.
# Some possible parameters: mode fail_over_mac arp_validate arp_interval
# arp_ip_target downdelay updelay lacp_rate ad_select xmit_hash_policy
# num_grat_arp num_unsol_na miimon primary primary_reselect use_carrier
# active_slave queue_id all_slaves_active resend_igmp min_links
#mode_bond0="round-robin"
#miimon_bond0="100"
# You can also configure the bond here, which must be done via sysfs on 2.6
# kernels or newer. See the kernel bonding documentation 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
@@ -793,8 +780,6 @@
#-----------------------------------------------------------------------------
# MAC changer
# Warning: Do NOT use this on bonding interfaces! Bonding changes MACs itself.
#
# To set a specific MAC address
#mac_eth0="00:11:22:33:44:55"
@@ -1111,13 +1096,6 @@
# Hypothetical network card that requires a change-eeprom toggle to enable flashing
#ethtool_order_eth0="change-eeprom flash change pause coalesce ring offload nfc rxfh-indir ntuple"
#-----------------------------------------------------------------------------
# Firewalld support
# If you are using the firewalld daemon to configure your firewall
# settings and you have specific zones you want to apply to your
# interfaces, you can do this here.
#firewalld_zone_eth0="myzone"
##############################################################################
# ADVANCED CONFIGURATION
#

View File

@@ -71,12 +71,7 @@ start()
done
if [ "$RC_UNAME" = Linux ]; then
local skiptypes x
for x in $net_fs_list $extra_net_fs_list; do
skiptypes="${skiptypes}no${x},"
done
skiptypes="${skiptypes}noopts=_netdev"
fsck_opts="$fsck_opts -C0 -T -t $skiptypes"
fsck_opts="$fsck_opts -C0 -T"
if [ -z "$fsck_passno" -a -z "$fsck_mnt" ]; then
fsck_args=${fsck_args--A -p}
if echo 2>/dev/null >/.test.$$; then

View File

@@ -5,38 +5,12 @@
description="Sets the hostname of the machine."
depend() {
need root
keyword -lxc
}
start()
{
hostname=${hostname-${HOSTNAME-localhost}}
out=$hostname
short=${hostname%%.*}
if [ "$short" != "$hostname" ]; then
out="$out $short"
fi
if [ "$nisdomainname" != "" ]; then
ebegin "Setting NIS domain name to $nisdomainname"
nisdomainname $nisdomainname
eend $? "Failed to set the NIS domain name"
fi
if [ "$short" != "localhost" ]; then
out="$out localhost"
fi
if [ "$hostname" != "localhost.localdomain" ]; then
out="$out localhost.localdomain"
fi
[ -n "$aliases" ] && out="$out $aliases"
ebegin "Configuring /etc/hosts"
[ -e /etc/hosts ] && sed -i -e '/[[:space:]]*127.0.0.1[[:space:]]/d' -e '/[[:space:]]*::1[[:space:]]/d' /etc/hosts
cat <<END >> /etc/hosts
127.0.0.1 $out
::1 $out
END
chmod 0644 /etc/hosts
eend $?
[ "$RC_SYS" = "LXC" ] && return 0
ebegin "Setting hostname to $hostname"
hostname "$hostname"
eend $? "Failed to set the hostname"

View File

@@ -9,7 +9,7 @@ depend()
need fsck
use lvm modules mtab
after lvm modules
keyword -jail -vserver -lxc
keyword -jail -openvz -vserver -lxc
}
start()
@@ -33,7 +33,6 @@ start()
stop()
{
yesno $RC_GOINGDOWN || return 0
# We never unmount / or /dev or $RC_SVCDIR
# Bug 381783
@@ -48,7 +47,7 @@ stop()
done
if [ "$RC_UNAME" = Linux ]; then
no_umounts_r="$no_umounts_r|/proc|/proc/.*|/run|/sys|/sys/.*|/usr"
no_umounts_r="$no_umounts_r|/proc|/proc/.*|/run|/sys|/sys/.*"
fi
no_umounts_r="^($no_umounts_r)$"

View File

@@ -23,7 +23,7 @@ start()
# Bug 381783
local rc_svcdir=$(echo $RC_SVCDIR | sed 's:/lib\(32\|64\)\?/:/lib(32|64)?/:g')
local m="/dev|/dev/.*|/proc|/proc.*|/sys|/sys/.*|/run|${rc_svcdir}" x= fs=
local m="/dev|/dev/.*|/proc|/proc.*|/sys|/sys/.*|${rc_svcdir}" x= fs=
m="$m|/bin|/sbin|/lib(32|64)?|/libexec"
# RC_NO_UMOUNTS is an env var that can be set by plugins
local IFS="$IFS:"

View File

@@ -19,9 +19,6 @@ depend()
local IFVAR=$(shell_var "${IFACE}")
need localmount
if [ "$RC_UNAME" = Linux ]; then
need sysfs
fi
after bootmisc
keyword -jail -vserver

View File

@@ -41,7 +41,7 @@ start()
fi
fi
[ "$RC_SYS" = "OPENVZ" ] && return 0
[ "$RC_SYS" == "OPENVZ" ] && return 0
# Check what USB fs the kernel support. Currently
# 2.5+ kernels, and later 2.4 kernels have 'usbfs',

View File

@@ -13,7 +13,7 @@ start()
local retval=0 var= comments= conf=
ebegin "Configuring kernel parameters"
eindent
for conf in @SYSCONFDIR@/sysctl.conf @SYSCONFDIR@/sysctl.d/*.conf; do
for conf in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
if [ -r "$conf" ]; then
vebegin "applying $conf"
while read var comments; do

View File

@@ -5,7 +5,7 @@
depend()
{
before bootmisc logger
keyword -lxc -vserver
keyword -vserver
}
start()
@@ -15,20 +15,12 @@ start()
ebegin "Configuring kernel parameters"
eindent
# default sysctl System V max shared memory to 1/4 of RAM:
mem_bytes=`awk '/MemTotal:/ { printf "%0.f",$2 * 1024}' /proc/meminfo`
mem_max=`expr $mem_bytes / 4`
page_size=`getconf PAGE_SIZE`
shmall=`expr $mem_bytes / $page_size`
sysctl kernel.shmmax=$mem_max > /dev/null
sysctl kernel.shmall=$shmall > /dev/null
for conf in @SYSCONFDIR@/sysctl.conf @SYSCONFDIR@/sysctl.d/*.conf; do
for conf in /etc/sysctl.d/*.conf /etc/sysctl.conf; do
if [ -r "$conf" ]; then
vebegin "applying $conf"
if ! err=$(sysctl -p "$conf" 2>&1 >/dev/null) ; then
if ! err=$(sysctl -q -p "$conf" 2>&1) ; then
errs="${errs} ${err}"
sysctl -e -p "${conf}" >/dev/null
sysctl -q -e -p "${conf}"
fi
veend $? || retval=1
fi

View File

@@ -9,7 +9,7 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
depend()
{
keyword -lxc -openvz -uml -vserver -xenu
keyword -openvz -uml -vserver -xenu
use root
after bootmisc
}

View File

@@ -92,8 +92,7 @@ or stopping them.
The following variables affect the service script:
.Bl -tag -width "RC_DEFAULTLEVEL"
.It Ar extra_commands
Space separated list of extra commands the service defines. These should
not depend on the service being stopped or started.
Space separated list of extra commands the service defines.
.It Ar extra_started_commands
Space separated list of extra commands the service defines. These only work if
the service has already been started.
@@ -124,10 +123,6 @@ Display name used for the above defined command.
.It Ar retry
Retry schedule to use when stopping the daemon. It can either be a
timeout in seconds or multiple signal/timeout pairs (like SIGTERM/5).
.It Ar required_dirs
A list of directories which must exist for the service to start.
.It Ar required_files
A list of files which must exist for the service to start.
.El
.Sh DEPENDENCIES
You should define a

View File

@@ -1,10 +1,5 @@
ifeq (${MKTERMCAP},ncurses)
LTERMCAP:= $(shell pkg-config ncurses --libs 2> /dev/null)
ifeq ($(LTERMCAP),)
LIBTERMCAP?= -lncurses
else
LIBTERMCAP?= $(LTERMCAP)
endif
CPPFLAGS+= -DHAVE_TERMCAP
LDADD+= ${LIBTERMCAP}
else ifeq (${MKTERMCAP},termcap)

View File

@@ -13,7 +13,7 @@ SRCS-Linux= iwconfig.sh.in
INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh
vlan.sh macvlan.sh
SRCS-NetBSD=
INC-NetBSD= ifwatchd.sh

View File

@@ -1,38 +0,0 @@
# Copyright (c) 2012 Doug Goldstein <cardoe@cardoe.com>
# Released under the 2-clause BSD license.
firewalld_depend()
{
after interface
before dhcp
program firewall-cmd
[ "$IFACE" != "lo" ] && need firewalld
}
_config_vars="$_config_vars firewalld_zone"
firewalld_post_start()
{
local firewalld_zone=
eval firewalld_zone=\$firewalld_zone_${IFVAR}
_exists || return 0
if [ "${IFACE}" != "lo" ]; then
firewall-cmd --zone="${firewalld_zone}" \
--change-interface="${IFACE}" > /dev/null 2>&1
fi
return 0
}
firewalld_pre_stop()
{
_exists || return 0
if [ "${IFACE}" != "lo" ]; then
firewall-cmd --remove-interface="${IFACE}" > /dev/null 2>&1
fi
return 0
}

View File

@@ -3,7 +3,7 @@
ifconfig_depend()
{
program /sbin/ifconfig /bin/ifconfig
program /sbin/ifconfig
provide interface
}
@@ -19,24 +19,24 @@ _down()
_exists()
{
[ -e /sys/class/net/"$IFACE" ]
grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/dev
}
_ifindex()
{
local index=-1
local f v
if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
index=$(cat /sys/class/net/"${IFACE}"/ifindex)
else
for f in /sys/class/net/*/ifindex ; do
v=$(cat $f)
[ $v -gt $index ] && index=$v
done
: $(( index += 1 ))
fi
echo "${index}"
return 0
local line= i=-2
while read line; do
: $(( i += 1 ))
[ ${i} -lt 1 ] && continue
case "${line}" in
"${IFACE}:"*) echo "${i}"; return 0;;
esac
done < /proc/net/dev
# Return the next available index
: $(( i += 1 ))
echo "${i}"
return 1
}
_is_wireless()

View File

@@ -20,24 +20,24 @@ _down()
_exists()
{
[ -e /sys/class/net/"$IFACE" ]
grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/dev
}
_ifindex()
{
local index=-1
local f v
if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
index=$(cat /sys/class/net/"${IFACE}"/ifindex)
else
for f in /sys/class/net/*/ifindex ; do
v=$(cat $f)
[ $v -gt $index ] && index=$v
done
: $(( index += 1 ))
fi
echo "${index}"
return 0
local line= i=-2
while read line; do
: $(( i += 1 ))
[ ${i} -lt 1 ] && continue
case "${line}" in
"${IFACE}:"*) echo "${i}"; return 0;;
esac
done < /proc/net/dev
# Return the next available index
: $(( i += 1 ))
echo "${i}"
return 1
}
_is_wireless()

View File

@@ -66,7 +66,7 @@ udhcpc_start()
if ${sendhost}; then
local hname="$(hostname)"
if [ "${hname}" != "(none)" ] && [ "${hname}" != "localhost" ]; then
args="${args} -x hostname:'${hname}'"
args="${args} --hostname='${hname}'"
fi
fi
;;

2
sh/.gitignore vendored
View File

@@ -9,5 +9,3 @@ init-early.sh
ifwatchd-carrier.sh
ifwatchd-nocarrier.sh
udhcpc-hook.sh
tmpfiles.sh
migrate-to-run.sh

View File

@@ -1,8 +1,8 @@
DIR= ${LIBEXECDIR}/sh
SRCS= init.sh.in functions.sh.in gendepends.sh.in init-common-post.sh.in \
rc-functions.sh.in runscript.sh.in tmpfiles.sh.in ${SRCS-${OS}}
rc-functions.sh.in runscript.sh.in ${SRCS-${OS}}
INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh
BIN= gendepends.sh init.sh runscript.sh tmpfiles.sh ${BIN-${OS}}
BIN= gendepends.sh init.sh runscript.sh ${BIN-${OS}}
INSTALLAFTER= _installafter
@@ -12,10 +12,8 @@ include ${MK}/os.mk
SRCS-FreeBSD=
BIN-FreeBSD=
SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in migrate-to-run.sh.in \
udhcpc-hook.sh.in
BIN-Linux= cgroup-release-agent.sh init-early.sh migrate-to-run.sh \
udhcpc-hook.sh
SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in udhcpc-hook.sh.in
BIN-Linux= cgroup-release-agent.sh init-early.sh udhcpc-hook.sh
SRCS-NetBSD= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
BIN-NetBSD= ifwatchd-carrier.sh ifwatchd-nocarrier.sh

View File

@@ -4,7 +4,7 @@
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.
. @LIBEXECDIR@/sh/functions.sh
. @SYSCONFDIR@/init.d/functions.sh
. @LIBEXECDIR@/sh/rc-functions.sh
config() {

View File

@@ -3,6 +3,62 @@
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.
# This basically mounts $RC_SVCDIR as a ramdisk.
# The tricky part is finding something our kernel supports
# tmpfs and ramfs are easy, so force one or the other.
svcdir_restorecon()
{
local rc=0
if [ -x /usr/sbin/selinuxenabled -a -c /selinux/null ] &&
selinuxenabled; then
restorecon $RC_SVCDIR
rc=$?
fi
return $rc
}
mount_svcdir()
{
# mount from fstab if we can
fstabinfo --mount "$RC_SVCDIR" && return 0
local fs= fsopts="-o rw,noexec,nodev,nosuid"
local svcsize=${rc_svcsize:-1024}
# Some buggy kernels report tmpfs even when not present :(
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
local tmpfsopts="${fsopts},mode=755,size=${svcsize}k"
mount -n -t tmpfs $tmpfsopts rc-svcdir "$RC_SVCDIR"
if [ $? -eq 0 ]; then
svcdir_restorecon
[ $? -eq 0 ] && return 0
fi
fi
if grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
fs="ramfs"
# ramfs has no special options
elif [ -e /dev/ram0 ] \
&& grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then
devdir="/dev/ram0"
fs="ext2"
dd if=/dev/zero of="$devdir" bs=1k count="$svcsize"
mkfs -t "$fs" -i 1024 -vm0 "$devdir" "$svcsize"
else
echo
eerror "OpenRC requires tmpfs, ramfs or a ramdisk + ext2"
eerror "compiled into the kernel"
echo
return 1
fi
mount -n -t "$fs" $fsopts rc-svcdir "$RC_SVCDIR"
if [ $? -eq 0 ]; then
svcdir_restorecon
[ $? -eq 0 ] && return 0
fi
}
. "$RC_LIBEXECDIR"/sh/functions.sh
[ -r /etc/rc.conf ] && . /etc/rc.conf
@@ -19,7 +75,7 @@ if [ -e $f ]; then
if [ "$(VAR=a cat $f)" = "$(VAR=b cat $f)" ]; then
eerror "You have cruft in /proc that should be deleted"
else
einfo "/proc is already mounted"
einfo "/proc is already mounted, skipping"
mountproc=false
fi
fi
@@ -35,32 +91,24 @@ if $mountproc; then
eend $?
fi
# Mount tmpfs on /run when directory exists.
# /run is a new directory for storing volatile runtime data.
# Read more about /run at https://lwn.net/Articles/436012
if [ ! -d /run ]; then
eerror "The /run directory does not exist. Unable to continue."
return 1
fi
if mountinfo -q /run; then
einfo "/run is already mounted, skipping"
else
ebegin "Mounting /run"
rc=0
if ! fstabinfo --mount /run; then
mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run
rc=$?
fi
if [ $rc != 0 ]; then
eerror "Unable to mount tmpfs on /run."
eerror "Can't continue."
exit 1
if [ -d /run ]; then
if mountinfo -q /run; then
einfo "/run is already mounted, skipping"
else
ebegin "Mounting /run"
if ! fstabinfo --mount /run; then
mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run
fi
eend $?
fi
checkpath -d -m 0775 -o root:uucp /run/lock
elif [ -e /run ]; then
einfo "Unable to mount /run since it is not a directory"
fi
checkpath -d $RC_SVCDIR
checkpath -d -m 0775 -o root:uucp /run/lock
# Try to mount xenfs as early as possible, otherwise rc_sys() will always
# return RC_SYS_XENU and will think that we are in a domU while it's not.
if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
@@ -71,9 +119,4 @@ if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
eend $?
fi
if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
fi
echo sysinit >"$RC_SVCDIR"/softlevel
exit 0
. "$RC_LIBEXECDIR"/sh/init-common-post.sh

View File

@@ -1,49 +0,0 @@
#!@SHELL@
# Copyright (c) 2012 William Hubbs <w.d.hubbs@gmail.com>
# Released under the 2-clause BSD license.
. "@LIBEXECDIR@/sh/functions.sh"
if ! mountinfo -q -f tmpfs "@LIBEXECDIR@/init.d"; then
einfo "The OpenRC dependency data has already been migrated."
exit 0
fi
if [ ! -d "@PREFIX@/run" ]; then
eerror "'@PREFIX@/run' is not a directory."
eerror "This means the OpenRC dependency data cannot be migrated."
eerror "Please create the '@PREFIX@/run' directory and reboot the system."
exit 1
fi
if ! mountinfo -q -f tmpfs "@PREFIX@/run"; then
for x in "@PREFIX@/run/."* "@PREFIX@/run/"*; do
case "$x" in
"@PREFIX@/run/."|"@PREFIX@/run/..")
continue
;;
esac
if [ -e "$x" ]; then
eerror "Your '@PREFIX@/run' directory contains files."
eerror "Please reboot the system."
exit 1
fi
done
mount -t tmpfs -o mode=0755,nosuid,nodev \
tmpfs "@PREFIX@/run" 2> /dev/null
if [ $? != 0 ]; then
eerror "Unable to mount a tmpfs on '@PREFIX@/run'."
eerror "This means the OpenRC dependency data cannot be migrated."
eerror "Please create the '@PREFIX@/run' directory and reboot the system."
exit 1
fi
fi
rm -rf "@PREFIX@/run/openrc"
cp -a "@LIBEXECDIR@/init.d" "@PREFIX@/run/openrc"
rc-update -u
rm -rf "@LIBEXECDIR@/init.d"
umount "@LIBEXECDIR@/init.d"
einfo "The OpenRC dependency data was migrated successfully."
exit 0

View File

@@ -4,22 +4,6 @@
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.
verify_boot()
{
if [ ! -e ${RC_SVCDIR}/softlevel ]; then
eerror "You are attempting to run an openrc service on a"
eerror "system which openrc did not boot."
eerror "You may be inside a chroot or you may have used"
eerror "another initialization system to boot this system."
eerror "In this situation, you will get unpredictable results!"
eerror
eerror "If you really want to do this, issue the following command:"
eerror "touch ${RC_SVCDIR}/softlevel"
exit 1
fi
return 0
}
sourcex()
{
if [ "$1" = "-e" ]; then
@@ -32,7 +16,7 @@ sourcex()
fi
}
sourcex "@LIBEXECDIR@/sh/functions.sh"
sourcex "@SYSCONFDIR@/init.d/functions.sh"
sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
# Support LiveCD foo
@@ -40,6 +24,18 @@ if sourcex -e "/sbin/livecd-functions.sh"; then
livecd_read_commandline
fi
if [ ! -e ${RC_SVCDIR}/softlevel ]; then
eerror "You are attempting to run an openrc service on a"
eerror "system which openrc did not boot."
eerror "You may be inside a chroot or you may have used"
eerror "another initialization system to boot this system."
eerror "In this situation, you will get unpredictable results!"
eerror
eerror "If you really want to do this, issue the following command:"
eerror "touch ${RC_SVCDIR}/softlevel"
exit 1
fi
if [ -z "$1" -o -z "$2" ]; then
eerror "$RC_SVCNAME: not enough arguments"
exit 1
@@ -233,12 +229,7 @@ while [ -n "$1" ]; do
# Special case depend
if [ "$1" = depend ]; then
shift
# Enter the dir of the init script to fix the globbing
# bug 412677
cd ${RC_SERVICE%/*}
_depend
cd /
continue
fi
# See if we have the required function and run it
@@ -265,7 +256,7 @@ while [ -n "$1" ]; do
# we can run this command
for _cmd in $extra_started_commands; do
if [ "$_cmd" = "$1" ]; then
if verify_boot && ! service_started; then
if ! service_started; then
eerror "$RC_SVCNAME: cannot \`$1' as it has not been started"
exit 1
fi
@@ -275,16 +266,13 @@ while [ -n "$1" ]; do
# we can run this command
for _cmd in $extra_stopped_commands; do
if [ "$_cmd" = "$1" ]; then
if verify_boot && ! service_stopped; then
if ! service_stopped; then
eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped"
exit 1
fi
fi
done
unset _cmd
case $1 in
start|stop|status) verify_boot;;
esac
if [ "$(command -v "$1_pre")" = "$1_pre" ]
then
"$1"_pre || exit $?

View File

@@ -1,288 +0,0 @@
#!/bin/sh
# This is a reimplementation of the systemd tmpfiles.d code
# Control creation, deletion, and cleaning of volatile and temporary files
#
# Copyright (c) 2012 Gentoo Foundation
#
# This instance based on the Arch Linux version:
# http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
# As of 2012/01/01
#
# See the tmpfiles.d manpage as well:
# http://0pointer.de/public/systemd-man/tmpfiles.d.html
# This script should match the manpage as of 2012/03/12
#
warninvalid() {
printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE"
error=$(( error+1 ))
} >&2
relabel() {
local path
local paths=$1 mode=$2 uid=$3 gid=$4
for path in ${paths}; do
if [ -e "$path" ]; then
[ $uid != '-' ] && chown $CHOPTS "$uid" "$path"
[ $gid != '-' ] && chgrp $CHOPTS "$gid" "$path"
[ $mode != '-' ] && chmod $CHOPTS "$mode" "$path"
[ -x /sbin/restorecon ] && restorecon $CHOPTS "$path"
fi
done
}
_b() {
# Create a block device node if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ ! -e "$path" ] && mknod $path b ${arg%:*} ${arg#*:}
}
_c() {
# Create a character device node if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ ! -e "$path" ] && mknod $path c ${arg%:*} ${arg#*:}
}
_f() {
# Create a file if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ $CREATE -gt 0 ] || return 0
if [ ! -e "$path" ]; then
install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
[ -n "$arg" ] && _w "$@"
fi
}
_F() {
# Create or truncate a file
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ $CREATE -gt 0 ] || return 0
install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
[ -n "$arg" ] && _w "$@"
}
_d() {
# Create a directory if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4
[ $CREATE -gt 0 ] || return 0
if [ ! -d "$path" ]; then
install -d -m"$mode" -o"$uid" -g"$gid" "$path"
fi
}
_D() {
# Create or empty a directory
local path=$1 mode=$2 uid=$3 gid=$4
if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
fi
if [ $CREATE -gt 0 ]; then
install -d -m"$mode" -o"$uid" -g"$gid" "$path"
fi
}
_L() {
# Create a symlink if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ ! -e "$path" ] && ln -s "$args" "$path"
}
_p() {
# Create a named pipe (FIFO) if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4
[ $CREATE -gt 0 ] || return 0
if [ ! -p "$path" ]; then
mkfifo -m$mode "$path"
chown "$uid:$gid" "$path"
fi
}
_x() {
# Ignore a path during cleaning. Use this type to exclude paths from clean-up as
# controlled with the Age parameter. Note that lines of this type do not
# influence the effect of r or R lines. Lines of this type accept shell-style
# globs in place of of normal path names.
:
# XXX: we don't implement this
}
_r() {
# Remove a file or directory if it exists. This may not be used to remove
# non-empty directories, use R for that. Lines of this type accept shell-style
# globs in place of normal path names.
local path
local paths=$1
[ $REMOVE -gt 0 ] || return 0
for path in ${paths}; do
if [ -f "$path" ]; then
rm -f "$path"
elif [ -d "$path" ]; then
rmdir "$path"
fi
done
}
_R() {
# Recursively remove a path and all its subdirectories (if it is a directory).
# Lines of this type accept shell-style globs in place of normal path names.
local path
local paths=$1
[ $REMOVE -gt 0 ] || return 0
for path in ${paths}; do
[ -d "$path" ] && rm -rf --one-file-system "$path"
done
}
_w() {
# Write the argument parameter to a file, if it exists.
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ -f "$path" ] && echo "$arg" >>"$path"
}
_z() {
# Set ownership, access mode and relabel security context of a file or
# directory if it exists. Lines of this type accept shell-style globs in
# place of normal path names.
[ $CREATE -gt 0 ] || return 0
relabel "$@"
}
_Z() {
# Recursively set ownership, access mode and relabel security context of a
# path and all its subdirectories (if it is a directory). Lines of this type
# accept shell-style globs in place of normal path names.
[ $CREATE -gt 0 ] || return 0
CHOPTS=-R relabel "$@"
}
CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
FILE=
fragments=
# XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
tmpfiles_dirs='/usr/lib/tmpfiles.d/ /etc/tmpfiles.d/ /run/tmpfiles.d/'
tmpfiles_basenames=''
tmpfiles_d=''
# Build a list of sorted unique basenames
# directories declared later in the tmpfiles_d array will override earlier
# directories, on a per file basename basis.
# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
for d in ${tmpfiles_dirs} ; do
[ -d $d ] && for f in ${d}/*.conf ; do
[ -f $f ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
done # for f in ${d}
done # for d in ${tmpfiles_dirs}
tmpfiles_basenames="`printf "${tmpfiles_basenames}\n" | sort | uniq`"
for b in $tmpfiles_basenames ; do
real_f=''
for d in $tmpfiles_dirs ; do
f=${d}/${b}
[ -f "${f}" ] && real_f=$f
done
[ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
done
while [ $# -gt 0 ]; do
case $1 in
--create) CREATE=1 ;;
--remove) REMOVE=1 ;;
--clean) CLEAN=1 ;; # TODO: Not implemented
--verbose) VERBOSE=1 ;;
--dryrun|--dry-run) DRYRUN=1 ;;
esac
shift
done
if [ $(( CREATE + REMOVE )) -ne 1 ] ; then
printf 'usage: %s [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
exit 1
fi
error=0
# loop through the gathered fragments, sorted globally by filename.
# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
for FILE in $tmpfiles_d ; do
LINENUM=0
### FILE FORMAT ###
# XXX: We ignore the 'Age' parameter
# 1 2 3 4 5 6 7
# Cmd Path Mode UID GID Age Argument
# d /run/user 0755 root root 10d -
# Mode, UID, GID, Age, Argument may be omitted!
# XXX: Upstream says whitespace is NOT permitted in the Path argument.
# But IS allowed when globs are expanded for the x/r/R/z/Z types.
while read line; do
LINENUM=$(( LINENUM+1 ))
# This will skip over comments and empty lines
set -- $line
# Unless we have both command and path, skip this line.
if [ -z "$1" -o -z "$2" ]; then
continue
fi
# whine about invalid entries
case $1 in
f|F|w|d|D|p|L|c|b|x|r|R|z|Z) ;;
*) warninvalid ; continue ;;
esac
cmd=$1
path=$2
# fall back on defaults when parameters are passed as '-'
if [ "$3" = '-' -o "$3" = '' ]; then
case ${1} in
p|f|F) mode=0644 ;;
d|D) mode=0755 ;;
z|Z|x|r|R|L) ;;
esac
else
mode=$3
fi
uid=$4
gid=$5
age=$6
arg=$7
[ ${4} = '-' ] && uid=0
[ ${5} = '-' ] && gid=0
[ ${6} = '-' ] && age=0
[ ${7} = '-' ] && arg=''
set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg"
[ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
if [ "${DRYRUN}" -eq "0" ]; then
_$cmd "$@"
rc=$?
[ $rc -ne 0 ] && error=$((error + 1))
fi
done <$FILE
done
exit $error
# vim: set ts=2 sw=2 sts=2 noet ft=sh:

View File

@@ -1,139 +0,0 @@
/*
helpers.h
This is private to us and not for user consumption
*/
/*
* Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
*
* 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.
*/
#ifndef __HELPERS_H__
#define __HELPERS_H__
#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
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/* Some libc implemntations don't have these */
#ifndef TAILQ_CONCAT
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (0)
#endif
#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#endif
#ifdef __GLIBC__
# if ! defined (__UCLIBC__) && ! defined (__dietlibc__)
# define strlcpy(dst, src, size) snprintf(dst, size, "%s", src)
# endif
#endif
#ifndef timespecsub
#define timespecsub(tsp, usp, vsp) \
do { \
(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
if ((vsp)->tv_nsec < 0) { \
(vsp)->tv_sec--; \
(vsp)->tv_nsec += 1000000000L; \
} \
} while (/* CONSTCOND */ 0)
#endif
_unused static void *xmalloc (size_t size)
{
void *value = malloc(size);
if (value)
return (value);
ERRX;
/* NOTREACHED */
}
_unused static void *xrealloc(void *ptr, size_t size)
{
void *value = realloc(ptr, size);
if (value)
return (value);
ERRX;
/* NOTREACHED */
}
_unused static char *xstrdup(const char *str)
{
char *value;
if (! str)
return (NULL);
value = strdup(str);
if (value)
return (value);
ERRX;
/* NOTREACHED */
}
#undef ERRX
/* basename_c never modifies the argument. As such, if there is a trailing
* slash then an empty string is returned. */
_unused static const char *basename_c(const char *path)
{
const char *slash = strrchr(path, '/');
if (slash)
return (++slash);
return (path);
}
#endif

View File

@@ -38,8 +38,6 @@
#include <string.h>
#include <unistd.h>
#include "helpers.h"
#define RC_LEVEL_BOOT "boot"
#define RC_LEVEL_DEFAULT "default"
@@ -54,6 +52,98 @@
#define RC_SVCDIR_STARTED RC_SVCDIR "/started"
#define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "/coldplugged"
#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 TAILQ_CONCAT
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (0)
#endif
#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#endif
#ifdef __GLIBC__
# if ! defined (__UCLIBC__) && ! defined (__dietlibc__)
# define strlcpy(dst, src, size) snprintf(dst, size, "%s", src)
# endif
#endif
#ifndef timespecsub
#define timespecsub(tsp, usp, vsp) \
do { \
(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
if ((vsp)->tv_nsec < 0) { \
(vsp)->tv_sec--; \
(vsp)->tv_nsec += 1000000000L; \
} \
} while (/* CONSTCOND */ 0)
#endif
_unused static void *xmalloc (size_t size)
{
void *value = malloc(size);
if (value)
return (value);
ERRX;
/* NOTREACHED */
}
_unused static void *xrealloc(void *ptr, size_t size)
{
void *value = realloc(ptr, size);
if (value)
return (value);
ERRX;
/* NOTREACHED */
}
_unused static char *xstrdup(const char *str)
{
char *value;
if (! str)
return (NULL);
value = strdup(str);
if (value)
return (value);
ERRX;
/* NOTREACHED */
}
#undef ERRX
_unused static bool exists(const char *pathname)
{
struct stat buf;
@@ -86,5 +176,16 @@ int is_writable(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. */
_unused static const char *basename_c(const char *path)
{
const char *slash = strrchr(path, '/');
if (slash)
return (++slash);
return (path);
}
int parse_mode(mode_t *, char *);
#endif

View File

@@ -51,7 +51,6 @@ const char libeinfo_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#include <unistd.h>
#include "einfo.h"
#include "helpers.h"
#include "hidden-visibility.h"
hidden_proto(ecolor)
@@ -135,7 +134,7 @@ static const struct ecolor ecolors[] = {
{ ECOLOR_BRACKET, BRACKET, "bracket" },
{ ECOLOR_NORMAL, 0, NULL },
};
static const char *ecolors_str[ARRAY_SIZE(ecolors)];
static const char *ecolors_str[sizeof(ecolors)/sizeof(ecolors[0])];
static char *flush = NULL;
static char *up = NULL;
@@ -226,6 +225,27 @@ 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)
{
const char *s = src;
size_t n = size;
if (n && --n)
do {
if (!(*dst++ = *src++))
break;
} while (--n);
if (!n) {
if (size)
*dst = '\0';
while (*src++);
}
return src - s - 1;
}
# endif
#endif
@@ -442,7 +462,7 @@ colour_terminal(FILE * EINFO_RESTRICT f)
/* Now setup our colours */
p = ebuffer;
for (i = 0; i < ARRAY_SIZE(ecolors); ++i) {
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) {
tmp[0] = '\0';
if (ecolors[i].name) {
bold = _md;
@@ -578,7 +598,7 @@ _ecolor(FILE * EINFO_RESTRICT f, ECOLOR color)
if (!colour_terminal(f))
return "";
for (i = 0; i < ARRAY_SIZE(ecolors); ++i)
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++)
if (ecolors[i].color == color)
return ecolors_str[i];
return "";

View File

@@ -687,27 +687,27 @@ rc_deptree_update_needed(time_t *newest, char *file)
if (!existss(RC_DEPTREE_CACHE))
return true;
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_INITDIR, newest, file))
return true;
newer = true;
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_CONFDIR, newest, file))
return true;
newer = true;
#ifdef RC_PKG_INITDIR
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_PKG_INITDIR, newest, file))
return true;
newer = true;
#endif
#ifdef RC_PKG_CONFDIR
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_PKG_CONFDIR, newest, file))
return true;
newer = true;
#endif
#ifdef RC_LOCAL_INITDIR
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_LOCAL_INITDIR, newest, file))
return true;
newer = true;
#endif
#ifdef RC_LOCAL_CONFDIR
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_LOCAL_CONFDIR, newest, file))
return true;
newer = true;
#endif
if (!rc_newer_than(RC_DEPTREE_CACHE, RC_CONF, newest, file))
return true;
newer = true;
/* Some init scripts dependencies change depending on config files
* outside of baselayout, like syslog-ng, so we check those too. */
@@ -715,7 +715,8 @@ rc_deptree_update_needed(time_t *newest, char *file)
TAILQ_FOREACH(s, config, entries) {
if (!rc_newer_than(RC_DEPTREE_CACHE, s->value, newest, file)) {
newer = true;
break;
if (newest == NULL)
break;
}
}
rc_stringlist_free(config);

View File

@@ -29,6 +29,7 @@
*/
#include "librc.h"
#include "einfo.h"
bool
rc_yesno(const char *value)
@@ -127,10 +128,10 @@ rc_getline(char **line, size_t *len, FILE *fp)
}
librc_hidden_def(rc_getline)
#ifdef __linux__
char *
rc_proc_getent(const char *ent)
{
#ifdef __linux__
FILE *fp;
char *proc, *p, *value = NULL;
size_t i, len;
@@ -138,13 +139,15 @@ rc_proc_getent(const char *ent)
if (!exists("/proc/cmdline"))
return NULL;
if (!(fp = fopen("/proc/cmdline", "r")))
if (!(fp = fopen("/proc/cmdline", "r"))) {
eerror("failed to open `/proc/cmdline': %s", strerror(errno));
return NULL;
}
proc = NULL;
i = 0;
if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
return NULL;
eerror("rc_getline: %s", strerror(errno));
if (proc != NULL) {
len = strlen(ent);
@@ -168,11 +171,9 @@ rc_proc_getent(const char *ent)
free(proc);
return value;
#else
return NULL;
#endif
}
librc_hidden_def(rc_proc_getent)
#endif
RC_STRINGLIST *
rc_config_list(const char *file)
@@ -391,10 +392,13 @@ rc_conf_value(const char *setting)
atexit(_free_rc_conf);
#endif
/* Support old configs. */
/* Support old configs, but complain about it. */
if (exists(RC_CONF_OLD)) {
old = rc_config_load(RC_CONF_OLD);
TAILQ_CONCAT(rc_conf, old, entries);
ewarn("Your system still has %s", RC_CONF_OLD);
ewarn("Please migrate to the appropriate settings in %s", RC_CONF);
ewarn("and delete %s.", RC_CONF_OLD);
#ifdef DEBUG_MEMORY
free(old);
#endif

View File

@@ -36,11 +36,7 @@ __BEGIN_DECLS
#define RC_SYSCONFDIR "@SYSCONFDIR@"
#define RC_LIBDIR "@PREFIX@/@LIB@/rc"
#define RC_LIBEXECDIR "@LIBEXECDIR@"
#ifdef __linux__
#define RC_SVCDIR "@PREFIX@/run/openrc"
#else
#define RC_SVCDIR RC_LIBEXECDIR "/init.d"
#endif
#define RC_RUNLEVELDIR RC_SYSCONFDIR "/runlevels"
#define RC_INITDIR RC_SYSCONFDIR "/init.d"
#define RC_CONFDIR RC_SYSCONFDIR "/conf.d"
@@ -364,10 +360,12 @@ bool rc_newer_than(const char *, const char *, time_t *, char *);
* @return true if source is older than target, otherwise false */
bool rc_older_than(const char *, const char *, time_t *, char *);
#ifdef __linux__
/*! Read variables/values from /proc/cmdline
* @param value
* @return pointer to the value, otherwise NULL */
char *rc_proc_getent(const char *);
#endif
/*! Update the cached dependency tree if it's older than any init script,
* its configuration file or an external configuration file the init script

View File

@@ -253,38 +253,13 @@ do_e(int argc, char **argv)
return retval;
}
static const struct {
const char * const name;
RC_SERVICE bit;
} service_bits[] = {
{ "service_started", RC_SERVICE_STARTED, },
{ "service_stopped", RC_SERVICE_STOPPED, },
{ "service_inactive", RC_SERVICE_INACTIVE, },
{ "service_starting", RC_SERVICE_STARTING, },
{ "service_stopping", RC_SERVICE_STOPPING, },
{ "service_hotplugged", RC_SERVICE_HOTPLUGGED, },
{ "service_wasinactive", RC_SERVICE_WASINACTIVE, },
{ "service_failed", RC_SERVICE_FAILED, },
};
static RC_SERVICE
lookup_service_state(const char *service)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(service_bits); ++i)
if (!strcmp(service, service_bits[i].name))
return service_bits[i].bit;
return 0;
}
static int
do_service(int argc, char **argv)
{
bool ok = false;
char *service;
char *exec;
int idx;
RC_SERVICE state, bit;
int idx = 0;
if (argc > 1)
service = argv[1];
@@ -294,11 +269,21 @@ do_service(int argc, char **argv)
if (service == NULL || *service == '\0')
eerrorx("%s: no service specified", applet);
state = rc_service_state(service);
bit = lookup_service_state(applet);
if (bit) {
ok = (state & bit);
} else if (strcmp(applet, "service_started_daemon") == 0) {
if (strcmp(applet, "service_started") == 0)
ok = (rc_service_state(service) & RC_SERVICE_STARTED);
else if (strcmp(applet, "service_stopped") == 0)
ok = (rc_service_state(service) & RC_SERVICE_STOPPED);
else if (strcmp(applet, "service_inactive") == 0)
ok = (rc_service_state(service) & RC_SERVICE_INACTIVE);
else if (strcmp(applet, "service_starting") == 0)
ok = (rc_service_state(service) & RC_SERVICE_STARTING);
else if (strcmp(applet, "service_stopping") == 0)
ok = (rc_service_state(service) & RC_SERVICE_STOPPING);
else if (strcmp(applet, "service_hotplugged") == 0)
ok = (rc_service_state(service) & RC_SERVICE_HOTPLUGGED);
else if (strcmp(applet, "service_wasinactive") == 0)
ok = (rc_service_state(service) & RC_SERVICE_WASINACTIVE);
else if (strcmp(applet, "service_started_daemon") == 0) {
service = getenv("RC_SVCNAME");
exec = argv[1];
if (argc > 3) {
@@ -330,34 +315,37 @@ do_mark_service(int argc, char **argv)
char *svcname = getenv("RC_SVCNAME");
char *service = NULL;
char *runscript_pid;
/* char *mtime; */
char *mtime;
pid_t pid;
RC_SERVICE bit;
/* size_t l; */
size_t l;
if (argc > 1)
service = argv[1];
else
service = svcname;
service = getenv("RC_SVCNAME");
if (service == NULL || *service == '\0')
eerrorx("%s: no service specified", applet);
if (!strncmp(applet, "mark_", 5) &&
(bit = lookup_service_state(applet + 5)))
ok = rc_service_mark(service, bit);
if (strcmp(applet, "mark_service_started") == 0)
ok = rc_service_mark(service, RC_SERVICE_STARTED);
else if (strcmp(applet, "mark_service_stopped") == 0)
ok = rc_service_mark(service, RC_SERVICE_STOPPED);
else if (strcmp(applet, "mark_service_inactive") == 0)
ok = rc_service_mark(service, RC_SERVICE_INACTIVE);
else if (strcmp(applet, "mark_service_starting") == 0)
ok = rc_service_mark(service, RC_SERVICE_STARTING);
else if (strcmp(applet, "mark_service_stopping") == 0)
ok = rc_service_mark(service, RC_SERVICE_STOPPING);
else if (strcmp(applet, "mark_service_hotplugged") == 0)
ok = rc_service_mark(service, RC_SERVICE_HOTPLUGGED);
else if (strcmp(applet, "mark_service_failed") == 0)
ok = rc_service_mark(service, RC_SERVICE_FAILED);
else
eerrorx("%s: unknown applet", applet);
/* If we're marking ourselves then we need to inform our parent
runscript process so they do not mark us based on our exit code */
/*
* FIXME: svcname and service are almost always equal except called from a
* shell with just argv[1] - So that doesn't seem to do what Roy initially
* expected.
* See 20120424041423.GA23657@odin.qasl.de (Tue, 24 Apr 2012 06:14:23 +0200,
* openrc@gentoo.org).
*/
if (ok && svcname && strcmp(svcname, service) == 0) {
runscript_pid = getenv("RC_RUNSCRIPT_PID");
if (runscript_pid && sscanf(runscript_pid, "%d", &pid) == 1)
@@ -367,7 +355,6 @@ do_mark_service(int argc, char **argv)
/* Remove the exclusive time test. This ensures that it's not
in control as well */
/*
l = strlen(RC_SVCDIR "/exclusive") + strlen(svcname) +
strlen(runscript_pid) + 4;
mtime = xmalloc(l);
@@ -376,7 +363,6 @@ do_mark_service(int argc, char **argv)
if (exists(mtime) && unlink(mtime) != 0)
eerror("%s: unlink: %s", applet, strerror(errno));
free(mtime);
*/
}
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
@@ -414,7 +400,7 @@ do_value(int argc, char **argv)
}
static int
shell_var(int argc, char **argv)
do_shell_var(int argc, char **argv)
{
int i;
char *p;
@@ -435,127 +421,106 @@ shell_var(int argc, char **argv)
return EXIT_SUCCESS;
}
static int
is_older_than(int argc, char **argv)
{
int i;
if (argc < 3)
return EXIT_FAILURE;
/* This test is perverted - historically the baselayout function
* returns 0 on *failure*, which is plain wrong */
for (i = 2; i < argc; ++i)
if (!rc_newer_than(argv[1], argv[i], NULL, NULL))
return EXIT_SUCCESS;
return EXIT_FAILURE;
}
static int
is_newer_than(int argc, char **argv)
{
int i;
if (argc < 3)
return EXIT_FAILURE;
/* This test is correct as it's not present in baselayout */
for (i = 2; i < argc; ++i)
if (!rc_newer_than(argv[1], argv[i], NULL, NULL))
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
static int
is_runlevel_start(_unused int argc, _unused char **argv)
{
return rc_runlevel_starting() ? 0 : 1;
}
static int
is_runlevel_stop(_unused int argc, _unused char **argv)
{
return rc_runlevel_stopping() ? 0 : 1;
}
static int
rc_abort(_unused int argc, _unused char **argv)
{
const char *p = getenv("RC_PID");
int pid;
if (p && sscanf(p, "%d", &pid) == 1) {
if (kill(pid, SIGUSR1) != 0)
eerrorx("rc-abort: failed to signal parent %d: %s",
pid, strerror(errno));
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
static const struct {
const char * const name;
int (* const applet)(int argc, char **argv);
} applets[] = {
#define A(a) { #a, a }
A(fstabinfo),
A(mountinfo),
{ "rc-depend", rc_depend, },
{ "rc-service", rc_service, },
{ "rc-status", rc_status, },
{ "rc-update", rc_update, },
{ "update-rc", rc_update, },
A(runscript),
{ "start-stop-daemon", start_stop_daemon, },
A(checkpath),
A(swclock),
A(shell_var),
A(is_older_than),
A(is_newer_than),
A(is_runlevel_start),
A(is_runlevel_stop),
{ "rc-abort", rc_abort, },
/* These are purely for init scripts and do not make sense as
* anything else */
{ "service_get_value", do_value, },
{ "service_set_value", do_value, },
{ "get_options", do_value, },
{ "save_options", do_value, },
#undef A
};
void
run_applets(int argc, char **argv)
{
size_t i;
int i = 2;
char *p;
pid_t pid = 0;
/* Bug 351712: We need an extra way to explicitly select an applet OTHER
* than trusting argv[0], as argv[0] is not going to be the applet value if
* we are doing SELinux context switching. For this, we allow calls such as
* 'rc --applet APPLET', and shift ALL of argv down by two array items. */
if (strcmp(applet, "rc") == 0 && argc >= 3 &&
(strcmp(argv[1],"--applet") == 0 || strcmp(argv[1], "-a") == 0)) {
(strcmp(argv[1],"--applet") == 0 || strcmp(argv[1], "-a") == 0)) {
applet = argv[2];
argv += 2;
argc -= 2;
}
for (i = 0; i < ARRAY_SIZE(applets); ++i)
if (!strcmp(applet, applets[i].name))
exit(applets[i].applet(argc, argv));
/* These are designed to be applications in their own right */
if (strcmp(applet, "fstabinfo") == 0)
exit(fstabinfo(argc, argv));
else if (strcmp(applet, "mountinfo") == 0)
exit(mountinfo(argc, argv));
else if (strcmp(applet, "rc-depend") == 0)
exit(rc_depend(argc, argv));
else if (strcmp(applet, "rc-service") == 0)
exit(rc_service(argc, argv));
else if (strcmp(applet, "rc-status") == 0)
exit(rc_status(argc, argv));
else if (strcmp(applet, "rc-update") == 0 ||
strcmp(applet, "update-rc") == 0)
exit(rc_update(argc, argv));
else if (strcmp(applet, "runscript") == 0)
exit(runscript(argc, argv));
else if (strcmp(applet, "start-stop-daemon") == 0)
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)
exit(do_shell_var(argc, argv));
/* This test is perverted - historically the baselayout function
* returns 0 on *failure*, which is plain wrong */
if (strcmp(applet, "is_older_than") == 0) {
if (argc < 3)
exit (EXIT_FAILURE);
while (i < argc) {
if (!rc_newer_than(argv[1], argv[i++], NULL, NULL))
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
};
/* This test is correct as it's not present in baselayout */
if (strcmp(applet, "is_newer_than") == 0) {
if (argc < 3)
exit (EXIT_FAILURE);
while (i < argc) {
if (!rc_newer_than(argv[1], argv[i++], NULL, NULL))
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
};
if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e'))
exit(do_e(argc, argv));
/* These are purely for init scripts and do not make sense as
* anything else */
if (strcmp(applet, "service_get_value") == 0 ||
strcmp(applet, "service_set_value") == 0 ||
strcmp(applet, "get_options") == 0 ||
strcmp(applet, "save_options") == 0)
exit(do_value(argc, argv));
if (strncmp(applet, "service_", strlen("service_")) == 0)
exit(do_service(argc, argv));
if (strncmp(applet, "mark_service_", strlen("mark_service_")) == 0)
exit(do_mark_service(argc, argv));
if (strcmp(applet, "is_runlevel_start") == 0)
exit(rc_runlevel_starting() ? 0 : 1);
else if (strcmp (applet, "is_runlevel_stop") == 0)
exit(rc_runlevel_stopping() ? 0 : 1);
if (strcmp(applet, "rc-abort") == 0) {
p = getenv("RC_PID");
if (p && sscanf(p, "%d", &pid) == 1) {
if (kill(pid, SIGUSR1) != 0)
eerrorx("rc-abort: failed to signal parent %d: %s",
pid, strerror(errno));
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
}
if (strcmp(applet, "rc") != 0)
eerrorx("%s: unknown applet", applet);
}

View File

@@ -793,13 +793,6 @@ main(int argc, char **argv)
env_filter();
env_config();
/* complain about old configuration settings if they exist */
if (exists(RC_CONF_OLD)) {
ewarn("%s still exists on your system and should be removed.",
RC_CONF_OLD);
ewarn("Please migrate to the appropriate settings in %s", RC_CONF);
}
argc++;
argv--;
while ((opt = getopt_long(argc, argv, getoptstring,

View File

@@ -192,7 +192,7 @@ parse_signal(const char *sig)
else
s = NULL;
for (i = 0; i < ARRAY_SIZE(signallist); ++i)
for (i = 0; i < sizeof(signallist) / sizeof(signallist[0]); i++)
if (strcmp(sig, signallist[i].name) == 0 ||
(s && strcmp(s, signallist[i].name) == 0))
return signallist[i].signal;

View File

@@ -93,7 +93,7 @@ ebegin "Checking for x* func usage"
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
-exec grep -n -E '\<(malloc|strdup)[[:space:]]*\(' {} + \
| grep -v \
-e src/includes/helpers.h \
-e src/includes/rc-misc.h \
-e src/libeinfo/libeinfo.c)
[ -z "${out}" ]
eend $? "These need to be using the x* variant:"$'\n'"${out}"