gs_kill_server.c

Go to the documentation of this file.
00001 
00008 /* $Id: gs_kill_server.c,v 1.25 2008/09/25 15:47:19 seymour Exp $ */
00009 /* $UTK_Copyright: $ */
00010 
00011 #include "utility.h"
00012 
00013 #include <stdlib.h>
00014 #include <string.h>
00015 
00016 #include "comm_data.h"
00017 #include "comm_basics.h"
00018 #include "comm_encode.h"
00019 #include "general.h"
00020 #include "gs_tools.h"
00021 
00022 #define DIE_BAD_USAGE() \
00023   do { \
00024     fprintf(stderr, "Usage: GS_killserver <agent name> <server name>\n"); \
00025     fprintf(stderr, "Usage: GS_killserver -c <agent name> <server component id>\n"); \
00026     exit(EXIT_FAILURE); \
00027   } while(0)
00028 
00038 int
00039 main(int argc, char **argv)
00040 {
00041   int agentport, by_cid;
00042   char *agent_name, *server_name;
00043 
00044   if((argc < 3) || (argc > 4))
00045     DIE_BAD_USAGE();
00046 
00047   agentport = getenv_int("GRIDSOLVE_AGENT_PORT", GRIDSOLVE_AGENT_PORT_DEFAULT);
00048 
00049   if(!strcmp(argv[1], "-c"))
00050     by_cid = 1;
00051   else
00052     by_cid = 0;
00053 
00054   if(argc == 3) {
00055     if(by_cid)
00056       DIE_BAD_USAGE();
00057     else {
00058       agent_name = argv[1];
00059       server_name = argv[2];
00060     }
00061   }
00062   else {
00063     if(by_cid) {
00064       agent_name = argv[2];
00065       server_name = (char *)malloc(strlen(argv[3]) + 2);
00066       if(!server_name) {
00067         fprintf(stderr, "failed to malloc memory\n");
00068         exit(EXIT_FAILURE);
00069       }
00070       sprintf(server_name, "-c%s", argv[3]);
00071     }
00072     else
00073       DIE_BAD_USAGE();
00074   }
00075 
00076   if(gs_kill_server(agent_name, agentport, server_name) < 0) {
00077     fprintf(stderr, "Failed to kill server %s\n", argv[3]);
00078     exit(EXIT_FAILURE);
00079   }
00080 
00081   exit(EXIT_SUCCESS);
00082 }