Skip to contentSkip to conversation

popen2 popen call

DISCUSSION F. Heitkamp 3 participants 7 messages Aug 27, 2009 – Sep 9, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

I am using vanilla kernel 2.6.31-rc7, glibc 2.10.x on a Core 2 Duo system.

When the popen call is made in sshd/session.c I get a error from strerror of "Function not Implemented". I googled a bit and found that there is sometimes an problem between the way the kernel and glibc are compiled that causes glibc not to find the popen2 call in the kernel. The fix seemed to imply I need a certain processor choice when compiling the kernel.

Strangely, simple popen test programs seem to work OK.

Can anyone shed some light on this for me? I would like to get this to work, so my X11 forwarding works in ssh.

BTW, kernels before 2.6.27 don't seem to cause the problem to manifest itself.

Thanks!

Fred

#1 lore raw
Quoted 2 lines · F. Heitkamp

When the popen call is made in sshd/session.c I get a error from strerror of "Function not Implemented".

Which function exactly returns this error?

Quoted 3 lines

I googled a bit and found that there is sometimes an problem between the way the kernel and glibc are compiled that causes glibc not to find the popen2 call in the kernel.

There is no such thing as a popen2 syscall.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."
#2 lore raw

-------------- Original message from Andreas Schwab <[email protected]>: --------------

Quoted 6 lines
Quoted 2 lines · F. Heitkamp

When the popen call is made in sshd/session.c I get a error from strerror of "Function not Implemented".

Which function exactly returns this error?

In the openssh source distribution there is a file, session.c that uses popen, with the
ultimate purpose of fixing the .Xauthority file for X11 forwarding. It uses popen to set the DISPLAY, MIT-MAGIC-COOKIE etc. via the shell I think, executing xauth. In session.c popen is used three times under different conditions. I put strerror calls where the popen call returns a NULL pointer to try to find out why the popen call fails. I could post the section of code if you want to see. I am not a professional programmer.

The gist of it is:

fp = popen( cmdstr, "w" );
if ( !fp )
/* call strerror, errno */

Quoted 2 lines

There is no such thing as a popen2 syscall.

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.

Fred

#3 lore raw
Quoted 2 lines · On Thu, Aug 27, 2009 at 11:39, <[email protected]> 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.

#4 lore raw
Quoted 6 lines · Ulrich Drepper
Quoted 3 lines · On Thu, Aug 27, 2009 at 11:39,<[email protected]> 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.

Quoted 10 lines

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 [email protected]
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);
    }
}
#5 lore raw
Quoted 2 lines · F. Heitkamp

linux-pipe.c:(.text+0x3b): warning: warning: pipe2 is not implemented and will always fail

you will get this warning if the glibc you're using was compiled without appropriate kernel headers. I.e., the definition of __NR_pipe2 wasn't available.

#6 lore raw
Quoted 6 lines · Ulrich Drepper
Quoted 3 lines · F. Heitkamp

linux-pipe.c:(.text+0x3b): warning: warning: pipe2 is not implemented and will always fail

Quoted 10 lines

you will get this warning if the glibc you're using was compiled without appropriate kernel headers. I.e., the definition of __NR_pipe2 wasn't available.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Compiling glibc with newer headers worked! Thank you all.

Fred