1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-04 20:38:50 +01:00

* options.h, exec.c: Add some debugging info, using the 1024 debug flag.

* exec.c (win_system): New system()-like function for win32 that does not
return until the child process terminates.  Of course, this doesn't help
if the process itself exits before it is finished.
This commit is contained in:
David Shaw 2002-05-29 18:46:49 +00:00
parent 9a9ae615ea
commit e77b643b4a
3 changed files with 65 additions and 4 deletions

View File

@ -1,3 +1,13 @@
2002-05-29 David Shaw <dshaw@jabberwocky.com>
* options.h, exec.c: Add some debugging info, using the 1024 debug
flag.
* exec.c (win_system): New system()-like function for win32 that
does not return until the child process terminates. Of course,
this doesn't help if the process itself exits before it is
finished.
2002-05-29 Werner Koch <wk@gnupg.org>
* encode.c (encode_simple): Intialize PKT when --no-literal is used.

View File

@ -58,6 +58,38 @@ int exec_finish(struct exec_info *info) { return G10ERR_GENERAL; }
char *mkdtemp(char *template);
#endif
#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
/* Makes a temp directory and filenames */
static int make_tempdir(struct exec_info *info)
{
@ -143,6 +175,9 @@ static int expand_args(struct exec_info *info,const char *args_in)
info->use_temp_files=0;
info->keep_temp_files=0;
if(DBG_EXTPROG)
log_debug("expanding string \"%s\"\n",args_in);
size=100;
info->command=m_alloc(size);
len=0;
@ -218,7 +253,9 @@ static int expand_args(struct exec_info *info,const char *args_in)
ch++;
}
/* printf("args expanded to \"%s\"\n",info->command); */
if(DBG_EXTPROG)
log_debug("args expanded to \"%s\", use %d, keep %d\n",
info->command,info->use_temp_files,info->keep_temp_files);
return 0;
@ -335,12 +372,16 @@ int exec_write(struct exec_info **info,const char *program,
if(args_in==NULL)
{
/* fprintf(stderr,"execing: %s\n",program); */
if(DBG_EXTPROG)
log_debug("execlp: %s\n",program);
execlp(program,program,NULL);
}
else
{
/* fprintf(stderr,"execing: %s -c %s\n",shell,(*info)->command); */
if(DBG_EXTPROG)
log_debug("execlp: %s -c %s\n",shell,(*info)->command);
execlp(shell,shell,"-c",(*info)->command,NULL);
}
@ -386,6 +427,9 @@ int exec_write(struct exec_info **info,const char *program,
}
#endif /* !EXEC_TEMPFILE_ONLY */
if(DBG_EXTPROG)
log_debug("using temp file \"%s\"\n",(*info)->tempfile_in);
/* It's not fork/exec/pipe, so create a temp file */
(*info)->tochild=fopen((*info)->tempfile_in,binary?"wb":"w");
if((*info)->tochild==NULL)
@ -411,9 +455,14 @@ int exec_read(struct exec_info *info)
if(info->use_temp_files)
{
/* printf("system command is %s\n",info->command); */
if(DBG_EXTPROG)
log_debug("system() command is %s\n",info->command);
#if defined (__MINGW32__) || defined (__CYGWIN32__)
info->progreturn=win_system(info->command);
#else
info->progreturn=system(info->command);
#endif
if(info->progreturn==-1)
{

View File

@ -180,6 +180,7 @@ struct {
#define DBG_MEMSTAT_VALUE 128 /* show memory statistics */
#define DBG_TRUST_VALUE 256 /* debug the trustdb */
#define DBG_HASHING_VALUE 512 /* debug hashing operations */
#define DBG_EXTPROG_VALUE 1024 /* debug external program calls */
#define DBG_PACKET (opt.debug & DBG_PACKET_VALUE)
@ -187,6 +188,7 @@ struct {
#define DBG_CACHE (opt.debug & DBG_CACHE_VALUE)
#define DBG_TRUST (opt.debug & DBG_TRUST_VALUE)
#define DBG_HASHING (opt.debug & DBG_HASHING_VALUE)
#define DBG_EXTPROG (opt.debug & DBG_EXTPROG_VALUE)
#endif /*G10_OPTIONS_H*/