Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
better handling of vtun process shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 10, 2009
1 parent 52714ba commit 2e4e973
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 17 deletions.
48 changes: 32 additions & 16 deletions net/vnetwork.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,16 +817,17 @@ int vnetKickDHCP(vnetConfig *vnetconfig) {

snprintf(file, 1024, "%s/euca-dhcp.pid", vnetconfig->path);
if (stat(file, &statbuf) == 0) {
char rootwrap[1024];

snprintf(rootwrap, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap", vnetconfig->eucahome);
snprintf(buf, 512, "%s/var/run/net/euca-dhcp.pid", vnetconfig->eucahome);
rc = safekillfile(buf, vnetconfig->dhcpdaemon, 9, rootwrap);

/*
snprintf (buf, 512, "%s/usr/lib/eucalyptus/euca_rootwrap kill `cat %s/euca-dhcp.pid`", vnetconfig->eucahome, vnetconfig->path);
logprintfl(EUCADEBUG, "executing: %s\n", buf);
rc = system (buf);
*/

snprintf (buf, 512, "%s/usr/lib/eucalyptus/euca_rootwrap kill -9 `cat %s/euca-dhcp.pid`", vnetconfig->eucahome, vnetconfig->path);
logprintfl(EUCADEBUG, "executing: %s\n", buf);
rc = system (buf);
*/
usleep(250000);
}

Expand Down Expand Up @@ -875,14 +876,19 @@ int vnetAddCCS(vnetConfig *vnetconfig, uint32_t cc) {
}

int vnetDelCCS(vnetConfig *vnetconfig, uint32_t cc) {
int i;
char file[1024];
int i, rc;
char file[1024], rootwrap[1024];
char *pidstr;
snprintf(rootwrap, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap", vnetconfig->eucahome);

for (i=0; i<NUMBER_OF_CCS; i++) {
if (vnetconfig->ccs[i] == cc) {
// bring down the tunnel

snprintf(file, 1024, "%s/var/run/eucalyptus/vtund-client-%d-%d.pid", vnetconfig->eucahome, vnetconfig->localIpId, i);
rc = safekillfile(file, "vtund", 9, rootwrap);

/*
pidstr = file2str(file);
if (pidstr) {
logprintfl(EUCADEBUG, "terminating vtund process (%d) for tunnel id %d-%d\n", atoi(pidstr), vnetconfig->localIpId, i);
Expand All @@ -892,6 +898,8 @@ int vnetDelCCS(vnetConfig *vnetconfig, uint32_t cc) {
} else {
// cannot find pidfile
}
*/

vnetconfig->ccs[i] = 0;
return(0);
}
Expand Down Expand Up @@ -1256,11 +1264,15 @@ int vnetTeardownTunnels(vnetConfig *vnetconfig) {
}

int vnetTeardownTunnelsVTUN(vnetConfig *vnetconfig) {

int i;
char file[1024], *pidstr;
int i, rc;
char file[1024], rootwrap[1024];

snprintf(rootwrap, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap", vnetconfig->eucahome);

snprintf(file, 1024, "%s/var/run/eucalyptus/vtund-server.pid", vnetconfig->eucahome);
rc = safekillfile(file, "vtund", 9, rootwrap);

/*
if (!check_file(file)) {
pidstr = file2str(file);
if (pidstr) {
Expand All @@ -1269,20 +1281,24 @@ int vnetTeardownTunnelsVTUN(vnetConfig *vnetconfig) {
free(pidstr);
}
}
*/

if (vnetconfig->localIpId != -1) {
for (i=0; i<NUMBER_OF_CCS; i++) {
if (vnetconfig->ccs[i] != 0) {
snprintf(file, 1024, "%s/var/run/eucalyptus/vtund-client-%d-%d.pid", vnetconfig->eucahome, vnetconfig->localIpId, i);
if (!check_file(file)) {
rc = safekillfile(file, "vtund", 9, rootwrap);
/*
if (!check_file(file)) {
pidstr = file2str(file);
if (pidstr) {
logprintfl(EUCADEBUG, "tearing down tunnel (%d)\n", atoi(pidstr));
kill(atoi(pidstr), 9);
unlink(file);
free(pidstr);
logprintfl(EUCADEBUG, "tearing down tunnel (%d)\n", atoi(pidstr));
kill(atoi(pidstr), 9);
unlink(file);
free(pidstr);
}
}
}
*/
}
}
}
Expand Down
26 changes: 25 additions & 1 deletion tools/eucalyptus-cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ do_stop() {
fi

# now kill the services
pidfiles="$EUCALYPTUS/var/run/eucalyptus/net/euca-dhcp.pid $EUCALYPTUS/var/run/eucalyptus/eucalyptus-cc.pid `ls -1 $EUCALYPTUS/var/run/eucalyptus/vtund*.pid 2>/dev/null`"
pidfiles="$EUCALYPTUS/var/run/eucalyptus/net/euca-dhcp.pid $EUCALYPTUS/var/run/eucalyptus/eucalyptus-cc.pid"
for pidfile in $pidfiles ; do
if [ -s $pidfile ]; then
pid=`cat $pidfile 2> /dev/null`
Expand Down Expand Up @@ -314,6 +314,30 @@ case "$1" in
fi
# reload clears all CC state
do_stop

pidfiles="`ls -1 $EUCALYPTUS/var/run/eucalyptus/vtund*.pid 2>/dev/null`"
for pidfile in $pidfiles ; do
if [ -s $pidfile ]; then
pid=`cat $pidfile 2> /dev/null`
kill $pid > /dev/null 2>&1
else
continue
fi
timeout=5
while [ $timeout -gt 0 ]; do
if ps $pid > /dev/null 2>&1 ; then
sleep 1
timeout=$(($timeout - 1))
else
break
fi
done
if [ $timeout -eq 0 ]; then
kill -9 $pid > /dev/null 2>&1
fi
rm -f $pidfile
done

rm -f $EUCALYPTUS/var/lib/eucalyptus/CC/*
rm -f /dev/shm/*eucalyptusCC*
do_start
Expand Down
60 changes: 60 additions & 0 deletions util/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,3 +965,63 @@ int uint32compar(const void *ina, const void *inb) {
}
return(0);
}

int safekillfile(char *pidfile, char *procname, int sig, char *rootwrap) {
int rc;
char *pidstr;

if (!pidfile || !procname || sig < 0 || check_file(pidfile)) {
return(1);
}

rc = 1;
pidstr = file2str(pidfile);
if (pidstr) {
logprintfl(EUCADEBUG, "calling safekill with pid %d\n", atoi(pidstr));
rc = safekill(atoi(pidstr), procname, sig, rootwrap);
free(pidstr);
}
unlink(pidfile);
return(rc);
}

int safekill(pid_t pid, char *procname, int sig, char *rootwrap) {
char cmdstr[1024], file[1024], cmd[1024];
FILE *FH;
int ret;

if (pid < 2 || !procname) {
return(1);
}

snprintf(file, 1024, "/proc/%d/cmdline", pid);
if (check_file(file)) {
return(1);
}

FH = fopen(file, "r");
if (FH) {
if (!fgets(cmdstr, 1024, FH)) {
fclose(FH);
return(1);
}
fclose(FH);
} else {
return(1);
}

ret=1;

// found running process
if (strstr(cmdstr, procname)) {
// passed in cmd matches running cmd
if (rootwrap) {
snprintf(cmd, 1024, "%s kill -%d %d", rootwrap, sig, pid);
ret = system(cmd)>>8;
} else {
ret = kill(pid, sig);
}
}

return(ret);
}
2 changes: 2 additions & 0 deletions util/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,7 @@ int write2file(const char *path, char *str);
long long str2longlong (const char * str, const char * begin, const char * end); /* extract integer from str bound by 'begin' and 'end' */
pid_t timewait(pid_t pid, int *status, int timeout);
int uint32compar(const void *ina, const void *inb);
int safekill(pid_t pid, char *procname, int sig, char *rootwrap);
int safekillfile(char *pidfile, char *procname, int sig, char *rootwrap);

#endif

0 comments on commit 2e4e973

Please sign in to comment.