From e77b643b4a7e30f64a3c28f6968b60a0a4ff7fcf Mon Sep 17 00:00:00 2001 From: David Shaw Date: Wed, 29 May 2002 18:46:49 +0000 Subject: [PATCH] * 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. --- g10/ChangeLog | 10 +++++++++ g10/exec.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++---- g10/options.h | 2 ++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 45a6354a0..8289b8694 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,13 @@ +2002-05-29 David Shaw + + * 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 * encode.c (encode_simple): Intialize PKT when --no-literal is used. diff --git a/g10/exec.c b/g10/exec.c index 7afd3eada..8aa87dd0c 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -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) { diff --git a/g10/options.h b/g10/options.h index 3f274d6b5..e7df37fe2 100644 --- a/g10/options.h +++ b/g10/options.h @@ -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*/