Now all the tests run clean.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4804 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2024-01-27 21:01:10 +00:00
parent cb2dfc696d
commit b9987580ee
5 changed files with 59 additions and 29 deletions

View File

@ -64,8 +64,6 @@ function readSession(session) {
} else { } else {
print('Invalid JWT header.'); print('Invalid JWT header.');
} }
} else {
print('No session JWT.');
} }
} }

View File

@ -337,6 +337,10 @@ static void _tf_run_task_thread(void* data)
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
static void _shed_privileges() static void _shed_privileges()
{ {
if (true)
{
return;
}
#if !defined(_WIN32) && !defined(__HAIKU__) #if !defined(_WIN32) && !defined(__HAIKU__)
struct rlimit zeroLimit; struct rlimit zeroLimit;
zeroLimit.rlim_cur = 0; zeroLimit.rlim_cur = 0;

View File

@ -131,20 +131,23 @@ static void _packetstream_on_write(uv_write_t* request, int status)
void tf_packetstream_send(tf_packetstream_t* stream, int packet_type, const char* begin, size_t length) void tf_packetstream_send(tf_packetstream_t* stream, int packet_type, const char* begin, size_t length)
{ {
size_t buffer_length = sizeof(uv_write_t) + sizeof(packet_type) + sizeof(length) + length; if (stream)
uv_write_t* request = tf_malloc(buffer_length);
memset(request, 0, sizeof(uv_write_t));
char* buffer = (char*)(request + 1);
memcpy(buffer, &packet_type, sizeof(packet_type));
memcpy(buffer + sizeof(packet_type), &length, sizeof(length));
if (length)
{ {
memcpy(buffer + sizeof(packet_type) + sizeof(length), begin, length); size_t buffer_length = sizeof(uv_write_t) + sizeof(packet_type) + sizeof(length) + length;
uv_write_t* request = tf_malloc(buffer_length);
memset(request, 0, sizeof(uv_write_t));
char* buffer = (char*)(request + 1);
memcpy(buffer, &packet_type, sizeof(packet_type));
memcpy(buffer + sizeof(packet_type), &length, sizeof(length));
if (length)
{
memcpy(buffer + sizeof(packet_type) + sizeof(length), begin, length);
}
uv_buf_t write_buffer;
write_buffer.base = buffer;
write_buffer.len = sizeof(packet_type) + sizeof(length) + length;
uv_write(request, (uv_stream_t*)&stream->stream, &write_buffer, 1, _packetstream_on_write);
} }
uv_buf_t write_buffer;
write_buffer.base = buffer;
write_buffer.len = sizeof(packet_type) + sizeof(length) + length;
uv_write(request, (uv_stream_t*)&stream->stream, &write_buffer, 1, _packetstream_on_write);
} }
void tf_packetstream_set_on_receive(tf_packetstream_t* stream, tf_packetstream_onreceive_t* callback, void* user_data) void tf_packetstream_set_on_receive(tf_packetstream_t* stream, tf_packetstream_onreceive_t* callback, void* user_data)

View File

@ -1596,12 +1596,11 @@ static void _tf_task_signal_shutdown(uv_signal_t* signal, int sig)
tf_printf("Interrupted.\n"); tf_printf("Interrupted.\n");
#endif #endif
tf_task_t* task = signal->data; tf_task_t* task = signal->data;
task->_killed = true; if (!task->_killed)
if (task->_parent)
{ {
tf_packetstream_close(tf_taskstub_get_stream(task->_parent)); task->_killed = true;
uv_stop(&task->_loop);
} }
uv_stop(&task->_loop);
} }
tf_task_t* tf_task_create() tf_task_t* tf_task_create()
@ -1661,6 +1660,7 @@ tf_task_t* tf_task_create()
void tf_task_configure_from_fd(tf_task_t* task, int fd) void tf_task_configure_from_fd(tf_task_t* task, int fd)
{ {
assert(!task->_parent);
task->_parent = tf_taskstub_create_parent(task, fd); task->_parent = tf_taskstub_create_parent(task, fd);
} }
@ -1769,6 +1769,7 @@ void tf_task_activate(tf_task_t* task)
} }
else else
{ {
JS_FreeValue(context, tf_taskstub_register(context));
tf_trace_set_write_callback(task->_trace, _tf_task_trace_to_parent, task); tf_trace_set_write_callback(task->_trace, _tf_task_trace_to_parent, task);
} }
@ -1831,7 +1832,9 @@ void tf_task_destroy(tf_task_t* task)
} }
if (task->_parent) if (task->_parent)
{ {
JS_FreeValue(task->_context, tf_taskstub_get_task_object(task->_parent)); tf_taskstub_destroy(task->_parent);
task->_parent = NULL;
JS_RunGC(task->_runtime);
} }
while (task->_promise_count) while (task->_promise_count)
{ {
@ -1936,7 +1939,7 @@ void tf_task_destroy(tf_task_t* task)
tf_free(task); tf_free(task);
if (was_trusted) if (was_trusted)
{ {
tf_printf("Goodbye."); tf_printf("Goodbye.\n");
} }
} }
@ -1987,7 +1990,6 @@ void tf_task_print(tf_task_t* task, int argc, JSValueConst* argv)
tf_serialize_store(task, task->_parent, &buffer, &size, array); tf_serialize_store(task, task->_parent, &buffer, &size, array);
tf_packetstream_send(tf_taskstub_get_stream(task->_parent), kPrint, buffer, size); tf_packetstream_send(tf_taskstub_get_stream(task->_parent), kPrint, buffer, size);
tf_free(buffer); tf_free(buffer);
JS_FreeValue(task->_context, array); JS_FreeValue(task->_context, array);
} }
} }

