[input] on construction failure, return NULL initdata #2289

This commit is contained in:
nick black 2021-10-21 03:16:53 -04:00
parent 7071cb42fa
commit d6e574f131
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -108,6 +108,7 @@ typedef struct inputctx {
ipipe readypipes[2]; // pipes[0]: poll()able fd indicating the presence of user input ipipe readypipes[2]; // pipes[0]: poll()able fd indicating the presence of user input
struct initial_responses* initdata; struct initial_responses* initdata;
struct initial_responses* initdata_complete; struct initial_responses* initdata_complete;
bool failed; // error initializing input automaton, abort
} inputctx; } inputctx;
static inline void static inline void
@ -1265,7 +1266,6 @@ build_cflow_automaton(inputctx* ictx){
// CSI (\e[) // CSI (\e[)
{ "[<\\N;\\N;\\NM", mouse_press_cb, }, { "[<\\N;\\N;\\NM", mouse_press_cb, },
{ "[<\\N;\\N;\\Nm", mouse_release_cb, }, { "[<\\N;\\N;\\Nm", mouse_release_cb, },
{ "[\\N;\\NR", cursor_location_cb, },
// technically these must begin with "4" or "8"; enforce in callbacks // technically these must begin with "4" or "8"; enforce in callbacks
{ "[\\N;\\N;\\Nt", geom_cb, }, { "[\\N;\\N;\\Nt", geom_cb, },
{ "[\\Nu", kitty_cb_simple, }, { "[\\Nu", kitty_cb_simple, },
@ -1287,6 +1287,7 @@ build_cflow_automaton(inputctx* ictx){
{ "[1;\\N:\\NH", kitty_cb_home, }, { "[1;\\N:\\NH", kitty_cb_home, },
{ "[?\\Nu", kitty_keyboard_cb, }, { "[?\\Nu", kitty_keyboard_cb, },
{ "[?2026;\\N$y", decrpm_asu_cb, }, { "[?2026;\\N$y", decrpm_asu_cb, },
{ "[\\N;\\NR", cursor_location_cb, },
{ "[?1;1S", NULL, }, // negative cregs XTSMGRAPHICS { "[?1;1S", NULL, }, // negative cregs XTSMGRAPHICS
{ "[?1;2S", NULL, }, // negative cregs XTSMGRAPHICS { "[?1;2S", NULL, }, // negative cregs XTSMGRAPHICS
{ "[?1;3;0S", NULL, }, // negative cregs XTSMGRAPHICS { "[?1;3;0S", NULL, }, // negative cregs XTSMGRAPHICS
@ -1425,6 +1426,7 @@ create_inputctx(tinfo* ti, FILE* infp, int lmargin, int tmargin, int rmargin,
i->rmargin = rmargin; i->rmargin = rmargin;
i->bmargin = bmargin; i->bmargin = bmargin;
i->drain = drain; i->drain = drain;
i->failed = false;
logdebug("input descriptors: %d/%d\n", i->stdinfd, i->termfd); logdebug("input descriptors: %d/%d\n", i->stdinfd, i->termfd);
return i; return i;
} }
@ -2000,11 +2002,9 @@ read_inputs_nblock(inputctx* ictx){
static void* static void*
input_thread(void* vmarshall){ input_thread(void* vmarshall){
inputctx* ictx = vmarshall; inputctx* ictx = vmarshall;
if(prep_all_keys(ictx)){ if(prep_all_keys(ictx) || build_cflow_automaton(ictx)){
abort(); // FIXME? ictx->failed = true;
} handoff_initial_responses(ictx);
if(build_cflow_automaton(ictx)){
abort(); // FIXME?
} }
for(;;){ for(;;){
read_inputs_nblock(ictx); read_inputs_nblock(ictx);
@ -2299,5 +2299,10 @@ struct initial_responses* inputlayer_get_responses(inputctx* ictx){
iresp = ictx->initdata_complete; iresp = ictx->initdata_complete;
ictx->initdata_complete = NULL; ictx->initdata_complete = NULL;
pthread_mutex_unlock(&ictx->ilock); pthread_mutex_unlock(&ictx->ilock);
if(ictx->failed){
logpanic("aborting after automaton construction failure\n");
free(iresp);
return NULL;
}
return iresp; return iresp;
} }