Re: popen2 popen call

From: F. Heitkamp
Date: Sat Sep 05 2009 - 13:51:19 EST


Ulrich Drepper wrote:
On Thu, Aug 27, 2009 at 11:39,<heitkamp@xxxxxxxxxxxxx> wrote:
OK. I read in one of the messages, that glibc, passes the popen call to a ABI in the kernel. I have not
looked at the code in glibc yet.

popen uses pipe2. There is fallback code to use pipe if necessary.
It's compiled out only of the libc assumes the kernel support is
available.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

OK. I think I found the problem but how do I fix it?
Did I miss a kernel config option?
I got the code from the man page:
http://linux.die.net/man/2/pipe
http://manpages.courier-mta.org/htmlman2/pipe.2.html

bash-4.0$ gcc -o linux-pipe linux-pipe.c
/tmp/ccHHOYkD.o: In function `main':
linux-pipe.c:(.text+0x3b): warning: warning: pipe2 is not implemented and will always fail
bash-4.0$ ./linux-pipe ls
pipe: Function not implemented
bash-4.0$


#include <sys/wait.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int
main(int argc, char *argv[])
{
int pfd[2];
pid_t cpid;
char buf;
assert(argc == 2);
if (pipe2(pfd) == -1) { perror("pipe"); exit(EXIT_FAILURE); }
cpid = fork();
if (cpid == -1) { perror("fork"); exit(EXIT_FAILURE); }
if (cpid == 0) { /* Child reads from pipe */
close(pfd[1]); /* Close unused write end */
while (read(pfd[0], &buf, 1) > 0)
write(STDOUT_FILENO, &buf, 1);
write(STDOUT_FILENO, "\n", 1);
close(pfd[0]);
_exit(EXIT_SUCCESS);
} else { /* Parent writes argv[1] to pipe */
close(pfd[0]); /* Close unused read end */
write(pfd[1], argv[1], strlen(argv[1]));
close(pfd[1]); /* Reader will see EOF */
wait(NULL); /* Wait for child */
exit(EXIT_SUCCESS);
}
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/