#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>

#include "global.h"
#include "custom.h"		/* for date FORMAT strings */

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_super_util.h"
#include "manhat-lib/shared_cs_util.h"


	 
int
main ()
{
  char key[MAX_KEY + 1];
  SESSION user;
  FILE *fp;
  char pid_string[25];
  pid_t pid;
  char msg[200];


  cs_cgi_init(); 
   read_param( key);
   validate_super_key(key, &user);
   

   fp = fopen(CHAT_PID_PATH,"r");
   if(!fp || (fp && !fgets(pid_string, 25, fp)))
      cs_critical_error( ERR_NO_PID_FILE, CHAT_PID_PATH);
      
   fclose(fp);
   
   unlink(CHAT_PID_PATH);
               
   pid = (pid_t)atoi(pid_string);
   
   
  if(kill(pid,SIGKILL))
   {
      snprintf(msg, 200, "%d",  pid);
      cs_critical_error(ERR_KILLING_MELANGE_AT_X_FAILED, msg);
   }   
   
   cs_cgi_display("super_chat_kill", 1);
   cs_cgi_destroy();
               
   
   return 0;
   
}

