2001-12-21 23:09:41 +00:00
|
|
|
/* exec.c - generic call-a-program code
|
2002-04-29 14:42:34 +00:00
|
|
|
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
2001-12-21 23:09:41 +00:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2001-12-27 20:48:05 +00:00
|
|
|
#ifndef EXEC_TEMPFILE_ONLY
|
2001-12-21 23:09:41 +00:00
|
|
|
#include <sys/wait.h>
|
2001-12-23 12:40:04 +00:00
|
|
|
#endif
|
2002-01-09 14:58:59 +00:00
|
|
|
#ifdef HAVE_DOSISH_SYSTEM
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2001-12-21 23:09:41 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "options.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "i18n.h"
|
|
|
|
#include "iobuf.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "exec.h"
|
|
|
|
|
2002-05-03 12:35:51 +00:00
|
|
|
#ifdef NO_EXEC
|
|
|
|
int exec_write(struct exec_info **info,const char *program,
|
|
|
|
const char *args_in,int writeonly,int binary)
|
|
|
|
{
|
|
|
|
log_error(_("no remote program execution supported\n"));
|
|
|
|
return G10ERR_GENERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exec_read(struct exec_info *info) { return G10ERR_GENERAL; }
|
|
|
|
int exec_finish(struct exec_info *info) { return G10ERR_GENERAL; }
|
|
|
|
|
|
|
|
#else /* ! NO_EXEC */
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
#ifndef HAVE_MKDTEMP
|
|
|
|
char *mkdtemp(char *template);
|
|
|
|
#endif
|
|
|
|
|
2002-05-29 18:46:49 +00:00
|
|
|
#if defined (__MINGW32__) || defined (__CYGWIN32__)
|
|
|
|
/* This is a nicer system() for windows that waits for programs to
|
|
|
|
return before returning control to the caller. I hate helpful
|
|
|
|
computers. */
|
|
|
|
static int win_system(const char *command)
|
|
|
|
{
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
char *string;
|
|
|
|
|
|
|
|
/* We must use a copy of the command as CreateProcess modifies this
|
|
|
|
argument. */
|
|
|
|
string=m_strdup(command);
|
|
|
|
|
|
|
|
memset(&pi,0,sizeof(pi));
|
|
|
|
memset(&si,0,sizeof(si));
|
|
|
|
si.cb=sizeof(si);
|
|
|
|
|
|
|
|
if(!CreateProcess(NULL,string,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Wait for the child to exit */
|
|
|
|
WaitForSingleObject(pi.hProcess,INFINITE);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
m_free(string);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
/* Makes a temp directory and filenames */
|
|
|
|
static int make_tempdir(struct exec_info *info)
|
|
|
|
{
|
2002-05-13 20:44:30 +00:00
|
|
|
char *tmp=opt.temp_dir,*name=info->name;
|
2002-05-04 00:39:15 +00:00
|
|
|
|
2002-05-13 20:44:30 +00:00
|
|
|
if(!name)
|
2002-05-13 23:07:22 +00:00
|
|
|
name=info->binary?"tempfile" EXTSEP_S "bin":"tempfile" EXTSEP_S "txt";
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
/* Make up the temp dir and files in case we need them */
|
2002-05-05 19:44:22 +00:00
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
if(tmp==NULL)
|
|
|
|
{
|
2002-05-05 19:44:22 +00:00
|
|
|
#if defined (__MINGW32__) || defined (__CYGWIN32__)
|
|
|
|
tmp=m_alloc(256);
|
|
|
|
if(GetTempPath(256,tmp)==0)
|
2002-05-14 09:57:32 +00:00
|
|
|
strcpy(tmp,"c:\\windows\\temp");
|
2002-05-05 19:44:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int len=strlen(tmp);
|
|
|
|
|
|
|
|
/* GetTempPath may return with \ on the end */
|
|
|
|
while(len>0 && tmp[len-1]=='\\')
|
|
|
|
{
|
|
|
|
tmp[len-1]='\0';
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* More unixish systems */
|
2001-12-21 23:09:41 +00:00
|
|
|
tmp=getenv("TMPDIR");
|
|
|
|
if(tmp==NULL)
|
|
|
|
{
|
|
|
|
tmp=getenv("TMP");
|
|
|
|
if(tmp==NULL)
|
|
|
|
{
|
|
|
|
#ifdef __riscos__
|
2002-04-22 15:49:31 +00:00
|
|
|
tmp="<Wimp$ScrapDir>.GnuPG";
|
|
|
|
mkdir(tmp,0700); /* Error checks occur later on */
|
2001-12-21 23:09:41 +00:00
|
|
|
#else
|
|
|
|
tmp="/tmp";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2002-05-05 19:44:22 +00:00
|
|
|
#endif
|
2001-12-21 23:09:41 +00:00
|
|
|
}
|
|
|
|
|
2002-04-08 15:10:51 +00:00
|
|
|
info->tempdir=m_alloc(strlen(tmp)+strlen(DIRSEP_S)+10+1);
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
sprintf(info->tempdir,"%s" DIRSEP_S "gpg-XXXXXX",tmp);
|
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
#if defined (__MINGW32__) || defined (__CYGWIN32__)
|
2001-12-22 15:22:59 +00:00
|
|
|
m_free(tmp);
|
|
|
|
#endif
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
if(mkdtemp(info->tempdir)==NULL)
|
|
|
|
log_error(_("%s: can't create directory: %s\n"),
|
|
|
|
info->tempdir,strerror(errno));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->madedir=1;
|
|
|
|
|
2002-05-13 20:44:30 +00:00
|
|
|
info->tempfile_in=m_alloc(strlen(info->tempdir)+
|
|
|
|
strlen(DIRSEP_S)+strlen(name)+1);
|
|
|
|
sprintf(info->tempfile_in,"%s" DIRSEP_S "%s",info->tempdir,name);
|
2001-12-21 23:09:41 +00:00
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
if(!info->writeonly)
|
|
|
|
{
|
2002-05-13 20:44:30 +00:00
|
|
|
info->tempfile_out=m_alloc(strlen(info->tempdir)+
|
|
|
|
strlen(DIRSEP_S)+strlen(name)+1);
|
|
|
|
sprintf(info->tempfile_out,"%s" DIRSEP_S "%s",info->tempdir,name);
|
2001-12-27 20:48:05 +00:00
|
|
|
}
|
2001-12-21 23:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return info->madedir?0:G10ERR_GENERAL;
|
|
|
|
}
|
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
/* Expands %i and %o in the args to the full temp files within the
|
|
|
|
temp directory. */
|
2001-12-21 23:09:41 +00:00
|
|
|
static int expand_args(struct exec_info *info,const char *args_in)
|
|
|
|
{
|
|
|
|
const char *ch=args_in;
|
|
|
|
int size,len;
|
|
|
|
|
|
|
|
info->use_temp_files=0;
|
|
|
|
info->keep_temp_files=0;
|
|
|
|
|
2002-05-29 18:46:49 +00:00
|
|
|
if(DBG_EXTPROG)
|
|
|
|
log_debug("expanding string \"%s\"\n",args_in);
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
size=100;
|
|
|
|
info->command=m_alloc(size);
|
|
|
|
len=0;
|
|
|
|
info->command[0]='\0';
|
|
|
|
|
|
|
|
while(*ch!='\0')
|
|
|
|
{
|
|
|
|
if(*ch=='%')
|
|
|
|
{
|
|
|
|
char *append=NULL;
|
|
|
|
|
|
|
|
ch++;
|
|
|
|
|
|
|
|
switch(*ch)
|
|
|
|
{
|
|
|
|
case 'O':
|
|
|
|
info->keep_temp_files=1;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case 'o': /* out */
|
|
|
|
if(!info->madedir)
|
|
|
|
{
|
|
|
|
if(make_tempdir(info))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
append=info->tempfile_out;
|
|
|
|
info->use_temp_files=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
info->keep_temp_files=1;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case 'i': /* in */
|
|
|
|
if(!info->madedir)
|
|
|
|
{
|
|
|
|
if(make_tempdir(info))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
append=info->tempfile_in;
|
|
|
|
info->use_temp_files=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
append="%";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(append)
|
|
|
|
{
|
|
|
|
while(strlen(append)+len>size-1)
|
|
|
|
{
|
|
|
|
size+=100;
|
|
|
|
info->command=m_realloc(info->command,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(info->command,append);
|
|
|
|
len+=strlen(append);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(len==size-1) /* leave room for the \0 */
|
|
|
|
{
|
|
|
|
size+=100;
|
|
|
|
info->command=m_realloc(info->command,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
info->command[len++]=*ch;
|
|
|
|
info->command[len]='\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
ch++;
|
|
|
|
}
|
|
|
|
|
2002-05-29 18:46:49 +00:00
|
|
|
if(DBG_EXTPROG)
|
|
|
|
log_debug("args expanded to \"%s\", use %d, keep %d\n",
|
|
|
|
info->command,info->use_temp_files,info->keep_temp_files);
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
m_free(info->command);
|
|
|
|
info->command=NULL;
|
|
|
|
|
|
|
|
return G10ERR_GENERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Either handles the tempfile creation, or the fork/exec. If it
|
2001-12-27 20:48:05 +00:00
|
|
|
returns ok, then info->tochild is a FILE * that can be written to.
|
|
|
|
The rules are: if there are no args, then it's a fork/exec/pipe.
|
2001-12-21 23:09:41 +00:00
|
|
|
If there are args, but no tempfiles, then it's a fork/exec/pipe via
|
2001-12-22 15:22:59 +00:00
|
|
|
shell -c. If there are tempfiles, then it's a system. */
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
int exec_write(struct exec_info **info,const char *program,
|
2002-05-13 20:44:30 +00:00
|
|
|
const char *args_in,const char *name,int writeonly,int binary)
|
2001-12-21 23:09:41 +00:00
|
|
|
{
|
|
|
|
int ret=G10ERR_GENERAL;
|
|
|
|
|
|
|
|
if(opt.exec_disable && !opt.no_perm_warn)
|
|
|
|
{
|
|
|
|
log_info(_("external program calls are disabled due to unsafe "
|
|
|
|
"options file permissions\n"));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
/* There should be no way to get to this spot while still carrying
|
|
|
|
setuid privs. Just in case, bomb out if we are. */
|
|
|
|
if(getuid()!=geteuid())
|
|
|
|
BUG();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(program==NULL && args_in==NULL)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
*info=m_alloc_clear(sizeof(struct exec_info));
|
|
|
|
|
2002-05-13 20:44:30 +00:00
|
|
|
if(name)
|
|
|
|
(*info)->name=m_strdup(name);
|
2001-12-21 23:09:41 +00:00
|
|
|
(*info)->binary=binary;
|
|
|
|
(*info)->writeonly=writeonly;
|
|
|
|
|
|
|
|
/* Expand the args, if any */
|
|
|
|
if(args_in && expand_args(*info,args_in))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
#ifdef EXEC_TEMPFILE_ONLY
|
|
|
|
if(!(*info)->use_temp_files)
|
|
|
|
{
|
|
|
|
log_error(_("this platform requires temp files when calling external "
|
|
|
|
"programs\n"));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !EXEC_TEMPFILE_ONLY */
|
|
|
|
|
|
|
|
/* If there are no args, or there are args, but no temp files, we
|
|
|
|
can use fork/exec/pipe */
|
|
|
|
if(args_in==NULL || (*info)->use_temp_files==0)
|
|
|
|
{
|
|
|
|
int to[2],from[2];
|
|
|
|
|
|
|
|
if(pipe(to)==-1)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if(pipe(from)==-1)
|
|
|
|
{
|
|
|
|
close(to[0]);
|
|
|
|
close(to[1]);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(((*info)->child=fork())==-1)
|
|
|
|
{
|
|
|
|
close(to[0]);
|
|
|
|
close(to[1]);
|
|
|
|
close(from[0]);
|
|
|
|
close(from[1]);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((*info)->child==0)
|
|
|
|
{
|
|
|
|
char *shell=getenv("SHELL");
|
|
|
|
|
|
|
|
if(shell==NULL)
|
|
|
|
shell="/bin/sh";
|
|
|
|
|
|
|
|
/* I'm the child */
|
|
|
|
|
|
|
|
/* If the program isn't going to respond back, they get to
|
|
|
|
keep their stdout/stderr */
|
|
|
|
if(!(*info)->writeonly)
|
|
|
|
{
|
|
|
|
/* implied close of STDERR */
|
|
|
|
if(dup2(STDOUT_FILENO,STDERR_FILENO)==-1)
|
|
|
|
_exit(1);
|
|
|
|
|
|
|
|
/* implied close of STDOUT */
|
|
|
|
close(from[0]);
|
|
|
|
if(dup2(from[1],STDOUT_FILENO)==-1)
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* implied close of STDIN */
|
|
|
|
close(to[1]);
|
|
|
|
if(dup2(to[0],STDIN_FILENO)==-1)
|
|
|
|
_exit(1);
|
|
|
|
|
|
|
|
if(args_in==NULL)
|
|
|
|
{
|
2002-05-29 18:46:49 +00:00
|
|
|
if(DBG_EXTPROG)
|
|
|
|
log_debug("execlp: %s\n",program);
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
execlp(program,program,NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-29 18:46:49 +00:00
|
|
|
if(DBG_EXTPROG)
|
|
|
|
log_debug("execlp: %s -c %s\n",shell,(*info)->command);
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
execlp(shell,shell,"-c",(*info)->command,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get this far the exec failed. Clean up and return. */
|
|
|
|
|
|
|
|
log_error(_("unable to execute %s \"%s\": %s\n"),
|
|
|
|
args_in==NULL?"program":"shell",
|
|
|
|
args_in==NULL?program:shell,
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
if(errno==ENOENT)
|
|
|
|
_exit(127);
|
|
|
|
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I'm the parent */
|
|
|
|
|
|
|
|
close(to[0]);
|
|
|
|
|
|
|
|
(*info)->tochild=fdopen(to[1],binary?"wb":"w");
|
|
|
|
if((*info)->tochild==NULL)
|
|
|
|
{
|
|
|
|
close(to[1]);
|
|
|
|
ret=G10ERR_WRITE_FILE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(from[1]);
|
|
|
|
|
|
|
|
(*info)->fromchild=iobuf_fdopen(from[0],"r");
|
|
|
|
if((*info)->fromchild==NULL)
|
|
|
|
{
|
|
|
|
close(from[0]);
|
|
|
|
ret=G10ERR_READ_FILE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2002-01-27 05:56:35 +00:00
|
|
|
/* fd iobufs are cached?! */
|
|
|
|
iobuf_ioctl((*info)->fromchild,3,1,NULL);
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* !EXEC_TEMPFILE_ONLY */
|
|
|
|
|
2002-05-29 18:46:49 +00:00
|
|
|
if(DBG_EXTPROG)
|
|
|
|
log_debug("using temp file \"%s\"\n",(*info)->tempfile_in);
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
/* It's not fork/exec/pipe, so create a temp file */
|
|
|
|
(*info)->tochild=fopen((*info)->tempfile_in,binary?"wb":"w");
|
|
|
|
if((*info)->tochild==NULL)
|
|
|
|
{
|
|
|
|
log_error(_("%s: can't create: %s\n"),
|
|
|
|
(*info)->tempfile_in,strerror(errno));
|
|
|
|
ret=G10ERR_WRITE_FILE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
ret=0;
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exec_read(struct exec_info *info)
|
|
|
|
{
|
|
|
|
int ret=G10ERR_GENERAL;
|
|
|
|
|
|
|
|
fclose(info->tochild);
|
|
|
|
info->tochild=NULL;
|
|
|
|
|
|
|
|
if(info->use_temp_files)
|
|
|
|
{
|
2002-05-29 18:46:49 +00:00
|
|
|
if(DBG_EXTPROG)
|
|
|
|
log_debug("system() command is %s\n",info->command);
|
2001-12-21 23:09:41 +00:00
|
|
|
|
2002-05-29 18:46:49 +00:00
|
|
|
#if defined (__MINGW32__) || defined (__CYGWIN32__)
|
|
|
|
info->progreturn=win_system(info->command);
|
|
|
|
#else
|
2001-12-21 23:09:41 +00:00
|
|
|
info->progreturn=system(info->command);
|
2002-05-29 18:46:49 +00:00
|
|
|
#endif
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
if(info->progreturn==-1)
|
|
|
|
{
|
|
|
|
log_error(_("system error while calling external program: %s\n"),
|
|
|
|
strerror(errno));
|
2001-12-27 20:48:05 +00:00
|
|
|
info->progreturn=127;
|
2001-12-21 23:09:41 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2001-12-27 20:48:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef WEXITSTATUS
|
|
|
|
info->progreturn=WEXITSTATUS(info->progreturn);
|
|
|
|
#else
|
|
|
|
info->progreturn/=256;
|
|
|
|
#endif
|
|
|
|
}
|
2001-12-21 23:09:41 +00:00
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
/* 127 is the magic value returned from system() to indicate
|
|
|
|
that the shell could not be executed, or from /bin/sh to
|
|
|
|
indicate that the program could not be executed. */
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
if(info->progreturn==127)
|
|
|
|
{
|
|
|
|
log_error(_("unable to execute external program\n"));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!info->writeonly)
|
|
|
|
{
|
|
|
|
info->fromchild=iobuf_open(info->tempfile_out);
|
|
|
|
if(info->fromchild==NULL)
|
|
|
|
{
|
|
|
|
log_error(_("unable to read external program response: %s\n"),
|
|
|
|
strerror(errno));
|
|
|
|
ret=G10ERR_READ_FILE;
|
|
|
|
goto fail;
|
|
|
|
}
|
2002-01-03 20:03:14 +00:00
|
|
|
|
|
|
|
/* Do not cache this iobuf on close */
|
|
|
|
iobuf_ioctl(info->fromchild,3,1,NULL);
|
2001-12-21 23:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
ret=0;
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exec_finish(struct exec_info *info)
|
|
|
|
{
|
|
|
|
int ret=info->progreturn;
|
|
|
|
|
2002-01-27 05:56:35 +00:00
|
|
|
if(info->fromchild)
|
|
|
|
iobuf_close(info->fromchild);
|
|
|
|
|
|
|
|
if(info->tochild)
|
|
|
|
fclose(info->tochild);
|
|
|
|
|
2001-12-21 23:09:41 +00:00
|
|
|
#ifndef EXEC_TEMPFILE_ONLY
|
|
|
|
if(info->child>0)
|
|
|
|
{
|
|
|
|
if(waitpid(info->child,&info->progreturn,0)!=0 &&
|
|
|
|
WIFEXITED(info->progreturn))
|
|
|
|
ret=WEXITSTATUS(info->progreturn);
|
|
|
|
else
|
|
|
|
ret=127;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(info->madedir && !info->keep_temp_files)
|
|
|
|
{
|
|
|
|
if(info->tempfile_in)
|
2001-12-27 20:48:05 +00:00
|
|
|
{
|
|
|
|
if(unlink(info->tempfile_in)==-1)
|
|
|
|
log_info(_("Warning: unable to remove tempfile (%s) \"%s\": %s\n"),
|
|
|
|
"in",info->tempfile_in,strerror(errno));
|
|
|
|
}
|
2001-12-21 23:09:41 +00:00
|
|
|
|
|
|
|
if(info->tempfile_out)
|
2001-12-27 20:48:05 +00:00
|
|
|
{
|
|
|
|
if(unlink(info->tempfile_out)==-1)
|
|
|
|
log_info(_("Warning: unable to remove tempfile (%s) \"%s\": %s\n"),
|
|
|
|
"out",info->tempfile_out,strerror(errno));
|
|
|
|
}
|
2001-12-21 23:09:41 +00:00
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
if(rmdir(info->tempdir)==-1)
|
|
|
|
log_info(_("Warning: unable to remove temp directory \"%s\": %s\n"),
|
|
|
|
info->tempdir,strerror(errno));
|
2001-12-21 23:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_free(info->command);
|
2002-05-13 20:44:30 +00:00
|
|
|
m_free(info->name);
|
2001-12-21 23:09:41 +00:00
|
|
|
m_free(info->tempdir);
|
|
|
|
m_free(info->tempfile_in);
|
|
|
|
m_free(info->tempfile_out);
|
|
|
|
m_free(info);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2002-05-03 12:35:51 +00:00
|
|
|
#endif /* ! NO_EXEC */
|