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);
                }

Reply via email to