mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
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
This commit is contained in:
commit
3479c52c68
4 files changed
+1
-264
No files matched your search
@@ -195,8 +195,6 @@
|
||||
3f8bcf29ulZIC9rC4wM70H_q4s6VPg tools/misc/xen_log.c
|
||||
3f13d81eQ9Vz-h-6RDGFkNR9CRP95g tools/misc/xen_nat_enable
|
||||
3f13d81e6Z6806ihYYUw8GVKNkYnuw tools/misc/xen_nat_enable.README
|
||||
3fafbef1fJFKCcJLq-ffpauvpM10jQ tools/misc/xen_netwatch.c
|
||||
3fafd0abTbQjsCr5W3DDyNdqdJezrA tools/misc/xen_netwatch_redhatscript
|
||||
3f1668d4F29Jsw0aC0bJEIkOBiagiQ tools/misc/xen_read_console.c
|
||||
3f87ba90EUVPQLVOlFG0sW89BCwouQ tools/misc/xen_refresh_dev.c
|
||||
3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
|
||||
|
||||
+1
-4
@@ -7,7 +7,7 @@ HDRS = $(wildcard *.h)
|
||||
SRCS = $(wildcard *.c)
|
||||
OBJS = $(patsubst %.c,%.o,$(SRCS))
|
||||
|
||||
TARGETS = xen_read_console xen_cpuperf xen_refresh_dev xen_netwatch
|
||||
TARGETS = xen_read_console xen_cpuperf xen_refresh_dev
|
||||
|
||||
INSTALL = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone
|
||||
|
||||
@@ -26,9 +26,6 @@ clean:
|
||||
$(RM) *.o $(TARGETS)
|
||||
$(MAKE) -C miniterm clean
|
||||
|
||||
xen_netwatch: %: %.c $(HDRS) Makefile
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
%: %.c $(HDRS) Makefile
|
||||
$(CC) $(CFLAGS) $(EXTRA_INC) -o $@ $<
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
/******************************************************************************
|
||||
* xen_netwatch.c
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <asm/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/if.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define DEFAULT_SCRIPT "/etc/xen/netwatch"
|
||||
#define DEFAULT_LOGFILE "/var/xen/netwatch"
|
||||
|
||||
#define LOG(_f, _a...) \
|
||||
do { \
|
||||
time_t now = time(NULL); \
|
||||
char *tstr = ctime(&now); \
|
||||
char *p = strchr(tstr, '\n'); if (p) *p = '\0'; \
|
||||
fprintf(logfd, "%s: " _f "\n", tstr, ## _a); \
|
||||
fflush(logfd); \
|
||||
} while ( 0 )
|
||||
|
||||
#define EXIT do { LOG("Exiting."); return 1; } while ( 0 )
|
||||
|
||||
static void daemonise(void)
|
||||
{
|
||||
int i;
|
||||
struct rlimit rlim;
|
||||
|
||||
/* Close all file handles we inherited from our parent. */
|
||||
if ( getrlimit(RLIMIT_NOFILE, &rlim) == 0 )
|
||||
for ( i = 0; i < rlim.rlim_cur; i++ )
|
||||
close(i);
|
||||
|
||||
/* Lose the controlling tty. */
|
||||
setsid();
|
||||
}
|
||||
|
||||
void handle_child_death(int dummy)
|
||||
{
|
||||
(void)waitpid(-1, NULL, WNOHANG);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *logfile = DEFAULT_LOGFILE;
|
||||
char *scriptfile = DEFAULT_SCRIPT;
|
||||
FILE *logfd;
|
||||
int i, nlfd, unixfd, bytes, last_index = ~0;
|
||||
unsigned int last_flags = ~0;
|
||||
char buffer[8192];
|
||||
struct sockaddr_nl nladdr;
|
||||
struct nlmsghdr *nlmsg;
|
||||
struct ifinfomsg *ifi;
|
||||
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;
|
||||
sigemptyset(&sigchld.sa_mask);
|
||||
sigchld.sa_flags = SA_NOCLDSTOP | SA_RESTART;
|
||||
(void)sigaction(SIGCHLD, &sigchld, NULL);
|
||||
|
||||
/*
|
||||
* After child daemonises it can't display errors until it opens the log
|
||||
* file. Since it may be unable to open the log file, we test for that
|
||||
* possibility here.
|
||||
*/
|
||||
if ( (logfd = fopen(logfile, "wb")) == NULL )
|
||||
{
|
||||
fprintf(stderr, "Could not open log file '%s' (%d)\n", logfile, errno);
|
||||
fprintf(stderr, "Exiting.\n");
|
||||
return 1;
|
||||
}
|
||||
fclose(logfd);
|
||||
|
||||
switch ( fork() )
|
||||
{
|
||||
case 0:
|
||||
daemonise();
|
||||
break;
|
||||
case -1:
|
||||
fprintf(stderr, "Could not daemonize. (%d)\n", errno);
|
||||
fprintf(stderr, "Exiting.\n");
|
||||
return 1;
|
||||
default:
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Silent error is forgiveable here, as our parent did a test for us. */
|
||||
if ( (logfd = fopen(logfile, "wb")) == NULL )
|
||||
return 1;
|
||||
|
||||
if ( (nlfd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) == -1 )
|
||||
{
|
||||
LOG("Could not open an rtnetlink socket. (%d)\n", errno);
|
||||
EXIT;
|
||||
}
|
||||
|
||||
if ( (unixfd = socket(PF_UNIX, SOCK_DGRAM, 0)) == -1 )
|
||||
{
|
||||
LOG("Could not open UNIX socket. (%d)\n", errno);
|
||||
EXIT;
|
||||
}
|
||||
|
||||
nladdr.nl_family = AF_NETLINK;
|
||||
nladdr.nl_pid = 0;
|
||||
nladdr.nl_groups = RTMGRP_LINK;
|
||||
if ( bind(nlfd, (struct sockaddr *)&nladdr, sizeof(nladdr)) == -1 )
|
||||
{
|
||||
LOG("Could not bind to kernel (%d)\n", errno);
|
||||
EXIT;
|
||||
}
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
if ( (bytes = read(nlfd, buffer, sizeof(buffer))) == -1 )
|
||||
{
|
||||
if ( errno != EINTR )
|
||||
LOG("Error when reading from socket (%d)", errno);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( bytes == 0 )
|
||||
continue;
|
||||
|
||||
for ( nlmsg = (struct nlmsghdr *)buffer;
|
||||
!(nlmsg->nlmsg_flags & NLMSG_DONE);
|
||||
nlmsg = NLMSG_NEXT(nlmsg, bytes) )
|
||||
{
|
||||
/*
|
||||
* This termination condition works. NLMSG_DONE doesn't always.
|
||||
* This therefore works around a Linux bug.
|
||||
*/
|
||||
if ( nlmsg->nlmsg_len == 0 )
|
||||
break;
|
||||
|
||||
if ( nlmsg->nlmsg_type != RTM_NEWLINK )
|
||||
continue;
|
||||
|
||||
ifi = NLMSG_DATA(nlmsg);
|
||||
|
||||
ifr.ifr_ifindex = ifi->ifi_index;
|
||||
if ( ioctl(unixfd, SIOCGIFNAME, &ifr) == -1 )
|
||||
continue;
|
||||
|
||||
if ( !(ifi->ifi_change & IFF_UP) )
|
||||
continue;
|
||||
|
||||
/* Ignore duplicate messages. This works around a Linux bug.*/
|
||||
if ( (last_index == ifr.ifr_ifindex) &&
|
||||
(last_flags == ifi->ifi_flags) )
|
||||
continue;
|
||||
last_index = ifr.ifr_ifindex;
|
||||
last_flags = ifi->ifi_flags;
|
||||
|
||||
LOG("Network %s event for interface %s",
|
||||
(ifi->ifi_flags & IFF_UP) ? "UP" : "DOWN",
|
||||
ifr.ifr_name);
|
||||
|
||||
switch ( fork() )
|
||||
{
|
||||
case 0:
|
||||
execl(scriptfile,
|
||||
ifr.ifr_name,
|
||||
(ifi->ifi_flags & IFF_UP) ? "up" : "down");
|
||||
LOG("Error executing network script '%s %s %s'",
|
||||
scriptfile, ifr.ifr_name,
|
||||
(ifi->ifi_flags & IFF_UP) ? "up" : "down");
|
||||
return 1;
|
||||
case -1:
|
||||
LOG("Error forking to exec script");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return 0;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Example xen_netwatch script for Red Hat systems.
|
||||
# If the network interface goes up or down then standard Red Hat
|
||||
# scripts are executed. This may be necessary to reconfigure default
|
||||
# routes, for example.
|
||||
#
|
||||
# This script should be placed at /etc/xen/netwatch
|
||||
# You should make sure that the directory /var/xen/ exists.
|
||||
#
|
||||
# Something like the follwoing should be placed in a startup script
|
||||
# such as /etc/rc.d/rc.local:
|
||||
#
|
||||
# if [ -x /usr/bin/xen_netwatch ]; then
|
||||
# if [ -a /etc/xen/netwatch ]; then
|
||||
# mkdir -p /var/xen
|
||||
# /usr/bin/xen_netwatch
|
||||
# fi
|
||||
# fi
|
||||
|
||||
cd /etc/sysconfig/network-scripts || exit 1
|
||||
|
||||
if [ "x$2" == "xup" ]; then
|
||||
if [ -x ./ifup ]; then
|
||||
./ifup $1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "x$2" == "xdown" ] ; then
|
||||
if [ -x ./ifdown ]; then
|
||||
./ifdown $1
|
||||
fi
|
||||
fi
|
||||