Linux PARISC architecture development
 help / color / mirror / Atom feed
From: "Paul J.Y. Lahaie" <pjlahaie@linuxcare.com>
To: parisc-linux@parisc-linux.org
Subject: [parisc-linux] popen/pclose problem
Date: Wed, 14 Mar 2001 15:09:25 -0500	[thread overview]
Message-ID: <20010314150925.E13965@achilles.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]

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);
  }
  closelog();
  return(pclose(output));
}

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

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

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

                 reply	other threads:[~2001-03-14 20:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010314150925.E13965@achilles.net \
    --to=pjlahaie@linuxcare.com \
    --cc=parisc-linux@parisc-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox