/* * The Spread Toolkit. * * The contents of this file are subject to the Spread Open-Source * License, Version 1.0 (the ``License''); you may not use * this file except in compliance with the License. You may obtain a * copy of the License at: * * http://www.spread.org/license/ * * or in the file ``license.txt'' found in this distribution. * * Software distributed under the License is distributed on an AS IS basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Creators of Spread are: * Yair Amir, Michal Miskin-Amir, Jonathan Stanton. * * Copyright (C) 1993-2004 Spread Concepts LLC * * All Rights Reserved. * * Major Contributor(s): * --------------- * Cristina Nita-Rotaru crisn@cs.purdue.edu - group communication security. * Theo Schlossnagle jesus@omniti.com - Perl, skiplists, autoconf. * Dan Schoenblum dansch@cnds.jhu.edu - Java interface. * John Schultz jschultz@cnds.jhu.edu - contribution to process group membership. * */ #define status_ext #include #include #include #include #include "arch.h" #include "mutex.h" #include "scatter.h" #include "configuration.h" #include "sp_events.h" #include "status.h" #include "net_types.h" #include "data_link.h" #include "alarm.h" static channel SendChan; static sys_scatter Pack_scat; static packet_header Pack; static configuration Cn; static proc My; static int My_port; static char *My_name; static char My_name_buf[80]; static char Config_file[80]; static int16 Kill_partition[MAX_PROCS_RING]; static char **kill_names; static void Kill_spreads(); static void Usage( int argc, char *argv[] ); int main( int argc, char *argv[] ) { fclose(stderr); Alarm_set_types( NONE ); Alarm( PRINT, "/===========================================================================\\\n"); Alarm( PRINT, "| The Spread Toolkit. |\n"); Alarm( PRINT, "| Copyright (c) 1993-2001 Spread Concepts LLC |\n"); Alarm( PRINT, "| All rights reserved. |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| The Spread package is licensed under the Spread Open-Source License. |\n"); Alarm( PRINT, "| You may only use this software in compliance with the License. |\n"); Alarm( PRINT, "| A copy of the license can be found at http://www.spread.org/license |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| This product uses software developed by Spread Concepts LLC for use |\n"); Alarm( PRINT, "| in the Spread toolkit. For more information about Spread, |\n"); Alarm( PRINT, "| see http://www.spread.org |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| This software is distributed on an \"AS IS\" basis, WITHOUT WARRANTY OF |\n"); Alarm( PRINT, "| ANY KIND, either express or implied. |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| Spread is developed at Spread Concepts LLC and the Center for Networking |\n"); Alarm( PRINT, "| and Distributed Systems, The Johns Hopkins University. |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| Creators: |\n"); Alarm( PRINT, "| Yair Amir yairamir@cs.jhu.edu |\n"); Alarm( PRINT, "| Michal Miskin-Amir michal@spread.org |\n"); Alarm( PRINT, "| Jonathan Stanton jstanton@gwu.edu |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| Contributors: |\n"); Alarm( PRINT, "| Cristina Nita-Rotaru crisn@cs.purdue.edu - GC security. |\n"); Alarm( PRINT, "| Theo Schlossnagle jesus@omniti.com - Perl, skiplists, autoconf. |\n"); Alarm( PRINT, "| Dan Schoenblum dansch@cnds.jhu.edu - Java Interface Developer. |\n"); Alarm( PRINT, "| John Schultz jschultz@cnds.jhu.edu - contribution to process group |\n"); Alarm( PRINT, "| membership. |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| Special thanks to the following for providing ideas and/or code: |\n"); Alarm( PRINT, "| Ken Birman, Danny Dolev, David Shaw, Robbert VanRenesse. |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| WWW: www.spread.org www.cnds.jhu.edu www.spreadconcepts.com |\n"); Alarm( PRINT, "| Contact: spread@spread.org |\n"); Alarm( PRINT, "| |\n"); Alarm( PRINT, "| Version %d.%02d.%02d Built 15/October/2004 |\n", (int)SP_MAJOR_VERSION, (int)SP_MINOR_VERSION, (int)SP_PATCH_VERSION); Alarm( PRINT, "\\===========================================================================/\n"); Usage( argc, argv ); Conf_init( Config_file, My_name ); Cn = Conf(); My = Conf_my(); Alarm_clear_types(ALL); Alarm_set_types(PRINT | EXIT ); #ifdef ARCH_PC_WIN95 ret = WSAStartup( MAKEWORD(2,0), &WSAData ); if( ret != 0 ) Alarm( EXIT, "sptmonitor: main: winsock initialization error %d\n", ret ); #endif /* ARCH_PC_WIN95 */ Pack_scat.elements[0].len = sizeof( packet_header ); Pack_scat.elements[0].buf = (char *)&Pack; Pack.proc_id = My.id; Pack.seq = My_port; Pack.memb_id.proc_id = 15051963; SendChan = DL_init_channel( SEND_CHANNEL , My_port, 0, 0 ); Kill_spreads(); return 0; } static void Kill_spreads() { proc p; int proc_index; int32 proc_id; int i, j; for( i=0; i < MAX_PROCS_RING; i++ ) Kill_partition[i] = 0; while ( NULL != kill_names[0] ) { if( !strcmp( kill_names[0], "all" ) ){ for( i=0; i < Conf_num_procs( &Cn ); i++ ) Kill_partition[i] = -1; }else{ proc_index = Conf_proc_by_name( kill_names[0], &p ); if( proc_index != -1 ){ Kill_partition[proc_index] = -1; } else { Alarm( EXIT, "Illegal proc name <%s>\n", kill_names[0] ); } } kill_names++; } Pack.type = PARTITION_TYPE; Pack.type = Set_endian( Pack.type ); Pack.data_len= sizeof( Kill_partition );; Pack_scat.num_elements = 2; Pack_scat.elements[1].len = sizeof( Kill_partition ); Pack_scat.elements[1].buf = (char *)&Kill_partition; for( i=0; i < Cn.num_segments ; i++ ) { for( j=0; j < Cn.segments[i].num_procs; j++ ) { proc_id = Cn.segments[i].procs[j]->id; proc_index = Conf_proc_by_id( proc_id, &p ); if( Kill_partition[proc_index] == -1 ) { Alarm( PRINT , "Monitor: Terminating %s\n", p.name ); DL_send( SendChan, p.id, p.port, &Pack_scat ); DL_send( SendChan, p.id, p.port, &Pack_scat ); } } } } static void Usage(int argc, char *argv[]) { My_name = 0; /* NULL */ My_port = 6543; strcpy( Config_file, "spread.conf" ); if( 1 == argc ) { Alarm( EXIT, "Usage: spmonitor\n%s\n%s\n%s\n%s\n", "\t[-p ]: specify port number", "\t[-n ] : force computer name", "\t[-c ] : specify configuration file" "\t" ); } while( --argc > 0 ) { argv++; if( !strncmp( *argv, "-p", 2 ) ) { sscanf(argv[1], "%d", &My_port ); argc--; argv++; }else if( !strncmp( *argv, "-n", 2 ) ) { if( strlen( argv[1] ) > MAX_PROC_NAME-1 ) /* -1 for the null */ Alarm( EXIT, "Usage: proc name %s too long\n", argv[1] ); memcpy( My_name_buf, argv[1], strlen( argv[1] ) ); My_name = My_name_buf; argc--; argv++; }else if( !strncmp( *argv, "-c", 2 ) ){ strcpy( Config_file, argv[1] ); argc--; argv++; }else{ kill_names = argv; return; } } }