From ba67fea5b9bb093f446dbd1ed2f88248d269d495 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 18 Apr 2023 08:04:05 +0200 Subject: gpgtar: Read common.conf for the log-file option. * common/util.h (GNUPG_MODULE_NAME_GPGTAR): New. * common/homedir.c (gnupg_module_name): Add it. * tools/gpgtar.c: Include comopt.h. (enum cmd_and_opt_values): Add oDebug. (opts): Add --debug. (any_debug): New. (main): Parse common.conf. -- Having a way to see the output of gpgtar is often useful for debugging. The only effect of the debug option is to show whether common.conf was read. --- common/homedir.c | 3 +++ common/util.h | 1 + tools/gpgtar.c | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/common/homedir.c b/common/homedir.c index 091964fc1..66e79e35c 100644 --- a/common/homedir.c +++ b/common/homedir.c @@ -1657,6 +1657,9 @@ gnupg_module_name (int which) case GNUPG_MODULE_NAME_CARD: X(bindir, "tools", "gpg-card"); + case GNUPG_MODULE_NAME_GPGTAR: + X(bindir, "tools", "gpgtar"); + default: BUG (); } diff --git a/common/util.h b/common/util.h index d80e4fb25..aa24e39e6 100644 --- a/common/util.h +++ b/common/util.h @@ -298,6 +298,7 @@ char *_gnupg_socketdir_internal (int skip_checks, unsigned *r_info); #define GNUPG_MODULE_NAME_KEYBOXD 13 #define GNUPG_MODULE_NAME_TPM2DAEMON 14 #define GNUPG_MODULE_NAME_CARD 15 +#define GNUPG_MODULE_NAME_GPGTAR 16 const char *gnupg_module_name (int which); void gnupg_module_name_flush_some (void); void gnupg_set_builddir (const char *newdir); diff --git a/tools/gpgtar.c b/tools/gpgtar.c index 64e5306b2..b2ccc9f8a 100644 --- a/tools/gpgtar.c +++ b/tools/gpgtar.c @@ -42,6 +42,7 @@ #include "../common/openpgpdefs.h" #include "../common/init.h" #include "../common/strlist.h" +#include "../common/comopt.h" #include "gpgtar.h" @@ -89,6 +90,7 @@ enum cmd_and_opt_values oTarProgram, /* Debugging. */ + oDebug, oDryRun }; @@ -145,6 +147,8 @@ static gpgrt_opt_t opts[] = { ARGPARSE_s_s (oTarArgs, "tar-args", "@"), ARGPARSE_s_s (oTarProgram, "tar", "@"), + ARGPARSE_s_s (oDebug, "debug", "@"), + ARGPARSE_end () }; @@ -166,7 +170,7 @@ static enum cmd_and_opt_values cmd = 0; static int skip_crypto = 0; static const char *files_from = NULL; static int null_names = 0; - +static int any_debug; @@ -438,6 +442,10 @@ parse_arguments (gpgrt_argparse_t *pargs, gpgrt_opt_t *popts) } break; + case oDebug: + any_debug = 1; + break; + case oDryRun: opt.dry_run = 1; break; @@ -471,6 +479,10 @@ main (int argc, char **argv) /* Set default options */ opt.status_fd = -1; + /* The configuraton directories for use by gpgrt_argparser. */ + gpgrt_set_confdir (GPGRT_CONFDIR_SYS, gnupg_sysconfdir ()); + gpgrt_set_confdir (GPGRT_CONFDIR_USER, gnupg_homedir ()); + /* Parse the command line. */ pargs.argc = &argc; pargs.argv = &argv; @@ -481,6 +493,10 @@ main (int argc, char **argv) if (log_get_errorcount (0)) exit (2); + /* Get a log file from common.conf. */ + if (!parse_comopt (GNUPG_MODULE_NAME_GPGTAR, any_debug) && comopt.logfile) + log_set_file (comopt.logfile); + /* Print a warning if an argument looks like an option. */ if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN)) { -- cgit v1.2.3