commit:     f0fd6d2e4884177af599416d1cca0423d1b7df08
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov  5 09:28:55 2021 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov  5 09:28:55 2021 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=f0fd6d2e

sandbox: add --debug option to control SANDBOX_DEBUG

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

 src/environ.c |  2 +-
 src/options.c | 14 +++++++++++++-
 src/sandbox.h |  1 +
 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

Reply via email to