size_t usvars_alloc;
size_t usvars_used;
+/* Annotate the output with extra info to aid the user. */
+static bool dev_debug;
+
static struct option const longopts[] =
{
{"ignore-environment", no_argument, NULL, 'i'},
{"null", no_argument, NULL, '0'},
{"unset", required_argument, NULL, 'u'},
{"chdir", required_argument, NULL, 'C'},
+ {"debug", no_argument, NULL, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
"), stdout);
fputs (_("\
-C, --chdir=DIR change working directory to DIR\n\
+"), stdout);
+ fputs (_("\
+ -v, --debug print verbose information for each processing step\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
{
for (size_t i = 0; i < usvars_used; ++i)
{
+ devmsg ("unset: %s\n", usvars[i]);
+
if (unsetenv (usvars[i]))
die (EXIT_CANCELED, errno, _("cannot unset %s"),
quote (usvars[i]));
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "+C:iu:0", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "+C:iu:v0", longopts, NULL)) != -1)
{
switch (optc)
{
case 'u':
append_unset_var (optarg);
break;
+ case 'v':
+ dev_debug = true;
+ break;
case '0':
opt_nul_terminate_output = true;
break;
if (ignore_environment)
{
+ devmsg ("cleaning environ\n");
static char *dummy_environ[] = { NULL };
environ = dummy_environ;
}
char *eq;
while (optind < argc && (eq = strchr (argv[optind], '=')))
{
+ devmsg ("setenv: %s\n", argv[optind]);
+
if (putenv (argv[optind]))
{
*eq = '\0';
if (newdir)
{
+ devmsg ("chdir: %s\n", quoteaf (newdir));
+
if (chdir (newdir) != 0)
die (EXIT_CANCELED, errno, _("cannot change directory to %s"),
quoteaf (newdir));
}
+ if (dev_debug)
+ {
+ devmsg ("executing: %s\n", argv[optind]);
+ for (int i=optind; i<argc; ++i)
+ devmsg (" arg[%d]= %s\n", i-optind, quote (argv[i]));
+ }
+
execvp (argv[optind], &argv[optind]);
int exit_status = errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE;