Whoa. Apps are running on android. Switched to a static build of OpenSSL 1.1.1t for simplicity.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4211 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
41
src/task.c
41
src/task.c
@ -309,7 +309,7 @@ bool tf_task_send_error_to_parent(tf_task_t* task, JSValue error)
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char* _task_loadFile(tf_task_t* task, const char* fileName)
|
||||
static const char* _task_loadFile(tf_task_t* task, const char* fileName, size_t* out_size)
|
||||
{
|
||||
char* result = NULL;
|
||||
if (task->_zip)
|
||||
@ -326,6 +326,10 @@ static const char* _task_loadFile(tf_task_t* task, const char* fileName)
|
||||
{
|
||||
buffer[info.uncompressed_size] = '\0';
|
||||
result = buffer;
|
||||
if (out_size)
|
||||
{
|
||||
*out_size = info.uncompressed_size;
|
||||
}
|
||||
buffer = NULL;
|
||||
}
|
||||
unzCloseCurrentFile(task->_zip);
|
||||
@ -367,7 +371,7 @@ int tf_task_execute(tf_task_t* task, const char* fileName)
|
||||
bool executed = false;
|
||||
|
||||
tf_trace_begin(task->_trace, "tf_task_execute");
|
||||
const char* source = _task_loadFile(task, fileName);
|
||||
const char* source = _task_loadFile(task, fileName, NULL);
|
||||
tf_printf("Running script %s\n", fileName);
|
||||
if (!*task->_scriptName)
|
||||
{
|
||||
@ -1500,7 +1504,7 @@ JSModuleDef* _tf_task_module_loader(JSContext* context, const char* module_name,
|
||||
|
||||
if (!source && task->_trusted)
|
||||
{
|
||||
source = (char*)_task_loadFile(task, module_name);
|
||||
source = (char*)_task_loadFile(task, module_name, NULL);
|
||||
length = source ? strlen(source) : 0;
|
||||
}
|
||||
|
||||
@ -1580,11 +1584,42 @@ static void _tf_task_trace_to_parent(tf_trace_t* trace, const char* buffer, size
|
||||
tf_packetstream_send(tf_taskstub_get_stream(task->_parent), kTaskTrace, buffer, size);
|
||||
}
|
||||
|
||||
static void _tf_task_extract_file(tf_task_t* task, const char* name, int mode)
|
||||
{
|
||||
size_t size = 0;
|
||||
char path_in_zip[256];
|
||||
snprintf(path_in_zip, sizeof(path_in_zip), "lib/arm64-v8a/%s", name);
|
||||
const char* exe_source = _task_loadFile(task, path_in_zip, &size);
|
||||
if (exe_source)
|
||||
{
|
||||
FILE* exe_target = fopen(name, "wb");
|
||||
if (exe_target)
|
||||
{
|
||||
fwrite(exe_source, size, 1, exe_target);
|
||||
fchmod(fileno(exe_target), mode);
|
||||
fclose(exe_target);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("failed to open %s for write", name);
|
||||
}
|
||||
tf_free((void*)exe_source);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("failed to read %s source", path_in_zip);
|
||||
}
|
||||
}
|
||||
|
||||
void tf_task_activate(tf_task_t* task)
|
||||
{
|
||||
assert(!task->_activated);
|
||||
task->_activated = true;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
_tf_task_extract_file(task, "tildefriends", 0755);
|
||||
#endif
|
||||
|
||||
JSContext* context = task->_context;
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue e = JS_NewObject(context);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "taskstub.js.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "mem.h"
|
||||
#include "packetstream.h"
|
||||
#include "serialize.h"
|
||||
@ -44,6 +45,11 @@ void tf_taskstub_startup()
|
||||
JS_NewClassID(&_classId);
|
||||
size_t size = sizeof(_executable);
|
||||
uv_exepath(_executable, &size);
|
||||
#if defined(__ANDROID__)
|
||||
/* We have already changed into our files directory. */
|
||||
snprintf(_executable, sizeof(_executable), "./tildefriends");
|
||||
#endif
|
||||
tf_printf("exepath is %s\n", _executable);
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@ -129,7 +135,7 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
memset(pipe, 0, sizeof(*pipe));
|
||||
if (uv_pipe_init(tf_task_get_loop(parent), pipe, 1) != 0)
|
||||
{
|
||||
fprintf(stderr, "uv_pipe_init failed\n");
|
||||
tf_printf("uv_pipe_init failed\n");
|
||||
}
|
||||
|
||||
uv_stdio_container_t io[3];
|
||||
@ -158,7 +164,7 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "uv_spawn failed: %s\n", uv_strerror(spawn_result));
|
||||
tf_printf("uv_spawn failed: %s\n", uv_strerror(spawn_result));
|
||||
JS_FreeValue(context, taskObject);
|
||||
}
|
||||
return result;
|
||||
@ -177,14 +183,15 @@ void _taskstub_gc_mark(JSRuntime* rt, JSValueConst value, JS_MarkFunc mark_func)
|
||||
|
||||
JSValue tf_taskstub_register(JSContext* context)
|
||||
{
|
||||
JSClassDef def = {
|
||||
JSClassDef def =
|
||||
{
|
||||
.class_name = "TaskStub",
|
||||
.finalizer = &_taskstub_finalizer,
|
||||
.gc_mark = _taskstub_gc_mark,
|
||||
};
|
||||
if (JS_NewClass(JS_GetRuntime(context), _classId, &def) != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to register TaskStub class.\n");
|
||||
tf_printf("Failed to register TaskStub class.\n");
|
||||
}
|
||||
return JS_NewCFunction2(context, _taskstub_create, "TaskStub", 0, JS_CFUNC_constructor, 0);
|
||||
}
|
||||
@ -226,12 +233,12 @@ tf_taskstub_t* tf_taskstub_create_parent(tf_task_t* task, uv_file file)
|
||||
|
||||
if (uv_pipe_init(tf_task_get_loop(task), tf_packetstream_get_pipe(parentStub->_stream), 1) != 0)
|
||||
{
|
||||
fprintf(stderr, "uv_pipe_init failed\n");
|
||||
tf_printf("uv_pipe_init failed\n");
|
||||
}
|
||||
tf_packetstream_set_on_receive(parentStub->_stream, tf_task_on_receive_packet, parentStub);
|
||||
if (uv_pipe_open(tf_packetstream_get_pipe(parentStub->_stream), file) != 0)
|
||||
{
|
||||
fprintf(stderr, "uv_pipe_open failed\n");
|
||||
tf_printf("uv_pipe_open failed\n");
|
||||
}
|
||||
tf_packetstream_start(parentStub->_stream);
|
||||
|
||||
@ -285,6 +292,7 @@ static void _taskstub_on_handle_close(uv_handle_t* handle)
|
||||
|
||||
static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int terminationSignal)
|
||||
{
|
||||
tf_printf("_taskstub_on_process_exit %d %d\n", (int)status, terminationSignal);
|
||||
tf_taskstub_t* stub = process->data;
|
||||
JSContext* context = tf_task_get_context(stub->_owner);
|
||||
if (!JS_IsUndefined(stub->_on_exit))
|
||||
|
Reference in New Issue
Block a user