aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-11-05 05:28:55 -0400
committerMike Frysinger <vapier@gentoo.org>2021-11-05 05:28:55 -0400
commitf0fd6d2e4884177af599416d1cca0423d1b7df08 (patch)
treec585841b6076125019d1331bb85c864ce74dedf2
parentbashrc: clarify default prompt behavior (diff)
downloadsandbox-f0fd6d2e4884177af599416d1cca0423d1b7df08.tar.gz
sandbox-f0fd6d2e4884177af599416d1cca0423d1b7df08.tar.bz2
sandbox-f0fd6d2e4884177af599416d1cca0423d1b7df08.zip
sandbox: add --debug option to control SANDBOX_DEBUG
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--src/environ.c2
-rw-r--r--src/options.c14
-rw-r--r--src/sandbox.h1
3 files changed, 15 insertions, 2 deletions
diff --git a/src/environ.c b/src/environ.c
index 1535f06..81a3e5f 100644
--- a/src/environ.c
+++ b/src/environ.c
@@ -303,7 +303,7 @@ char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
if (!getenv(ENV_SANDBOX_VERBOSE))
sb_setenv(&new_environ, ENV_SANDBOX_VERBOSE, "1");
if (!getenv(ENV_SANDBOX_DEBUG))
- sb_setenv(&new_environ, ENV_SANDBOX_DEBUG, "0");
+ sb_setenv(&new_environ, ENV_SANDBOX_DEBUG, opt_debug ? "1" : "0");
if (!getenv(ENV_NOCOLOR))
sb_setenv(&new_environ, ENV_NOCOLOR, "no");
if (!getenv(ENV_SANDBOX_METHOD))
diff --git a/src/options.c b/src/options.c
index 64cd750..5332318 100644
--- a/src/options.c
+++ b/src/options.c
@@ -21,6 +21,7 @@ int opt_use_ns_time = -1;
int opt_use_ns_user = -1;
int opt_use_ns_uts = -1;
bool opt_use_bash = false;
+int opt_debug = -1;
static const struct {
const char *name;
@@ -38,6 +39,7 @@ static const struct {
{ "NAMESPACE_TIME_ENABLE", &opt_use_ns_time, false, },
{ "NAMESPACE_USER_ENABLE", &opt_use_ns_user, false, },
{ "NAMESPACE_UTS_ENABLE", &opt_use_ns_uts, false, },
+ { "SANDBOX_DEBUG", &opt_debug, false, },
};
static void read_config(void)
@@ -77,7 +79,7 @@ static void show_version(void)
exit(0);
}
-#define PARSE_FLAGS "+chV"
+#define PARSE_FLAGS "+cdhV"
#define a_argument required_argument
static struct option const long_opts[] = {
{"ns-on", no_argument, &opt_use_namespaces, true},
@@ -101,6 +103,7 @@ static struct option const long_opts[] = {
{"ns-uts-on", no_argument, &opt_use_ns_uts, true},
{"ns-uts-off", no_argument, &opt_use_ns_uts, false},
{"bash", no_argument, NULL, 'c'},
+ {"debug", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{"run-configure", no_argument, NULL, 0x800},
@@ -128,6 +131,7 @@ static const char * const opts_help[] = {
"Enable the use of UTS (hostname/uname) namespaces",
"Disable the use of UTS (hostname/uname) namespaces",
"Run command through bash shell",
+ "Enable debug output",
"Print this help and exit",
"Print version and exit",
"Run local sandbox configure in same way and exit (developer only)",
@@ -207,6 +211,12 @@ void parseargs(int argc, char *argv[])
case 'c':
opt_use_bash = true;
break;
+ case 'd':
+ if (opt_debug <= 0)
+ opt_debug = 1;
+ else
+ ++opt_debug;
+ break;
case 'V':
show_version();
case 'h':
@@ -215,6 +225,8 @@ void parseargs(int argc, char *argv[])
run_configure(argc, argv);
case '?':
show_usage(1);
+ default:
+ sb_ebort("ISE: unhandled CLI option %c\n", i);
}
}
diff --git a/src/sandbox.h b/src/sandbox.h
index 0c0430f..28961f5 100644
--- a/src/sandbox.h
+++ b/src/sandbox.h
@@ -53,5 +53,6 @@ extern int opt_use_ns_time;
extern int opt_use_ns_user;
extern int opt_use_ns_uts;
extern bool opt_use_bash;
+extern int opt_debug;
#endif