| # 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 shill 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 shill share the "user selected" network device? |
| |
| newdrv='' |
| for dev in eth0 wlan0 mlan0; do |
| # Get the module name |
| mod_link="/sys/class/net/${dev}/device/driver/module" |
| if [ -e "$mod_link" ]; then |
| drvmod=$(basename $(readlink "$mod_link")) |
| else |
| 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 |