
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<signal.h>
#include <sys/types.h>
#include<pthread.h>

#include"zither.h"
#include<almemsys/almemsys.h>
#include"jpreturn.h"

extern global_data_t gd;
extern pthread_mutex_t name_mutex;


int safe_exit(char * data) 
{
pid_t ppid =  getpid();
char * time_data = (char *)calloc(BUF_DEFLEN, sizeof(char));

safe_pthread_mutex_lock(&name_mutex);
fprintf(stderr,"safe_exit(): %d = miname_dump(void);\n", miname_dump(gd.fi.midump_filename));
pthread_mutex_unlock(&name_mutex);

time_data = time_getr(time_data);
fprintf(stderr,"safe_exit(): %s time=(%s) Procces killd pgid=%d out=%s\n", CL_VAR, time_data, (ppid * -1), data);
fprintf(stdout,"safe_exit(): %s time=(%s) Procces killd pgid=%d out=%s\n", CL_VAR, time_data, (ppid * -1), data);
free(time_data);

malloc_free();

if(kill((ppid * -1), SIGKILL)){
   fprintf(stderr,"safe_exit(): child process not killd GPID = %d\n", (ppid * -1));
   } 

return 0;
}





