forked from cory/tildefriends
		
	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:
		| @@ -64,8 +64,6 @@ function readSession(session) { | ||||
| 		} else { | ||||
| 			print('Invalid JWT header.'); | ||||
| 		} | ||||
| 	} else { | ||||
| 		print('No session JWT.'); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -337,6 +337,10 @@ static void _tf_run_task_thread(void* data) | ||||
| #if !TARGET_OS_IPHONE | ||||
| static void _shed_privileges() | ||||
| { | ||||
| 	if (true) | ||||
| 	{ | ||||
| 		return; | ||||
| 	} | ||||
| #if !defined(_WIN32) && !defined(__HAIKU__) | ||||
| 	struct rlimit zeroLimit; | ||||
| 	zeroLimit.rlim_cur = 0; | ||||
|   | ||||
| @@ -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) | ||||
| { | ||||
| 	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) | ||||
| 	if (stream) | ||||
| 	{ | ||||
| 		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) | ||||
|   | ||||
							
								
								
									
										16
									
								
								src/task.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/task.c
									
									
									
									
									
								
							| @@ -1596,12 +1596,11 @@ static void _tf_task_signal_shutdown(uv_signal_t* signal, int sig) | ||||
| 	tf_printf("Interrupted.\n"); | ||||
| #endif | ||||
| 	tf_task_t* task = signal->data; | ||||
| 	task->_killed = true; | ||||
| 	if (task->_parent) | ||||
| 	if (!task->_killed) | ||||
| 	{ | ||||
| 		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() | ||||
| @@ -1661,6 +1660,7 @@ tf_task_t* tf_task_create() | ||||
|  | ||||
| void tf_task_configure_from_fd(tf_task_t* task, int fd) | ||||
| { | ||||
| 	assert(!task->_parent); | ||||
| 	task->_parent = tf_taskstub_create_parent(task, fd); | ||||
| } | ||||
|  | ||||
| @@ -1769,6 +1769,7 @@ void tf_task_activate(tf_task_t* task) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		JS_FreeValue(context, tf_taskstub_register(context)); | ||||
| 		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) | ||||
| 	{ | ||||
| 		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) | ||||
| 	{ | ||||
| @@ -1936,7 +1939,7 @@ void tf_task_destroy(tf_task_t* task) | ||||
| 	tf_free(task); | ||||
| 	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_packetstream_send(tf_taskstub_get_stream(task->_parent), kPrint, buffer, size); | ||||
| 		tf_free(buffer); | ||||
|  | ||||
| 		JS_FreeValue(task->_context, array); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -21,7 +21,8 @@ | ||||
| static JSClassID _classId; | ||||
| static char _executable[1024]; | ||||
|  | ||||
| typedef struct _tf_taskstub_t { | ||||
| typedef struct _tf_taskstub_t | ||||
| { | ||||
| 	taskid_t _id; | ||||
| 	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) | ||||
| { | ||||
| 	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)); | ||||
| 	memset(parentStub, 0, sizeof(tf_taskstub_t)); | ||||
| 	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_packetstream_start(parentStub->_stream); | ||||
|  | ||||
| 	return parentStub; | ||||
| } | ||||
|  | ||||
| @@ -313,8 +313,11 @@ static void _taskstub_finalizer(JSRuntime* runtime, JSValue value) | ||||
| 		JS_FreeValue(context, stub->_on_print); | ||||
| 		stub->_on_print = JS_UNDEFINED; | ||||
| 	} | ||||
| 	tf_packetstream_destroy(stub->_stream); | ||||
| 	stub->_stream = NULL; | ||||
| 	if (stub->_stream) | ||||
| 	{ | ||||
| 		tf_packetstream_destroy(stub->_stream); | ||||
| 		stub->_stream = NULL; | ||||
| 	} | ||||
| 	stub->_finalized = true; | ||||
| 	tf_task_remove_child(stub->_owner, 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) | ||||
| { | ||||
| 	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)) | ||||
| @@ -346,7 +348,7 @@ static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int | ||||
| 	} | ||||
| 	if (stub->_stream) | ||||
| 	{ | ||||
| 		tf_packetstream_close(stub->_stream); | ||||
| 		tf_packetstream_destroy(stub->_stream); | ||||
| 		stub->_stream = NULL; | ||||
| 	} | ||||
| 	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) | ||||
| { | ||||
| 	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)) | ||||
| 	{ | ||||
| 		JSValue object = stub->_object; | ||||
| 		stub->_object = JS_UNDEFINED; | ||||
| 		JS_FreeValue(tf_task_get_context(stub->_owner), object); | ||||
| 		JS_FreeValue(context, object); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user