diff --git a/ChangeLog b/ChangeLog index 2173cb5199..5a330397aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2004-08-16 Dan Williams + + * initscript/NetworkManager + - Check for /sbin/ip + - Do sysctl magic that network service does + - sleep 4s after start to allow network time to come up [hack] + + * src/Makefile.am + src/NMLoadModules + - Load all network device kernel modules (hal doesn't know devices + are ethernet until the module is loaded, and therefore we don't know) + + * src/NetworkManager.c + - (main): daemonize later, launch NMLoadModules to alert HAL of our + network devices, and bring up the loopback device explicitly + + * src/NetworkManagerUtils.[ch] + - (nm_enable_loopback): new function + 2004-08-13 Dan Williams * configure.in diff --git a/initscript/Makefile.am b/initscript/Makefile.am index e0337290dd..28cb50c619 100644 --- a/initscript/Makefile.am +++ b/initscript/Makefile.am @@ -1,5 +1,4 @@ EXTRA_DIST = NetworkManager initddir = $(sysconfdir)/rc.d/init.d - initd_SCRIPTS = NetworkManager diff --git a/initscript/NetworkManager b/initscript/NetworkManager index c6a7cada41..79a8ac1653 100755 --- a/initscript/NetworkManager +++ b/initscript/NetworkManager @@ -9,9 +9,15 @@ # processname: NetworkManager # pidfile: /var/run/NetworkManager.pid # +### BEGIN INIT INFO +# Provides: $network +### END INIT INFO # Sanity checks. -[ -x /usr/bin/NetworkManager ] || exit 0 +[ -x /usr/bin/NetworkManager ] || exit 1 + +# We need /sbin/ip +[ -x /sbin/ip ] || exit 1 # Source function library. . /etc/rc.d/init.d/functions @@ -19,53 +25,58 @@ # so we can rearrange this easily processname=NetworkManager servicename=NetworkManager +pidfile=/var/run/NetworkManager.pid RETVAL=0 -start() { - echo -n $"Starting NetworkManager daemon: " - daemon --check $servicename $processname - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > /var/run/NetworkManager.pid +start() +{ + action $"Setting network parameters: " sysctl -e -p /etc/sysctl.conf + echo -n $"Starting NetworkManager daemon: " + daemon --check $servicename $processname + sleep 4 + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > $pidfile } -stop() { - echo -n $"Stopping NetworkManager daemon: " +stop() +{ + echo -n $"Stopping NetworkManager daemon: " - killproc $servicename -TERM - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - rm -f /var/lock/subsys/$servicename - rm -f /var/run/NetworkManager.pid - fi + killproc $servicename -TERM + RETVAL=$? + echo + if [ $RETVAL -eq 0 ]; then + rm -f /var/lock/subsys/$servicename + rm -f $pidfile + fi } # See how we were called. case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status $processname - RETVAL=$? - ;; - restart) - stop - start - ;; - condrestart) - if [ -f /var/lock/subsys/$servicename ]; then - stop - start - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart}" - ;; + start) + start + ;; + stop) + stop + ;; + status) + status $processname + RETVAL=$? + ;; + restart) + stop + start + ;; + condrestart) + if [ -f /var/lock/subsys/$servicename ]; then + stop + start + fi + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + ;; esac exit $RETVAL diff --git a/src/Makefile.am b/src/Makefile.am index 5912ff6428..ca08812089 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,4 +33,7 @@ NetworkManager_LDADD = $(NM_LIBS) $(IWLIB) $(OPENSSL_LIBS) dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = NetworkManager.conf -EXTRA_DIST = $(dbusservice_DATA) +helperdir = $(bindir) +helper_SCRIPTS = NMLoadModules + +EXTRA_DIST = $(dbusservice_DATA) $(helper_SCRIPTS) diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 89938486b8..56b30dd379 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -543,37 +543,18 @@ int main( int argc, char *argv[] ) } } - if (become_daemon) - { - int child_pid; - - if (chdir ("/") < 0) - { - fprintf( stderr, "NetworkManager could not chdir to /. errno=%d", errno); - return (1); - } - - child_pid = fork (); - switch (child_pid) - { - case -1: - fprintf( stderr, "NetworkManager could not daemonize. errno = %d\n", errno ); - break; - - case 0: - /* Child */ - break; - - default: - exit (EXIT_SUCCESS); - break; - } - } - g_type_init (); if (!g_thread_supported ()) g_thread_init (NULL); + /* Load all network device kernel modules. + * NOTE: this hack is temporary until device modules get loaded + * on startup by something else. The problem is that unless + * the module is loaded, HAL doesn't know its a network device, + * and therefore can't tell us about it. + */ + nm_spawn_process ("/usr/bin/NMLoadModules"); + /* Initialize our instance data */ nm_data = nm_data_new (); if (!nm_data) @@ -601,10 +582,19 @@ int main( int argc, char *argv[] ) } nm_data->hal_ctx = ctx; hal_ctx_set_user_data (nm_data->hal_ctx, nm_data); + hal_device_property_watch_all (nm_data->hal_ctx); /* Grab network devices that are already present and add them to our list */ nm_add_initial_devices (nm_data); + /* We run dhclient when we need to, and we don't want any stray ones + * lying around upon launch. + */ + nm_spawn_process ("/usr/bin/killall dhclient"); + + /* Bring up the loopback interface. */ + nm_enable_loopback (); + /* Create a watch function that monitors cards for link status (hal doesn't do * this for wireless cards yet). */ @@ -618,13 +608,32 @@ int main( int argc, char *argv[] ) /* Keep a current list of access points */ wireless_scan_source = g_timeout_add (10000, nm_wireless_scan_monitor, nm_data); - /* Watch all devices that HAL knows about for state changes */ - hal_device_property_watch_all (nm_data->hal_ctx); + if (become_daemon) + { + int child_pid; - /* We run dhclient when we need to, and we don't want any stray ones - * lying around upon launch. - */ - nm_spawn_process ("/usr/bin/killall dhclient"); + if (chdir ("/") < 0) + { + fprintf( stderr, "NetworkManager could not chdir to /. errno=%d", errno); + return (1); + } + + child_pid = fork (); + switch (child_pid) + { + case -1: + fprintf( stderr, "NetworkManager could not daemonize. errno = %d\n", errno ); + break; + + case 0: + /* Child */ + break; + + default: + exit (EXIT_SUCCESS); + break; + } + } /* Wheeee!!! */ loop = g_main_loop_new (NULL, FALSE); diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index d8acdf4071..04c561260b 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -199,3 +199,17 @@ int nm_spawn_process (char *args) return (-1); } + + +/* + * nm_enable_loopback + * + * Bring up the loopback interface + * + */ +void nm_enable_loopback (void) +{ + nm_spawn_process ("/sbin/ip link set dev lo up"); + nm_spawn_process ("ip addr add 127.0.0.1/8 brd 127.255.255.255 dev lo label loopback"); +} + diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 48508c969a..7fb2804c9a 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -50,4 +50,6 @@ void nm_dispose_scan_results (wireless_scan *result_list); int nm_spawn_process (char *args); +void nm_enable_loopback (void); + #endif