On Sat, Mar 03, 2007 at 01:56:19PM +0100, Dag Leine wrote:
Hallo,
I've just played aroudn with the popen(2)-call. After getting a
segmentation fault on a quite old OpenBSD 3.8 machine I've tried to
understand the source.
/usr/src/lib/libc/gen/popen.c
what I am missing is the initialization of *pidlist. If I initialize
this static pointer with NULL everything seems to work fine.
Did I missunderstand the source or the usage of popen??
Thanks for Comments
Dag
The simple test programm (which dies only on ONE machine):
#include stdio.h
#include stdlib.h
FILE *p;
int main(void)
{
if(NULL == (p = popen(/bin/cat, w)))
{
printf(popen() failed\n);
exit(1);
}
fprintf(p, hallo to pipe\n);
printf(pclose exiting with %d\n, pclose(p));
return(0);
}
static struct pid {
// ...
} *pidlist;
is defined at file scope (and static). It should be initialised to the
default value 0 by the compiler.
Your testprogram also looks ok, are you sure this machine doesn't have
a hardware problem?
Tobias