From bb83acce9622f6b053a04788d3be5e2d657d1a85 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 18 Dec 2019 00:19:37 -0800 Subject: [PATCH 01/10] vere: fixes Makefile test-runner, exiting on failed test --- pkg/urbit/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/Makefile b/pkg/urbit/Makefile index cd567871e4..850f56e8f2 100644 --- a/pkg/urbit/Makefile +++ b/pkg/urbit/Makefile @@ -33,7 +33,12 @@ CFLAGS := $(CFLAGS) all: $(all_exes) test: $(test_exes) - for x in $^; do echo "\n$$x" && ./$$x; done + @FAIL=0; \ + for x in $^; \ + do echo "\n$$x" && ./$$x; \ + if [ $$? != 0 ]; then FAIL=1; fi; \ + done; \ + if [ $$FAIL != 0 ]; then echo "\n" && exit 1; fi; clean: rm -f ./tags $(all_objs) $(all_exes) From adb41996f0d8bb65482d39d291feb4fb6b27c84c Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 18 Dec 2019 00:48:13 -0800 Subject: [PATCH 02/10] vere: plugs leak in terminal spinner --- pkg/urbit/vere/term.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/vere/term.c b/pkg/urbit/vere/term.c index ea820714a5..bc06ab846f 100644 --- a/pkg/urbit/vere/term.c +++ b/pkg/urbit/vere/term.c @@ -835,7 +835,7 @@ u3_term_start_spinner(c3_c* why_c, c3_o now_o) u3_utty* uty_u = _term_main(); u3_utat* tat_u = &uty_u->tat_u; - c3_free(tat_u-> sun_u.why_c); + c3_free(tat_u->sun_u.why_c); tat_u->sun_u.why_c = why_c; tat_u->sun_u.eve_d = 0; @@ -854,6 +854,9 @@ u3_term_start_spinner(c3_c* why_c, c3_o now_o) wen_d, _SPIN_RATE_US); } } + else { + c3_free(why_c); + } } /* u3_term_stop_spinner(): reset spinner state and restore input line. @@ -865,6 +868,9 @@ u3_term_stop_spinner(void) u3_utty* uty_u = _term_main(); u3_utat* tat_u = &uty_u->tat_u; + c3_free(tat_u->sun_u.why_c); + tat_u->sun_u.why_c = 0; + uv_timer_stop(&tat_u->sun_u.tim_u); if ( c3y == tat_u->sun_u.diz_o ) { From 5f3a697aabfe2053a592e8e2fe38460d97843f8d Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 18 Dec 2019 19:39:38 -0800 Subject: [PATCH 03/10] vere: re-plugs leak in terminal spinner --- pkg/urbit/include/vere/vere.h | 4 ++-- pkg/urbit/vere/pier.c | 10 +++++----- pkg/urbit/vere/term.c | 17 ++++++----------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index 85399f63f9..e2e0beb00a 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -394,7 +394,7 @@ c3_o diz_o; // spinner activated c3_d eve_d; // spin count c3_d end_d; // spinner end tick (ms) - c3_c* why_c; // spinner label + c3_c why_c[5]; // spinner label } sun_u; } u3_utat; @@ -871,7 +871,7 @@ /* u3_term_start_spinner(): prepare spinner state. RETAIN. */ void - u3_term_start_spinner(c3_c* why_c, c3_o now_o); + u3_term_start_spinner(u3_noun say, c3_o now_o); /* u3_term_stop_spinner(): reset spinner state and restore input line. */ diff --git a/pkg/urbit/vere/pier.c b/pkg/urbit/vere/pier.c index 0597b5b398..dd83f71979 100644 --- a/pkg/urbit/vere/pier.c +++ b/pkg/urbit/vere/pier.c @@ -643,11 +643,11 @@ static void _pier_work_spin_start(u3_writ* wit_u) { u3_pier* pir_u = wit_u->pir_u; - c3_o now_o = c3n; - c3_c* why_c = 0; + c3_o now_o = c3n; + u3_noun say = u3_blip; if ( wit_u->evt_d <= pir_u->lif_d ) { - why_c = strdup("nock"); + say = c3__nock; } else { u3_noun why; @@ -661,7 +661,7 @@ _pier_work_spin_start(u3_writ* wit_u) if ( c3__term != why ) { - why_c = u3r_string(why); + say = why; } else if ( ( u3_none != (cad = u3r_at(7, wit_u->job)) ) && ( u3_none != (tag = u3r_at(2, cad)) ) && @@ -674,7 +674,7 @@ _pier_work_spin_start(u3_writ* wit_u) } } - u3_term_start_spinner(why_c, now_o); + u3_term_start_spinner(say, now_o); } /* _pier_work_spin_stop(): deactivate spinner. diff --git a/pkg/urbit/vere/term.c b/pkg/urbit/vere/term.c index bc06ab846f..3d7e550be5 100644 --- a/pkg/urbit/vere/term.c +++ b/pkg/urbit/vere/term.c @@ -787,12 +787,11 @@ _term_spin_timer_cb(uv_timer_t* tim_u) *cur_c++ = daz_c[lag_d % strlen(daz_c)]; c3_w sol_w = 1; // spinner length (utf-32) - if ( tat_u->sun_u.why_c ) { + if ( tat_u->sun_u.why_c[0] ) { strncpy(cur_c, dal_c, 2); cur_c += 2; sol_w += 1; // length of dal_c (utf-32) - // c3_w wel_w = strlen(tat_u.sun_u->why_c); strncpy(cur_c, tat_u->sun_u.why_c, 4); cur_c += 4; sol_w += 4; // XX assumed utf-8 @@ -826,17 +825,17 @@ _term_spin_timer_cb(uv_timer_t* tim_u) #define _SPIN_RATE_US 250UL // spinner rate (ms/frame) #define _SPIN_IDLE_US 500UL // spinner cools down if stopped this long -/* u3_term_start_spinner(): prepare spinner state +/* u3_term_start_spinner(): prepare spinner state. RETAIN. */ void -u3_term_start_spinner(c3_c* why_c, c3_o now_o) +u3_term_start_spinner(u3_noun say, c3_o now_o) { if ( c3n == u3_Host.ops_u.tem ) { u3_utty* uty_u = _term_main(); u3_utat* tat_u = &uty_u->tat_u; - c3_free(tat_u->sun_u.why_c); - tat_u->sun_u.why_c = why_c; + tat_u->sun_u.why_c[4] = 0; + u3r_bytes(0, 4, (c3_y*)tat_u->sun_u.why_c, say); tat_u->sun_u.eve_d = 0; // XX must be c3n for cursor backoff from EOL? @@ -854,9 +853,6 @@ u3_term_start_spinner(c3_c* why_c, c3_o now_o) wen_d, _SPIN_RATE_US); } } - else { - c3_free(why_c); - } } /* u3_term_stop_spinner(): reset spinner state and restore input line. @@ -868,8 +864,7 @@ u3_term_stop_spinner(void) u3_utty* uty_u = _term_main(); u3_utat* tat_u = &uty_u->tat_u; - c3_free(tat_u->sun_u.why_c); - tat_u->sun_u.why_c = 0; + memset(tat_u->sun_u.why_c, 0, 5); uv_timer_stop(&tat_u->sun_u.tim_u); From c945c583757f242060783d4359ed9d837e8ed6a6 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 18 Dec 2019 02:00:38 -0800 Subject: [PATCH 04/10] worker: free jet dashboard on exit --- pkg/urbit/worker/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index fbf9f2b326..f79c87b270 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -850,6 +850,10 @@ _worker_poke_exit(c3_w cod_w) // exit code } } + // XX move to jets.c + // + c3_free(u3D.ray_u); + exit(cod_w); } From d71c26417aff10312803f2408e54002f1ce86aa5 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 11 Dec 2019 14:32:14 -0800 Subject: [PATCH 05/10] vere: properly un/initialize openssl --- pkg/urbit/daemon/main.c | 26 ++++++++++++++++++++++---- pkg/urbit/vere/daemon.c | 5 ++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pkg/urbit/daemon/main.c b/pkg/urbit/daemon/main.c index 1e1679ef3b..152f743f3f 100644 --- a/pkg/urbit/daemon/main.c +++ b/pkg/urbit/daemon/main.c @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -744,12 +747,27 @@ main(c3_i argc, } } - /* Initialize OpenSSL for client and server - */ - SSL_library_init(); - SSL_load_error_strings(); + // Initialize OpenSSL for client and server + // + { + SSL_library_init(); + SSL_load_error_strings(); + } u3_daemon_commence(); + + // uninitialize OpenSSL + // + // see https://wiki.openssl.org/index.php/Library_Initialization + // + { + ENGINE_cleanup(); + CONF_modules_unload(1); + EVP_cleanup(); + CRYPTO_cleanup_all_ex_data(); + SSL_COMP_free_compression_methods(); + ERR_free_strings(); + } } return 0; diff --git a/pkg/urbit/vere/daemon.c b/pkg/urbit/vere/daemon.c index b76e20fe13..4981c820e1 100644 --- a/pkg/urbit/vere/daemon.c +++ b/pkg/urbit/vere/daemon.c @@ -928,8 +928,8 @@ u3_daemon_commence() } } - /* listen on command socket - */ + // listen on command socket + // { c3_c buf_c[256]; @@ -948,7 +948,6 @@ u3_daemon_commence() uv_run(u3L, UV_RUN_DEFAULT); _daemon_loop_exit(); - exit(0); } /* u3_daemon_bail(): immediately shutdown. From 84ccfa97d87c41618975f565c5be6817de275e19 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 11 Dec 2019 14:38:34 -0800 Subject: [PATCH 06/10] vere: properly un/initialize curl --- pkg/urbit/daemon/main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/urbit/daemon/main.c b/pkg/urbit/daemon/main.c index 152f743f3f..02f69acf8a 100644 --- a/pkg/urbit/daemon/main.c +++ b/pkg/urbit/daemon/main.c @@ -754,8 +754,19 @@ main(c3_i argc, SSL_load_error_strings(); } + // initialize curl + // + if ( 0 != curl_global_init(CURL_GLOBAL_DEFAULT) ) { + u3l_log("boot: curl initialization failed\r\n"); + exit(1); + } + u3_daemon_commence(); + // uninitialize curl + // + curl_global_cleanup(); + // uninitialize OpenSSL // // see https://wiki.openssl.org/index.php/Library_Initialization From 0393047847eb08ce66fdbcbf66e00ce3c5b62dad Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 18 Dec 2019 23:43:21 -0800 Subject: [PATCH 07/10] vere: close terminal driver last --- pkg/urbit/vere/pier.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/urbit/vere/pier.c b/pkg/urbit/vere/pier.c index 0597b5b398..69467f104f 100644 --- a/pkg/urbit/vere/pier.c +++ b/pkg/urbit/vere/pier.c @@ -1261,10 +1261,6 @@ _pier_loop_exit(u3_pier* pir_u) // XX legacy handlers, not yet scoped to a pier // { - cod_l = u3a_lush(c3__term); - u3_term_io_exit(); - u3a_lop(cod_l); - cod_l = u3a_lush(c3__http); u3_http_io_exit(); u3a_lop(cod_l); @@ -1272,6 +1268,10 @@ _pier_loop_exit(u3_pier* pir_u) cod_l = u3a_lush(c3__cttp); u3_cttp_io_exit(); u3a_lop(cod_l); + + cod_l = u3a_lush(c3__term); + u3_term_io_exit(); + u3a_lop(cod_l); } } From b7138abd0b83616f00feea94471b2ee6abc8f5d3 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 19 Dec 2019 00:04:37 -0800 Subject: [PATCH 08/10] vere: dispose of http-client resources on exit --- pkg/urbit/include/vere/vere.h | 3 +- pkg/urbit/vere/cttp.c | 57 +++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index 85399f63f9..f824df11a3 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -231,7 +231,8 @@ */ typedef struct _u3_cttp { u3_creq* ceq_u; // request list - h2o_http1client_ctx_t* // + h2o_timeout_t tim_u; // request timeout + h2o_http1client_ctx_t // ctx_u; // h2o client ctx void* tls_u; // client SSL_CTX* } u3_cttp; diff --git a/pkg/urbit/vere/cttp.c b/pkg/urbit/vere/cttp.c index 6af90ea096..c541b9cf13 100644 --- a/pkg/urbit/vere/cttp.c +++ b/pkg/urbit/vere/cttp.c @@ -835,7 +835,7 @@ _cttp_creq_connect(u3_creq* ceq_u) ( c3y == ceq_u->sec ) ? 443 : 80; // connect by IP - h2o_http1client_connect(&ceq_u->cli_u, ceq_u, u3_Host.ctp_u.ctx_u, ipf_u, + h2o_http1client_connect(&ceq_u->cli_u, ceq_u, &u3_Host.ctp_u.ctx_u, ipf_u, por_s, c3y == ceq_u->sec, _cttp_creq_on_connect); // set hostname for TLS handshake @@ -947,22 +947,6 @@ _cttp_init_tls() return tls_u; } -/* _cttp_init_h2o: initialize h2o client ctx and timeout -*/ -static h2o_http1client_ctx_t* -_cttp_init_h2o() -{ - h2o_timeout_t* tim_u = c3_malloc(sizeof(*tim_u)); - - h2o_timeout_init(u3L, tim_u, 300 * 1000); - - h2o_http1client_ctx_t* ctx_u = c3_calloc(sizeof(*ctx_u)); - ctx_u->loop = u3L; - ctx_u->io_timeout = tim_u; - - return ctx_u; -}; - /* u3_cttp_ef_http_client(): send an %http-client (outgoing request) to cttp. */ void @@ -1011,9 +995,26 @@ u3_cttp_ef_bake() void u3_cttp_io_init() { + // zero-initialize h2o ctx + // + memset(&u3_Host.ctp_u.ctx_u, 0, sizeof(u3_Host.ctp_u.ctx_u)); + + // link to event loop + // + u3_Host.ctp_u.ctx_u.loop = u3L; + + // link to initialized request timeout + // + h2o_timeout_init(u3L, &u3_Host.ctp_u.tim_u, 300 * 1000); + u3_Host.ctp_u.ctx_u.io_timeout = &u3_Host.ctp_u.tim_u; + + // link to initialized tls ctx + // u3_Host.ctp_u.tls_u = _cttp_init_tls(); - u3_Host.ctp_u.ctx_u = _cttp_init_h2o(); - u3_Host.ctp_u.ctx_u->ssl_ctx = u3_Host.ctp_u.tls_u; + u3_Host.ctp_u.ctx_u.ssl_ctx = u3_Host.ctp_u.tls_u; + + // zero-initialize request list + // u3_Host.ctp_u.ceq_u = 0; } @@ -1022,7 +1023,19 @@ u3_cttp_io_init() void u3_cttp_io_exit(void) { - SSL_CTX_free(u3_Host.ctp_u.tls_u); - c3_free(u3_Host.ctp_u.ctx_u->io_timeout); - c3_free(u3_Host.ctp_u.ctx_u); + // cancel requests + // + { + u3_creq* ceq_u = u3_Host.ctp_u.ceq_u; + + while ( ceq_u ) { + _cttp_creq_quit(ceq_u); + ceq_u = ceq_u->nex_u; + } + } + + // dispose of global resources + // + h2o_timeout_dispose(u3L, &u3_Host.ctp_u.tim_u); + SSL_CTX_free(u3_Host.ctp_u.tls_u); } From 9abe805933cea93af1f7f9aeb299782c0e5e1cad Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 20 Dec 2019 13:27:02 -0800 Subject: [PATCH 09/10] vere: dispose of http-server resources on exit --- pkg/urbit/vere/http.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/urbit/vere/http.c b/pkg/urbit/vere/http.c index 1de98afb61..5ca88a7e60 100644 --- a/pkg/urbit/vere/http.c +++ b/pkg/urbit/vere/http.c @@ -1764,14 +1764,15 @@ u3_http_io_talk(void) void u3_http_io_exit(void) { - // Note: nothing in this codepath can print to uH! - // it will seriously mess up your terminal + // dispose of configuration to avoid restarts + // + _http_form_free(); - // u3_http* htp_u; - - // for ( htp_u = u3_Host.htp_u; htp_u; htp_u = htp_u->nex_u ) { - // _http_serv_close_hard(htp_u); - // } + // close all servers + // + for ( u3_http* htp_u = u3_Host.htp_u; htp_u; htp_u = htp_u->nex_u ) { + _http_serv_close(htp_u); + } // XX close u3_Host.fig_u.cli_u and con_u From 561db380c41acb28db24fb33f82f85d25c4f8206 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 19 Dec 2019 15:32:57 -0800 Subject: [PATCH 10/10] vere: adds trivial i/o driver exit handlers --- pkg/urbit/vere/ames.c | 1 - pkg/urbit/vere/behn.c | 2 ++ pkg/urbit/vere/save.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/vere/ames.c b/pkg/urbit/vere/ames.c index 1c28df28b1..371ac95daa 100644 --- a/pkg/urbit/vere/ames.c +++ b/pkg/urbit/vere/ames.c @@ -576,7 +576,6 @@ u3_ames_io_exit(u3_pier* pir_u) u3_ames* sam_u = pir_u->sam_u; if ( c3y == sam_u->liv ) { - // XX remove had_u/wax_u union, cast and close wax_u uv_close(&sam_u->had_u, 0); } } diff --git a/pkg/urbit/vere/behn.c b/pkg/urbit/vere/behn.c index 9586b73ab5..96b9a0b9d0 100644 --- a/pkg/urbit/vere/behn.c +++ b/pkg/urbit/vere/behn.c @@ -31,6 +31,8 @@ u3_behn_io_init(u3_pier *pir_u) void u3_behn_io_exit(u3_pier *pir_u) { + u3_behn* teh_u = pir_u->teh_u; + uv_close((uv_handle_t*)&teh_u->tim_u, 0); } /* _behn_time_cb(): timer callback. diff --git a/pkg/urbit/vere/save.c b/pkg/urbit/vere/save.c index 1c62e8442e..63ad738766 100644 --- a/pkg/urbit/vere/save.c +++ b/pkg/urbit/vere/save.c @@ -63,4 +63,6 @@ u3_save_io_init(u3_pier *pir_u) void u3_save_io_exit(u3_pier *pir_u) { + u3_save* sav_u = pir_u->sav_u; + uv_close((uv_handle_t*)&sav_u->tim_u, 0); }