Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 04 Dec 1997 09:27:00 +0530
From:      A Joseph Koshy <koshy@india.hp.com>
To:        freebsd-current@freebsd.org
Subject:   -pthread / popen() problem?
Message-ID:  <199712040404.UAA07892@palrel1.hp.com>

next in thread | raw e-mail | index | archive | help

`popen(3)' and -pthread seem to have a problem working together.

Symptoms:

  (foo) $ cat a.c
  #include <stdio.h>
  char buf[1024];
  int main(int ac, char **av)
  {
    FILE *x;  int c = 0;
    sprintf(buf, "/bin/cat %s", av[1]);
    if (x = popen(buf, "r"))
    {
      while(fgets(buf, 1024, x) != NULL)
            c++;
      printf("%d\n", c);
    }
    else
    {
      printf("open failed\n");
    }
  }

  (foo) $ cc -pthread a.c && ./a.out /etc/termcap
  0 cat: stdout: Resource temporarily unavailable <-- ``0''??? 

[the error message is seen intermittently on stderr]

  (foo) $ ./a.out /dev/zero
  0				<-- ???
  (foo) $

However,
  
  (foo) $ cc a.c && ./a.out /etc/termcap
  4126
  (foo) $ ./a.out /dev/zero
  ^C				# <-- interrupted from the keyboard
  (foo) $ ./a.out /dev/null
  0
  (foo) $

I.e. it works perfectly for non threaded compiles.

I saw this problem when looking into why Python (1.4) was failing
on -current.

  (foo) $ python1.4	# <-- from the precompiled package
  Python 1.4 (Jul 18 1997)  [GCC 2.7.2.1]
  Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
  >>> import os
  >>> x=os.popen('/bin/cat /etc/termcap')
  >>> cat: stdout: Resource temporarily unavailable
  [program misbehaves from this point]      

  (foo) $ ldd /usr/local/bin/python1.4
  /usr/local/bin/python1.4:
        -lm.2 => /usr/lib/libm.so.2.0 (0x20054000)
        -lcrypt.2 => /usr/lib/libcrypt.so.2.0 (0x2006f000)
        -lc_r.3 => /usr/lib/libc_r.so.3.0 (0x20072000)
        -lc.3 => /usr/lib/libc.so.3.0 (0x200fd000)                 
   
Koshy
<koshy@india.hp.com>			#include STD_DISCLAIMER



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199712040404.UAA07892>