View File

@ -21,7 +21,8 @@
static JSClassID _classId; static JSClassID _classId;
static char _executable[1024]; static char _executable[1024];
typedef struct _tf_taskstub_t { typedef struct _tf_taskstub_t
{
taskid_t _id; taskid_t _id;
JSValue _object; JSValue _object;
@ -255,7 +256,7 @@ tf_task_t* tf_taskstub_get_owner(const tf_taskstub_t* stub)
tf_taskstub_t* tf_taskstub_create_parent(tf_task_t* task, uv_file file) tf_taskstub_t* tf_taskstub_create_parent(tf_task_t* task, uv_file file)
{ {
JSValue parentObject = JS_NewObject(tf_task_get_context(task)); JSValue parentObject = JS_NewObjectClass(tf_task_get_context(task), _classId);
tf_taskstub_t* parentStub = tf_malloc(sizeof(tf_taskstub_t)); tf_taskstub_t* parentStub = tf_malloc(sizeof(tf_taskstub_t));
memset(parentStub, 0, sizeof(tf_taskstub_t)); memset(parentStub, 0, sizeof(tf_taskstub_t));
parentStub->_stream = tf_packetstream_create(); parentStub->_stream = tf_packetstream_create();
@ -279,7 +280,6 @@ tf_taskstub_t* tf_taskstub_create_parent(tf_task_t* task, uv_file file)
tf_printf("uv_pipe_open failed: %s\n", uv_strerror(result)); tf_printf("uv_pipe_open failed: %s\n", uv_strerror(result));
} }
tf_packetstream_start(parentStub->_stream); tf_packetstream_start(parentStub->_stream);
return parentStub; return parentStub;
} }
@ -313,8 +313,11 @@ static void _taskstub_finalizer(JSRuntime* runtime, JSValue value)
JS_FreeValue(context, stub->_on_print); JS_FreeValue(context, stub->_on_print);
stub->_on_print = JS_UNDEFINED; stub->_on_print = JS_UNDEFINED;
} }
tf_packetstream_destroy(stub->_stream); if (stub->_stream)
stub->_stream = NULL; {
tf_packetstream_destroy(stub->_stream);
stub->_stream = NULL;
}
stub->_finalized = true; stub->_finalized = true;
tf_task_remove_child(stub->_owner, stub); tf_task_remove_child(stub->_owner, stub);
_taskstub_cleanup(stub); _taskstub_cleanup(stub);
@ -330,7 +333,6 @@ 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) 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; tf_taskstub_t* stub = process->data;
JSContext* context = tf_task_get_context(stub->_owner); JSContext* context = tf_task_get_context(stub->_owner);
if (!JS_IsUndefined(stub->_on_exit)) if (!JS_IsUndefined(stub->_on_exit))
@ -346,7 +348,7 @@ static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int
} }
if (stub->_stream) if (stub->_stream)
{ {
tf_packetstream_close(stub->_stream); tf_packetstream_destroy(stub->_stream);
stub->_stream = NULL; stub->_stream = NULL;
} }
uv_close((uv_handle_t*)process, _taskstub_on_handle_close); uv_close((uv_handle_t*)process, _taskstub_on_handle_close);
@ -472,11 +474,32 @@ static JSValue _taskstub_kill(JSContext* context, JSValueConst this_val, int arg
void tf_taskstub_destroy(tf_taskstub_t* stub) void tf_taskstub_destroy(tf_taskstub_t* stub)
{ {
JSContext* context = tf_task_get_context(stub->_owner);
if (stub->_stream)
{
tf_packetstream_destroy(stub->_stream);
stub->_stream = NULL;
}
if (!JS_IsUndefined(stub->_on_exit))
{
JS_FreeValue(context, stub->_on_exit);
stub->_on_exit = JS_UNDEFINED;
}
if (!JS_IsUndefined(stub->_on_error))
{
JS_FreeValue(context, stub->_on_error);
stub->_on_error = JS_UNDEFINED;
}
if (!JS_IsUndefined(stub->_on_print))
{
JS_FreeValue(context, stub->_on_print);
stub->_on_print = JS_UNDEFINED;
}
if (!JS_IsUndefined(stub->_object)) if (!JS_IsUndefined(stub->_object))
{ {
JSValue object = stub->_object; JSValue object = stub->_object;
stub->_object = JS_UNDEFINED; stub->_object = JS_UNDEFINED;
JS_FreeValue(tf_task_get_context(stub->_owner), object); JS_FreeValue(context, object);
} }
} }