[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Portable IPC
From: |
Bill Moseley |
Subject: |
Portable IPC |
Date: |
Mon, 6 Nov 2006 21:14:52 -0800 |
User-agent: |
Mutt/1.5.12-2006-07-14 |
I suspect this is beyond the scope of the autoconf list.
Our application, Swish-e, can use "filters" -- which are external
programs that filter input and the application reads the output from
the filter program.
Besides the fact that my unix IPC skills are not that great, I'm
wondering if there's any examples someone can point me to that use
autoconf tests for fork/exec/wait written in a reasonably portable
way (whatever that means).
Currently, I assume if HAVE_WORKING_FORK is defined that I can also
have pipe(), dup2(), and fdopen().
Another example, here's a first pass at the function to close the filter
program -- which might happen before the filter has finished
generating all its output.
What I'm concerned with is knowing what features need to be tested for
in configure.
int FilterClose(FileProp *fprop)
{
#ifdef HAVE_WORKING_FORK
FilterList *fl = fprop->hasfilter;
char *prog = fl->prog;
#ifdef HAVE_SYS_WAIT_H
int status;
pid_t pid;
#ifdef HAVE_KILL
pid = waitpid( fprop->filter_pid, &status, WNOHANG );
/* Is program still running? */
if ( 0 == pid )
{
/* kill -9 might be a bit harsh */
if ( -1 == kill( fprop->filter_pid, 9 ) )
progerrno("Failed to kill filter program %s with pid %d", prog,
fprop->filter_pid );
/* Now reap killed filter */
pid = waitpid( fprop->filter_pid, &status, 0 );
}
#else
pid = wait(&status);
#endif /* HAVE_KILL */
if ( !WIFEXITED(status) )
progwarn("filter '%s' did not terminate normally", prog );
else if ( WEXITSTATUS(status) )
progwarn("filter '%s' exited with non-zero status: [%d]", prog,
WEXITSTATUS(status));
else if ( WIFSIGNALED(status) )
progwarn("filter '%s' killed by signal: [%d]", prog, WTERMSIG(status) );
#endif /* HAVE_SYS_WAIT_H */
if ( fclose( fprop->fp ) != 0 )
progwarnno("Error closing filter '%s'", prog );
return 0;
#else
return pclose(fprop->fp);
#endif /* HAVE_WORKING_FORK */
}
--
Bill Moseley
address@hidden
- Portable IPC,
Bill Moseley <=