blob: cec53f9b3b91b7fb6462f9cdaf82909347b0bb68 [file] [log] [blame]
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "Preload network drivers"
author "chromium-os-dev@chromium.org"
# Run on boot-services; "stay running" until the udev-trigger completes
# (which is guaranteed to happen after boot-services)
start on starting boot-services
stop on stopped udev-trigger
env drvfile=/var/lib/preload-network-drivers
pre-start script
# If the drivers for Ethernet or WiFi devices are modules, our post-stop
# script will have recorded the driver names on the previous boot cycle.
# Load those drivers now so flimflam can config the network sooner,
# ideally by the time login screen is up.
#
# Note: failure to probe the module here is NOT fatal.
if [ -s $drvfile ] ; then
for drv in $(head -1 $drvfile); do
if ! modprobe "$drv" >/dev/null 2>&1 ; then
# If modprobe didn't like the alias file for some reason, just
# move it out of the way. The post-stop script will make a new
# one.
mv $drvfile $drvfile.bad
logger -t "$UPSTART_JOB" \
"modprobe $drv failed. Renamed $drvfile with .bad suffix."
fi
done
fi
end script
post-stop script
# Create/Update driver names for the Ethernet and WiFi drivers.
# Used to preload Ethernet and WiFi drivers in pre-start script.
# TODO(ggg): can flimflam share the "user selected" network device?
newdrv=''
for dev in eth0 wlan0; do
# Get the driver name
drv=$(ethtool -i "$dev" | awk '/driver:/ { print $2 }')
if [ -z "$drv" ] ; then
continue
fi
# Is the driver a module?
drvmod=$(lsmod | awk 'd==$1 { print $1 }' d="$drv")
if [ -z "$drvmod" ] ; then
logger -t "UPSTART_JOB" "$dev: $drv is not a module."
continue
fi
if [ -n "$newdrv" ] ; then
newdrv="$drvmod $newdrv"
else
newdrv="$drvmod"
fi
done
if [ -s $drvfile ] ; then
olddrv=$(head -1 $drvfile)
fi
# Only update contents if they've changed.
if [ "$newdrv" != "$olddrv" ] ; then
echo "$newdrv" > $drvfile
fi
end script