[lxc-devel] [lxc/master] Fixing hooks functionality Android where 'sh' is placed under /system

kubiko on Github lxc-bot at linuxcontainers.org
Fri Jan 18 08:17:42 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 452 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190118/8913feef/attachment.bin>
-------------- next part --------------
From 649717cea8a5a7963f6ec589e5e4057a0019b9cd Mon Sep 17 00:00:00 2001
From: ondra <ondrak at localhost.localdomain>
Date: Fri, 11 Jan 2019 16:42:13 +0000
Subject: [PATCH] Fixing hooks functionality Android where 'sh' is placed under
 /system/bin

Signed-off-by: ondra <ondrak at localhost.localdomain>
---
 src/lxc/utils.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index ef71b6df7..cf343abca 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -405,6 +405,7 @@ struct lxc_popen_FILE *lxc_popen(const char *command)
 	int pipe_fds[2];
 	pid_t child_pid;
 	struct lxc_popen_FILE *fp = NULL;
+	FILE *sh;
 
 	ret = pipe2(pipe_fds, O_CLOEXEC);
 	if (ret < 0)
@@ -447,7 +448,14 @@ struct lxc_popen_FILE *lxc_popen(const char *command)
 		if (ret < 0)
 			_exit(EXIT_FAILURE);
 
-		execl("/bin/sh", "sh", "-c", command, (char *)NULL);
+		// check if we are not on android where sh is under /system/bin/sh
+		if ((sh = fopen("/bin/sh", "r"))) {
+			fclose(sh);
+			execl("/bin/sh", "sh", "-c", command, (char *)NULL);
+		} else {
+			// try /system/bin/sh
+			execl("/system/bin/sh", "sh", "-c", command, (char *)NULL);
+		}
 		_exit(127);
 	}
 


More information about the lxc-devel mailing list