aboutgitcodebugslistschat
path: root/pasta.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-28 14:33:14 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-29 12:21:48 +0200
commit5823dc5c682eb752e89fd8cc5be21bc4fae452a3 (patch)
tree64d431878b2c071dfff0aa18c062d60dd02ae8fd /pasta.c
parent798b7ff1c0f7e155ccb3a1fa9bbcc69f750bafd9 (diff)
downloadpasst-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.tar
passt-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.tar.gz
passt-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.tar.bz2
passt-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.tar.lz
passt-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.tar.xz
passt-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.tar.zst
passt-5823dc5c682eb752e89fd8cc5be21bc4fae452a3.zip
clang-tidy: Fix spurious null pointer warning in pasta_start_ns()
clang-tidy isn't quite clever enough to figure out that getenv("SHELL") will return the same thing both times here, which makes it conclude that shell could be NULL, causing problems later. It's a bit ugly that we call getenv() twice in any case, so rework this in a way that clang-tidy can figure out shell won't be NULL. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'pasta.c')
-rw-r--r--pasta.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/pasta.c b/pasta.c
index e233762..1dd8267 100644
--- a/pasta.c
+++ b/pasta.c
@@ -184,7 +184,7 @@ void pasta_start_ns(struct ctx *c, int argc, char *argv[])
struct pasta_setup_ns_arg arg = {
.argv = argv,
};
- char *shell = getenv("SHELL") ? getenv("SHELL") : "/bin/sh";
+ char *shell = getenv("SHELL");
char *sh_argv[] = { shell, NULL };
char *bash_argv[] = { shell, "-l", NULL };
char ns_fn_stack[NS_FN_STACK_SIZE];
@@ -193,6 +193,9 @@ void pasta_start_ns(struct ctx *c, int argc, char *argv[])
if (!c->debug)
c->quiet = 1;
+ if (!shell)
+ shell = "/bin/sh";
+
if (argc == 0) {
if (strstr(shell, "/bash")) {
arg.argv = bash_argv;