hi all
cou;ld someone help me out with this segmentation fault .
i have given the code here .
somewhere there is a segmentation fault .
iam unable to find out .could u help me .
the main aim of the code is to run a particular process
"get" at an interval as specified in the ENv variable "TIME" .
The process is getting executed once but the second time iam getting a segmentation fault error .
iam not able to pass through it .
if can put ur idea it would be useful.
ramki
THE CODE :
-----------
#include<stdio.h>
#include<signal.h>
#include<time.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
#include "/home/ipcpe/process/lib/ERR_logerror.c"
#define CONFIG "/home/ipcpe/process/config.ini"
#define YES 1
#define NO 0
#define TRUE 1
#define FALSE 0
/*********Global Variables ***********/
int CDRcoll_pid = -1; /* pid of the get process */
int CDRdaemon_pid; /* pid of this daemon */
FILE *fp1;
/******************Function Declaration *******************/
int collt();
void sigtrap();
void sigcld();
void sigalrm();
main()
{
char *ptr,*getenv();
char c;
int sig,i;
/********** Change to the root ************/
chdir("/"
;
/************ Mask the file permissions*******/
umask(0);
/**************** set the effective gid and pid ************/
setpgrp();
/**********The Following Signals are ignored *********/
signal(SIGHUP,SIG_IGN);
signal(SIGINT,SIG_IGN);
signal(SIGQUIT,SIG_IGN);
/***********For the following Signals execute sigtrap ************/
signal(SIGILL,sigtrap);
signal(SIGIO,sigtrap);
signal(SIGIOT,sigtrap);
signal(SIGPOLL,sigtrap);
signal(SIGCLD,sigcld);
signal(SIGALRM,sigalrm);
while(1)
{
/*
fp1=fopen("/home/ipcpe/process/test","r"
;
if(fp1==NULL)
{
printf("Error opening file \n"
;
exit(1);
}
rewind(fp1);
for(c=fgetc(fp1); !feof(fp1) && c != '=';c=fgetc(fp1));
fscanf(fp1,"%d",&i);
fclose(fp1);
*/
if( ( ptr = getenv("TIME"
) == (char *) 0)
{
printf("TIME is not defined \n"
;
}
else
{
i=atoi(ptr);
printf("%d\n",i);
}
alarm(i);
sleep(i);
}
}
cou;ld someone help me out with this segmentation fault .
i have given the code here .
somewhere there is a segmentation fault .
iam unable to find out .could u help me .
the main aim of the code is to run a particular process
"get" at an interval as specified in the ENv variable "TIME" .
The process is getting executed once but the second time iam getting a segmentation fault error .
iam not able to pass through it .
if can put ur idea it would be useful.
ramki
THE CODE :
-----------
#include<stdio.h>
#include<signal.h>
#include<time.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
#include "/home/ipcpe/process/lib/ERR_logerror.c"
#define CONFIG "/home/ipcpe/process/config.ini"
#define YES 1
#define NO 0
#define TRUE 1
#define FALSE 0
/*********Global Variables ***********/
int CDRcoll_pid = -1; /* pid of the get process */
int CDRdaemon_pid; /* pid of this daemon */
FILE *fp1;
/******************Function Declaration *******************/
int collt();
void sigtrap();
void sigcld();
void sigalrm();
main()
{
char *ptr,*getenv();
char c;
int sig,i;
/********** Change to the root ************/
chdir("/"
/************ Mask the file permissions*******/
umask(0);
/**************** set the effective gid and pid ************/
setpgrp();
/**********The Following Signals are ignored *********/
signal(SIGHUP,SIG_IGN);
signal(SIGINT,SIG_IGN);
signal(SIGQUIT,SIG_IGN);
/***********For the following Signals execute sigtrap ************/
signal(SIGILL,sigtrap);
signal(SIGIO,sigtrap);
signal(SIGIOT,sigtrap);
signal(SIGPOLL,sigtrap);
signal(SIGCLD,sigcld);
signal(SIGALRM,sigalrm);
while(1)
{
/*
fp1=fopen("/home/ipcpe/process/test","r"
if(fp1==NULL)
{
printf("Error opening file \n"
exit(1);
}
rewind(fp1);
for(c=fgetc(fp1); !feof(fp1) && c != '=';c=fgetc(fp1));
fscanf(fp1,"%d",&i);
fclose(fp1);
*/
if( ( ptr = getenv("TIME"
{
printf("TIME is not defined \n"
}
else
{
i=atoi(ptr);
printf("%d\n",i);
}
alarm(i);
sleep(i);
}
}