summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-11 23:09:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-11 23:09:57 -0700
commit50e8eeacba515a73d21eebfddee84a299de51895 (patch)
treeac006e06475e9f409470ee4700fb4f89304cbc51 /txr.c
parentcc11af59cfd039558f9bdac872b2cf0d8ff1e446 (diff)
downloadtxr-50e8eeacba515a73d21eebfddee84a299de51895.tar.gz
txr-50e8eeacba515a73d21eebfddee84a299de51895.tar.bz2
txr-50e8eeacba515a73d21eebfddee84a299de51895.zip
txr: fix inappropriate "takes no argument".
txr is reporting "option --<foo> takes no argument" for any unknown option <foo>, which is silly. * txr.c (no_dbg_support): Drop setuid privilege here before doing the output. (txr_main): Block that diagnoses "takes no argument" is now reachable only by goto. Every no-argument option tests the org variable and branches there if there are arguments. Some rearrangement of drop_privilege() calls and insertion of missing ones via it now being called in no_dbug_support.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/txr.c b/txr.c
index 888fa4da..843a0713 100644
--- a/txr.c
+++ b/txr.c
@@ -483,6 +483,7 @@ static void free_all(void)
#ifndef CONFIG_DEBUG_SUPPORT
static void no_dbg_support(val arg)
{
+ drop_privilege();
format(std_error,
lit("~a: option ~a requires debug support compiled in\n"),
prog_string, arg, nao);
@@ -689,7 +690,7 @@ int txr_main(int argc, char **argv)
}
/* Long opts with no arguments */
- if (org) {
+ if (0) noarg: {
drop_privilege();
format(std_error,
lit("~a: option --~a takes no argument, ~a given\n"),
@@ -698,6 +699,8 @@ int txr_main(int argc, char **argv)
}
if (equal(opt, lit("version"))) {
+ if (org)
+ goto noarg;
drop_privilege();
format(std_output, lit("~a: version ~a\n"),
prog_string, static_str(version), nao);
@@ -705,6 +708,8 @@ int txr_main(int argc, char **argv)
}
if (equal(opt, lit("build-id"))) {
+ if (org)
+ goto noarg;
drop_privilege();
#ifdef TXR_BUILD_ID
format(std_output, lit("~a\n"), static_str(build_id), nao);
@@ -719,46 +724,65 @@ int txr_main(int argc, char **argv)
}
if (equal(opt, lit("license"))) {
+ if (org)
+ goto noarg;
drop_privilege();
return license();
}
if (equal(opt, lit("gc-debug"))) {
+ if (org)
+ goto noarg;
drop_privilege();
opt_gc_debug = 1;
continue;
} else if (equal(opt, lit("vg-debug"))) {
- drop_privilege();
#if HAVE_VALGRIND
+ if (org)
+ goto noarg;
+ drop_privilege();
opt_vg_debug = 1;
continue;
#else
+ drop_privilege();
format(std_error,
lit("~a: option ~a requires Valgrind support compiled in\n"),
prog_string, arg, nao);
return EXIT_FAILURE;
#endif
} else if (equal(opt, lit("dv-regex"))) {
+ if (org)
+ goto noarg;
opt_derivative_regex = 1;
continue;
} else if (equal(opt, lit("lisp-bindings"))) {
+ if (org)
+ goto noarg;
opt_lisp_bindings = 1;
opt_print_bindings = 1;
continue;
} else if (equal(opt, lit("lisp"))) {
+ if (org)
+ goto noarg;
txr_lisp_p = t;
continue;
} else if (equal(opt, lit("compiled"))) {
+ if (org)
+ goto noarg;
txr_lisp_p = chr('o');
continue;
#if HAVE_FORK_STUFF
} else if (equal(opt, lit("reexec"))) {
+ if (org)
+ goto noarg;
exec_wrap(prog_path, arg_list);
return EXIT_FAILURE;
#endif
} else if (equal(opt, lit("debugger"))) {
- drop_privilege();
#if CONFIG_DEBUG_SUPPORT
+ if (org)
+ goto noarg;
+ drop_privilege();
opt_debugger = 1;
debug_set(DBG_ENABLE | DBG_BACKTRACE);
continue;
@@ -767,8 +791,10 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
#endif
} else if (equal(opt, lit("debug-autoload"))) {
- drop_privilege();
#if CONFIG_DEBUG_SUPPORT
+ if (org)
+ goto noarg;
+ drop_privilege();
opt_debugger = 1;
opt_dbg_autoload = 1;
debug_set(DBG_ENABLE | DBG_BACKTRACE);
@@ -778,8 +804,10 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
#endif
} else if (equal(opt, lit("debug-expansion"))) {
- drop_privilege();
#if CONFIG_DEBUG_SUPPORT
+ if (org)
+ goto noarg;
+ drop_privilege();
opt_debugger = 1;
opt_dbg_expansion = 1;
debug_set(DBG_ENABLE | DBG_BACKTRACE);
@@ -789,6 +817,8 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
#endif
} else if (equal(opt, lit("yydebug"))) {
+ if (org)
+ goto noarg;
drop_privilege();
if (have_yydebug) {
yydebug_onoff(1);
@@ -804,6 +834,8 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
}
} else if (equal(opt, lit("backtrace"))) {
+ if (org)
+ goto noarg;
#if CONFIG_DEBUG_SUPPORT
debug_set(DBG_BACKTRACE);
continue;
@@ -812,13 +844,19 @@ int txr_main(int argc, char **argv)
return EXIT_FAILURE;
#endif
} else if (equal(opt, lit("noninteractive"))) {
+ if (org)
+ goto noarg;
opt_noninteractive = 1;
stream_set_prop(std_input, real_time_k, nil);
continue;
} else if (equal(opt, lit("free-all"))) {
+ if (org)
+ goto noarg;
atexit(free_all);
continue;
} else if (equal(opt, lit("noprofile"))) {
+ if (org)
+ goto noarg;
opt_noprofile = 1;
continue;
} else {