diff options
author | Christian Heim <phreak@gentoo.org> | 2005-10-12 08:29:57 +0000 |
---|---|---|
committer | Christian Heim <phreak@gentoo.org> | 2005-10-12 08:29:57 +0000 |
commit | 62620220f3618f76d201a885aa1ce09814c75634 (patch) | |
tree | 6a937548cac9c480cf24e9a3723c04f92a8501b5 | |
parent | fix release helper (diff) | |
download | baselayout-vserver-62620220f3618f76d201a885aa1ce09814c75634.tar.gz baselayout-vserver-62620220f3618f76d201a885aa1ce09814c75634.tar.bz2 baselayout-vserver-62620220f3618f76d201a885aa1ce09814c75634.zip |
Syncing up with baselayout revision 1566 (_pre9-r1)
svn path=/baselayout-vserver/trunk/; revision=57
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | ChangeLog.vserver | 9 | ||||
-rw-r--r-- | man/start-stop-daemon.8 | 8 | ||||
-rwxr-xr-x | net-scripts/init.d/net.lo | 8 | ||||
-rw-r--r-- | net-scripts/net.modules.d/arping | 3 | ||||
-rwxr-xr-x | net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper | 33 | ||||
-rw-r--r-- | net-scripts/net.modules.d/ifconfig | 2 | ||||
-rw-r--r-- | net-scripts/net.modules.d/ifplugd | 10 | ||||
-rw-r--r-- | net-scripts/net.modules.d/netplugd | 12 | ||||
-rw-r--r-- | net-scripts/net.modules.d/tuntap | 9 | ||||
-rwxr-xr-x | sbin/rc-daemon.sh | 32 | ||||
-rw-r--r-- | src/start-stop-daemon.c | 62 |
12 files changed, 172 insertions, 40 deletions
@@ -1,6 +1,30 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2005 Gentoo Foundation; Distributed under the GPLv2 + 12 Oct 2005; Roy Marples <uberlord@gentoo.org>: + + Changed number of preferred modules from 3 to 4 in net.lo, #108960. + + 11 Oct 2005; Mike Frysinger <vapier@gentoo.org>: + + Note that RC_BOOTLOG won't work with boot splash stuff #108645. + +* baselayout-1.12.0_pre9 (11 Oct 2005) + + 11 Oct 2005; Roy Marples <uberlord@gentoo.org>: + + arping now dis-regards 0.0.0.0 and 0 addresses, #108737. + + dhcpcd now allows the user to configure the -c script option, #108345. + + bash doesn't handle floats, so we eumlate it. Fixes the issue + where some daemons didn't stop, #107492. Thanks to Giampaolo Tomassoni. + + 09 Oct 2005; Roy Marples <uberlord@gentoo.org>: + + Fix chroot handling and enable custom env vars for start-stop-daemon + binary #101642, thanks to Quequero. + 07 Oct 2005; Roy Marples <uberlord@gentoo.org>: Fix some vlan/bridge/tap/neplugd/ifplugd interdependencies #107406. diff --git a/ChangeLog.vserver b/ChangeLog.vserver index f791f73..6b32243 100644 --- a/ChangeLog.vserver +++ b/ChangeLog.vserver @@ -1,6 +1,15 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2005 Gentoo Foundation; Distributed under the GPLv2 + 12 Oct 2005; Christian Heim <phreak@gentoo.org> ChangeLog, ChangeLog.vserver, + man/start-stop-daemon.8, net-scripts/init.d/net.lo, + net-scripts/net.modules.d/arping, + net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper, + net-scripts/net.modules.d/ifconfig, + net-scripts/net.modules.d/ifplugd, net-scripts/net.modules.d/netplugd, + net-scripts/net.modules.d/tuntap, sbin/rc-daemon.sh, src/start-stop-daemon.c: + Syncing up with baselayout revision 1566 (_pre9-r1) + 09 Oct 2005; Benedikt Boehm <hollow@gentoo.org> +net-scripts/: Adding back net services diff --git a/man/start-stop-daemon.8 b/man/start-stop-daemon.8 index d0d8f0b..e1ac686 100644 --- a/man/start-stop-daemon.8 +++ b/man/start-stop-daemon.8 @@ -186,6 +186,14 @@ Chdir and chroot to before starting the process. Please note that the pidfile is also written after the chroot. .TP +\fB-e\fP|\fB--env\fP \fIenv-name\fP +Set an environment variable whose name and value is +.I env-name +before starting +.I executable. +Example: -e HOME="/home/user" exports an environment variable whose name +is HOME with value "/home/user". +.TP .BR -b | --background Typically used with programs that don't detach on their own. This option will force diff --git a/net-scripts/init.d/net.lo b/net-scripts/init.d/net.lo index c408a67..523dd65 100755 --- a/net-scripts/init.d/net.lo +++ b/net-scripts/init.d/net.lo @@ -171,7 +171,7 @@ modules_check_installed() { # bool modules_check_user(void) modules_check_user() { local -a umods - local i j k l npref nmods="${#MODULES[@]}" + local i j k l nmods="${#MODULES[@]}" # Has the interface got any specific modules? eval umods=( \"\$\{modules_${iface}\[@\]\}\" ) @@ -180,8 +180,8 @@ modules_check_user() { umods=( "${umods[@]}" "${modules[@]}" ) # Add our preferred modules - npref=3 - umods=( "${umods[@]}" "iproute2" "dhcpcd" "iwconfig" "netplugd" ) + local -a pmods=( "iproute2" "dhcpcd" "iwconfig" "netplugd" ) + umods=( "${umods[@]}" "${pmods[@]}" ) # First we strip any modules that conflict from user settings # So if the user specifies pump then we don't use dhcpcd @@ -219,7 +219,7 @@ modules_check_user() { # If the module is one of our preferred modules, then # ignore this error; whatever is available will be # used instead. - (( i < ${#umods[@]} - npref )) || continue + (( i < ${#umods[@]} - ${#pmods[@]} )) || continue # The function may not exist because the modules software is # not installed. Load the module and report its error diff --git a/net-scripts/net.modules.d/arping b/net-scripts/net.modules.d/arping index f5e83c3..5f04978 100644 --- a/net-scripts/net.modules.d/arping +++ b/net-scripts/net.modules.d/arping @@ -56,6 +56,9 @@ address_exists() { # We only handle IPv4 addresses [[ ${address} != *.*.*.* ]] && return 1 + # 0.0.0.0 isn't a valid address - and some lusers have configured this + [[ ${address} == "0.0.0.0" || ${address} == "0" ]] && return 1 + # We need to bring the interface up to test interface_up "${iface}" diff --git a/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper b/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper index 9768535..6568d10 100755 --- a/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper +++ b/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper @@ -15,24 +15,25 @@ fi . /lib/rcscripts/net.modules.d/helpers.d/module-loader -if [[ ${action} == "up" ]]; then - # Map MAC address variables to interface variables - macnet_pre_start "${interface}" 1>/dev/null +# Map MAC address variables to interface variables +macnet_pre_start "${interface}" 1>/dev/null - # Map wireless ESSID variables to interface variables - if [[ -n ${wireless_module} ]]; then - if wireless_check_extensions "${interface}" ; then - essidnet_pre_start "${interface}" 1>/dev/null - fi +# Map wireless ESSID variables to interface variables +if [[ -n ${wireless_module} ]]; then + if wireless_check_extensions "${interface}" ; then + essidnet_pre_start "${interface}" 1>/dev/null fi +fi - # Add any search paths if we have any defined - ifvar=$( bash_variable "${interface}" ) +# Add any search paths if we have any defined +ifvar=$( bash_variable "${interface}" ) + +if [[ ${action} == "up" ]]; then eval d=\" \$\{dhcp_${ifvar}\} \" [[ ${d} == " " ]] && d=" ${dhcp} " resolv="${statedir}/${interface}/resolv.conf" - + if [[ ${d} != *" nodns "* ]]; then eval search=\"\$\{dns_search_${ifvar}\}\" if [[ -n ${search} ]]; then @@ -46,6 +47,16 @@ if [[ ${action} == "up" ]]; then system_dns_extra "${interface}" "${resolv}" fi +# As we override the -c option, we need to call the specified script ourself +eval opts=\"\$\{dhcpcd_${ifvar}\}\" +exe="${opts##* -c }" +if [[ -n ${exe} && ${exe} != "${opts}" ]]; then + exe="${exe%% *}" +else + exe="/etc/dhcpc/dhcpcd.exe" +fi +[[ -x ${exe} ]] && ( ${exe} "$@" 1>/dev/null ) + . /lib/rcscripts/net.modules.d/helpers.d/dhcp-state # vim:ts=4 diff --git a/net-scripts/net.modules.d/ifconfig b/net-scripts/net.modules.d/ifconfig index 9bc31f1..48a65fb 100644 --- a/net-scripts/net.modules.d/ifconfig +++ b/net-scripts/net.modules.d/ifconfig @@ -110,7 +110,7 @@ ifconfig_get_address() { local -a x=( $( ifconfig "$1" \ | sed -n -e 's/.*inet addr:\([^ ]*\).*Mask:\([^ ]*\).*/\1 \2/p' ) ) x[1]=$( netmask2cidr "${x[1]}" ) - echo "${x[0]}/${x[1]}" + [[ -n ${x[0]} ]] && echo "${x[0]}/${x[1]}" } # void ifconfig_get_mac_address(char *interface) diff --git a/net-scripts/net.modules.d/ifplugd b/net-scripts/net.modules.d/ifplugd index 21e4bfa..d7006ea 100644 --- a/net-scripts/net.modules.d/ifplugd +++ b/net-scripts/net.modules.d/ifplugd @@ -78,6 +78,14 @@ ifplugd_pre_start() { return 0 fi fi + + # We don't work on tun/tap interfaces + if [[ $(type -t tuntap_exists) == "function" ]]; then + if tuntap_exists "${iface}"; then + veinfo "netplug does not work on tun/tap interfaces" + return 0 + fi + fi # Do some options eval opts=\" \$\{ifplugd_${ifvar}\} \" @@ -124,7 +132,7 @@ ifplugd_pre_start() { while true ; do if service_started "net.${iface}"; then local addr=$( interface_get_address "${iface}" ) - einfo "${iface} configured with address ${addr}" + einfo "${iface} configured with address ${addr}" exit 0 fi sleep 1 diff --git a/net-scripts/net.modules.d/netplugd b/net-scripts/net.modules.d/netplugd index 4dc872f..2307a17 100644 --- a/net-scripts/net.modules.d/netplugd +++ b/net-scripts/net.modules.d/netplugd @@ -72,7 +72,15 @@ netplugd_pre_start() { return 0 fi fi - + + # We don't work on tun/tap interfaces + if [[ $(type -t tuntap_exists) == "function" ]]; then + if tuntap_exists "${iface}"; then + veinfo "netplug does not work on tun/tap interfaces" + return 0 + fi + fi + # We don't work on wirelesss interfaces if [[ $(type -t wireless_check_extensions) == "function" ]]; then if wireless_check_extensions "${iface}"; then @@ -111,7 +119,7 @@ netplugd_pre_start() { while true ; do if service_started "net.${iface}"; then local addr=$( interface_get_address "${iface}" ) - einfo "${iface} configured with address ${addr}" + einfo "${iface} configured with address ${addr}" exit 0 fi sleep 1 diff --git a/net-scripts/net.modules.d/tuntap b/net-scripts/net.modules.d/tuntap index 22281e2..eea33db 100644 --- a/net-scripts/net.modules.d/tuntap +++ b/net-scripts/net.modules.d/tuntap @@ -69,6 +69,13 @@ tuntap_get_vars() { echo "tunctl_$1" } +# bool tuntap_exists(char *interface) +# +# Returns 0 if the tun/tap interface exists, otherwise 1 +tuntap_exists() { + tunctl -d "$1" &>/dev/null +} + # bool tuntap_pre_start(char *iface) # # Create the device, give it the right perms @@ -105,7 +112,7 @@ tuntap_stop() { # tunctl doesn't always error on on tun/tap # interfaces (mainly aliases, etc) - if tunctl -d "${iface}" &>/dev/null ; then + if tuntap_exists "${iface}" ; then interface_exists "${iface}" \ || einfo "Destroyed Tun/Tap interface ${iface}" fi diff --git a/sbin/rc-daemon.sh b/sbin/rc-daemon.sh index e5cc63e..b59eb66 100755 --- a/sbin/rc-daemon.sh +++ b/sbin/rc-daemon.sh @@ -68,6 +68,10 @@ rc_shift_args() { --pid=*) pidfile="${1##--pid=}" ;; + -R|--retry) + unset RC_RETRY_COUNT + addvar="RC_RETRY_COUNT" + ;; -s|--signal) addvar="signal" ;; @@ -77,6 +81,8 @@ rc_shift_args() { esac shift done + + [[ -z ${RC_RETRY_COUNT} ]] && RC_RETRY_COUNT=5 } # void rc_setup_daemon_vars(void) @@ -128,23 +134,33 @@ rc_setup_daemon_vars() { # via pkill # Returns 0 if successfuly otherwise 1 rc_try_kill_pid() { - local pid="$1" signal="${2:-TERM}" session="${3:-false}" i s + local pid="$1" signal="${2:-TERM}" session="${3:-false}" i s p e # We split RC_RETRY_TIMEOUT into tenths of seconds # So we return as fast as possible - (( s=${RC_RETRY_TIMEOUT}/10 )) + s=$(( ${RC_RETRY_TIMEOUT}/10 )).$(( ${RC_RETRY_TIMEOUT}%10 )) for (( i=0; i<RC_RETRY_COUNT*10; i++ )); do if ${session} ; then if [[ -x /usr/bin/pkill ]]; then - /usr/bin/pkill "-${signal}" -s "${pid}" || return 0 + pkill "-${signal}" -s "${pid}" + pgrep -s "${pid}" >/dev/null || return 0 else - local pids=$(/bin/ps -eo pid,sid | /bin/sed -n 's/'${pid}'$//p') + local pids=$(ps -eo pid,sid | sed -n 's/'${pid}'$//p') [[ -z ${pids} ]] && return 0 - /bin/kill -s "${signal}" ${pids} 2>/dev/null + kill -s "${signal}" ${pids} 2>/dev/null + e=false + for p in ${pids}; do + if [[ -d "/proc/${p}" ]]; then + e=true + break + fi + done + ${e} || return 0 fi else - /bin/kill -s "${signal}" "${pid}" 2>/dev/null || return 0 + kill -s "${signal}" "${pid}" 2>/dev/null + [[ ! -d "/proc/${pid}" ]] && return 0 fi LC_ALL=C /bin/sleep "${s}" done @@ -267,12 +283,12 @@ rc_stop_daemon() { for pid in ${pids}; do if [[ ${RC_FAIL_ON_ZOMBIE} == "yes" ]]; then - /bin/ps -p "${pid}" &>/dev/null || return 1 + ps -p "${pid}" &>/dev/null || return 1 fi if rc_kill_pid "${pid}" false ; then # Remove the pidfile if the process didn't - [[ -f ${pidfile} ]] && /bin/rm -f "${pidfile}" + [[ -f ${pidfile} ]] && rm -f "${pidfile}" else retval=1 fi diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 8be9d23..61499fb 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -18,6 +18,16 @@ * and Andreas Schuldei <andreas@schuldei.org> * * Changes by Ian Jackson: added --retry (and associated rearrangements). + * + * + * Changes by Quequero <quequero@bitchx.it>: + * Added -e|--env for setting an environment variable before starting the + * process. + * Moved --make-pidfile after chrooting process (pid file will be wrote in + * new root if -r option is used!). + * Daemon binary will be stat()ed correctly if it's going to be chrooted + * with -r|--chroot. + * */ #define VERSION "1.13.11+gentoo" @@ -113,6 +123,7 @@ static const char *signal_str = NULL; static int user_id = -1; static int runas_uid = -1; static int runas_gid = -1; +static char *env = NULL; static const char *userspec = NULL; static char *changeuser = NULL; static const char *changegroup = NULL; @@ -291,6 +302,8 @@ do_help(void) " -b|--background force the process to detach\n" " -m|--make-pidfile create the pidfile before starting\n" " -R|--retry <schedule> check whether processes die, and retry\n" +" -e|--env <env-name> set an environment variable (PWD=\"/\")\n" +" -r|--chroot <path> chroot process to given directory\n" " -t|--test test mode, don't do anything\n" " -o|--oknodo exit status 0 (not 1) if nothing done\n" " -q|--quiet be more quiet\n" @@ -459,6 +472,7 @@ parse_options(int argc, char * const *argv) { "start", 0, NULL, 'S'}, { "version", 0, NULL, 'V'}, { "startas", 1, NULL, 'a'}, + { "env", 1, NULL, 'e'}, { "name", 1, NULL, 'n'}, { "oknodo", 0, NULL, 'o'}, { "pidfile", 1, NULL, 'p'}, @@ -481,7 +495,7 @@ parse_options(int argc, char * const *argv) int c; for (;;) { - c = getopt_long(argc, argv, "HKSVa:n:op:qr:s:tu:vx:c:N:bmR:g:d:", + c = getopt_long(argc, argv, "HKSVa:n:op:qr:e:s:tu:vx:c:N:bmR:g:d:", longopts, (int *) 0); if (c == -1) break; @@ -541,6 +555,9 @@ parse_options(int argc, char * const *argv) case 'r': /* --chroot /new/root */ changeroot = optarg; break; + case 'e': /* --env <env-name> */ + env = optarg; + break; case 'N': /* --nice */ nicelevel = atoi(optarg); break; @@ -1247,8 +1264,25 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (execname && stat(execname, &exec_stat)) - fatal("stat %s: %s", execname, strerror(errno)); + if (changeroot == NULL) { + if (execname && stat(execname, &exec_stat)) + fatal("stat %s: %s", execname, strerror(errno)); + } else { + if (execname) { + char *tmp = NULL; + + tmp = malloc(strlen(changeroot) + strlen(execname) + 1); + strncpy(tmp, changeroot, strlen(changeroot)); + strncat(tmp, execname, strlen(execname)); + + if (stat(tmp, &exec_stat)) { + fatal("stat %s: %s", tmp, strerror(errno)); + free(tmp); + } else { + free(tmp); + } + } + } if (userspec && sscanf(userspec, "%d", &user_id) != 1) { struct passwd *pw; @@ -1336,15 +1370,6 @@ main(int argc, char **argv) fatal("Unable to alter nice level by %i: %s", nicelevel, strerror(errno)); } - if (mpidfile && pidfile != NULL) { /* user wants _us_ to make the pidfile :) */ - FILE *pidf = fopen(pidfile, "w"); - pid_t pidt = getpid(); - if (pidf == NULL) - fatal("Unable to open pidfile `%s' for writing: %s", pidfile, - strerror(errno)); - fprintf(pidf, "%d\n", pidt); - fclose(pidf); - } if (changeroot != NULL) { if (chdir(changeroot) < 0) fatal("Unable to chdir() to %s", changeroot); @@ -1353,6 +1378,15 @@ main(int argc, char **argv) } if (chdir(changedir) < 0) fatal("Unable to chdir() to %s", changedir); + if (mpidfile && pidfile != NULL) { /* user wants _us_ to make the pidfile :) */ + FILE *pidf = fopen(pidfile, "w"); + pid_t pidt = getpid(); + if (pidf == NULL) + fatal("Unable to open pidfile `%s' for writing: %s", pidfile, + strerror(errno)); + fprintf(pidf, "%d\n", pidt); + fclose(pidf); + } if (changeuser != NULL) { if (setgid(runas_gid)) fatal("Unable to set gid to %d", runas_gid); @@ -1361,6 +1395,10 @@ main(int argc, char **argv) if (setuid(runas_uid)) fatal("Unable to set uid to %s", changeuser); } + if (env != NULL) { + if(putenv(env)) + fatal("Unable to set variable: %s", env); + } if (background) { /* continue background setup */ int i; #ifdef HAVE_TIOCNOTTY |