ia64/xen-unstable
changeset 923:cd3505c22fa4
bitkeeper revision 1.586 (3fafc1b0qUj0PVr0hH3XvA9CFCZBAg)
Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Mon Nov 10 16:49:52 2003 +0000 (2003-11-10) |
parents | e2a517ef1be8 fc5ae656dd1e |
children | 4f30a5c41876 |
files | tools/misc/xen_netwatch.c |
line diff
1.1 --- a/tools/misc/xen_netwatch.c Mon Nov 10 16:40:53 2003 +0000 1.2 +++ b/tools/misc/xen_netwatch.c Mon Nov 10 16:49:52 2003 +0000 1.3 @@ -1,7 +1,13 @@ 1.4 /****************************************************************************** 1.5 - * netwatch.c 1.6 + * xen_netwatch.c 1.7 * 1.8 - * Watch for network interfaces needing frobbing. 1.9 + * Watch for network interfaces changing state (IFF_UP), and call a standard 1.10 + * script '/etc/xen/netwatch <ifname> up|down'. Logging from the netwatch 1.11 + * daemon is written to '/var/xen/netwatch' -- other programs can therefore 1.12 + * watch that file to take action on interface state changes. 1.13 + * 1.14 + * Note that, apart from the names of the default action script and log file, 1.15 + * this program is not actually Xen-dependent. 1.16 * 1.17 * Copyright (c) 2003, K A Fraser 1.18 */ 1.19 @@ -24,6 +30,9 @@ 1.20 #include <unistd.h> 1.21 #include <time.h> 1.22 1.23 +#define DEFAULT_SCRIPT "/var/xen/netwatch" 1.24 +#define DEFAULT_LOGFILE "/etc/xen/netwatch" 1.25 + 1.26 #define LOG(_f, _a...) \ 1.27 do { \ 1.28 time_t now = time(NULL); \ 1.29 @@ -56,11 +65,10 @@ void handle_child_death(int dummy) 1.30 1.31 int main(int argc, char **argv) 1.32 { 1.33 - char *logfile = "/var/xen/netwatch"; 1.34 - char *scriptfile = "/etc/xen/netwatch"; 1.35 + char *logfile = DEFAULT_LOGFILE; 1.36 + char *scriptfile = DEFAULT_SCRIPT; 1.37 FILE *logfd; 1.38 - int nlfd, unixfd, bytes; 1.39 - int last_index = ~0; 1.40 + int i, nlfd, unixfd, bytes, last_index = ~0; 1.41 unsigned int last_flags = ~0; 1.42 char buffer[8192]; 1.43 struct sockaddr_nl nladdr; 1.44 @@ -69,6 +77,25 @@ int main(int argc, char **argv) 1.45 struct ifreq ifr; 1.46 struct sigaction sigchld; 1.47 1.48 + for ( i = 1; i < argc; i++ ) 1.49 + { 1.50 + if ( strncmp("-s", argv[i], 2) == 0 ) 1.51 + { 1.52 + scriptfile = argv[i] + 2; 1.53 + } 1.54 + else if ( strncmp("-l", argv[i], 2) == 0 ) 1.55 + { 1.56 + logfile = argv[i] + 2; 1.57 + } 1.58 + else 1.59 + { 1.60 + printf("Usage: %s [-s<script>] [-l<logfile>]\n", argv[0]); 1.61 + printf("Default script: %s\n", scriptfile); 1.62 + printf("Default log file: %s\n", logfile); 1.63 + return 0; 1.64 + } 1.65 + } 1.66 + 1.67 /* Ensure that zombie children are reaped. */ 1.68 memset(&sigchld, 0, sizeof(sigchld)); 1.69 sigchld.sa_handler = handle_child_death; 1.70 @@ -145,7 +172,10 @@ int main(int argc, char **argv) 1.71 !(nlmsg->nlmsg_flags & NLMSG_DONE); 1.72 nlmsg = NLMSG_NEXT(nlmsg, bytes) ) 1.73 { 1.74 - /* This termination condition works. NLMSG_DONE doesn't always. */ 1.75 + /* 1.76 + * This termination condition works. NLMSG_DONE doesn't always. 1.77 + * This therefore works around a Linux bug. 1.78 + */ 1.79 if ( nlmsg->nlmsg_len == 0 ) 1.80 break; 1.81 1.82 @@ -161,7 +191,7 @@ int main(int argc, char **argv) 1.83 if ( !(ifi->ifi_change & IFF_UP) ) 1.84 continue; 1.85 1.86 - /* Ignore duplicate messages. */ 1.87 + /* Ignore duplicate messages. This works around a Linux bug.*/ 1.88 if ( (last_index == ifr.ifr_ifindex) && 1.89 (last_flags == ifi->ifi_flags) ) 1.90 continue; 1.91 @@ -184,7 +214,6 @@ int main(int argc, char **argv) 1.92 return 1; 1.93 case -1: 1.94 LOG("Error forking to exec script"); 1.95 - break; 1.96 default: 1.97 break; 1.98 }