* [parisc-linux] popen/pclose problem
@ 2001-03-14 20:09 Paul J.Y. Lahaie
0 siblings, 0 replies; only message in thread
From: Paul J.Y. Lahaie @ 2001-03-14 20:09 UTC (permalink / raw)
To: parisc-linux
[-- 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 --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-03-14 20:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-03-14 20:09 [parisc-linux] popen/pclose problem Paul J.Y. Lahaie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox