Skip to content

Commit cce6dfe

Browse files
Fix issue where RUN_COMMAND intent was failing for coreutils/busybox applets
1 parent 56c3826 commit cce6dfe

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/src/main/java/com/termux/app/RunCommandService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.termux.shared.data.DataUtils;
1414
import com.termux.shared.data.IntentUtils;
1515
import com.termux.shared.file.TermuxFileUtils;
16+
import com.termux.shared.file.filesystem.FileType;
1617
import com.termux.shared.models.errors.Errno;
1718
import com.termux.shared.models.errors.Error;
1819
import com.termux.shared.termux.TermuxConstants;
@@ -75,8 +76,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
7576
return Service.START_NOT_STICKY;
7677
}
7778

78-
executionCommand.executable = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_PATH, null);
79-
79+
String executableExtra = executionCommand.executable = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_PATH, null);
8080
executionCommand.arguments = IntentUtils.getStringArrayExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_ARGUMENTS, null);
8181

8282
/*
@@ -176,9 +176,17 @@ public int onStartCommand(Intent intent, int flags, int startId) {
176176
}
177177
}
178178

179+
// If the executable passed as the extra was an applet for coreutils/busybox, then we must
180+
// use it instead of the canonical path above since otherwise arguments would be passed to
181+
// coreutils/busybox instead and command would fail. Broken symlinks would already have been
182+
// validated so it should be fine to use it.
183+
executableExtra = TermuxFileUtils.getExpandedTermuxPath(executableExtra);
184+
if (FileUtils.getFileType(executableExtra, false) == FileType.SYMLINK) {
185+
Logger.logVerbose(LOG_TAG, "The executableExtra path \"" + executableExtra + "\" is a symlink so using it instead of the canonical path \"" + executionCommand.executable + "\"");
186+
executionCommand.executable = executableExtra;
187+
}
179188

180-
181-
executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(TermuxFileUtils.getExpandedTermuxPath(executionCommand.executable)).build();
189+
executionCommand.executableUri = new Uri.Builder().scheme(TERMUX_SERVICE.URI_SCHEME_SERVICE_EXECUTE).path(executionCommand.executable).build();
182190

183191
Logger.logVerbose(LOG_TAG, executionCommand.toString());
184192

0 commit comments

Comments
 (0)