@@ -69,9 +69,27 @@ _Noreturn void exec_am_broadcast(int argc, char** argv, char* input_address_stri
6969_Noreturn void exec_callback (int fd )
7070{
7171 char * fds ;
72- if (asprintf (& fds , "%d" , fd ) == -1 ) { perror ("asprintf" ); }
73- execl (PREFIX "/libexec/termux-callback" , "termux-callback" , fds , NULL );
74- perror ("execl(\"" PREFIX "/libexec/termux-callback\")" );
72+ char * callback_fun = getenv ("TERMUX_CALLBACK" );
73+ if (callback_fun == NULL ) {
74+ perror ("TERMUX_CALLBACK is not set" );
75+ exit (1 );
76+ }
77+
78+ if (asprintf (& fds , "%d" , fd ) == -1 )
79+ perror ("asprintf" );
80+
81+ char errmsg [256 ];
82+ char * export_to_env = getenv ("TERMUX_EXPORT_FD" );
83+ if (strncmp (export_to_env , "true" , 4 ) == 0 ) {
84+ if (setenv ("TERMUX_USB_FD" , fds , true) == -1 )
85+ perror ("setenv" );
86+ execl (callback_fun , callback_fun , NULL );
87+ sprintf (errmsg , "execl(\"%s\", %s)" , callback_fun , fds );
88+ } else {
89+ execl (callback_fun , callback_fun , fds , NULL );
90+ sprintf (errmsg , "execl(\"%s\")" , callback_fun );
91+ }
92+ perror (errmsg );
7593 exit (1 );
7694}
7795
0 commit comments