Skip to content

Commit 895b0c3

Browse files
committed
Revert back to a termux-callback shell script again
Using a shell script has the benefit of dealing with argument expansion for us, with the current termux-usb script we need to run something like `termux-usb -e "my_cmd my_cmd_arg"`, and just trying to execl that fails due to there being no file named `my_cmd my_cmd_arg`.
1 parent 231ed74 commit 895b0c3

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ foreach(file ${script_files})
6363
)
6464
endforeach()
6565

66+
configure_file(
67+
${CMAKE_CURRENT_SOURCE_DIR}/termux-callback.in
68+
termux-callback @ONLY
69+
)
70+
6671
install(
6772
FILES ${CMAKE_BINARY_DIR}/termux-api
6873
DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec
@@ -78,3 +83,11 @@ foreach(file ${script_files})
7883
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
7984
)
8085
endforeach()
86+
87+
install(
88+
FILES ${CMAKE_BINARY_DIR}/termux-callback
89+
DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec
90+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
91+
GROUP_READ GROUP_EXECUTE
92+
WORLD_READ WORLD_EXECUTE
93+
)

termux-api.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,19 @@ _Noreturn void exec_am_broadcast(int argc, char** argv,
7474
_Noreturn void exec_callback(int fd)
7575
{
7676
char *fds;
77-
char *callback_fun = getenv("TERMUX_CALLBACK");
78-
if (callback_fun == NULL) {
79-
perror("TERMUX_CALLBACK is not set");
80-
exit(1);
81-
}
82-
8377
if (asprintf(&fds, "%d", fd) == -1)
8478
perror("asprintf");
8579

8680
char errmsg[256];
8781
char *export_to_env = getenv("TERMUX_EXPORT_FD");
88-
if (export_to_env && strncmp(export_to_env, "true", 4) == 0) {
82+
if (strncmp(export_to_env, "true", 4) == 0) {
8983
if (setenv("TERMUX_USB_FD", fds, true) == -1)
9084
perror("setenv");
91-
execl(callback_fun, callback_fun, NULL);
92-
sprintf(errmsg, "execl(\"%s\", %s)", callback_fun, fds);
85+
execl(PREFIX "/libexec/termux-callback", "termux-callback", NULL);
86+
sprintf(errmsg, "execl(\"" PREFIX "/libexec/termux-callback\")");
9387
} else {
94-
execl(callback_fun, callback_fun, fds, NULL);
95-
sprintf(errmsg, "execl(\"%s\")", callback_fun);
88+
execl(PREFIX "/libexec/termux-callback", "termux-callback", fds, NULL);
89+
sprintf(errmsg, "execl(\"" PREFIX "/libexec/termux-callback\", %s)", fds);
9690
}
9791
perror(errmsg);
9892
exit(1);

termux-callback.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!@TERMUX_PREFIX@/bin/bash
2+
set -e -u
3+
$TERMUX_CALLBACK "$@"

0 commit comments

Comments
 (0)