summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-04-10 10:33:44 +0000
committerRoy Marples <roy@marples.name>2007-04-10 10:33:44 +0000
commit0c98067d57606c59866e9ff35f2a6aedaaedaf76 (patch)
tree6cb5a27b2e26d8c669770b3ff3b2516ff2e3db98
parentc5ddc6ef74460f72ea56350c6ff002c9630f6552 (diff)
downloadopenrc-0c98067d57606c59866e9ff35f2a6aedaaedaf76.tar.gz
openrc-0c98067d57606c59866e9ff35f2a6aedaaedaf76.tar.bz2
openrc-0c98067d57606c59866e9ff35f2a6aedaaedaf76.tar.xz
Misc network fixes so we work on my stable server. Splash plugin removed as splashtuils-1.4 now ships with its own.
-rw-r--r--net.Linux/ifconfig.sh36
-rw-r--r--net.Linux/iproute2.sh38
-rw-r--r--net.Linux/iwconfig.sh55
-rw-r--r--net.Linux/macchanger.sh88
-rw-r--r--net.Linux/tuntap.sh6
-rw-r--r--net/macchanger.sh1
-rwxr-xr-xsh/net.sh2
-rw-r--r--src/Makefile4
-rw-r--r--src/librc-misc.c9
-rw-r--r--src/runscript.c18
-rw-r--r--src/splash.c130
11 files changed, 89 insertions, 298 deletions
diff --git a/net.Linux/ifconfig.sh b/net.Linux/ifconfig.sh
index 637c42f..0b0af97 100644
--- a/net.Linux/ifconfig.sh
+++ b/net.Linux/ifconfig.sh
@@ -6,22 +6,6 @@ ifconfig_depend() {
provide interface
}
-_get_mac_address() {
- local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
- sed -n -e 's/.* HWaddr \(..:..:..:..:..:..\).*/\1/p')
-
-
- case "${mac}" in
- 00:00:00:00:00:00) ;;
- 44:44:44:44:44:44) ;;
- FF:FF:FF:FF:FF:FF) ;;
- "") ;;
- *) echo "${mac}"; return 0 ;;
- esac
-
- return 1
-}
-
_up() {
ifconfig "${IFACE}" up
}
@@ -54,6 +38,26 @@ _is_wireless() {
grep -Eq "^[[:space:]]*${IFACE}:[[:space:]]+" /proc/net/wireless
}
+_get_mac_address() {
+ local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
+ sed -n -e 's/.* HWaddr \(..:..:..:..:..:..\).*/\1/p')
+
+
+ case "${mac}" in
+ 00:00:00:00:00:00) ;;
+ 44:44:44:44:44:44) ;;
+ FF:FF:FF:FF:FF:FF) ;;
+ "") ;;
+ *) echo "${mac}"; return 0 ;;
+ esac
+
+ return 1
+}
+
+_set_mac_address() {
+ ifconfig "${IFACE}" hw ether "$1"
+}
+
_get_inet_address() {
set -- $(LC_ALL=C ifconfig "${IFACE}" |
sed -n -e 's/.*inet addr:\([^ ]*\).*Mask:\([^ ]*\).*/\1 \2/p')
diff --git a/net.Linux/iproute2.sh b/net.Linux/iproute2.sh
index 1b1b70f..ccab1db 100644
--- a/net.Linux/iproute2.sh
+++ b/net.Linux/iproute2.sh
@@ -7,21 +7,6 @@ iproute2_depend() {
after ifconfig
}
-_get_mac_address() {
- local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \
- -e 'y/abcdef/ABCDEF/' \
- -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
-
- case "${mac}" in
- 00:00:00:00:00:00) ;;
- 44:44:44:44:44:44) ;;
- FF:FF:FF:FF:FF:FF) ;;
- "") ;;
- *) echo "${mac}"; return 0 ;;
- esac
-
- return 1
-}
_up() {
ip link set up dev "${IFACE}"
@@ -55,6 +40,26 @@ _is_wireless() {
grep -Eq "^[[:space:]]*${IFACE}:[[:space:]]+" /proc/net/wireless
}
+_get_mac_address() {
+ local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \
+ -e 'y/abcdef/ABCDEF/' \
+ -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
+
+ case "${mac}" in
+ 00:00:00:00:00:00) ;;
+ 44:44:44:44:44:44) ;;
+ FF:FF:FF:FF:FF:FF) ;;
+ "") ;;
+ *) echo "${mac}"; return 0 ;;
+ esac
+
+ return 1
+}
+
+_set_mac_address() {
+ ip link set address "$1" dev "${IFACE}"
+}
+
_get_inet_addresses() {
LC_ALL=C ip -family inet addr show "${IFACE}" | \
sed -n -e 's/.*inet \([^ ]*\).*/\1/p'
@@ -160,8 +165,9 @@ iproute2_pre_start() {
metric=1000
ebegin "Creating tunnel ${IFVAR}"
- ip tunnel add "${tunnel}"
+ ip tunnel add ${tunnel} name "${IFACE}"
eend $? || return 1
+ _up
fi
return 0
diff --git a/net.Linux/iwconfig.sh b/net.Linux/iwconfig.sh
index bed13a5..6dfbc98 100644
--- a/net.Linux/iwconfig.sh
+++ b/net.Linux/iwconfig.sh
@@ -3,7 +3,7 @@
# Many thanks to all the people in the Gentoo forums for their ideas and
# motivation for me to make this and keep on improving it
-_config_vars="$_config_vars essid mode associate_timeout sleep_scan preferred_aps blacklist_aps"
+_config_vars="$_config_vars ssid mode associate_timeout sleep_scan preferred_aps blacklist_aps"
iwconfig_depend() {
program /sbin/iwconfig
@@ -155,8 +155,8 @@ iwconfig_setup_specific() {
fi
# Then set the SSID
- if ! eval iwconfig "${IFACE}" essid "${SSID}" ; then
- eerror "${IFACE} does not support setting SSID to \"${ESSID}\""
+ if ! iwconfig "${IFACE}" essid "${SSID}" ; then
+ eerror "${IFACE} does not support setting SSID to \"${SSID}\""
return 1
fi
@@ -187,7 +187,7 @@ iwconfig_wait_for_association() {
# Use sysfs if we can
if [ -e /sys/class/net/"${IFACE}"/carrier ] ; then
if [ "$(cat /sys/class/net/"${IFACE}"/carrier)" = "1" ] ; then
- # Double check we have an essid. This is mainly for buggy
+ # Double check we have an ssid. This is mainly for buggy
# prism54 drivers that always set their carrier on :/
[ -n "$(iwgetid --raw "${IFACE}")" ] && return 0
fi
@@ -220,7 +220,7 @@ iwconfig_associate() {
if [ "${SSID}" = "any" ]; then
iwconfig "${IFACE}" ap any 2>/dev/null
- unset ESSIDVAR
+ unset SSIDVAR
else
SSIDVAR=$(_shell_var "${SSID}")
key="$(iwconfig_get_wep_key "${mac}")"
@@ -243,9 +243,9 @@ iwconfig_associate() {
[ "${key}" != "off" ] && w="$(iwconfig_get_wep_status "${iface}")"
fi
- if ! eval iwconfig "${IFACE}" essid "${SSID}" ; then
+ if ! iwconfig "${IFACE}" essid "${SSID}" ; then
if [ "${SSID}" != "any" ] ; then
- ewarn "${IFACE} does not support setting ESSID to \"${SSID}\""
+ ewarn "${IFACE} does not support setting SSID to \"${SSID}\""
fi
fi
@@ -315,7 +315,7 @@ iwconfig_scan() {
if [ -z "${scan}" ] ; then
ewarn "${iface} does not support scanning"
eoutdent
- eval x=\$adhoc_essid_${IFVAR}
+ eval x=\$adhoc_ssid_${IFVAR}
[ -n "${x}" ] && return 0
if [ -n "${preferred_aps}" ] ; then
[ "${associate_order}" = "forcepreferred" ] || \
@@ -328,9 +328,9 @@ iwconfig_scan() {
eerror "or hardcode the SSID to \"any\" and let the driver find an Access Point"
eerror " ssid_${IFVAR}=\"any\""
eerror "or configure defaulting to Ad-Hoc when Managed fails"
- eerror " adhoc_essid_${IFVAR}=\"WLAN\""
- eerror "or hardcode the ESSID against the interface (not recommended)"
- eerror " essid_${IFVAR}=\"ESSID\""
+ eerror " adhoc_ssid_${IFVAR}=\"WLAN\""
+ eerror "or hardcode the SSID against the interface (not recommended)"
+ eerror " ssid_${IFVAR}=\"SSID\""
return 1
fi
@@ -507,13 +507,13 @@ iwconfig_force_preferred() {
}
iwconfig_connect_preferred() {
- local essid= i=0 mode= mac= enc= freq= chan=
+ local ssid= i=0 mode= mac= enc= freq= chan=
eval "$(_get_array preferred_aps)"
- for essid in "$@"; do
+ for ssid in "$@"; do
while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i}
- if [ "${e}" = "${essid}" ] ; then
+ if [ "${e}" = "${ssid}" ] ; then
SSID=${e}
eval mode=\$MODE_${i}
eval mac=\$MAC_${i}
@@ -531,13 +531,13 @@ iwconfig_connect_preferred() {
}
iwconfig_connect_not_preferred() {
- local essid= i=0 mode= mac= enc= freq= chan= pref=false
+ local ssid= i=0 mode= mac= enc= freq= chan= pref=false
while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i}
eval "$(_get_array preferred_aps)"
- for essid in "$@" ; do
- if [ "${e}" = "${essid}" ] ; then
+ for ssid in "$@" ; do
+ if [ "${e}" = "${ssid}" ] ; then
pref=true
break
fi
@@ -566,14 +566,17 @@ iwconfig_defaults() {
done
# Release the AP forced
- # Must do ap and then essid otherwise scanning borks
+ # Must do ap and then ssid otherwise scanning borks
iwconfig "${IFACE}" ap off 2>/dev/null
iwconfig "${IFACE}" essid off 2>/dev/null
}
iwconfig_configure() {
local x APS
- eval ESSID=\$ssid_${IFVAR}
+ eval SSID=\$ssid_${IFVAR}
+
+ # Support old variable
+ [ -z "${SSID}" ] && eval SSID=\$essid_${IFVAR}
# Setup ad-hoc mode?
eval x=\$mode_${IFVAR}
@@ -588,14 +591,14 @@ iwconfig_configure() {
return 1
fi
- # Has an ESSID been forced?
- if [ -n "${ESSID}" ]; then
+ # Has an SSID been forced?
+ if [ -n "${SSID}" ]; then
iwconfig_set_mode "${x}"
iwconfig_associate && return 0
- [ "${ESSID}" = "any" ] && iwconfig_force_preferred && return 0
+ [ "${SSID}" = "any" ] && iwconfig_force_preferred && return 0
- eval ESSID=\$adhoc_essid_${IFVAR}
- if [ -n "${ESSID}" ]; then
+ eval SSID=\$adhoc_ssid_${IFVAR}
+ if [ -n "${SSID}" ]; then
iwconfig_setup_specific ad-hoc
return $?
fi
@@ -688,14 +691,14 @@ iwconfig_pre_start() {
fi
if iwconfig_configure ; then
- save_options "ESSID" "${ESSID}"
+ save_options "SSID" "${SSID}"
return 0
fi
eerror "Failed to configure wireless for ${IFACE}"
iwconfig_defaults
iwconfig "${IFACE}" txpower off 2>/dev/null
- unset ESSID ESSIDVAR
+ unset SSID SSIDVAR
_down
return 1
}
diff --git a/net.Linux/macchanger.sh b/net.Linux/macchanger.sh
deleted file mode 100644
index 9d71513..0000000
--- a/net.Linux/macchanger.sh
+++ /dev/null
@@ -1,88 +0,0 @@
-# Copyright 2004-2007 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-macchanger_depend() {
- before macnet
-}
-
-_config_vars="$_config_vars mac"
-
-macchanger_pre_start() {
- # We don't change MAC addresses from background
- ${IN_BACKGROUND} && return 0
-
- local mac= opts=
-
- eval mac=\$mac_${IFVAR}
- [ -z "${mac}" ] && return 0
-
- _exists true || return 1
-
- ebegin "Changing MAC address of ${IFACE}"
-
- # The interface needs to be up for macchanger to work most of the time
- _down
-
- mac=$(echo "${mac}" | sed -e 'y/ABCDEF/abcdef')
- case "${mac}" in
- # specific mac-addr, i wish there were a shorter way to specify this
- [0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])
- # We don't need macchanger to change to a specific mac address
- _set_mac_address "${mac}"
- if eend "$?" ; then
- mac=$(_get_mac_address)
- eindent
- einfo "changed to ${mac}"
- eoutdent
- return 0
- fi
- ;;
-
- # increment MAC address, default macchanger behavior
- increment) opts="${opts}" ;;
-
- # randomize just the ending bytes
- random-ending) opts="${opts} -e" ;;
-
- # keep the same kind of physical layer (eg fibre, copper)
- random-samekind) opts="${opts} -a" ;;
-
- # randomize to any known vendor of any physical layer type
- random-anykind) opts="${opts} -A" ;;
-
- # fully random bytes
- random-full|random) opts="${opts} -r" ;;
-
- # default case is just to pass on all the options
- *) opts="${opts} ${mac}" ;;
- esac
-
- if [ ! -x /sbin/macchanger ] ; then
- eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
- return 1
- fi
-
- mac=$(LC_ALL=C macchanger ${opts} "${IFACE}" \
- | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\1/p' )
- _up
-
- # Sometimes the interface needs to be up ....
- if [ -z "${mac}" ] ; then
- mac=$(LC_ALL=C macchanger ${opts} "${IFACE}" \
- | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\1/p' )
- fi
-
- if [ -z "${mac}" ] ; then
- eend 1 "Failed to set MAC address"
- return 1
- fi
-
- eend 0
- eindent
- einfo "changed to" "${mac}"
- eoutdent
-
- return 0
-}
-
-# vim: set ts=4 :
diff --git a/net.Linux/tuntap.sh b/net.Linux/tuntap.sh
index 829bf13..ba9b2e8 100644
--- a/net.Linux/tuntap.sh
+++ b/net.Linux/tuntap.sh
@@ -17,9 +17,9 @@ tuntap_pre_start() {
[ -z "${tuntap}" ] && return 0
- if [ ! -a /dev/net/tun ] ; then
+ if [ ! -e /dev/net/tun ] ; then
modprobe tun && sleep 1
- if [ ! -a /dev/net/tun ] ; then
+ if [ ! -e /dev/net/tun ] ; then
eerror "TUN/TAP support is not present in this kernel"
return 1
fi
@@ -37,7 +37,7 @@ tuntap_pre_start() {
eval opts=\$tunctl_${IFVAR}
tunctl ${opts} -t "${IFACE}" >/dev/null
fi
- eend $? && save_options tuntap "${tuntap}"
+ eend $? && _up && save_options tuntap "${tuntap}"
}
tuntap_post_stop() {
diff --git a/net/macchanger.sh b/net/macchanger.sh
index dce481c..300a0f6 100644
--- a/net/macchanger.sh
+++ b/net/macchanger.sh
@@ -34,6 +34,7 @@ macchanger_pre_start() {
eindent
einfo "changed to ${mac}"
eoutdent
+ _up
return 0
fi
;;
diff --git a/sh/net.sh b/sh/net.sh
index 30c68fc..22c2215 100755
--- a/sh/net.sh
+++ b/sh/net.sh
@@ -553,7 +553,7 @@ stop() {
[ -x /sbin/resolvconf ] && resolvconf -d "${IFACE}"
- if type predown >/dev/null 2>/dev/null ; then
+ if type postdown >/dev/null 2>/dev/null ; then
ebegin "Running postdown"
eindent
postdown
diff --git a/src/Makefile b/src/Makefile
index 91398f4..8996ce4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -113,10 +113,6 @@ $(LIBRCSO): $(LIBRCOBJS)
$(CC) -fPIC -shared -Wl,-soname,$(LIBRCSO) -o $(LIBRCSO) $(LIBRCOBJS)
ln -sf $(LIBRCSO) librc.so
-splash: CFLAGS += -fPIC
-splash: splash.o
- $(CC) -fPIC -shared -Wl,-soname,splash.so -o splash.so splash.o
-
env-update: $(LIBEINFOSO) $(LIBRCSO) env-update.o
fstabinfo: $(LIBEINFOSO) fstabinfo.o
diff --git a/src/librc-misc.c b/src/librc-misc.c
index fcb536f..b367ccc 100644
--- a/src/librc-misc.c
+++ b/src/librc-misc.c
@@ -447,7 +447,10 @@ char **rc_get_list (char **list, const char *file)
token = strsep (&p, "#");
if (token && (strlen (token) > 1))
{
- token[strlen (token) - 1] = 0;
+ /* Stip the newline if present */
+ if (token[strlen (token) - 1] == '\n')
+ token[strlen (token) - 1] = 0;
+
list = rc_strlist_add (list, token);
}
}
@@ -745,9 +748,5 @@ char **rc_config_env (char **env)
free (line);
}
- /* Set this var to ensure that things are POSIX, which makes scripts work
- on non GNU systems with less effort. */
- env = rc_strlist_add (env, "POSIXLY_CORRECT=1");
-
return (env);
}
diff --git a/src/runscript.c b/src/runscript.c
index ad8a251..0b440e2 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -234,14 +234,7 @@ static void cleanup (void)
if (in_control ())
{
- if (rc_service_state (applet, rc_service_starting))
- {
- if (rc_service_state (applet, rc_service_wasinactive))
- rc_mark_service (applet, rc_service_inactive);
- else
- rc_mark_service (applet, rc_service_stopped);
- }
- else if (rc_service_state (applet, rc_service_stopping))
+ if (rc_service_state (applet, rc_service_stopping))
{
/* If the we're shutting down, do it cleanly */
if ((softlevel &&
@@ -254,6 +247,13 @@ static void cleanup (void)
else
rc_mark_service (applet, rc_service_started);
}
+ else if (rc_service_state (applet, rc_service_starting))
+ {
+ if (rc_service_state (applet, rc_service_wasinactive))
+ rc_mark_service (applet, rc_service_inactive);
+ else
+ rc_mark_service (applet, rc_service_stopped);
+ }
if (exclusive && rc_exists (exclusive))
unlink (exclusive);
}
@@ -778,7 +778,7 @@ static void svc_stop (const char *service, bool deps)
if (rc_service_state (service, rc_service_wasinactive))
rc_mark_service (service, rc_service_inactive);
else
- rc_mark_service (service, rc_service_stopped);
+ rc_mark_service (service, rc_service_started);
eerrorx ("ERROR: %s failed to stop", applet);
}
diff --git a/src/splash.c b/src/splash.c
deleted file mode 100644
index dbea79a..0000000
--- a/src/splash.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- splash.c
-
- Splash plugin for the Gentoo RC sytsem.
- splashutils needs to be re-written to support our new system.
- Until then, we provide this compatible module which calls the
- legacy bash scripts which is nasty. And slow.
-
- For any themes that use scripts, such as the live-cd theme,
- they will have to source /sbin/splash-functions.sh themselves like so
-
- if ! type splash >/dev/null 2>/dev/null ; then
- . /sbin/splash-functions.sh
- fi
-
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <rc.h>
-
-#ifndef LIB
-# define LIB "lib"
-#endif
-
-#define SPLASH_CACHEDIR "/" LIB "/splash/cache"
-
-#define SPLASH_CMD "bash -c 'export SOFTLEVEL='%s'; export BOOTLEVEL=${RC_BOOTLEVEL}; export DEFAULTLEVEL=${RC_DEFAULTLEVEL}; export svcdir=${RC_SVCDIR}; add_suffix() { echo \"$@\"; }; . /etc/init.d/functions.sh; . /sbin/splash-functions.sh; splash %s %s %s'"
-
-int _splash_hook (rc_hook_t hook, const char *name);
-
-static int _do_splash (const char *cmd, const char *arg1, const char *arg2)
-{
- char *c;
- int l;
- char *soft = getenv ("RC_SOFTLEVEL");
-
- if (! cmd || ! soft)
- return (-1);
-
- l = strlen (SPLASH_CMD) + strlen (soft) + strlen (cmd);
- if (arg1)
- l += strlen (arg1);
- if (arg2)
- l += strlen (arg2);
- c = malloc (sizeof (char *) * l);
- if (! c)
- return (-1);
-
- snprintf (c, l, SPLASH_CMD,
- arg1 ? strcmp (arg1, RC_LEVEL_SYSINIT) == 0 ? RC_LEVEL_BOOT : soft : soft,
- cmd, arg1 ? arg1 : "", arg2 ? arg2 : "");
- l = system (c);
- free (c);
- return (l);
-}
-
-int _splash_hook (rc_hook_t hook, const char *name)
-{
- switch (hook)
- {
- case rc_hook_runlevel_stop_in:
- if (strcmp (name, RC_LEVEL_SYSINIT) != 0)
- return (_do_splash ("rc_init", name, NULL));
- break;
- case rc_hook_runlevel_start_out:
- if (strcmp (name, RC_LEVEL_SYSINIT) == 0)
- return (_do_splash ("rc_init", name, NULL));
- else
- return (_do_splash ("rc_exit", name, NULL));
- default: ;
- }
-
- /* We don't care about splash unless we're changing runlevels */
- if (! rc_runlevel_starting () &&
- ! rc_runlevel_stopping ())
- return (0);
-
- switch (hook)
- {
- case rc_hook_service_stop_in:
- /* We need to stop localmount from unmounting our cache dir.
- Luckily plugins can add to the unmount list. */
- if (name && strcmp (name, "localmount") == 0)
- {
- char *umounts = getenv ("RC_NO_UMOUNTS");
- char *new;
- int i = strlen (SPLASH_CACHEDIR) + 1;
-
- if (umounts)
- i += strlen (umounts) + 1;
-
- new = malloc (sizeof (char *) * i);
- if (new)
- {
- if (umounts)
- snprintf (new, i, "%s:%s", umounts, SPLASH_CACHEDIR);
- else
- snprintf (new, i, "%s", SPLASH_CACHEDIR);
- }
-
- /* We unsetenv first as some libc's leak memory if we overwrite
- a var with a bigger value */
- if (umounts)
- unsetenv ("RC_NO_UMOUNTS");
- setenv ("RC_NO_UMOUNTS", new, 1);
-
- free (new);
- }
- return (_do_splash ("svc_stop", name, NULL));
- case rc_hook_service_stop_out:
- if (rc_service_state (name, rc_service_stopped))
- return (_do_splash ("svc_stopped", name, "0"));
- else
- return (_do_splash ("svc_started", name, "1"));
- case rc_hook_service_start_in:
- return (_do_splash ("svc_start", name, NULL));
- case rc_hook_service_start_out:
- if (rc_service_state (name, rc_service_stopped))
- return (_do_splash ("svc_started", name, "1"));
- else
- return (_do_splash ("svc_started", name, "0"));
- default: ;
- }
-
- return (0);
-}