Coldplug net devices on the BSD's as found by getifaddrs.
This commit is contained in:
		
							
								
								
									
										45
									
								
								src/rc/rc.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								src/rc/rc.c
									
									
									
									
									
								
							| @@ -56,6 +56,12 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples"; | |||||||
| #include <termios.h> | #include <termios.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
|  |  | ||||||
|  | /* So we can coldplug net devices */ | ||||||
|  | #ifdef BSD | ||||||
|  | # include <sys/socket.h> | ||||||
|  | # include <ifaddrs.h> | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #include "builtins.h" | #include "builtins.h" | ||||||
| #include "einfo.h" | #include "einfo.h" | ||||||
| #include "rc.h" | #include "rc.h" | ||||||
| @@ -557,10 +563,15 @@ static void run_script (const char *script) | |||||||
| #ifndef PREFIX | #ifndef PREFIX | ||||||
| static void do_coldplug (void) | static void do_coldplug (void) | ||||||
| { | { | ||||||
|  | 	size_t s; | ||||||
| 	int i; | 	int i; | ||||||
| 	DIR *dp; | 	DIR *dp; | ||||||
| 	struct dirent *d; | 	struct dirent *d; | ||||||
| 	char *service; | 	char *service; | ||||||
|  | #ifdef BSD | ||||||
|  | 	struct ifaddrs *ifap; | ||||||
|  | 	struct ifaddrs *ifa; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	if (! rc_conf_yesno ("rc_coldplug") && errno != ENOENT) | 	if (! rc_conf_yesno ("rc_coldplug") && errno != ENOENT) | ||||||
| 		return; | 		return; | ||||||
| @@ -570,21 +581,21 @@ static void do_coldplug (void) | |||||||
| 	rc_deptree_update_needed (); | 	rc_deptree_update_needed (); | ||||||
|  |  | ||||||
| #ifdef BSD | #ifdef BSD | ||||||
| #if defined(__DragonFly__) || defined(__FreeBSD__) | 	if (getifaddrs(&ifap) == 0) { | ||||||
| 	/* The net interfaces are easy - they're all in net /dev/net :) */ | 		for (ifa = ifap; ifa; ifa = ifa->ifa_next) { | ||||||
| 	if ((dp = opendir ("/dev/net"))) { | 			if (ifa->ifa_addr->sa_family != AF_LINK) | ||||||
| 		while ((d = readdir (dp))) { | 				continue; | ||||||
| 			i = (strlen ("net.") + strlen (d->d_name) + 1); |  | ||||||
| 			tmp = xmalloc (sizeof (char) * i); | 			s = strlen ("net.") + strlen (ifa->ifa_name) + 1; | ||||||
| 			snprintf (tmp, i, "net.%s", d->d_name); | 			tmp = xmalloc (sizeof (char) * s); | ||||||
|  | 			snprintf (tmp, s, "net.%s", ifa->ifa_name); | ||||||
| 			if (rc_service_exists (tmp) && | 			if (rc_service_exists (tmp) && | ||||||
| 			    service_plugable (tmp)) | 			    service_plugable (tmp)) | ||||||
| 				rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); | 				rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); | ||||||
| 			CHAR_FREE (tmp); | 			CHAR_FREE (tmp); | ||||||
| 		} | 		} | ||||||
| 		closedir (dp); | 		freeifaddrs (ifap); | ||||||
| 	} | 	} | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	/* The mice are a little more tricky. | 	/* The mice are a little more tricky. | ||||||
| 	 * If we coldplug anything else, we'll probably do it here. */ | 	 * If we coldplug anything else, we'll probably do it here. */ | ||||||
| @@ -595,10 +606,9 @@ static void do_coldplug (void) | |||||||
| 			{ | 			{ | ||||||
| 				char *p = d->d_name + 3; | 				char *p = d->d_name + 3; | ||||||
| 				if (p && isdigit ((int) *p)) { | 				if (p && isdigit ((int) *p)) { | ||||||
| 					size_t len; | 					s = strlen ("moused.") + strlen (d->d_name) + 1; | ||||||
| 					len = (strlen ("moused.") + strlen (d->d_name) + 1); | 					tmp = xmalloc (sizeof (char) * s); | ||||||
| 					tmp = xmalloc (sizeof (char) * len); | 					snprintf (tmp, s, "moused.%s", d->d_name); | ||||||
| 					snprintf (tmp, len, "moused.%s", d->d_name); |  | ||||||
| 					if (rc_service_exists (tmp) && | 					if (rc_service_exists (tmp) && | ||||||
| 					    service_plugable (tmp)) | 					    service_plugable (tmp)) | ||||||
| 						rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); | 						rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); | ||||||
| @@ -609,7 +619,8 @@ static void do_coldplug (void) | |||||||
| 		closedir (dp); | 		closedir (dp); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #elif __linux__ | #else | ||||||
|  |  | ||||||
| 	/* udev likes to start services before we're ready when it does | 	/* udev likes to start services before we're ready when it does | ||||||
| 	 * its coldplugging thing. runscript knows when we're not ready so it | 	 * its coldplugging thing. runscript knows when we're not ready so it | ||||||
| 	 * stores a list of coldplugged services in DEVBOOT for us to pick up | 	 * stores a list of coldplugged services in DEVBOOT for us to pick up | ||||||
| @@ -625,9 +636,9 @@ static void do_coldplug (void) | |||||||
| 			    service_plugable (d->d_name)) | 			    service_plugable (d->d_name)) | ||||||
| 				rc_service_mark (d->d_name, RC_SERVICE_COLDPLUGGED); | 				rc_service_mark (d->d_name, RC_SERVICE_COLDPLUGGED); | ||||||
|  |  | ||||||
| 			i = strlen (DEVBOOT "/") + strlen (d->d_name) + 1; | 			s = strlen (DEVBOOT "/") + strlen (d->d_name) + 1; | ||||||
| 			tmp = xmalloc (sizeof (char) * i); | 			tmp = xmalloc (sizeof (char) * s); | ||||||
| 			snprintf (tmp, i, DEVBOOT "/%s", d->d_name); | 			snprintf (tmp, s, DEVBOOT "/%s", d->d_name); | ||||||
| 			if (tmp) { | 			if (tmp) { | ||||||
| 				if (unlink (tmp)) | 				if (unlink (tmp)) | ||||||
| 					eerror ("%s: unlink `%s': %s", applet, tmp, | 					eerror ("%s: unlink `%s': %s", applet, tmp, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user