WmError.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Motif Release 1.2.4
  29. */
  30. /*
  31. * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
  32. /*
  33. * Included Files:
  34. */
  35. #include "WmGlobal.h"
  36. #include <stdio.h>
  37. #include <Dt/UserMsg.h>
  38. #include "WmXSMP.h"
  39. /*
  40. * Function Declarations:
  41. */
  42. #include "WmError.h"
  43. #ifdef DEBUG
  44. #define E_MAJOR_CODE 0
  45. #define E_MINOR_CODE 1
  46. #define E_RESOURCE_ID 2
  47. #define E_ERROR_SERIAL 3
  48. #define E_CURRENT_SERIAL 4
  49. #define NUM_E_STRINGS 5
  50. static char *pchErrorFormatNames [NUM_E_STRINGS] = {
  51. "MajorCode",
  52. "MinorCode",
  53. "ResourceID",
  54. "ErrorSerial",
  55. "CurrentSerial"
  56. };
  57. static char *pchDefaultErrorFormat [NUM_E_STRINGS] = {
  58. " %d ",
  59. " %d ",
  60. " %ld ",
  61. " %ld ",
  62. " %ld "
  63. };
  64. static char *pchErrorFormat [NUM_E_STRINGS];
  65. #endif /* DEBUG */
  66. /*************************************<->*************************************
  67. *
  68. * WmInitErrorHandler (display)
  69. *
  70. *
  71. * Description:
  72. * -----------
  73. * This function initializes the window manager error handler.
  74. *
  75. *
  76. * Inputs:
  77. * ------
  78. * display = display we're talking about
  79. * -------
  80. *
  81. *************************************<->***********************************/
  82. void
  83. WmInitErrorHandler (Display *display)
  84. {
  85. #ifdef DEBUG
  86. char buffer[BUFSIZ];
  87. int i;
  88. /*
  89. * Fetch the X error format strings from XErrorDB
  90. */
  91. for (i = 0; i< NUM_E_STRINGS; i++)
  92. {
  93. XGetErrorDatabaseText (display, "XlibMessage",
  94. pchErrorFormatNames[i],
  95. pchDefaultErrorFormat[i], buffer, BUFSIZ);
  96. if ((pchErrorFormat[i] = (char *) XtMalloc (1+strlen(buffer))) == NULL)
  97. {
  98. Warning ("Insufficient memory for error message initialization.");
  99. ExitWM (1);
  100. }
  101. strcpy(pchErrorFormat[i], buffer);
  102. }
  103. #endif /* DEBUG */
  104. XSetErrorHandler (WmXErrorHandler);
  105. XSetIOErrorHandler (WmXIOErrorHandler);
  106. XtSetWarningHandler (WmXtWarningHandler);
  107. XtSetErrorHandler (WmXtErrorHandler);
  108. } /* END OF FUNCTION WmInitErrorHandler */
  109. /*************************************<->*************************************
  110. *
  111. * WmXErrorHandler (display, errorEvent)
  112. *
  113. *
  114. * Description:
  115. * -----------
  116. * This function is the X error handler that is registered with X to
  117. * handle X errors resulting from window management activities.
  118. *
  119. *
  120. * Inputs:
  121. * ------
  122. * display = display on which X error occurred
  123. *
  124. * errorEvent = pointer to a block of information describing the error
  125. *
  126. *
  127. * Outputs:
  128. * -------
  129. * wmGD.errorFlag = set to True
  130. *
  131. * Return = 0
  132. *
  133. *************************************<->***********************************/
  134. int
  135. WmXErrorHandler (Display *display, XErrorEvent *errorEvent)
  136. {
  137. ClientData *pCD;
  138. #ifdef DEBUG
  139. char buffer[BUFSIZ];
  140. char message[BUFSIZ];
  141. XGetErrorText (display, errorEvent->error_code, buffer, BUFSIZ);
  142. Warning ("X error occurred during window management operation");
  143. fprintf (stderr, "Description = '%s'\n ", buffer);
  144. fprintf (stderr, pchErrorFormat[E_MAJOR_CODE], errorEvent->request_code);
  145. sprintf(message, "%d", errorEvent->request_code);
  146. XGetErrorDatabaseText (display, "XRequest", message,
  147. " ", buffer, BUFSIZ);
  148. fprintf (stderr, " (%s)\n ", buffer);
  149. fprintf (stderr, pchErrorFormat[E_MINOR_CODE], errorEvent->minor_code);
  150. fprintf (stderr, "\n ");
  151. fprintf (stderr, pchErrorFormat[E_RESOURCE_ID], errorEvent->resourceid);
  152. fprintf (stderr, "\n ");
  153. fprintf (stderr, pchErrorFormat[E_ERROR_SERIAL], errorEvent->serial);
  154. fprintf (stderr, "\n ");
  155. fprintf (stderr, pchErrorFormat[E_CURRENT_SERIAL],
  156. LastKnownRequestProcessed(display));
  157. fprintf (stderr, "\n");
  158. #endif /* DEBUG */
  159. /*
  160. * Check for a BadWindow error for a managed window. If this error
  161. * is detected indicate in the client data that the window no longer
  162. * exists.
  163. */
  164. if ((errorEvent->error_code == BadWindow) &&
  165. !XFindContext (DISPLAY, errorEvent->resourceid, wmGD.windowContextType,
  166. (caddr_t *)&pCD))
  167. {
  168. if (errorEvent->resourceid == pCD->client)
  169. {
  170. pCD->clientFlags |= CLIENT_DESTROYED;
  171. }
  172. }
  173. wmGD.errorFlag = True;
  174. wmGD.errorResource = errorEvent->resourceid;
  175. wmGD.errorRequestCode = errorEvent->request_code;
  176. return (0);
  177. } /* END OF FUNCTION WmXErrorHandler */
  178. /*************************************<->*************************************
  179. *
  180. * WmXIOErrorHandler (display)
  181. *
  182. *
  183. * Description:
  184. * -----------
  185. * This function is the X IO error handler that is registered with X to
  186. * handle X IO errors. This function exits the window manager.
  187. *
  188. *
  189. * Inputs:
  190. * ------
  191. * display = X display on which the X IO error occurred
  192. *
  193. *************************************<->***********************************/
  194. int
  195. WmXIOErrorHandler (Display *display)
  196. {
  197. char err[100];
  198. sprintf (err, "%s: %s\n", "I/O error on display:", XDisplayString(display));
  199. Warning(err);
  200. ExitWM (WM_ERROR_EXIT_VALUE);
  201. /*NOTREACHED*/
  202. return 1;
  203. } /* END OF FUNCTIONS WmXIOErrorHandler */
  204. /*************************************<->*************************************
  205. *
  206. * WmXtErrorHandler (message)
  207. *
  208. *
  209. * Description:
  210. * -----------
  211. * This function is registered as the X Toolkit fatal error handler.
  212. *
  213. *
  214. * Inputs:
  215. * ------
  216. * message = pointer to an error message
  217. *
  218. *************************************<->***********************************/
  219. void
  220. WmXtErrorHandler (char *message)
  221. {
  222. Warning (message);
  223. ExitWM (WM_ERROR_EXIT_VALUE);
  224. } /* END OF FUNCTION WmXtErrorHandler */
  225. /*************************************<->*************************************
  226. *
  227. * WmXtWarningHandler (message)
  228. *
  229. *
  230. * Description:
  231. * -----------
  232. * This function is registered as an X Toolkit warning handler.
  233. *
  234. *
  235. * Inputs:
  236. * ------
  237. * message = pointer to a warning message
  238. *
  239. *************************************<->***********************************/
  240. void
  241. WmXtWarningHandler (char *message)
  242. {
  243. #ifdef DEBUG
  244. Warning (message);
  245. #endif /* DEBUG */
  246. } /* END OF FUNCTIONS WmXtWarningHandler */
  247. /*************************************<->*************************************
  248. *
  249. * Warning (message)
  250. *
  251. *
  252. * Description:
  253. * -----------
  254. * This function lists a message to stderr.
  255. *
  256. *
  257. * Inputs:
  258. * ------
  259. * message = pointer to a message string
  260. *
  261. *************************************<->***********************************/
  262. void
  263. Warning (char *message)
  264. {
  265. char pch[MAXWMPATH+1];
  266. sprintf (pch, "%s: %s\n",
  267. GETMESSAGE(20, 1, "Workspace Manager"), message);
  268. _DtSimpleError (wmGD.mwmName, DtIgnore, NULL, pch, NULL);
  269. } /* END OF FUNCTION Warning */
  270. #ifdef DEBUGGER
  271. /******************************<->*************************************
  272. *
  273. * PrintFormatted (format, message, message, ...)
  274. *
  275. *
  276. * Description:
  277. * -----------
  278. * This function lists several messages to stderr using fprintf()
  279. * formatting capabilities.
  280. *
  281. * Inputs:
  282. * ------
  283. * s0-s9 = pointers to message strings
  284. *
  285. * Comments:
  286. * ------
  287. * Caller must provide his/her own argv[0] to this function.
  288. ******************************<->***********************************/
  289. /*VARARGS1*/
  290. void
  291. PrintFormatted(char *f, char *s0, char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9)
  292. /* limit of ten args */
  293. {
  294. fprintf( stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  295. fflush (stderr);
  296. } /* END OF FUNCTION PrintFormatted */
  297. /************************ eof **************************/
  298. #endif /* DEBUGGER */