[parisc-linux] popen/pclose problem

Paul J.Y. Lahaie pjlahaie@linuxcare.com
Wed, 14 Mar 2001 15:09:25 -0500

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

There seems to be a bug with popen/pclose on parisc.  In dbootstrap,
the Debian bootstrap install program, there is a function that will
run an application with its output redirected to syslog with the use
of popen/pclose.  In this application, pclose always returns -1 which
is (according to the manpage):

"The  pclose function returns -1 if wait4 returns an error, or some other
error is detected."

The function with the error is execlog in utilities/dbootstrap/util.c.

Interestingly, if I take out that function and wrap a main around it,
pclose returns the right values.  Here follows the standalone program
I wrote using the function.

--- cut here ---
#include <stdio.h>
#include <syslog.h>
#define MAXLINE 1024
int  execlog (const char *incmd, int priority)
  FILE *output;
  char line[MAXLINE];
  char cmd[strlen(incmd) + 6];
  strcpy(cmd, incmd);

    openlog("sysrun", LOG_PID, LOG_USER);

  /* FIXME: this can cause the shell command if there's redirection
            already in the passed string */
  strcat(cmd, " 2>&1");
  output = popen(cmd, "r");
  while (fgets(line, MAXLINE, output) != NULL ) {
    syslog(priority, line);

int main(int argc,char **argv)
    int ret;
    if( argc < 2 )
        fprintf( stderr, "Missing arguments.\n" );

    ret = execlog( argv[1], LOG_INFO);
    if( ret != 0 )
        fprintf( stderr, "Bad return value %d\n", ret );
        return ret;
    return 0;
--- cut here ---

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org