Merge branches 'vere-test-exit', 'spinner-leak' and 'exit-cleanup'

* origin/vere-test-exit:
  vere: fixes Makefile test-runner, exiting on failed test

* origin/spinner-leak:
  vere: re-plugs leak in terminal spinner
  vere: plugs leak in terminal spinner

* origin/exit-cleanup:
  vere: adds trivial i/o driver exit handlers
  vere: dispose of http-server resources on exit
  vere: dispose of http-client resources on exit
  vere: close terminal driver last
  vere: properly un/initialize curl
  vere: properly un/initialize openssl
  worker: free jet dashboard on exit

Signed-off-by: Jared Tobin <jared@tlon.io>
This commit is contained in:
Jared Tobin 2020-01-16 06:26:14 -08:00
commit 8ab2afe8b4
No known key found for this signature in database
GPG Key ID: 0E4647D58F8A69E4
12 changed files with 112 additions and 56 deletions

View File

@ -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)

View File

@ -13,6 +13,9 @@
#include <termios.h>
#include <ncurses/term.h>
#include <dirent.h>
#include <openssl/conf.h>
#include <openssl/engine.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <h2o.h>
#include <curl/curl.h>
@ -744,12 +747,38 @@ 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();
}
// 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
//
{
ENGINE_cleanup();
CONF_modules_unload(1);
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
SSL_COMP_free_compression_methods();
ERR_free_strings();
}
}
return 0;

View File

@ -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;
@ -394,7 +395,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 +872,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.
*/

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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);
}

View File

@ -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.

View File

@ -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

View File

@ -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.
@ -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);
}
}

View File

@ -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);
}

View File

@ -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?
@ -865,6 +864,8 @@ u3_term_stop_spinner(void)
u3_utty* uty_u = _term_main();
u3_utat* tat_u = &uty_u->tat_u;
memset(tat_u->sun_u.why_c, 0, 5);
uv_timer_stop(&tat_u->sun_u.tim_u);
if ( c3y == tat_u->sun_u.diz_o ) {

View File

@ -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);
}