2004-08-16 Dan Williams <dcbw@redhat.com>

* 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


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@55 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2004-08-16 19:46:43 +00:00
parent 20f439a9ac
commit 098099929e
7 changed files with 131 additions and 74 deletions

View File

@@ -1,3 +1,22 @@
2004-08-16 Dan Williams <dcbw@redhat.com>
* 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 <dcbw@redhat.com> 2004-08-13 Dan Williams <dcbw@redhat.com>
* configure.in * configure.in

View File

@@ -1,5 +1,4 @@
EXTRA_DIST = NetworkManager EXTRA_DIST = NetworkManager
initddir = $(sysconfdir)/rc.d/init.d initddir = $(sysconfdir)/rc.d/init.d
initd_SCRIPTS = NetworkManager initd_SCRIPTS = NetworkManager

View File

@@ -9,9 +9,15 @@
# processname: NetworkManager # processname: NetworkManager
# pidfile: /var/run/NetworkManager.pid # pidfile: /var/run/NetworkManager.pid
# #
### BEGIN INIT INFO
# Provides: $network
### END INIT INFO
# Sanity checks. # 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. # Source function library.
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
@@ -19,18 +25,23 @@
# so we can rearrange this easily # so we can rearrange this easily
processname=NetworkManager processname=NetworkManager
servicename=NetworkManager servicename=NetworkManager
pidfile=/var/run/NetworkManager.pid
RETVAL=0 RETVAL=0
start() { start()
{
action $"Setting network parameters: " sysctl -e -p /etc/sysctl.conf
echo -n $"Starting NetworkManager daemon: " echo -n $"Starting NetworkManager daemon: "
daemon --check $servicename $processname daemon --check $servicename $processname
sleep 4
RETVAL=$? RETVAL=$?
echo echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > /var/run/NetworkManager.pid [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > $pidfile
} }
stop() { stop()
{
echo -n $"Stopping NetworkManager daemon: " echo -n $"Stopping NetworkManager daemon: "
killproc $servicename -TERM killproc $servicename -TERM
@@ -38,7 +49,7 @@ stop() {
echo echo
if [ $RETVAL -eq 0 ]; then if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/$servicename rm -f /var/lock/subsys/$servicename
rm -f /var/run/NetworkManager.pid rm -f $pidfile
fi fi
} }

View File

@@ -33,4 +33,7 @@ NetworkManager_LDADD = $(NM_LIBS) $(IWLIB) $(OPENSSL_LIBS)
dbusservicedir = $(DBUS_SYS_DIR) dbusservicedir = $(DBUS_SYS_DIR)
dbusservice_DATA = NetworkManager.conf dbusservice_DATA = NetworkManager.conf
EXTRA_DIST = $(dbusservice_DATA) helperdir = $(bindir)
helper_SCRIPTS = NMLoadModules
EXTRA_DIST = $(dbusservice_DATA) $(helper_SCRIPTS)

View File

@@ -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 (); g_type_init ();
if (!g_thread_supported ()) if (!g_thread_supported ())
g_thread_init (NULL); 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 */ /* Initialize our instance data */
nm_data = nm_data_new (); nm_data = nm_data_new ();
if (!nm_data) if (!nm_data)
@@ -601,10 +582,19 @@ int main( int argc, char *argv[] )
} }
nm_data->hal_ctx = ctx; nm_data->hal_ctx = ctx;
hal_ctx_set_user_data (nm_data->hal_ctx, nm_data); 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 */ /* Grab network devices that are already present and add them to our list */
nm_add_initial_devices (nm_data); 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 /* Create a watch function that monitors cards for link status (hal doesn't do
* this for wireless cards yet). * this for wireless cards yet).
*/ */
@@ -618,13 +608,32 @@ int main( int argc, char *argv[] )
/* Keep a current list of access points */ /* Keep a current list of access points */
wireless_scan_source = g_timeout_add (10000, nm_wireless_scan_monitor, nm_data); wireless_scan_source = g_timeout_add (10000, nm_wireless_scan_monitor, nm_data);
/* Watch all devices that HAL knows about for state changes */ if (become_daemon)
hal_device_property_watch_all (nm_data->hal_ctx); {
int child_pid;
/* We run dhclient when we need to, and we don't want any stray ones if (chdir ("/") < 0)
* lying around upon launch. {
*/ fprintf( stderr, "NetworkManager could not chdir to /. errno=%d", errno);
nm_spawn_process ("/usr/bin/killall dhclient"); 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!!! */ /* Wheeee!!! */
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);

View File

@@ -199,3 +199,17 @@ int nm_spawn_process (char *args)
return (-1); 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");
}

View File

@@ -50,4 +50,6 @@ void nm_dispose_scan_results (wireless_scan *result_list);
int nm_spawn_process (char *args); int nm_spawn_process (char *args);
void nm_enable_loopback (void);
#endif #endif