2
0

WmSignal.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Motif Release 1.2
  29. */
  30. /*
  31. * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
  32. /*
  33. * Included Files:
  34. */
  35. #include "WmGlobal.h" /* This should be the first include */
  36. #include <signal.h>
  37. #include <unistd.h>
  38. /*
  39. * include extern functions
  40. */
  41. #include "WmFeedback.h"
  42. #include "WmFunction.h"
  43. /*
  44. * Function Declarations:
  45. */
  46. #include "WmSignal.h"
  47. /*
  48. * Global Variables:
  49. */
  50. /*************************************<->*************************************
  51. *
  52. * AbortWmSignalHandler ()
  53. *
  54. *
  55. * Description:
  56. * -----------
  57. * This function is called on receipt of a fatal signal. We reset
  58. * the keyboard focus to pointer root before aborting.
  59. *
  60. *************************************<->***********************************/
  61. static void
  62. AbortWmSignalHandler (int sig)
  63. {
  64. struct sigaction sa;
  65. /*
  66. * Set input focus back to pointer root
  67. */
  68. XSetInputFocus(DISPLAY, PointerRoot, RevertToPointerRoot, CurrentTime);
  69. XSync (DISPLAY, False);
  70. XCloseDisplay (DISPLAY);
  71. /*
  72. * Invoke the default handler
  73. */
  74. (void) sigemptyset(&sa.sa_mask);
  75. sa.sa_flags = 0;
  76. sa.sa_handler = SIG_DFL;
  77. (void) sigaction (sig, &sa, (struct sigaction *) 0);
  78. kill (getpid(), sig);
  79. } /* END OF FUNCTION AbortSignalHandler */
  80. /*************************************<->*************************************
  81. *
  82. * RestoreDefaultSignalHandlers ()
  83. *
  84. *
  85. * Description:
  86. * -----------
  87. * This function sets up the signal handlers for the window manager.
  88. *
  89. *************************************<->***********************************/
  90. void
  91. RestoreDefaultSignalHandlers (void)
  92. {
  93. struct sigaction sa;
  94. struct sigaction osa;
  95. /*
  96. * Restore default action for signals we're interested in.
  97. */
  98. (void) sigemptyset(&sa.sa_mask);
  99. sa.sa_flags = 0;
  100. sa.sa_handler = SIG_DFL;
  101. if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
  102. (osa.sa_handler != SIG_IGN))
  103. {
  104. (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
  105. }
  106. if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
  107. (osa.sa_handler != SIG_IGN))
  108. {
  109. (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
  110. }
  111. (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
  112. (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
  113. (void) sigaction (SIGPIPE, &sa, (struct sigaction *) 0);
  114. (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
  115. (void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
  116. (void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
  117. (void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
  118. (void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
  119. #ifdef SIGSYS
  120. (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
  121. #endif
  122. }
  123. /*************************************<->*************************************
  124. *
  125. * SetupWmSignalHandlers ()
  126. *
  127. *
  128. * Description:
  129. * -----------
  130. * This function sets up the signal handlers for the window manager.
  131. *
  132. *************************************<->***********************************/
  133. void SetupWmSignalHandlers (int dummy)
  134. {
  135. struct sigaction sa;
  136. struct sigaction osa;
  137. /*
  138. * Catch software signals that we ask the user about
  139. * before quitting.
  140. */
  141. (void) sigemptyset(&sa.sa_mask);
  142. sa.sa_flags = 0;
  143. sa.sa_handler = QuitWmSignalHandler;
  144. if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
  145. (osa.sa_handler != SIG_IGN))
  146. {
  147. (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
  148. }
  149. if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
  150. (osa.sa_handler != SIG_IGN))
  151. {
  152. (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
  153. }
  154. (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
  155. (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
  156. /*
  157. * Ignore child death
  158. */
  159. #ifdef SA_NOCLDWAIT
  160. sa.sa_flags = SA_NOCLDWAIT; /* Don't create zombies */
  161. #else
  162. sa.sa_flags = 0;
  163. #endif
  164. sa.sa_handler = SIG_IGN;
  165. (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
  166. sa.sa_flags = 0;
  167. /*
  168. * Catch other fatal signals so we can reset the
  169. * keyboard focus to pointer root before aborting
  170. */
  171. sa.sa_handler = AbortWmSignalHandler;
  172. (void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
  173. (void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
  174. (void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
  175. (void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
  176. #ifdef SIGSYS
  177. (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
  178. #endif
  179. } /* END OF FUNCTION SetupWmSignalHandlers */
  180. /*************************************<->*************************************
  181. *
  182. * QuitWmSignalHandler ()
  183. *
  184. *
  185. * Description:
  186. * -----------
  187. * This function is called on receipt of a signal that is to terminate the
  188. * window manager.
  189. *
  190. *************************************<->***********************************/
  191. void QuitWmSignalHandler (int dummy)
  192. {
  193. if (wmGD.showFeedback & WM_SHOW_FB_KILL)
  194. {
  195. ConfirmAction (ACTIVE_PSD, QUIT_MWM_ACTION);
  196. XFlush(DISPLAY);
  197. }
  198. else
  199. {
  200. Do_Quit_Mwm(False);
  201. }
  202. } /* END OF FUNCTION QuitWmSignalHandler */