debuggers.hg
changeset 970:f1177a48a360
bitkeeper revision 1.592 (3fb0ac15PpvexPwsNAKwcJ7oNjLC-A)
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 | Tue Nov 11 09:29:57 2003 +0000 (2003-11-11) |
parents | 5e91938ceb1b 48a22092d446 |
children | baade9a49791 |
files | .rootkeys tools/misc/Makefile tools/misc/xen_netwatch.c tools/misc/xen_netwatch_redhatscript |
line diff
1.1 --- a/.rootkeys Mon Nov 10 23:31:43 2003 +0000 1.2 +++ b/.rootkeys Tue Nov 11 09:29:57 2003 +0000 1.3 @@ -195,8 +195,6 @@ 3f870808zS6T6iFhqYPGelroZlVfGQ tools/mis 1.4 3f8bcf29ulZIC9rC4wM70H_q4s6VPg tools/misc/xen_log.c 1.5 3f13d81eQ9Vz-h-6RDGFkNR9CRP95g tools/misc/xen_nat_enable 1.6 3f13d81e6Z6806ihYYUw8GVKNkYnuw tools/misc/xen_nat_enable.README 1.7 -3fafbef1fJFKCcJLq-ffpauvpM10jQ tools/misc/xen_netwatch.c 1.8 -3fafd0abTbQjsCr5W3DDyNdqdJezrA tools/misc/xen_netwatch_redhatscript 1.9 3f1668d4F29Jsw0aC0bJEIkOBiagiQ tools/misc/xen_read_console.c 1.10 3f87ba90EUVPQLVOlFG0sW89BCwouQ tools/misc/xen_refresh_dev.c 1.11 3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
2.1 --- a/tools/misc/Makefile Mon Nov 10 23:31:43 2003 +0000 2.2 +++ b/tools/misc/Makefile Tue Nov 11 09:29:57 2003 +0000 2.3 @@ -7,7 +7,7 @@ HDRS = $(wildcard *.h) 2.4 SRCS = $(wildcard *.c) 2.5 OBJS = $(patsubst %.c,%.o,$(SRCS)) 2.6 2.7 -TARGETS = xen_read_console xen_cpuperf xen_refresh_dev xen_netwatch 2.8 +TARGETS = xen_read_console xen_cpuperf xen_refresh_dev 2.9 2.10 INSTALL = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone 2.11 2.12 @@ -26,9 +26,6 @@ clean: 2.13 $(RM) *.o $(TARGETS) 2.14 $(MAKE) -C miniterm clean 2.15 2.16 -xen_netwatch: %: %.c $(HDRS) Makefile 2.17 - $(CC) $(CFLAGS) -o $@ $< 2.18 - 2.19 %: %.c $(HDRS) Makefile 2.20 $(CC) $(CFLAGS) $(EXTRA_INC) -o $@ $< 2.21
3.1 --- a/tools/misc/xen_netwatch.c Mon Nov 10 23:31:43 2003 +0000 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,225 +0,0 @@ 3.4 -/****************************************************************************** 3.5 - * xen_netwatch.c 3.6 - * 3.7 - * Watch for network interfaces changing state (IFF_UP), and call a standard 3.8 - * script '/etc/xen/netwatch <ifname> up|down'. Logging from the netwatch 3.9 - * daemon is written to '/var/xen/netwatch' -- other programs can therefore 3.10 - * watch that file to take action on interface state changes. 3.11 - * 3.12 - * Note that, apart from the names of the default action script and log file, 3.13 - * this program is not actually Xen-dependent. 3.14 - * 3.15 - * Copyright (c) 2003, K A Fraser 3.16 - */ 3.17 - 3.18 -#include <asm/types.h> 3.19 -#include <sys/types.h> 3.20 -#include <sys/socket.h> 3.21 -#include <sys/ioctl.h> 3.22 -#include <sys/resource.h> 3.23 -#include <sys/time.h> 3.24 -#include <sys/un.h> 3.25 -#include <sys/wait.h> 3.26 -#include <linux/netlink.h> 3.27 -#include <linux/rtnetlink.h> 3.28 -#include <linux/if.h> 3.29 - 3.30 -#include <errno.h> 3.31 -#include <signal.h> 3.32 -#include <stdio.h> 3.33 -#include <unistd.h> 3.34 -#include <time.h> 3.35 - 3.36 -#define DEFAULT_SCRIPT "/etc/xen/netwatch" 3.37 -#define DEFAULT_LOGFILE "/var/xen/netwatch" 3.38 - 3.39 -#define LOG(_f, _a...) \ 3.40 - do { \ 3.41 - time_t now = time(NULL); \ 3.42 - char *tstr = ctime(&now); \ 3.43 - char *p = strchr(tstr, '\n'); if (p) *p = '\0'; \ 3.44 - fprintf(logfd, "%s: " _f "\n", tstr, ## _a); \ 3.45 - fflush(logfd); \ 3.46 - } while ( 0 ) 3.47 - 3.48 -#define EXIT do { LOG("Exiting."); return 1; } while ( 0 ) 3.49 - 3.50 -static void daemonise(void) 3.51 -{ 3.52 - int i; 3.53 - struct rlimit rlim; 3.54 - 3.55 - /* Close all file handles we inherited from our parent. */ 3.56 - if ( getrlimit(RLIMIT_NOFILE, &rlim) == 0 ) 3.57 - for ( i = 0; i < rlim.rlim_cur; i++ ) 3.58 - close(i); 3.59 - 3.60 - /* Lose the controlling tty. */ 3.61 - setsid(); 3.62 -} 3.63 - 3.64 -void handle_child_death(int dummy) 3.65 -{ 3.66 - (void)waitpid(-1, NULL, WNOHANG); 3.67 -} 3.68 - 3.69 -int main(int argc, char **argv) 3.70 -{ 3.71 - char *logfile = DEFAULT_LOGFILE; 3.72 - char *scriptfile = DEFAULT_SCRIPT; 3.73 - FILE *logfd; 3.74 - int i, nlfd, unixfd, bytes, last_index = ~0; 3.75 - unsigned int last_flags = ~0; 3.76 - char buffer[8192]; 3.77 - struct sockaddr_nl nladdr; 3.78 - struct nlmsghdr *nlmsg; 3.79 - struct ifinfomsg *ifi; 3.80 - struct ifreq ifr; 3.81 - struct sigaction sigchld; 3.82 - 3.83 - for ( i = 1; i < argc; i++ ) 3.84 - { 3.85 - if ( strncmp("-s", argv[i], 2) == 0 ) 3.86 - { 3.87 - scriptfile = argv[i] + 2; 3.88 - } 3.89 - else if ( strncmp("-l", argv[i], 2) == 0 ) 3.90 - { 3.91 - logfile = argv[i] + 2; 3.92 - } 3.93 - else 3.94 - { 3.95 - printf("Usage: %s [-s<script>] [-l<logfile>]\n", argv[0]); 3.96 - printf("Default script: %s\n", scriptfile); 3.97 - printf("Default log file: %s\n", logfile); 3.98 - return 0; 3.99 - } 3.100 - } 3.101 - 3.102 - /* Ensure that zombie children are reaped. */ 3.103 - memset(&sigchld, 0, sizeof(sigchld)); 3.104 - sigchld.sa_handler = handle_child_death; 3.105 - sigemptyset(&sigchld.sa_mask); 3.106 - sigchld.sa_flags = SA_NOCLDSTOP | SA_RESTART; 3.107 - (void)sigaction(SIGCHLD, &sigchld, NULL); 3.108 - 3.109 - /* 3.110 - * After child daemonises it can't display errors until it opens the log 3.111 - * file. Since it may be unable to open the log file, we test for that 3.112 - * possibility here. 3.113 - */ 3.114 - if ( (logfd = fopen(logfile, "wb")) == NULL ) 3.115 - { 3.116 - fprintf(stderr, "Could not open log file '%s' (%d)\n", logfile, errno); 3.117 - fprintf(stderr, "Exiting.\n"); 3.118 - return 1; 3.119 - } 3.120 - fclose(logfd); 3.121 - 3.122 - switch ( fork() ) 3.123 - { 3.124 - case 0: 3.125 - daemonise(); 3.126 - break; 3.127 - case -1: 3.128 - fprintf(stderr, "Could not daemonize. (%d)\n", errno); 3.129 - fprintf(stderr, "Exiting.\n"); 3.130 - return 1; 3.131 - default: 3.132 - goto out; 3.133 - } 3.134 - 3.135 - /* Silent error is forgiveable here, as our parent did a test for us. */ 3.136 - if ( (logfd = fopen(logfile, "wb")) == NULL ) 3.137 - return 1; 3.138 - 3.139 - if ( (nlfd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) == -1 ) 3.140 - { 3.141 - LOG("Could not open an rtnetlink socket. (%d)\n", errno); 3.142 - EXIT; 3.143 - } 3.144 - 3.145 - if ( (unixfd = socket(PF_UNIX, SOCK_DGRAM, 0)) == -1 ) 3.146 - { 3.147 - LOG("Could not open UNIX socket. (%d)\n", errno); 3.148 - EXIT; 3.149 - } 3.150 - 3.151 - nladdr.nl_family = AF_NETLINK; 3.152 - nladdr.nl_pid = 0; 3.153 - nladdr.nl_groups = RTMGRP_LINK; 3.154 - if ( bind(nlfd, (struct sockaddr *)&nladdr, sizeof(nladdr)) == -1 ) 3.155 - { 3.156 - LOG("Could not bind to kernel (%d)\n", errno); 3.157 - EXIT; 3.158 - } 3.159 - 3.160 - for ( ; ; ) 3.161 - { 3.162 - memset(buffer, 0, sizeof(buffer)); 3.163 - 3.164 - if ( (bytes = read(nlfd, buffer, sizeof(buffer))) == -1 ) 3.165 - { 3.166 - if ( errno != EINTR ) 3.167 - LOG("Error when reading from socket (%d)", errno); 3.168 - continue; 3.169 - } 3.170 - 3.171 - if ( bytes == 0 ) 3.172 - continue; 3.173 - 3.174 - for ( nlmsg = (struct nlmsghdr *)buffer; 3.175 - !(nlmsg->nlmsg_flags & NLMSG_DONE); 3.176 - nlmsg = NLMSG_NEXT(nlmsg, bytes) ) 3.177 - { 3.178 - /* 3.179 - * This termination condition works. NLMSG_DONE doesn't always. 3.180 - * This therefore works around a Linux bug. 3.181 - */ 3.182 - if ( nlmsg->nlmsg_len == 0 ) 3.183 - break; 3.184 - 3.185 - if ( nlmsg->nlmsg_type != RTM_NEWLINK ) 3.186 - continue; 3.187 - 3.188 - ifi = NLMSG_DATA(nlmsg); 3.189 - 3.190 - ifr.ifr_ifindex = ifi->ifi_index; 3.191 - if ( ioctl(unixfd, SIOCGIFNAME, &ifr) == -1 ) 3.192 - continue; 3.193 - 3.194 - if ( !(ifi->ifi_change & IFF_UP) ) 3.195 - continue; 3.196 - 3.197 - /* Ignore duplicate messages. This works around a Linux bug.*/ 3.198 - if ( (last_index == ifr.ifr_ifindex) && 3.199 - (last_flags == ifi->ifi_flags) ) 3.200 - continue; 3.201 - last_index = ifr.ifr_ifindex; 3.202 - last_flags = ifi->ifi_flags; 3.203 - 3.204 - LOG("Network %s event for interface %s", 3.205 - (ifi->ifi_flags & IFF_UP) ? "UP" : "DOWN", 3.206 - ifr.ifr_name); 3.207 - 3.208 - switch ( fork() ) 3.209 - { 3.210 - case 0: 3.211 - execl(scriptfile, 3.212 - ifr.ifr_name, 3.213 - (ifi->ifi_flags & IFF_UP) ? "up" : "down"); 3.214 - LOG("Error executing network script '%s %s %s'", 3.215 - scriptfile, ifr.ifr_name, 3.216 - (ifi->ifi_flags & IFF_UP) ? "up" : "down"); 3.217 - return 1; 3.218 - case -1: 3.219 - LOG("Error forking to exec script"); 3.220 - default: 3.221 - break; 3.222 - } 3.223 - } 3.224 - } 3.225 - 3.226 - out: 3.227 - return 0; 3.228 -}
4.1 --- a/tools/misc/xen_netwatch_redhatscript Mon Nov 10 23:31:43 2003 +0000 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,33 +0,0 @@ 4.4 -#!/bin/sh 4.5 - 4.6 -# Example xen_netwatch script for Red Hat systems. 4.7 -# If the network interface goes up or down then standard Red Hat 4.8 -# scripts are executed. This may be necessary to reconfigure default 4.9 -# routes, for example. 4.10 -# 4.11 -# This script should be placed at /etc/xen/netwatch 4.12 -# You should make sure that the directory /var/xen/ exists. 4.13 -# 4.14 -# Something like the follwoing should be placed in a startup script 4.15 -# such as /etc/rc.d/rc.local: 4.16 -# 4.17 -# if [ -x /usr/bin/xen_netwatch ]; then 4.18 -# if [ -a /etc/xen/netwatch ]; then 4.19 -# mkdir -p /var/xen 4.20 -# /usr/bin/xen_netwatch 4.21 -# fi 4.22 -# fi 4.23 - 4.24 -cd /etc/sysconfig/network-scripts || exit 1 4.25 - 4.26 -if [ "x$2" == "xup" ]; then 4.27 - if [ -x ./ifup ]; then 4.28 - ./ifup $1 4.29 - fi 4.30 -fi 4.31 - 4.32 -if [ "x$2" == "xdown" ] ; then 4.33 - if [ -x ./ifdown ]; then 4.34 - ./ifdown $1 4.35 - fi 4.36 -fi