avrdude: Fix exit hook not being adapted properly

This commit is contained in:
Vojtech Kral 2018-05-21 18:34:45 +02:00
parent ee5a5df2a7
commit 5697754c5e

View File

@ -163,6 +163,7 @@ static LISTID extended_params = NULL;
static LISTID additional_config_files = NULL; static LISTID additional_config_files = NULL;
static PROGRAMMER * pgm; static PROGRAMMER * pgm;
static bool pgm_setup = false;
/* /*
* global options * global options
@ -365,14 +366,18 @@ static void list_parts(FILE * f, const char *prefix, LISTID avrparts)
walk_avrparts(avrparts, list_avrparts_callback, &c); walk_avrparts(avrparts, list_avrparts_callback, &c);
} }
static void exithook(void) // static void exithook(void)
{ // {
if (pgm->teardown) // if (pgm->teardown)
pgm->teardown(pgm); // pgm->teardown(pgm);
} // }
static int cleanup_main(int status) static int cleanup_main(int status)
{ {
if (pgm_setup && pgm->teardown) {
pgm->teardown(pgm);
}
if (updates) { if (updates) {
ldestroy_cb(updates, (void(*)(void*))free_update); ldestroy_cb(updates, (void(*)(void*))free_update);
updates = NULL; updates = NULL;
@ -889,6 +894,7 @@ int avrdude_main(int argc, char * argv [], const char *sys_config)
if (pgm->setup) { if (pgm->setup) {
pgm->setup(pgm); pgm->setup(pgm);
} }
pgm_setup = true; // Replaces the atexit hook
// if (pgm->teardown) { // if (pgm->teardown) {
// atexit(exithook); // atexit(exithook);
// } // }
@ -1500,6 +1506,5 @@ main_exit:
avrdude_message(MSG_INFO, "\n%s done. Thank you.\n\n", progname); avrdude_message(MSG_INFO, "\n%s done. Thank you.\n\n", progname);
} }
exithook();
return cleanup_main(exitrc); return cleanup_main(exitrc);
} }