diff options
author | kaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk> | 2003-11-10 16:49:44 +0000 |
---|---|---|
committer | kaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk> | 2003-11-10 16:49:44 +0000 |
commit | 0a5f82bb9dd8d9169c4499bc7007c4f6daf372d5 (patch) | |
tree | 72eb2ec7b2ac20eb2a409a903e74378aa7f9e8f0 /tools/misc | |
parent | 671ef04c764dbe2c4bea2c9fdabf839a23396cc4 (diff) | |
download | xen-0a5f82bb9dd8d9169c4499bc7007c4f6daf372d5.tar.gz xen-0a5f82bb9dd8d9169c4499bc7007c4f6daf372d5.tar.bz2 xen-0a5f82bb9dd8d9169c4499bc7007c4f6daf372d5.zip |
bitkeeper revision 1.582.1.2 (3fafc1a8WtDmHzijhEouIqSThPp1nA)
xen_netwatch.c:
Fixes to xen_netwatch.
Diffstat (limited to 'tools/misc')
-rw-r--r-- | tools/misc/xen_netwatch.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/tools/misc/xen_netwatch.c b/tools/misc/xen_netwatch.c index b4aac6da1b..d6624d5e30 100644 --- a/tools/misc/xen_netwatch.c +++ b/tools/misc/xen_netwatch.c @@ -1,7 +1,13 @@ /****************************************************************************** - * netwatch.c + * xen_netwatch.c * - * Watch for network interfaces needing frobbing. + * Watch for network interfaces changing state (IFF_UP), and call a standard + * script '/etc/xen/netwatch <ifname> up|down'. Logging from the netwatch + * daemon is written to '/var/xen/netwatch' -- other programs can therefore + * watch that file to take action on interface state changes. + * + * Note that, apart from the names of the default action script and log file, + * this program is not actually Xen-dependent. * * Copyright (c) 2003, K A Fraser */ @@ -24,6 +30,9 @@ #include <unistd.h> #include <time.h> +#define DEFAULT_SCRIPT "/var/xen/netwatch" +#define DEFAULT_LOGFILE "/etc/xen/netwatch" + #define LOG(_f, _a...) \ do { \ time_t now = time(NULL); \ @@ -56,11 +65,10 @@ void handle_child_death(int dummy) int main(int argc, char **argv) { - char *logfile = "/var/xen/netwatch"; - char *scriptfile = "/etc/xen/netwatch"; + char *logfile = DEFAULT_LOGFILE; + char *scriptfile = DEFAULT_SCRIPT; FILE *logfd; - int nlfd, unixfd, bytes; - int last_index = ~0; + int i, nlfd, unixfd, bytes, last_index = ~0; unsigned int last_flags = ~0; char buffer[8192]; struct sockaddr_nl nladdr; @@ -69,6 +77,25 @@ int main(int argc, char **argv) struct ifreq ifr; struct sigaction sigchld; + for ( i = 1; i < argc; i++ ) + { + if ( strncmp("-s", argv[i], 2) == 0 ) + { + scriptfile = argv[i] + 2; + } + else if ( strncmp("-l", argv[i], 2) == 0 ) + { + logfile = argv[i] + 2; + } + else + { + printf("Usage: %s [-s<script>] [-l<logfile>]\n", argv[0]); + printf("Default script: %s\n", scriptfile); + printf("Default log file: %s\n", logfile); + return 0; + } + } + /* Ensure that zombie children are reaped. */ memset(&sigchld, 0, sizeof(sigchld)); sigchld.sa_handler = handle_child_death; @@ -145,7 +172,10 @@ int main(int argc, char **argv) !(nlmsg->nlmsg_flags & NLMSG_DONE); nlmsg = NLMSG_NEXT(nlmsg, bytes) ) { - /* This termination condition works. NLMSG_DONE doesn't always. */ + /* + * This termination condition works. NLMSG_DONE doesn't always. + * This therefore works around a Linux bug. + */ if ( nlmsg->nlmsg_len == 0 ) break; @@ -161,7 +191,7 @@ int main(int argc, char **argv) if ( !(ifi->ifi_change & IFF_UP) ) continue; - /* Ignore duplicate messages. */ + /* Ignore duplicate messages. This works around a Linux bug.*/ if ( (last_index == ifr.ifr_ifindex) && (last_flags == ifi->ifi_flags) ) continue; @@ -184,7 +214,6 @@ int main(int argc, char **argv) return 1; case -1: LOG("Error forking to exec script"); - break; default: break; } |