File 0188-kernel-Make-os-cmd-compatible-with-Android.patch of Package erlang

From 39159367dd20f18f9386ac9c7180d9df79887d11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20de=20Bretagne?=
 <jerome.debretagne@gmail.com>
Date: Sun, 30 May 2021 15:13:21 +0200
Subject: [PATCH] kernel: Make os:cmd compatible with Android

Support when the shell is in /system/bin/sh on Android.
---
 lib/kernel/src/os.erl | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl
index 96b5da9881..f4c5d01b05 100644
--- a/lib/kernel/src/os.erl
+++ b/lib/kernel/src/os.erl
@@ -313,7 +313,22 @@ mk_cmd(_,Cmd) ->
     %% We use an absolute path here because we do not want the path to be
     %% searched in case a stale NFS handle is somewhere in the path before
     %% the sh command.
-    {"/bin/sh -s unix:cmd", [out],
+    %%
+    %% Check if the default shell is located in /bin/sh as expected usually
+    %% or in /system/bin/sh as implemented on Android. The raw option is
+    %% used to bypass the file server and speed up the file access.
+    Shell = case file:read_file_info("/bin/sh",[raw]) of
+                {ok,#file_info{type=regular}} ->
+                    "/bin/sh";
+                _ ->
+                    case file:read_file_info("/system/bin/sh",[raw]) of
+                        {ok,#file_info{type=regular}} ->
+                            "/system/bin/sh";
+                        _ ->
+                            "/bin/sh"
+                    end
+            end,
+    {Shell ++ " -s unix:cmd", [out],
      %% We insert a new line after the command, in case the command
      %% contains a comment character.
      %%
-- 
2.26.2

openSUSE Build Service is sponsored by