void mal_exit(void){ str err; /* * Before continuing we should make sure that all clients * (except the console) have left the scene. */ MCstopClients(0); #if 0 { int reruns=0, go_on; do{ if ( (go_on = MCactiveClients()) ) MT_sleep_ms(1000); mnstr_printf(mal_clients->fdout,"#MALexit: %d clients still active\n", go_on); } while (++reruns < SERVERSHUTDOWNDELAY && go_on > 1); } #endif stopHeartbeat(); #ifdef HAVE_JSONSTORE stopHttpdaemon(); #endif stopMALdataflow(); stopProfiling(); RECYCLEdrop(mal_clients); /* remove any left over intermediates */ unloadLibraries(); #if 0 /* skip this to solve random crashes, needs work */ freeModuleList(mal_clients->nspace); finishNamespace(); if( mal_clients->prompt) GDKfree(mal_clients->prompt); if( mal_clients->errbuf) GDKfree(mal_clients->errbuf); if( mal_clients->bak) GDKfree(mal_clients->bak); if( mal_clients->fdin){ /* missing protection against closing stdin stream */ (void) mnstr_close(mal_clients->fdin->s); (void) bstream_destroy(mal_clients->fdin); } if( mal_clients->fdout && mal_clients->fdout != GDKstdout) { (void) mnstr_close(mal_clients->fdout); (void) mnstr_destroy(mal_clients->fdout); } #endif /* deregister everything that was registered, ignore errors */ if ((err = msab_wildRetreat()) != NULL) { fprintf(stderr, "!%s", err); free(err); } /* the server will now be shut down */ if ((err = msab_registerStop()) != NULL) { fprintf(stderr, "!%s", err); free(err); } GDKexit(0); /* properly end GDK */ }
/* * The default method to interact with the database server is to connect * using a port number. The first line received should contain * authorization information, such as user name. * * The scheduleClient receives a challenge response consisting of * endian:user:password:lang:database: */ static void exit_streams( bstream *fin, stream *fout ) { if (fout && fout != GDKstdout) { mnstr_flush(fout); mnstr_close(fout); mnstr_destroy(fout); } if (fin) (void) bstream_destroy(fin); }
void MCexitClient(Client c) { #ifdef MAL_CLIENT_DEBUG printf("# Exit client %d\n", c->idx); #endif MPresetProfiler(c->fdout); if (c->father == NULL) { /* normal client */ if (c->fdout && c->fdout != GDKstdout) { (void) mnstr_close(c->fdout); (void) mnstr_destroy(c->fdout); } assert(c->bak == NULL); if (c->fdin) { /* missing protection against closing stdin stream */ (void) bstream_destroy(c->fdin); } c->fdout = NULL; c->fdin = NULL; } }