提交 b2bba2a6 authored 作者: Joao Mesquita's avatar Joao Mesquita

Do things the right way ignoring sigchild and using popen. Now I think its right.

上级 76dde4b6
...@@ -52,43 +52,29 @@ typedef struct { ...@@ -52,43 +52,29 @@ typedef struct {
static inbound_event_profile_t profiles[128] = {{{0}}}; static inbound_event_profile_t profiles[128] = {{{0}}};
static int pcount = 0; static int pcount = 0;
static void mycallback (esl_event_t *event, char * path)
static void mycallback(esl_event_t *event, char * path)
{ {
int pipefd[2]; FILE *output;
int pid; char *serialized = NULL;
char * serialized = NULL;
if (fork() == 0) {
/*make a pipe (fds go in pipefd[0] and pipefd[1])*/ output = popen (path, "w");
pipe(pipefd); if (!output) {
fprintf (stderr, "Could not execute script.\n");
pid = fork(); exit (EXIT_FAILURE);
}
if (pid == 0) /* Pass information to new process */
{
/* Wire fd to stdin */
dup2(pipefd[0], 0);
// close unused hald of pipe
close(pipefd[1]);
// execute grep
execl(path, path, (char *)NULL);
_exit(EXIT_SUCCESS);
}
else /* Parent */
{
// close unused unput half of pipe
close(pipefd[0]);
esl_event_serialize(event, &serialized, ESL_FALSE); esl_event_serialize(event, &serialized, ESL_FALSE);
write(pipefd[1], serialized, strlen(serialized)); fprintf (output, "%s", serialized);
close(pipefd[1]); if (ferror (output)) {
fprintf (stderr, "Output to stream failed.\n");
exit (EXIT_FAILURE);
}
pclose (output); /* Might be already closed, but might as well try */
/* Free memory */
esl_safe_free(serialized); esl_safe_free(serialized);
exit(0);
} }
return;
} }
static int usage(char *name){ static int usage(char *name){
...@@ -136,6 +122,7 @@ int main(int argc, char *argv[]) ...@@ -136,6 +122,7 @@ int main(int argc, char *argv[])
int argv_conf = 0; int argv_conf = 0;
esl_global_set_default_logger(6); esl_global_set_default_logger(6);
signal(SIGCHLD, SIG_IGN);
for(;;) { for(;;) {
int option_index = 0; int option_index = 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论