Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: src/
Date: Fri, 05 Nov 2021 10:25:17
Message-Id: 1636104535.f0fd6d2e4884177af599416d1cca0423d1b7df08.vapier@gentoo
1 commit: f0fd6d2e4884177af599416d1cca0423d1b7df08
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Fri Nov 5 09:28:55 2021 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Fri Nov 5 09:28:55 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=f0fd6d2e
7
8 sandbox: add --debug option to control SANDBOX_DEBUG
9
10 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
11
12 src/environ.c | 2 +-
13 src/options.c | 14 +++++++++++++-
14 src/sandbox.h | 1 +
15 3 files changed, 15 insertions(+), 2 deletions(-)
16
17 diff --git a/src/environ.c b/src/environ.c
18 index 1535f06..81a3e5f 100644
19 --- a/src/environ.c
20 +++ b/src/environ.c
21 @@ -303,7 +303,7 @@ char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
22 if (!getenv(ENV_SANDBOX_VERBOSE))
23 sb_setenv(&new_environ, ENV_SANDBOX_VERBOSE, "1");
24 if (!getenv(ENV_SANDBOX_DEBUG))
25 - sb_setenv(&new_environ, ENV_SANDBOX_DEBUG, "0");
26 + sb_setenv(&new_environ, ENV_SANDBOX_DEBUG, opt_debug ? "1" : "0");
27 if (!getenv(ENV_NOCOLOR))
28 sb_setenv(&new_environ, ENV_NOCOLOR, "no");
29 if (!getenv(ENV_SANDBOX_METHOD))
30
31 diff --git a/src/options.c b/src/options.c
32 index 64cd750..5332318 100644
33 --- a/src/options.c
34 +++ b/src/options.c
35 @@ -21,6 +21,7 @@ int opt_use_ns_time = -1;
36 int opt_use_ns_user = -1;
37 int opt_use_ns_uts = -1;
38 bool opt_use_bash = false;
39 +int opt_debug = -1;
40
41 static const struct {
42 const char *name;
43 @@ -38,6 +39,7 @@ static const struct {
44 { "NAMESPACE_TIME_ENABLE", &opt_use_ns_time, false, },
45 { "NAMESPACE_USER_ENABLE", &opt_use_ns_user, false, },
46 { "NAMESPACE_UTS_ENABLE", &opt_use_ns_uts, false, },
47 + { "SANDBOX_DEBUG", &opt_debug, false, },
48 };
49
50 static void read_config(void)
51 @@ -77,7 +79,7 @@ static void show_version(void)
52 exit(0);
53 }
54
55 -#define PARSE_FLAGS "+chV"
56 +#define PARSE_FLAGS "+cdhV"
57 #define a_argument required_argument
58 static struct option const long_opts[] = {
59 {"ns-on", no_argument, &opt_use_namespaces, true},
60 @@ -101,6 +103,7 @@ static struct option const long_opts[] = {
61 {"ns-uts-on", no_argument, &opt_use_ns_uts, true},
62 {"ns-uts-off", no_argument, &opt_use_ns_uts, false},
63 {"bash", no_argument, NULL, 'c'},
64 + {"debug", no_argument, NULL, 'd'},
65 {"help", no_argument, NULL, 'h'},
66 {"version", no_argument, NULL, 'V'},
67 {"run-configure", no_argument, NULL, 0x800},
68 @@ -128,6 +131,7 @@ static const char * const opts_help[] = {
69 "Enable the use of UTS (hostname/uname) namespaces",
70 "Disable the use of UTS (hostname/uname) namespaces",
71 "Run command through bash shell",
72 + "Enable debug output",
73 "Print this help and exit",
74 "Print version and exit",
75 "Run local sandbox configure in same way and exit (developer only)",
76 @@ -207,6 +211,12 @@ void parseargs(int argc, char *argv[])
77 case 'c':
78 opt_use_bash = true;
79 break;
80 + case 'd':
81 + if (opt_debug <= 0)
82 + opt_debug = 1;
83 + else
84 + ++opt_debug;
85 + break;
86 case 'V':
87 show_version();
88 case 'h':
89 @@ -215,6 +225,8 @@ void parseargs(int argc, char *argv[])
90 run_configure(argc, argv);
91 case '?':
92 show_usage(1);
93 + default:
94 + sb_ebort("ISE: unhandled CLI option %c\n", i);
95 }
96 }
97
98
99 diff --git a/src/sandbox.h b/src/sandbox.h
100 index 0c0430f..28961f5 100644
101 --- a/src/sandbox.h
102 +++ b/src/sandbox.h
103 @@ -53,5 +53,6 @@ extern int opt_use_ns_time;
104 extern int opt_use_ns_user;
105 extern int opt_use_ns_uts;
106 extern bool opt_use_bash;
107 +extern int opt_debug;
108
109 #endif