diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 027e1eff..7697ff12 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -5261,12 +5261,13 @@ with the GPGME API. The function @code{gpgme_op_spawn} runs the program @var{file} with the arguments taken from the NULL terminated array @var{argv}. If no -arguments are required @var{argv} may be given as @code{NULL} (in that -case GPGME uses the basename of @var{file} for @code{argv[0]}). The -file descriptors @code{stdin}, @code{stdout}, and @code{stderr} are -connected to the data objects @var{datain}, @var{dataout}, and -@var{dataerr}. If NULL is passed for one of these data objects the -corresponding file descriptor is connected to @file{/dev/null}. +arguments are required @var{argv} may be given as @code{NULL}. In the +latter case or if @code{argv[0]} is the empty string, GPGME uses the +basename of @var{file} for @code{argv[0]}. The file descriptors +@code{stdin}, @code{stdout}, and @code{stderr} are connected to the +data objects @var{datain}, @var{dataout}, and @var{dataerr}. If NULL +is passed for one of these data objects the corresponding file +descriptor is connected to @file{/dev/null}. The value in @var{flags} is a bitwise-or combination of one or multiple of the following bit values: diff --git a/src/engine-backend.h b/src/engine-backend.h index dbb9e932..b3cc412a 100644 --- a/src/engine-backend.h +++ b/src/engine-backend.h @@ -130,7 +130,7 @@ struct engine_ops const char *file, const char *argv[], gpgme_data_t datain, gpgme_data_t dataout, - gpgme_data_t dataerr); + gpgme_data_t dataerr, unsigned int flags); }; diff --git a/src/engine-spawn.c b/src/engine-spawn.c index 1e71c1cc..bfcad3d9 100644 --- a/src/engine-spawn.c +++ b/src/engine-spawn.c @@ -231,6 +231,7 @@ engspawn_start (engine_spawn_t esp, const char *file, const char *argv[], struct spawn_fd_item_s *fd_list; pid_t pid; unsigned int spflags; + const char *save_argv0 = NULL; if (!esp || !file || !argv || !argv[0]) return gpg_error (GPG_ERR_INV_VALUE); @@ -264,8 +265,15 @@ engspawn_start (engine_spawn_t esp, const char *file, const char *argv[], fd_list[n].fd = -1; fd_list[n].dup_to = -1; + if (argv[0] && !*argv[0]) + { + save_argv0 = argv[0]; + argv[0] = _gpgme_get_basename (file); + } status = _gpgme_io_spawn (file, (char * const *)argv, spflags, fd_list, NULL, NULL, &pid); + if (save_argv0) + argv[0] = save_argv0; free (fd_list); if (status == -1) return gpg_error_from_syserror (); diff --git a/src/engine.c b/src/engine.c index f5034306..ff015c00 100644 --- a/src/engine.c +++ b/src/engine.c @@ -944,7 +944,8 @@ gpgme_error_t _gpgme_engine_op_spawn (engine_t engine, const char *file, const char *argv[], gpgme_data_t datain, - gpgme_data_t dataout, gpgme_data_t dataerr) + gpgme_data_t dataout, gpgme_data_t dataerr, + unsigned int flags) { if (!engine) return gpg_error (GPG_ERR_INV_VALUE); @@ -953,5 +954,5 @@ _gpgme_engine_op_spawn (engine_t engine, return gpg_error (GPG_ERR_NOT_IMPLEMENTED); return (*engine->ops->opspawn) (engine->engine, file, argv, - datain, dataout, dataerr); + datain, dataout, dataerr, flags); } diff --git a/src/engine.h b/src/engine.h index ade7de15..bbf009d6 100644 --- a/src/engine.h +++ b/src/engine.h @@ -167,7 +167,8 @@ gpgme_error_t _gpgme_engine_op_spawn (engine_t engine, const char *file, const char *argv[], gpgme_data_t datain, gpgme_data_t dataout, - gpgme_data_t dataerr); + gpgme_data_t dataerr, + unsigned int flags); #endif /* ENGINE_H */ diff --git a/src/spawn.c b/src/spawn.c index e3454f3b..7b3b4476 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -34,7 +34,8 @@ static gpgme_error_t spawn_start (gpgme_ctx_t ctx, int synchronous, const char *file, const char *argv[], gpgme_data_t datain, - gpgme_data_t dataout, gpgme_data_t dataerr) + gpgme_data_t dataout, gpgme_data_t dataerr, + unsigned int flags) { gpgme_error_t err; const char *tmp_argv[2]; @@ -54,7 +55,7 @@ spawn_start (gpgme_ctx_t ctx, int synchronous, } return _gpgme_engine_op_spawn (ctx->engine, file, argv, - datain, dataout, dataerr); + datain, dataout, dataerr, flags); } @@ -75,7 +76,7 @@ gpgme_op_spawn_start (gpgme_ctx_t ctx, const char *file, const char *argv[], if (!ctx) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); - err = spawn_start (ctx, 0, file, argv, datain, dataout, dataerr); + err = spawn_start (ctx, 0, file, argv, datain, dataout, dataerr, flags); return err; } @@ -97,7 +98,7 @@ gpgme_op_spawn (gpgme_ctx_t ctx, const char *file, const char *argv[], if (!ctx) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); - err = spawn_start (ctx, 1, file, argv, datain, dataout, dataerr); + err = spawn_start (ctx, 1, file, argv, datain, dataout, dataerr, flags); if (!err) err = _gpgme_wait_one (ctx);