diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2021-07-09 10:45:50 +0200 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2021-07-09 12:08:05 +0200 |
commit | 1c530126810655b645951da50a8f1863312419b0 (patch) | |
tree | d80016a565c2f3fdf4c08a68a083992188bde40e | |
parent | c75b6982397afe85f83d8a81d220c3290d5fe60d (diff) | |
download | genimage-1c530126810655b645951da50a8f1863312419b0.tar.gz genimage-1c530126810655b645951da50a8f1863312419b0.tar.xz |
util: systemp(): use shell defined in SHELL rather than /bin/sh
This patch changes systemp() to use the shell defined in the environment
variable SHELL rather then hard coded /bin/sh, so that the called
programs can use shell functions exported in the calling shell. Use
"/bin/sh" as a fall back.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | util.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -216,6 +216,7 @@ int systemp(struct image *image, const char *fmt, ...) pid = fork(); if (!pid) { + const char *shell; int fd; if (loglevel() < 1) { @@ -230,7 +231,11 @@ int systemp(struct image *image, const char *fmt, ...) dup2(STDERR_FILENO, STDOUT_FILENO); } - ret = execl("/bin/sh", "sh", "-c", buf, NULL); + shell = getenv("SHELL"); + if (!shell || shell[0] == 0x0) + shell = "/bin/sh"; + + ret = execl(shell, shell, "-c", buf, NULL); if (ret < 0) { ret = -errno; error("Cannot execute %s: %s\n", buf, strerror(errno)); |