SDL  2.0
SDL_quit.c File Reference
#include "../SDL_internal.h"
#include "SDL_hints.h"
#include "SDL_assert.h"
#include "SDL_events.h"
#include "SDL_events_c.h"
+ Include dependency graph for SDL_quit.c:

Go to the source code of this file.

Functions

static void SDL_HandleSIG (int sig)
 
static int SDL_QuitInit_Internal (void)
 
int SDL_QuitInit (void)
 
static void SDL_QuitQuit_Internal (void)
 
void SDL_QuitQuit (void)
 
int SDL_SendQuit (void)
 
void SDL_SendPendingQuit (void)
 

Variables

static SDL_bool disable_signals = SDL_FALSE
 
static SDL_bool send_quit_pending = SDL_FALSE
 

Function Documentation

◆ SDL_HandleSIG()

static void SDL_HandleSIG ( int  sig)
static

Definition at line 39 of file SDL_quit.c.

References SDL_TRUE, and send_quit_pending.

Referenced by SDL_QuitInit_Internal(), and SDL_QuitQuit_Internal().

40 {
41  /* Reset the signal handler */
42  signal(sig, SDL_HandleSIG);
43 
44  /* Send a quit event next time the event loop pumps. */
45  /* We can't send it in signal handler; malloc() might be interrupted! */
47 }
static void SDL_HandleSIG(int sig)
Definition: SDL_quit.c:39
static SDL_bool send_quit_pending
Definition: SDL_quit.c:35

◆ SDL_QuitInit()

int SDL_QuitInit ( void  )

Definition at line 92 of file SDL_quit.c.

References SDL_FALSE, SDL_GetHintBoolean, SDL_HINT_NO_SIGNAL_HANDLERS, and SDL_QuitInit_Internal().

Referenced by SDL_InitSubSystem().

93 {
95  return SDL_QuitInit_Internal();
96  }
97  return 0;
98 }
#define SDL_GetHintBoolean
#define SDL_HINT_NO_SIGNAL_HANDLERS
Tell SDL not to catch the SIGINT or SIGTERM signals.
Definition: SDL_hints.h:791
static int SDL_QuitInit_Internal(void)
Definition: SDL_quit.c:52

◆ SDL_QuitInit_Internal()

static int SDL_QuitInit_Internal ( void  )
static

Definition at line 52 of file SDL_quit.c.

References NULL, SDL_HandleSIG(), and void.

Referenced by SDL_QuitInit().

53 {
54 #ifdef HAVE_SIGACTION
55  struct sigaction action;
56  sigaction(SIGINT, NULL, &action);
57 #ifdef HAVE_SA_SIGACTION
58  if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
59 #else
60  if ( action.sa_handler == SIG_DFL ) {
61 #endif
62  action.sa_handler = SDL_HandleSIG;
63  sigaction(SIGINT, &action, NULL);
64  }
65  sigaction(SIGTERM, NULL, &action);
66 
67 #ifdef HAVE_SA_SIGACTION
68  if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
69 #else
70  if ( action.sa_handler == SIG_DFL ) {
71 #endif
72  action.sa_handler = SDL_HandleSIG;
73  sigaction(SIGTERM, &action, NULL);
74  }
75 #elif HAVE_SIGNAL_H
76  void (*ohandler) (int);
77 
78  /* Both SIGINT and SIGTERM are translated into quit interrupts */
79  ohandler = signal(SIGINT, SDL_HandleSIG);
80  if (ohandler != SIG_DFL)
81  signal(SIGINT, ohandler);
82  ohandler = signal(SIGTERM, SDL_HandleSIG);
83  if (ohandler != SIG_DFL)
84  signal(SIGTERM, ohandler);
85 #endif /* HAVE_SIGNAL_H */
86 
87  /* That's it! */
88  return 0;
89 }
static void SDL_HandleSIG(int sig)
Definition: SDL_quit.c:39
#define NULL
Definition: begin_code.h:164
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void

◆ SDL_QuitQuit()

void SDL_QuitQuit ( void  )

Definition at line 128 of file SDL_quit.c.

References disable_signals, and SDL_QuitQuit_Internal().

Referenced by SDL_QuitSubSystem().

129 {
130  if (!disable_signals) {
132  }
133 }
static SDL_bool disable_signals
Definition: SDL_quit.c:34
static void SDL_QuitQuit_Internal(void)
Definition: SDL_quit.c:101

◆ SDL_QuitQuit_Internal()

static void SDL_QuitQuit_Internal ( void  )
static

Definition at line 101 of file SDL_quit.c.

References NULL, SDL_HandleSIG(), and void.

Referenced by SDL_QuitQuit().

102 {
103 #ifdef HAVE_SIGACTION
104  struct sigaction action;
105  sigaction(SIGINT, NULL, &action);
106  if ( action.sa_handler == SDL_HandleSIG ) {
107  action.sa_handler = SIG_DFL;
108  sigaction(SIGINT, &action, NULL);
109  }
110  sigaction(SIGTERM, NULL, &action);
111  if ( action.sa_handler == SDL_HandleSIG ) {
112  action.sa_handler = SIG_DFL;
113  sigaction(SIGTERM, &action, NULL);
114  }
115 #elif HAVE_SIGNAL_H
116  void (*ohandler) (int);
117 
118  ohandler = signal(SIGINT, SIG_DFL);
119  if (ohandler != SDL_HandleSIG)
120  signal(SIGINT, ohandler);
121  ohandler = signal(SIGTERM, SIG_DFL);
122  if (ohandler != SDL_HandleSIG)
123  signal(SIGTERM, ohandler);
124 #endif /* HAVE_SIGNAL_H */
125 }
static void SDL_HandleSIG(int sig)
Definition: SDL_quit.c:39
#define NULL
Definition: begin_code.h:164
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void

◆ SDL_SendPendingQuit()

void SDL_SendPendingQuit ( void  )

Definition at line 144 of file SDL_quit.c.

References SDL_assert, SDL_SendQuit(), and send_quit_pending.

Referenced by SDL_PumpEvents().

145 {
146  if (send_quit_pending) {
147  SDL_SendQuit();
149  }
150 }
static SDL_bool send_quit_pending
Definition: SDL_quit.c:35
int SDL_SendQuit(void)
Definition: SDL_quit.c:137
#define SDL_assert(condition)
Definition: SDL_assert.h:169

◆ SDL_SendQuit()

int SDL_SendQuit ( void  )

Definition at line 137 of file SDL_quit.c.

References SDL_FALSE, SDL_QUIT, SDL_SendAppEvent(), and send_quit_pending.

Referenced by SDL_SendPendingQuit(), and SDL_SendWindowEvent().

138 {
140  return SDL_SendAppEvent(SDL_QUIT);
141 }
static SDL_bool send_quit_pending
Definition: SDL_quit.c:35
int SDL_SendAppEvent(SDL_EventType eventType)
Definition: SDL_events.c:919

Variable Documentation

◆ disable_signals

SDL_bool disable_signals = SDL_FALSE
static

Definition at line 34 of file SDL_quit.c.

Referenced by SDL_QuitQuit().

◆ send_quit_pending

SDL_bool send_quit_pending = SDL_FALSE
static

Definition at line 35 of file SDL_quit.c.

Referenced by SDL_HandleSIG(), SDL_SendPendingQuit(), and SDL_SendQuit().