I'm having trouble with a daemon done in C , which reads the stdout php content and saves the contents to a file. The problem happens only for a PHP script file, while another does not.
If I invoke the script manually, you write the contents on stdout normally.
After giving fork , I am running the following code snippet:
void startScriptCollector(char *php , char *collectorName , char *collectorRaw , char *collectorLog){
char str_script[80];
char str_raw[80];
char str_log[80];
int result = 0;
int fd_output , fd_error; //File Descriptor
setreuid(geteuid(), geteuid());
//stat_rtrim(collectorLog);
//removeChar(collectorLog,'
');
if(collectorLog != NULL) trim(collectorLog);
tmLogPrintf(Log, TMLOG_LEVEL_ERROR , "On startScriptCollector collectorName : %s , collectorRaw : %s , collectorLog : %s...
",
collectorName, collectorRaw , collectorLog);
//exit(-1);
sprintf(str_script , "%s/%s" , SLAVIEW_CUSTOM_SCRIPTS , collectorName);
sprintf(str_raw , "%s/%s" , SLAVIEW_CUSTOM_TMPCOL , collectorRaw);
sprintf(str_log , "%s/%s" , VARDIR , collectorLog);
fd_output = open(str_raw, O_CREAT | O_WRONLY , 0777);
fd_error = open(str_log, O_CREAT | O_WRONLY , 0777);
if(fd_output < 0){
tmLogPrintf(Log, TMLOG_LEVEL_ERROR , "Script %s not could save data in %s...
",
collectorName , str_raw);
exit(-1);
}
if(fd_error < 0){
tmLogPrintf(Log, TMLOG_LEVEL_ERROR , "Script %s not could save error log ...
",
collectorName);
//exit(-1);
}
dup2(fd_output , 1); //write on data file
dup2(fd_error , 2); //write on error file
result = execl(PHPEXEC , "php" , str_script , NULL);
if(result == -1){
tmLogPrintf(Log, TMLOG_LEVEL_ERROR , "Error, on execute script %s ...", collectorName);
exit(-1);
}
}