Conversation
|
My tentative patch: --- a/platform/android/luajit-launcher/assets/android.lua
+++ w/platform/android/luajit-launcher/assets/android.lua
@@ -2642,13 +2642,7 @@ local function run(android_app_state)
os.execute = function(command) -- luacheck: ignore 122
if command == nil then return -1 end
- local argv = {}
- command:gsub("([^ ]+)", function(arg)
- -- strip quotes around argument, since they are not necessary here
- arg = arg:gsub('"(.*)"', "%1") -- strip double quotes
- arg = arg:gsub("'(.*)'", "%1") -- strip single quotes
- table.insert(argv, arg)
- end)
+ local argv = {'sh', '-c', command}
return android.execute(unpack(argv))
end
--- a/plugins/terminal.koplugin/main.lua
+++ b/plugins/terminal.koplugin/main.lua
@@ -93,29 +93,35 @@ local Terminal = WidgetContainer:extend{
}
function Terminal:isExecutable(file)
- if os.execute(string.format("test -x %s", file)) == 0 then -- full path
- return true
- elseif os.execute(string.format("which %s 2>/dev/null 1>/dev/null", file)) == 0 then
- return true
- end
+ -- check if file is an executable or a command in PATH
+ return os.execute(string.format("test -x %s || command -v %s", file, file)) == 0
end
-- Try SHELL environment variable and some standard shells
function Terminal:getDefaultShellExecutable()
if self.default_shell_executable then return self.default_shell_executable end
- local shell = {"mksh", "ksh", "zsh", "ash", "dash", "sh", "bash"}
- table.insert(shell, os.getenv("SHELL"))
+ local shell = {
+ -- os.getenv("SHELL"),
+ "pouet",
+ "bash",
+ "sh",
+ "dash",
+ "ash",
+ "zsh",
+ "ksh",
+ "mksh",
+ }
- while #shell >= 1 do
- if self:isExecutable(shell[#shell]) then
- self.default_shell_executable = shell[#shell]
+ for i, file in ipairs(shell) do
+ if self:isExecutable(file) then
+ self.default_shell_executable = file
break
- else
- shell[#shell] = nil
end
end
+ logger.info('Terminal:default shell', self.default_shell_executable)
+
return self.default_shell_executable
end
|
If our
It's a POSIX shell builtin, so any compatible shell must support it.
Another thing that does not really make sense to me: Also, I forgot to uncomment the |
|
The most straightforward solution is probably local shell = {
os.getenv("SHELL") or "",
if file ~= "" and self:isExecutable(file) then
Edit: the current code is the more elegant solution. |
|
So this works on the emulator, a Kobo Sage and a Android Pixel (Android S). |
|
|
||
| if not self:isExecutable(shell) then | ||
| UIManager:show(InfoMessage:new{ | ||
| text = -("Shell is not executable"), |
There was a problem hiding this comment.
typo
| text = -("Shell is not executable"), | |
| text = _("Shell is not executable"), |
| end | ||
| else | ||
| UIManager:show(InfoMessage:new{ | ||
| text = _("Shell not executable"), |
There was a problem hiding this comment.
This text should be identical to the other Shell is not executable
|
ping @benoit-pierre Does this PR fix your issue on Marshmallow? |
|
No, still the same issue: |
|
Thanks, I will look into that tomorrow. |
Btw could you Post a langer Part of the crash.log, pleas? |
|
Here's the full log. |
|
Thanks @benoit-pierre ; It might be the main cause, that android does not have a Before changing |
benoit-pierre
left a comment
There was a problem hiding this comment.
I'll test it later tonight.
| -- This should be moved inside `platform/android/luajit-launcher/assets/android.lua` | ||
| -- once we now it works as expected | ||
| if Device:isAndroid() and not os.getenv("SHELL") and os.execute() == nil then | ||
| local dummy, android = pcall(require, "android") |
There was a problem hiding this comment.
| local dummy, android = pcall(require, "android") | |
| local android = require("android") |
There was a problem hiding this comment.
In which case? What's the error?
| if Device:isAndroid() and not os.getenv("SHELL") and os.execute() == nil then | ||
| local dummy, android = pcall(require, "android") | ||
| os.execute = function(command) -- luacheck: ignore 122 | ||
| command = command .. "; exit $?" |
There was a problem hiding this comment.
The exit code from the shell is already the code from the last command.
There was a problem hiding this comment.
In which case is this not true?
There was a problem hiding this comment.
The exit code from the shell is already the code from the last command.
Yup:
The equivalent of a bare exit is exit $? or even just omitting the exit.
(c.f., https://tldp.org/LDP/abs/html/exit-status.html#AEN2981)
Granted, this is Bash, but I assume this is the standard POSIX behavior. Anything else would be utter madness.
(A quick glance at toybox/busybox sh seems to confirm that).
There was a problem hiding this comment.
Android doesn't care about standard POSIX behavior. Hard to imagine it wouldn't do the exit status in a semi-normal manner though.
There was a problem hiding this comment.
https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md says
Since IceCreamSandwich Android has used mksh as its shell. Before then it used ash (which actually remained unused in the tree up to and including KitKat).
Hard to imagine a Korn shell from a BSD distro fucking up that bad either ;).
|
|
||
| -- This should be moved inside `platform/android/luajit-launcher/assets/android.lua` | ||
| -- once we now it works as expected | ||
| if Device:isAndroid() and not os.getenv("SHELL") and os.execute() == nil then |
There was a problem hiding this comment.
It still does not make sense to me to do it conditionally and end up with different implementation with completely different behaviors, one of them incompatible with how os.execute is supposed to work (again, supporting cmd … >redirect, like on other platforms).
There was a problem hiding this comment.
This ia test Here, as i dont want to Change luajit right now. If we know it Works now, this pice of Code should be in Android lua. Bit this is in a different subproject
There was a problem hiding this comment.
So once moved to android.lua, that variant of the function is always going to be used? No not os.getenv("SHELL") and os.execute() == nil conditional?
For testing, why not just use if Device:isAndroid() then?
|
@benoit-pierre So much questions! I Just politely asked If this Works ... I expected an answer |
Largely based on @benoit-pierre's original patch in koreader#12384 (comment)
… process Salvaged from @zwim's original code in koreader#12384
Largely based on @benoit-pierre's original patch in koreader#12384 (comment)
… process Salvaged from @zwim's original code in koreader#12384
Largely based on @benoit-pierre's original patch in #12384 (comment)
Largely based on @benoit-pierre's original patch in koreader#12384 (comment)
… process Salvaged from @zwim's original code in koreader#12384
Fix for #12375 (comment) .
This change is