Functions

gs_kill_all.c File Reference

#include "utility.h"
#include <stdlib.h>
#include <string.h>
#include "comm_data.h"
#include "comm_basics.h"
#include "comm_encode.h"
#include "general.h"
#include "gs_tools.h"
Include dependency graph for gs_kill_all.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Detailed Description

This program will kill all servers. The usage is: GS_kill_all <agent name>="">

Definition in file gs_kill_all.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Entry point for GS_kill_all.

Parameters:
argc -- arg count
argv -- array of command line args
Returns:
EXIT_SUCCESS on success, EXIT_FAILURE on error.

Definition at line 32 of file gs_kill_all.c.

{
  char dottedIP[20], proxy_dottedIP[20], cid_string[2 * CID_LEN + 1];
  char server_name[2 * CID_LEN + 3];
  int i, num_failed, sock, num_servers, agentport;
  gs_server_t **server_list;

  if(argc < 2) {
    fprintf(stderr,"Usage: GS_kill_all <agent name>\n");
    exit(EXIT_FAILURE);
  }
  
  initialize_sockets();

  agentport = getenv_int("GRIDSOLVE_AGENT_PORT", GRIDSOLVE_AGENT_PORT_DEFAULT);
  if((sock = gs_connect_direct(argv[1], agentport)) == INVALID_SOCKET) {
    fprintf(stderr,"%s cannot be contacted\n", argv[1]);
    exit(EXIT_FAILURE);
  }

  server_list = gs_tools_get_all_servers(argv[1], agentport, &num_servers);

  num_failed = 0;

  for(i=0;i<num_servers;i++) {
    proxy_cid_to_str(cid_string, server_list[i]->componentid);
    proxy_ip_to_str(server_list[i]->ipaddress, dottedIP);
    proxy_ip_to_str(server_list[i]->proxyip, proxy_dottedIP);
    if(server_list[i]->proxyip != 0)
      printf("killing server %s (%s:%d, proxy=%s:%d) [cid=%s]\n", server_list[i]->hostname, 
        dottedIP, server_list[i]->port, proxy_dottedIP, 
        server_list[i]->proxyport, cid_string);
    else
      printf("killing server %s (%s:%d) [cid=%s]\n", server_list[i]->hostname, 
        dottedIP, server_list[i]->port, cid_string);

    sprintf(server_name, "-c%s", cid_string);

    if(gs_kill_server(argv[1], agentport, server_name) < 0) {
      fprintf(stderr, "Failed to kill server %s (%s)\n", server_list[i]->hostname, cid_string);
      num_failed++;
    }
  }

  if(gs_kill_agent(argv[1], agentport) < 0)
    fprintf(stderr, "Failed to kill agent %s\n", argv[1]);

  cleanup_sockets();

  return 0;
}

Here is the call graph for this function: