public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/
@ 2021-10-23  6:10 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2021-10-23  6:10 UTC (permalink / raw
  To: gentoo-commits

commit:     3459f28f82fdf4e1da0b6ca0d24d00ce4dfd0fe7
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 23 06:05:30 2021 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Oct 23 06:05:30 2021 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=3459f28f

sandbox: add a --run-configure option

When setting up sandbox on a new system for development, it helps to
be able to build the new sandbox checkout in the same way as it is
currently installed in the system.  Add a command line option for
this explicitly to speed up development.

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

 libsbutil/sbutil.h |  8 ++++++++
 src/namespaces.c   |  7 -------
 src/options.c      | 23 ++++++++++++++++++++---
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index 5194dde..d81543b 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -153,6 +153,14 @@ char *__xstrndup(const char *str, size_t size, const char *file, const char *fun
 #define xstrndup(_str, _size)  __xstrndup(_str, _size, __FILE__, __func__, __LINE__)
 #define xalloc_die()           __sb_ebort(__FILE__, __func__, __LINE__, "out of memory")
 
+#define xasprintf(fmt, ...) \
+({ \
+	int _ret = asprintf(fmt, __VA_ARGS__); \
+	if (_ret == 0) \
+		sb_perr("asprintf(%s) failed", #fmt); \
+	_ret; \
+})
+
 /* string helpers */
 #define streq(s1, s2) (strcmp(s1, s2) == 0)
 

diff --git a/src/namespaces.c b/src/namespaces.c
index 1f93b60..ee9f82a 100644
--- a/src/namespaces.c
+++ b/src/namespaces.c
@@ -26,13 +26,6 @@
 #define xchmod(...) sb_assert(chmod(__VA_ARGS__) == 0)
 #define xsymlink(...) sb_assert(symlink(__VA_ARGS__) == 0)
 
-#define xasprintf(fmt, ...) \
-({ \
-	int _ret = asprintf(fmt, __VA_ARGS__); \
-	if (_ret == 0) \
-		sb_perr("asprintf(%s) failed", #fmt); \
-	_ret; \
-})
 #define xfopen(path, ...) \
 ({ \
 	FILE *_ret = fopen(path, __VA_ARGS__); \

diff --git a/src/options.c b/src/options.c
index 383b139..03cffda 100644
--- a/src/options.c
+++ b/src/options.c
@@ -50,9 +50,11 @@ static void read_config(void)
 	}
 }
 
+static const char sb_sonfigure_opts[] = SANDBOX_CONFIGURE_OPTS;
+
 static void show_version(void)
 {
-	puts(
+	printf(
 		"Gentoo path sandbox\n"
 		" version: " PACKAGE_VERSION "\n"
 		" C lib:   " LIBC_VERSION " (" LIBC_PATH ")\n"
@@ -68,8 +70,8 @@ static void show_version(void)
 # define SB_SCHIZO "no"
 #endif
 		" schizo:  " SB_SCHIZO "\n"
-		"\nconfigured with these options:\n"
-		SANDBOX_CONFIGURE_OPTS
+		"\nconfigured with these options:\n%s\n",
+		sb_sonfigure_opts
 	);
 	exit(0);
 }
@@ -99,6 +101,7 @@ static struct option const long_opts[] = {
 	{"ns-uts-off",    no_argument, &opt_use_ns_uts, false},
 	{"help",          no_argument, NULL, 'h'},
 	{"version",       no_argument, NULL, 'V'},
+	{"run-configure", no_argument, NULL, 0x800},
 	{NULL,            no_argument, NULL, 0x0}
 };
 static const char * const opts_help[] = {
@@ -124,6 +127,7 @@ static const char * const opts_help[] = {
 	"Disable the use of UTS (hostname/uname) namespaces",
 	"Print this help and exit",
 	"Print version and exit",
+	"Run local sandbox configure in same way and exit (developer only)",
 	NULL
 };
 
@@ -180,6 +184,17 @@ static void show_usage(int status)
 	exit(status);
 }
 
+static void run_configure(int argc, char *argv[])
+{
+	int i;
+	char *cmd;
+	xasprintf(&cmd, "set -x; ./configure %s", sb_sonfigure_opts);
+	/* This doesn't need to be fast, so keep it simple. */
+	for (i = optind; i < argc; ++i)
+		xasprintf(&cmd, "%s %s", cmd, argv[i]);
+	exit(system(cmd));
+}
+
 void parseargs(int argc, char *argv[])
 {
 	int i;
@@ -190,6 +205,8 @@ void parseargs(int argc, char *argv[])
 			show_version();
 		case 'h':
 			show_usage(0);
+		case 0x800:
+			run_configure(argc, argv);
 		case '?':
 			show_usage(1);
 		}


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/
@ 2021-11-05 10:25 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2021-11-05 10:25 UTC (permalink / raw
  To: gentoo-commits

commit:     163a378b532c03c0199c489b6d829a84875e32c2
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov  5 09:04:41 2021 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov  5 09:04:41 2021 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=163a378b

sandbox: restore SANDBOX_INTRACTV variable

I incorrectly dropped this as unused a while back, but the bashrc hook
definitely still relies on it for checking portage settings.  I think
I got confused by the interaction with SANDBOX_TESTING.

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

 libsbutil/sbutil.h | 2 ++
 src/environ.c      | 6 +++++-
 src/sandbox.c      | 2 +-
 src/sandbox.h      | 2 +-
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index 267f717..cf97179 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -57,6 +57,8 @@
 #define ENV_SANDBOX_METHOD     "SANDBOX_METHOD"
 #define ENV_SANDBOX_ON         "SANDBOX_ON"
 
+#define ENV_SANDBOX_INTRACTV   "SANDBOX_INTRACTV"
+
 #define ENV_SANDBOX_ACTIVE     "SANDBOX_ACTIVE"
 #define SANDBOX_ACTIVE         "armedandready"
 

diff --git a/src/environ.c b/src/environ.c
index ecff0dc..1535f06 100644
--- a/src/environ.c
+++ b/src/environ.c
@@ -241,7 +241,7 @@ static void sb_setenv(char ***envp, const char *name, const char *val)
 
 /* We setup the environment child side only to prevent issues with
  * setting LD_PRELOAD parent side */
-char **setup_environ(struct sandbox_info_t *sandbox_info)
+char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
 {
 	int have_ld_preload = 0;
 
@@ -264,6 +264,7 @@ char **setup_environ(struct sandbox_info_t *sandbox_info)
 	unsetenv(ENV_SANDBOX_MESSAGE_PATH);
 	unsetenv(ENV_SANDBOX_WORKDIR);
 	unsetenv(ENV_SANDBOX_ACTIVE);
+	unsetenv(ENV_SANDBOX_INTRACTV);
 	unsetenv(ENV_BASH_ENV);
 
 	orig_ld_preload_envvar = getenv(ENV_LD_PRELOAD);
@@ -295,6 +296,9 @@ char **setup_environ(struct sandbox_info_t *sandbox_info)
 	sb_setenv(&new_environ, ENV_SANDBOX_LOG, sandbox_info->sandbox_log);
 	sb_setenv(&new_environ, ENV_SANDBOX_DEBUG_LOG, sandbox_info->sandbox_debug_log);
 	sb_setenv(&new_environ, ENV_SANDBOX_MESSAGE_PATH, sandbox_info->sandbox_message_path);
+	/* Is this an interactive session? */
+	if (interactive)
+		sb_setenv(&new_environ, ENV_SANDBOX_INTRACTV, "1");
 	/* Just set the these if not already set so that is_env_on() work */
 	if (!getenv(ENV_SANDBOX_VERBOSE))
 		sb_setenv(&new_environ, ENV_SANDBOX_VERBOSE, "1");

diff --git a/src/sandbox.c b/src/sandbox.c
index ed0c7f6..063974d 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -255,7 +255,7 @@ int main(int argc, char **argv)
 
 	/* Setup the child environment stuff.
 	 * XXX:  We free this in spawn_shell(). */
-	sandbox_environ = setup_environ(&sandbox_info);
+	sandbox_environ = setup_environ(&sandbox_info, print_debug);
 	if (NULL == sandbox_environ)
 		goto oom_error;
 

diff --git a/src/sandbox.h b/src/sandbox.h
index cdc1b9e..0c0430f 100644
--- a/src/sandbox.h
+++ b/src/sandbox.h
@@ -24,7 +24,7 @@ struct sandbox_info_t {
 	char *home_dir;
 };
 
-extern char **setup_environ(struct sandbox_info_t *sandbox_info);
+extern char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive);
 
 extern bool sb_get_cnf_bool(const char *, bool);
 


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/
@ 2021-11-05 21:40 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2021-11-05 21:40 UTC (permalink / raw
  To: gentoo-commits

commit:     2f99599214eeb36b329ddc90559c17210312f7d1
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov  5 20:56:28 2021 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov  5 20:56:28 2021 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=2f995992

sandbox: move xasprintf helper here

Since this is only used by sandbox, and is not usable by libsandbox,
move it out of libsbutil.  Leave a note behind for possible future
macros too.

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

 libsbutil/sbutil.h | 17 ++++++++---------
 src/sandbox.h      |  8 ++++++++
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index cf97179..c146b80 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -140,7 +140,14 @@ void sb_maybe_gdb(void);
 #define sb_fprintf(fp, ...) sb_fdprintf(fileno(fp), __VA_ARGS__)
 #define sb_vfprintf(fp, ...) sb_vfdprintf(fileno(fp), __VA_ARGS__)
 
-/* Memory functions */
+/*
+ * Memory functions.
+ *
+ * NB: These are wrappers around libsbutil functions that build off memory calls that we
+ * implement directly (see libsandbox/memory.c).  Do not add any helpers here that cannot
+ * be mirrored in libsandbox as attempts to pass memory between the two allocators will
+ * lead to corruption & crashes.
+ */
 void *__xcalloc(size_t nmemb, size_t size, const char *file, const char *func, size_t line);
 void *__xmalloc(size_t size, const char *file, const char *func, size_t line);
 void *__xzalloc(size_t size /*, const char *file, const char *func, size_t line */);
@@ -155,14 +162,6 @@ char *__xstrndup(const char *str, size_t size, const char *file, const char *fun
 #define xstrndup(_str, _size)  __xstrndup(_str, _size, __FILE__, __func__, __LINE__)
 #define xalloc_die()           __sb_ebort(__FILE__, __func__, __LINE__, "out of memory")
 
-#define xasprintf(fmt, ...) \
-({ \
-	int _ret = asprintf(fmt, __VA_ARGS__); \
-	if (_ret == 0) \
-		sb_perr("asprintf(%s) failed", #fmt); \
-	_ret; \
-})
-
 /* string helpers */
 #define streq(s1, s2) (strcmp(s1, s2) == 0)
 

diff --git a/src/sandbox.h b/src/sandbox.h
index 28961f5..477973a 100644
--- a/src/sandbox.h
+++ b/src/sandbox.h
@@ -40,6 +40,14 @@ extern pid_t setup_namespaces(void);
 #define sb_err(fmt, args...)  _sb_err(warn, fmt, ## args)
 #define sb_perr(fmt, args...) _sb_err(pwarn, fmt, ## args)
 
+#define xasprintf(fmt, ...) \
+({ \
+	int _ret = asprintf(fmt, __VA_ARGS__); \
+	if (_ret == 0) \
+		sb_perr("asprintf(%s) failed", #fmt); \
+	_ret; \
+})
+
 /* Option parsing related code */
 extern void parseargs(int argc, char *argv[]);
 extern int opt_use_namespaces;


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-05 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-23  6:10 [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/ Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2021-11-05 10:25 Mike Frysinger
2021-11-05 21:40 Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox