Add flag for stderr to popen.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@769 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -53,7 +53,7 @@ void delete(char *);
|
|||||||
void dologout(int);
|
void dologout(int);
|
||||||
void fatal(char *);
|
void fatal(char *);
|
||||||
int ftpd_pclose(FILE *);
|
int ftpd_pclose(FILE *);
|
||||||
FILE *ftpd_popen(char *, char *);
|
FILE *ftpd_popen(char *, char *, int);
|
||||||
char *getline(char *, int);
|
char *getline(char *, int);
|
||||||
void logwtmp(char *, char *, char *);
|
void logwtmp(char *, char *, char *);
|
||||||
void lreply(int, const char *, ...);
|
void lreply(int, const char *, ...);
|
||||||
|
@@ -41,12 +41,13 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
||||||
#else
|
#else
|
||||||
static char rcsid[] = "$NetBSD: popen.c,v 1.5 1995/04/11 02:45:00 cgd Exp $";
|
static char xrcsid[] = "$NetBSD: popen.c,v 1.5 1995/04/11 02:45:00 cgd Exp $";
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
RCSID("$Id$");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -68,16 +69,16 @@ static char rcsid[] = "$NetBSD: popen.c,v 1.5 1995/04/11 02:45:00 cgd Exp $";
|
|||||||
|
|
||||||
#include <roken.h>
|
#include <roken.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Special version of popen which avoids call to shell. This ensures noone
|
* Special version of popen which avoids call to shell. This ensures
|
||||||
* may create a pipe to a hidden program as a side effect of a list or dir
|
* no one may create a pipe to a hidden program as a side effect of a
|
||||||
* command.
|
* list or dir command.
|
||||||
*/
|
*/
|
||||||
static int *pids;
|
static int *pids;
|
||||||
static int fds;
|
static int fds;
|
||||||
|
|
||||||
FILE *
|
FILE *
|
||||||
ftpd_popen(char *program, char *type)
|
ftpd_popen(char *program, char *type, int do_stderr)
|
||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
FILE *iop;
|
FILE *iop;
|
||||||
@@ -126,24 +127,25 @@ ftpd_popen(char *program, char *type)
|
|||||||
iop = NULL;
|
iop = NULL;
|
||||||
switch(pid = fork()) {
|
switch(pid = fork()) {
|
||||||
case -1: /* error */
|
case -1: /* error */
|
||||||
(void)close(pdes[0]);
|
close(pdes[0]);
|
||||||
(void)close(pdes[1]);
|
close(pdes[1]);
|
||||||
goto pfree;
|
goto pfree;
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case 0: /* child */
|
case 0: /* child */
|
||||||
if (*type == 'r') {
|
if (*type == 'r') {
|
||||||
if (pdes[1] != STDOUT_FILENO) {
|
if (pdes[1] != STDOUT_FILENO) {
|
||||||
dup2(pdes[1], STDOUT_FILENO);
|
dup2(pdes[1], STDOUT_FILENO);
|
||||||
(void)close(pdes[1]);
|
close(pdes[1]);
|
||||||
}
|
}
|
||||||
dup2(STDOUT_FILENO, STDERR_FILENO); /* stderr too! */
|
if(do_stderr)
|
||||||
(void)close(pdes[0]);
|
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||||
|
close(pdes[0]);
|
||||||
} else {
|
} else {
|
||||||
if (pdes[0] != STDIN_FILENO) {
|
if (pdes[0] != STDIN_FILENO) {
|
||||||
dup2(pdes[0], STDIN_FILENO);
|
dup2(pdes[0], STDIN_FILENO);
|
||||||
(void)close(pdes[0]);
|
close(pdes[0]);
|
||||||
}
|
}
|
||||||
(void)close(pdes[1]);
|
close(pdes[1]);
|
||||||
}
|
}
|
||||||
execv(gargv[0], gargv);
|
execv(gargv[0], gargv);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
@@ -151,10 +153,10 @@ ftpd_popen(char *program, char *type)
|
|||||||
/* parent; assume fdopen can't fail... */
|
/* parent; assume fdopen can't fail... */
|
||||||
if (*type == 'r') {
|
if (*type == 'r') {
|
||||||
iop = fdopen(pdes[0], type);
|
iop = fdopen(pdes[0], type);
|
||||||
(void)close(pdes[1]);
|
close(pdes[1]);
|
||||||
} else {
|
} else {
|
||||||
iop = fdopen(pdes[1], type);
|
iop = fdopen(pdes[1], type);
|
||||||
(void)close(pdes[0]);
|
close(pdes[0]);
|
||||||
}
|
}
|
||||||
pids[fileno(iop)] = pid;
|
pids[fileno(iop)] = pid;
|
||||||
|
|
||||||
@@ -177,7 +179,7 @@ ftpd_pclose(FILE *iop)
|
|||||||
*/
|
*/
|
||||||
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
|
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
(void)fclose(iop);
|
fclose(iop);
|
||||||
sigemptyset(&sigset);
|
sigemptyset(&sigset);
|
||||||
sigaddset(&sigset, SIGINT);
|
sigaddset(&sigset, SIGINT);
|
||||||
sigaddset(&sigset, SIGQUIT);
|
sigaddset(&sigset, SIGQUIT);
|
||||||
|
Reference in New Issue
Block a user