1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-25 01:42:45 +02:00

* exec.h, exec.c (make_tempdir, expand_args, exec_write, exec_read):

Minor cleanup to use bitfield flags instead of a bunch of integers.
This commit is contained in:
David Shaw 2005-08-21 14:20:27 +00:00
parent 5cb51422f9
commit 2e8c02b54b
3 changed files with 38 additions and 24 deletions

View File

@ -1,3 +1,9 @@
2005-08-21 David Shaw <dshaw@jabberwocky.com>
* exec.h, exec.c (make_tempdir, expand_args, exec_write,
exec_read): Minor cleanup to use bitfield flags instead of a bunch
of integers.
2005-08-20 David Shaw <dshaw@jabberwocky.com> 2005-08-20 David Shaw <dshaw@jabberwocky.com>
* g10.c (main): Add aliases sign-with->local-user and * g10.c (main): Add aliases sign-with->local-user and

View File

@ -120,9 +120,9 @@ static int make_tempdir(struct exec_info *info)
char *tmp=opt.temp_dir,*namein=info->name,*nameout; char *tmp=opt.temp_dir,*namein=info->name,*nameout;
if(!namein) if(!namein)
namein=info->binary?"tempin" EXTSEP_S "bin":"tempin" EXTSEP_S "txt"; namein=info->flags.binary?"tempin" EXTSEP_S "bin":"tempin" EXTSEP_S "txt";
nameout=info->binary?"tempout" EXTSEP_S "bin":"tempout" EXTSEP_S "txt"; nameout=info->flags.binary?"tempout" EXTSEP_S "bin":"tempout" EXTSEP_S "txt";
/* Make up the temp dir and files in case we need them */ /* Make up the temp dir and files in case we need them */
@ -174,13 +174,13 @@ static int make_tempdir(struct exec_info *info)
info->tempdir,strerror(errno)); info->tempdir,strerror(errno));
else else
{ {
info->madedir=1; info->flags.madedir=1;
info->tempfile_in=xmalloc(strlen(info->tempdir)+ info->tempfile_in=xmalloc(strlen(info->tempdir)+
strlen(DIRSEP_S)+strlen(namein)+1); strlen(DIRSEP_S)+strlen(namein)+1);
sprintf(info->tempfile_in,"%s" DIRSEP_S "%s",info->tempdir,namein); sprintf(info->tempfile_in,"%s" DIRSEP_S "%s",info->tempdir,namein);
if(!info->writeonly) if(!info->flags.writeonly)
{ {
info->tempfile_out=xmalloc(strlen(info->tempdir)+ info->tempfile_out=xmalloc(strlen(info->tempdir)+
strlen(DIRSEP_S)+strlen(nameout)+1); strlen(DIRSEP_S)+strlen(nameout)+1);
@ -188,7 +188,7 @@ static int make_tempdir(struct exec_info *info)
} }
} }
return info->madedir?0:G10ERR_GENERAL; return info->flags.madedir?0:G10ERR_GENERAL;
} }
/* Expands %i and %o in the args to the full temp files within the /* Expands %i and %o in the args to the full temp files within the
@ -198,8 +198,8 @@ static int expand_args(struct exec_info *info,const char *args_in)
const char *ch=args_in; const char *ch=args_in;
unsigned int size,len; unsigned int size,len;
info->use_temp_files=0; info->flags.use_temp_files=0;
info->keep_temp_files=0; info->flags.keep_temp_files=0;
if(DBG_EXTPROG) if(DBG_EXTPROG)
log_debug("expanding string \"%s\"\n",args_in); log_debug("expanding string \"%s\"\n",args_in);
@ -220,31 +220,31 @@ static int expand_args(struct exec_info *info,const char *args_in)
switch(*ch) switch(*ch)
{ {
case 'O': case 'O':
info->keep_temp_files=1; info->flags.keep_temp_files=1;
/* fall through */ /* fall through */
case 'o': /* out */ case 'o': /* out */
if(!info->madedir) if(!info->flags.madedir)
{ {
if(make_tempdir(info)) if(make_tempdir(info))
goto fail; goto fail;
} }
append=info->tempfile_out; append=info->tempfile_out;
info->use_temp_files=1; info->flags.use_temp_files=1;
break; break;
case 'I': case 'I':
info->keep_temp_files=1; info->flags.keep_temp_files=1;
/* fall through */ /* fall through */
case 'i': /* in */ case 'i': /* in */
if(!info->madedir) if(!info->flags.madedir)
{ {
if(make_tempdir(info)) if(make_tempdir(info))
goto fail; goto fail;
} }
append=info->tempfile_in; append=info->tempfile_in;
info->use_temp_files=1; info->flags.use_temp_files=1;
break; break;
case '%': case '%':
@ -285,8 +285,8 @@ static int expand_args(struct exec_info *info,const char *args_in)
} }
if(DBG_EXTPROG) if(DBG_EXTPROG)
log_debug("args expanded to \"%s\", use %d, keep %d\n", log_debug("args expanded to \"%s\", use %u, keep %u\n",info->command,
info->command,info->use_temp_files,info->keep_temp_files); info->flags.use_temp_files,info->flags.keep_temp_files);
return 0; return 0;
@ -331,15 +331,15 @@ int exec_write(struct exec_info **info,const char *program,
if(name) if(name)
(*info)->name=xstrdup(name); (*info)->name=xstrdup(name);
(*info)->binary=binary; (*info)->flags.binary=binary;
(*info)->writeonly=writeonly; (*info)->flags.writeonly=writeonly;
/* Expand the args, if any */ /* Expand the args, if any */
if(args_in && expand_args(*info,args_in)) if(args_in && expand_args(*info,args_in))
goto fail; goto fail;
#ifdef EXEC_TEMPFILE_ONLY #ifdef EXEC_TEMPFILE_ONLY
if(!(*info)->use_temp_files) if(!(*info)->flags.use_temp_files)
{ {
log_error(_("this platform requires temporary files when calling" log_error(_("this platform requires temporary files when calling"
" external programs\n")); " external programs\n"));
@ -350,7 +350,7 @@ int exec_write(struct exec_info **info,const char *program,
/* If there are no args, or there are args, but no temp files, we /* If there are no args, or there are args, but no temp files, we
can use fork/exec/pipe */ can use fork/exec/pipe */
if(args_in==NULL || (*info)->use_temp_files==0) if(args_in==NULL || (*info)->flags.use_temp_files==0)
{ {
int to[2],from[2]; int to[2],from[2];
@ -384,7 +384,7 @@ int exec_write(struct exec_info **info,const char *program,
/* If the program isn't going to respond back, they get to /* If the program isn't going to respond back, they get to
keep their stdout/stderr */ keep their stdout/stderr */
if(!(*info)->writeonly) if(!(*info)->flags.writeonly)
{ {
/* implied close of STDERR */ /* implied close of STDERR */
if(dup2(STDOUT_FILENO,STDERR_FILENO)==-1) if(dup2(STDOUT_FILENO,STDERR_FILENO)==-1)
@ -494,7 +494,7 @@ int exec_read(struct exec_info *info)
fclose(info->tochild); fclose(info->tochild);
info->tochild=NULL; info->tochild=NULL;
if(info->use_temp_files) if(info->flags.use_temp_files)
{ {
if(DBG_EXTPROG) if(DBG_EXTPROG)
log_debug("system() command is %s\n",info->command); log_debug("system() command is %s\n",info->command);
@ -537,7 +537,7 @@ int exec_read(struct exec_info *info)
goto fail; goto fail;
} }
if(!info->writeonly) if(!info->flags.writeonly)
{ {
info->fromchild=iobuf_open(info->tempfile_out); info->fromchild=iobuf_open(info->tempfile_out);
if (info->fromchild if (info->fromchild
@ -590,7 +590,7 @@ int exec_finish(struct exec_info *info)
} }
#endif #endif
if(info->madedir && !info->keep_temp_files) if(info->flags.madedir && !info->flags.keep_temp_files)
{ {
if(info->tempfile_in) if(info->tempfile_in)
{ {

View File

@ -28,7 +28,15 @@
struct exec_info struct exec_info
{ {
int progreturn,binary,writeonly,madedir,use_temp_files,keep_temp_files; int progreturn;
struct
{
unsigned int binary:1;
unsigned int writeonly:1;
unsigned int madedir:1;
unsigned int use_temp_files:1;
unsigned int keep_temp_files:1;
} flags;
pid_t child; pid_t child;
FILE *tochild; FILE *tochild;
IOBUF fromchild; IOBUF fromchild;