diff --git a/hw/source/master.c b/hw/source/master.c index 6e744c4ac..afa01cc2b 100644 --- a/hw/source/master.c +++ b/hw/source/master.c @@ -469,7 +469,7 @@ SV_WriteFilterList (void) } static void -SV_Shutdown (void) +SV_Shutdown (void *data) { NET_Shutdown (); @@ -525,7 +525,7 @@ main (int argc, const char **argv) mst_cbuf = Cbuf_New (&id_interp); - Sys_RegisterShutdown (SV_Shutdown); + Sys_RegisterShutdown (SV_Shutdown, 0); Sys_Init (); diff --git a/include/QF/sys.h b/include/QF/sys.h index 06e2590fa..a1a5402c7 100644 --- a/include/QF/sys.h +++ b/include/QF/sys.h @@ -77,7 +77,7 @@ void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2), noret void Sys_FatalError (const char *error, ...) __attribute__((format(printf,1,2), noreturn)); void Sys_Quit (void) __attribute__((noreturn)); void Sys_Shutdown (void); -void Sys_RegisterShutdown (void (*func) (void)); +void Sys_RegisterShutdown (void (*func) (void *), void *data); int64_t Sys_LongTime (void); double Sys_DoubleTime (void); void Sys_TimeOfDay(date_t *date); diff --git a/include/netchan.h b/include/netchan.h index d811ba913..cfdcf1066 100644 --- a/include/netchan.h +++ b/include/netchan.h @@ -70,7 +70,7 @@ void Log_Incoming_Packet (const byte *p, int len, int has_sequence, int is_server); void Log_Outgoing_Packet (const byte *p, int len, int has_sequence, int is_server); -void Net_LogStop (void); +void Net_LogStop (void *data); void Analyze_Client_Packet (const byte * data, int len, int has_sequence); void Analyze_Server_Packet (const byte * data, int len, int has_sequence); diff --git a/libs/util/sys.c b/libs/util/sys.c index 811cac886..de1cb35d8 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -105,7 +105,8 @@ static sys_printf_t sys_err_printf_function = Sys_ErrPrintf; typedef struct shutdown_list_s { struct shutdown_list_s *next; - void (*func)(void); + void (*func) (void *); + void *data; } shutdown_list_t; typedef struct error_handler_s { @@ -492,7 +493,7 @@ Sys_Shutdown (void) shutdown_list_t *t; while (shutdown_list) { - shutdown_list->func (); + shutdown_list->func (shutdown_list->data); t = shutdown_list; shutdown_list = shutdown_list->next; free (t); @@ -571,7 +572,7 @@ Sys_Error (const char *error, ...) } VISIBLE void -Sys_RegisterShutdown (void (*func) (void)) +Sys_RegisterShutdown (void (*func) (void *), void *data) { shutdown_list_t *p; if (!func) @@ -580,6 +581,7 @@ Sys_RegisterShutdown (void (*func) (void)) if (!p) Sys_Error ("Sys_RegisterShutdown: insufficient memory"); p->func = func; + p->data = data; p->next = shutdown_list; shutdown_list = p; } diff --git a/nq/include/host.h b/nq/include/host.h index 8601ea4c2..9300abbfe 100644 --- a/nq/include/host.h +++ b/nq/include/host.h @@ -61,7 +61,7 @@ void Host_ClearMemory (void); void Host_ServerFrame (void); void Host_InitCommands (void); void Host_Init (void); -void Host_Shutdown(void); +void Host_Shutdown(void *data); void Host_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn)); void Host_EndGame (const char *message, ...) __attribute__((format(printf,1,2), noreturn)); void Host_Frame (float time); diff --git a/nq/source/host.c b/nq/source/host.c index 67b55507b..c08a4c093 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -957,7 +957,7 @@ Host_Init (void) better to run quit through here before final handoff to the sys code. */ void -Host_Shutdown (void) +Host_Shutdown (void *data) { static qboolean isdown = false; diff --git a/nq/source/sys_sdl.c b/nq/source/sys_sdl.c index 3f4fa726e..37ff959aa 100644 --- a/nq/source/sys_sdl.c +++ b/nq/source/sys_sdl.c @@ -85,7 +85,7 @@ startup (void) } static void -shutdown_f (void) +shutdown_f (void *data) { #ifndef _WIN32 // change stdin to blocking @@ -113,8 +113,8 @@ SDL_main (int argc, char *argv[]) isDedicated = (COM_CheckParm ("-dedicated") != 0); - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/nq/source/sys_unix.c b/nq/source/sys_unix.c index ec21a1d7b..2803d31f6 100644 --- a/nq/source/sys_unix.c +++ b/nq/source/sys_unix.c @@ -55,7 +55,7 @@ qboolean isDedicated = false; static void -shutdown_f (void) +shutdown_f (void *data) { // change stdin to blocking fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); @@ -75,8 +75,8 @@ main (int argc, const char **argv) isDedicated = (COM_CheckParm ("-dedicated") != 0); - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/nq/source/sys_unixd.c b/nq/source/sys_unixd.c index 55d956268..f9ff4ca74 100644 --- a/nq/source/sys_unixd.c +++ b/nq/source/sys_unixd.c @@ -53,7 +53,7 @@ qboolean isDedicated = true; static void -shutdown_f (void) +shutdown_f (void *data) { // change stdin to blocking fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); @@ -86,8 +86,8 @@ main (int argc, const char **argv) host_parms.argc = com_argc; host_parms.argv = com_argv; - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/nq/source/sys_win.c b/nq/source/sys_win.c index 421690748..e4593ffd0 100644 --- a/nq/source/sys_win.c +++ b/nq/source/sys_win.c @@ -104,7 +104,7 @@ startup (void) } static void -shutdown_f (void) +shutdown_f (void *data) { if (tevent) CloseHandle (tevent); @@ -207,8 +207,8 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, if (!isDedicated) init_handles (hInstance); - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/nq/source/sys_wind.c b/nq/source/sys_wind.c index b38461448..b0555ec43 100644 --- a/nq/source/sys_wind.c +++ b/nq/source/sys_wind.c @@ -39,7 +39,7 @@ qboolean isDedicated = true; static void -shutdown_f (void) +shutdown_f (void *data) { } @@ -69,8 +69,8 @@ main (int argc, const char **argv) host_parms.argc = com_argc; host_parms.argv = com_argv; - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/qtv/source/qtv.c b/qtv/source/qtv.c index 4980dea9b..1274254d5 100644 --- a/qtv/source/qtv.c +++ b/qtv/source/qtv.c @@ -220,7 +220,7 @@ qtv_memory_init (void) } static void -qtv_shutdown (void) +qtv_shutdown (void *data) { NET_Shutdown (); Con_Shutdown (); @@ -253,7 +253,7 @@ qtv_init (void) qtv_cbuf = Cbuf_New (&id_interp); qtv_args = Cbuf_ArgsNew (); - Sys_RegisterShutdown (qtv_shutdown); + Sys_RegisterShutdown (qtv_shutdown, 0); Sys_Init (); COM_ParseConfig (); diff --git a/qtv/source/server.c b/qtv/source/server.c index c664f36e4..c36465d31 100644 --- a/qtv/source/server.c +++ b/qtv/source/server.c @@ -508,7 +508,7 @@ sv_list_f (void) } static void -server_shutdown (void) +server_shutdown (void *data) { Hash_FlushTable (server_hash); Hash_DelTable (server_hash); @@ -540,7 +540,7 @@ server_run (server_t *sv) void Server_Init (void) { - Sys_RegisterShutdown (server_shutdown); + Sys_RegisterShutdown (server_shutdown, 0); server_hash = Hash_NewTable (61, server_get_key, server_free, 0); Cmd_AddCommand ("sv_new", sv_new_f, "Add a new server"); Cmd_AddCommand ("sv_del", sv_del_f, "Remove an existing server"); diff --git a/qw/include/host.h b/qw/include/host.h index 0c1492f47..27ad77325 100644 --- a/qw/include/host.h +++ b/qw/include/host.h @@ -50,7 +50,7 @@ extern int host_framecount; // incremented every frame, never reset void Host_ServerFrame (void); void Host_InitCommands (void); void Host_Init (void); -void Host_Shutdown(void); +void Host_Shutdown(void *data); void Host_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn)); void Host_EndGame (const char *message, ...) __attribute__((format(printf,1,2), noreturn)); void Host_Frame (float time); diff --git a/qw/include/server.h b/qw/include/server.h index abc5fdd9d..b32a46c63 100644 --- a/qw/include/server.h +++ b/qw/include/server.h @@ -488,7 +488,7 @@ client_t *SV_AllocClient (int spectator, int server); void SV_SavePenaltyFilter (client_t *cl, filtertype_t type, double pentime); double SV_RestorePenaltyFilter (client_t *cl, filtertype_t type); -void SV_Shutdown (void); +void SV_Shutdown (void *data); void SV_Frame (float time); void SV_FinalMessage (const char *message); void SV_DropClient (client_t *drop); diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index aa223736f..b78038ca9 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1867,7 +1867,7 @@ Host_Init (void) } void -Host_Shutdown (void) +Host_Shutdown (void *data) { static qboolean isdown = false; diff --git a/qw/source/cl_sys_sdl.c b/qw/source/cl_sys_sdl.c index 75f7c0024..79357134a 100644 --- a/qw/source/cl_sys_sdl.c +++ b/qw/source/cl_sys_sdl.c @@ -93,7 +93,7 @@ startup (void) } static void -shutdown_f (void) +shutdown_f (void *data) { #ifndef _WIN32 // change stdin to blocking @@ -122,9 +122,9 @@ SDL_main (int argc, char *argv[]) if (!COM_CheckParm ("-noconinput")) fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); #endif - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (Net_LogStop); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (Net_LogStop, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/qw/source/cl_sys_unix.c b/qw/source/cl_sys_unix.c index 05aedf9ff..4c7071ba2 100644 --- a/qw/source/cl_sys_unix.c +++ b/qw/source/cl_sys_unix.c @@ -52,7 +52,7 @@ #include "netchan.h" static void -shutdown_f (void) +shutdown_f (void *data) { // change stdin to blocking fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); @@ -73,9 +73,9 @@ main (int argc, const char **argv) if (!COM_CheckParm ("-noconinput")) fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (Net_LogStop); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (Net_LogStop, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/qw/source/cl_sys_win.c b/qw/source/cl_sys_win.c index 44d7c8afb..388166e7a 100644 --- a/qw/source/cl_sys_win.c +++ b/qw/source/cl_sys_win.c @@ -93,7 +93,7 @@ startup (void) } static void -shutdown_f (void) +shutdown_f (void *data) { if (tevent) CloseHandle (tevent); @@ -181,9 +181,9 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, if (!tevent) Sys_Error ("Couldn't create event"); - Sys_RegisterShutdown (Host_Shutdown); - Sys_RegisterShutdown (Net_LogStop); - Sys_RegisterShutdown (shutdown_f); + Sys_RegisterShutdown (Host_Shutdown, 0); + Sys_RegisterShutdown (Net_LogStop, 0); + Sys_RegisterShutdown (shutdown_f, 0); Host_Init (); diff --git a/qw/source/net_packetlog.c b/qw/source/net_packetlog.c index 3ec8078e5..189c6fefe 100644 --- a/qw/source/net_packetlog.c +++ b/qw/source/net_packetlog.c @@ -177,7 +177,7 @@ Net_LogStart (const char *fname) } void -Net_LogStop (void) +Net_LogStop (void *data) { if (Net_PacketLog) Qclose (Net_PacketLog); @@ -954,7 +954,7 @@ Net_PacketLog_f (cvar_t *var) if (var->int_val) { Net_LogStart ("qfpacket.log"); } else { - Net_LogStop (); + Net_LogStop (0); } } diff --git a/qw/source/sv_ccmds.c b/qw/source/sv_ccmds.c index 318a2edaf..93c5247f6 100644 --- a/qw/source/sv_ccmds.c +++ b/qw/source/sv_ccmds.c @@ -223,7 +223,7 @@ SV_Restart_f (void) net_message->message->data); } Sys_Printf ("Shutting down: server restart, shell must relaunch server\n"); - SV_Shutdown (); + SV_Shutdown (0); // Error code 2 on exit, indication shell must restart the server exit (2); } diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index d764c012f..56d135e16 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -237,7 +237,7 @@ Master_Shutdown (void) Quake calls this before calling Sys_Quit or Sys_Error */ void -SV_Shutdown (void) +SV_Shutdown (void *data) { Master_Shutdown (); if (sv_fraglogfile) { @@ -2486,7 +2486,7 @@ SV_Init (void) sv_cbuf = Cbuf_New (&id_interp); sv_args = Cbuf_ArgsNew (); - Sys_RegisterShutdown (SV_Shutdown); + Sys_RegisterShutdown (SV_Shutdown, 0); Sys_Init (); GIB_Init (true); diff --git a/qw/source/sv_sys_unix.c b/qw/source/sv_sys_unix.c index b3781bf5b..24b3adb4b 100644 --- a/qw/source/sv_sys_unix.c +++ b/qw/source/sv_sys_unix.c @@ -122,7 +122,7 @@ main (int argc, const char **argv) SV_Init (); - Sys_RegisterShutdown (Net_LogStop); + Sys_RegisterShutdown (Net_LogStop, 0); // run one frame immediately for first heartbeat SV_Frame (0.1); diff --git a/qw/source/sv_sys_win.c b/qw/source/sv_sys_win.c index 4397f5d92..52f3b230a 100644 --- a/qw/source/sv_sys_win.c +++ b/qw/source/sv_sys_win.c @@ -93,7 +93,7 @@ main (int argc, const char **argv) if (WinNT) Cvar_Set (sys_sleep, "0"); - Sys_RegisterShutdown (Net_LogStop); + Sys_RegisterShutdown (Net_LogStop, 0); // run one frame immediately for first heartbeat SV_Frame (0.1); diff --git a/ruamoko/qwaq/qwaq-bi.c b/ruamoko/qwaq/qwaq-bi.c index 7e21a9259..82bce4996 100644 --- a/ruamoko/qwaq/qwaq-bi.c +++ b/ruamoko/qwaq/qwaq-bi.c @@ -159,7 +159,7 @@ static builtin_t builtins[] = { }; static void -bi_shutdown (void) +bi_shutdown (void *data) { S_Shutdown (); IN_Shutdown (); @@ -177,7 +177,7 @@ BI_Init (progs_t *pr) PI_Init (); PI_RegisterPlugins (client_plugin_list); - Sys_RegisterShutdown (bi_shutdown); + Sys_RegisterShutdown (bi_shutdown, 0); VID_Init_Cvars (); IN_Init_Cvars (); diff --git a/ruamoko/qwaq/qwaq-curses.c b/ruamoko/qwaq/qwaq-curses.c index 6ab3f6154..27306fc28 100644 --- a/ruamoko/qwaq/qwaq-curses.c +++ b/ruamoko/qwaq/qwaq-curses.c @@ -921,7 +921,7 @@ process_input (qwaq_resources_t *res) static int need_endwin; static void -bi_shutdown (void) +bi_shutdown (void *_pr) { if (need_endwin) { write(1, MOUSE_MOVES_OFF, sizeof (MOUSE_MOVES_OFF) - 1); @@ -1950,7 +1950,7 @@ BI_Init (progs_t *pr) PR_Resources_Register (pr, "qwaq", res, bi_qwaq_clear); PR_RegisterBuiltins (pr, builtins); - Sys_RegisterShutdown (bi_shutdown); + Sys_RegisterShutdown (bi_shutdown, pr); logfile = fopen ("qwaq-curses.log", "wt"); Sys_SetStdPrintf (qwaq_print); }