summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-03-28 10:13:08 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2017-03-28 14:16:54 +0000
commit1a710dc8183522fc4c9b0efec4d76caa3a62d529 (patch)
treed5c79747eb99edbcfeafbb46281e29912e188138
parent76f9460298203369f62d0c3f084948630512972a (diff)
downloadbubblewrap-1a710dc8183522fc4c9b0efec4d76caa3a62d529.tar.gz
main: Parse --version early before acquiring capabilities
This should fix querying the bwrap version in flatpak's `configure.ac`. Closes: https://github.com/projectatomic/bubblewrap/issues/185 Closes: #187 Approved by: alexlarsson
-rw-r--r--bubblewrap.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/bubblewrap.c b/bubblewrap.c
index 81ebd96..a8dfd76 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -1142,6 +1142,13 @@ read_priv_sec_op (int read_socket,
return op->op;
}
+static void __attribute__ ((noreturn))
+print_version_and_exit (void)
+{
+ printf ("%s\n", PACKAGE_STRING);
+ exit (0);
+}
+
static void
parse_args_recurse (int *argcp,
char ***argvp,
@@ -1176,8 +1183,7 @@ parse_args_recurse (int *argcp,
}
else if (strcmp (arg, "--version") == 0)
{
- printf ("%s\n", PACKAGE_STRING);
- exit (0);
+ print_version_and_exit ();
}
else if (strcmp (arg, "--args") == 0)
{
@@ -1716,6 +1722,14 @@ main (int argc,
size_t seccomp_len;
struct sock_fprog seccomp_prog;
+ /* Handle --version early on before we try to acquire/drop
+ * any capabilities so it works in a build environment;
+ * right now flatpak's build runs bubblewrap --version.
+ * https://github.com/projectatomic/bubblewrap/issues/185
+ */
+ if (argc == 2 && (strcmp (argv[1], "--version") == 0))
+ print_version_and_exit ();
+
real_uid = getuid ();
real_gid = getgid ();