use C shim to start Android app
This should avoid relying on features of the Android builtin shell, and so hopefully avoid failures like this one http://git-annex.branchable.com/design/assistant/blog/day_197__template_haskell/#comment-07f90830f78f6495dcbdf90eb8636129 The C shim sets up busybox, and uses its builtin shell to run runshell. It's important that busybox be configured with CONFIG_FEATURE_SH_STANDALONE, so that while runshell is running, it does not rely on either system utilities, or busybox being already installed.
This commit is contained in:
parent
920138d5fb
commit
ac0292df95
6 changed files with 64 additions and 12 deletions
1
standalone/android/.gitignore
vendored
1
standalone/android/.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
build-utils
|
build-utils
|
||||||
|
start
|
||||||
|
|
|
@ -12,7 +12,7 @@ export ANDROID_NDK_ROOT=$(HOME)/tmp/android-ndk-r8d
|
||||||
|
|
||||||
GITTREE=source/git/installed-tree
|
GITTREE=source/git/installed-tree
|
||||||
|
|
||||||
build: source build-utils
|
build: source build-utils start
|
||||||
# Debug build because it does not need signing keys.
|
# Debug build because it does not need signing keys.
|
||||||
cd source/term && tools/build-debug
|
cd source/term && tools/build-debug
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ build: source build-utils
|
||||||
cp source/git/git-upload-pack source/term/libs/armeabi/lib.git-upload-pack.so
|
cp source/git/git-upload-pack source/term/libs/armeabi/lib.git-upload-pack.so
|
||||||
arm-linux-androideabi-strip --strip-unneeded --remove-section=.comment --remove-section=.note source/term/libs/armeabi/*
|
arm-linux-androideabi-strip --strip-unneeded --remove-section=.comment --remove-section=.note source/term/libs/armeabi/*
|
||||||
cp runshell source/term/libs/armeabi/lib.runshell.so
|
cp runshell source/term/libs/armeabi/lib.runshell.so
|
||||||
|
cp start source/term/libs/armeabi/lib.start.so
|
||||||
|
|
||||||
# remove git stuff we don't need to save space
|
# remove git stuff we don't need to save space
|
||||||
rm -rf $(GITTREE)/bin/git-cvsserver \
|
rm -rf $(GITTREE)/bin/git-cvsserver \
|
||||||
|
@ -117,7 +118,8 @@ source:
|
||||||
git clone git://github.com/jackpal/Android-Terminal-Emulator.git source/term
|
git clone git://github.com/jackpal/Android-Terminal-Emulator.git source/term
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(GITTREE) build-utils
|
rm -rf $(GITTREE)
|
||||||
|
rm -f build-utils start
|
||||||
cd source/busybox && $(MAKE) clean
|
cd source/busybox && $(MAKE) clean
|
||||||
#cd source/openssl && $(MAKE) clean
|
#cd source/openssl && $(MAKE) clean
|
||||||
cd source/openssh && $(MAKE) clean
|
cd source/openssh && $(MAKE) clean
|
||||||
|
|
|
@ -966,9 +966,9 @@ CONFIG_CTTYHACK=y
|
||||||
# CONFIG_HUSH_EXPORT_N is not set
|
# CONFIG_HUSH_EXPORT_N is not set
|
||||||
# CONFIG_HUSH_MODE_X is not set
|
# CONFIG_HUSH_MODE_X is not set
|
||||||
# CONFIG_MSH is not set
|
# CONFIG_MSH is not set
|
||||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
CONFIG_FEATURE_SH_IS_ASH=y
|
||||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||||
CONFIG_FEATURE_SH_IS_NONE=y
|
# CONFIG_FEATURE_SH_IS_NONE is not set
|
||||||
# CONFIG_FEATURE_BASH_IS_ASH is not set
|
# CONFIG_FEATURE_BASH_IS_ASH is not set
|
||||||
# CONFIG_FEATURE_BASH_IS_HUSH is not set
|
# CONFIG_FEATURE_BASH_IS_HUSH is not set
|
||||||
CONFIG_FEATURE_BASH_IS_NONE=y
|
CONFIG_FEATURE_BASH_IS_NONE=y
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
#!/system/bin/sh
|
#!/system/bin/sh
|
||||||
# This is run by the Android app, and runs a shell in an environment
|
# This is runs a shell in an environment configured for git-annex.
|
||||||
# configured for git-annex.
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
prep () {
|
prep () {
|
||||||
# I'm installed as lib/lib.runshell.so
|
# lib.start.so will run us in the root of our app directory
|
||||||
orig="$(pwd)"
|
|
||||||
cd "$0/../.."
|
|
||||||
base="$(pwd)"
|
base="$(pwd)"
|
||||||
|
|
||||||
# Cannot rely on Android providing a sane HOME
|
# Cannot rely on Android providing a sane HOME
|
||||||
|
@ -57,7 +54,7 @@ buildtree () {
|
||||||
}
|
}
|
||||||
|
|
||||||
install () {
|
install () {
|
||||||
if [ ! -d "$base/bin" ]; then
|
if [ ! -e "$base/git-annex" ]; then
|
||||||
if ! mkdir -p "$HOME"; then
|
if ! mkdir -p "$HOME"; then
|
||||||
echo "mkdir of $HOME failed!"
|
echo "mkdir of $HOME failed!"
|
||||||
fi
|
fi
|
||||||
|
|
52
standalone/android/start.c
Normal file
52
standalone/android/start.c
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/* Installed as lib.start.so, this bootstraps a working busybox and uses
|
||||||
|
* it to run lib.runshell.so. */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
void chopdir (char *s) {
|
||||||
|
char *p=strrchr(s, '/');
|
||||||
|
if (p == NULL) {
|
||||||
|
fprintf(stderr, "cannot find directory in %s", s);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
p[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
char buf[1024];
|
||||||
|
char *p;
|
||||||
|
struct stat st_buf;
|
||||||
|
|
||||||
|
/* Get something like /data/data/ga.androidterm/lib/lib.start.so */
|
||||||
|
int n=readlink("/proc/self/exe", buf, 1023);
|
||||||
|
if (n < 1) {
|
||||||
|
fprintf(stderr, "failed to find own name");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
buf[n] = '\0';
|
||||||
|
|
||||||
|
/* Change directory to something like /data/data/ga.androidterm */
|
||||||
|
chopdir(buf);
|
||||||
|
chopdir(buf);
|
||||||
|
if (chdir(buf) != 0) {
|
||||||
|
perror("chdir");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If this is the first run, set up busybox link. */
|
||||||
|
if (stat("bin/busybox", &st_buf) != 0) {
|
||||||
|
mkdir("bin", 0777);
|
||||||
|
if (link("lib/lib.busybox.so", "bin/busybox") != 0) {
|
||||||
|
perror("link busybox");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
execl("bin/busybox", "bin/busybox", "sh", "lib/lib.runshell.so", NULL);
|
||||||
|
perror("error running busybox sh");
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ index f6952f0..4b2aa5f 100644
|
||||||
String execPath = LaunchActivity.getDataDir(this) + "/bin/execpty";
|
String execPath = LaunchActivity.getDataDir(this) + "/bin/execpty";
|
||||||
ProcessBuilder execBuild =
|
ProcessBuilder execBuild =
|
||||||
- new ProcessBuilder(execPath, "/system/bin/sh", "-");
|
- new ProcessBuilder(execPath, "/system/bin/sh", "-");
|
||||||
+ new ProcessBuilder(execPath, "/data/data/ga.androidterm/lib/lib.runshell.so", "");
|
+ new ProcessBuilder(execPath, "/data/data/ga.androidterm/lib/lib.start.so", "");
|
||||||
execBuild.redirectErrorStream(true);
|
execBuild.redirectErrorStream(true);
|
||||||
Process exec = null;
|
Process exec = null;
|
||||||
try {
|
try {
|
||||||
|
@ -50,7 +50,7 @@ index 67287b2..1f9afa1 100644
|
||||||
<string name="pref_ime_default">0</string>
|
<string name="pref_ime_default">0</string>
|
||||||
<bool name="pref_alt_sends_esc_default">false</bool>
|
<bool name="pref_alt_sends_esc_default">false</bool>
|
||||||
- <string name="pref_shell_default">/system/bin/sh -</string>
|
- <string name="pref_shell_default">/system/bin/sh -</string>
|
||||||
+ <string name="pref_shell_default">/data/data/ga.androidterm/lib/lib.runshell.so</string>
|
+ <string name="pref_shell_default">/data/data/ga.androidterm/lib/lib.start.so</string>
|
||||||
<string name="pref_initialcommand_default"></string>
|
<string name="pref_initialcommand_default"></string>
|
||||||
<string name="pref_termtype_default">screen</string>
|
<string name="pref_termtype_default">screen</string>
|
||||||
- <bool name="pref_close_window_on_process_exit_default">true</bool>
|
- <bool name="pref_close_window_on_process_exit_default">true</bool>
|
||||||
|
|
Loading…
Add table
Reference in a new issue