SmError.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. /* $TOG: SmError.c /main/5 1998/10/26 17:20:29 mgreess $ */
  24. /* *
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  26. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  27. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  28. * (c) Copyright 1993, 1994 Novell, Inc. *
  29. */
  30. /*************************************<+>*************************************
  31. *****************************************************************************
  32. **
  33. ** File: SmError.c
  34. **
  35. ** Project: HP DT Session Manager (dtsession)
  36. **
  37. ** Description:
  38. ** -----------
  39. ** This file contains all session manager error functions. The session
  40. ** manager traps all errors from the toolkit and server, and takes action
  41. ** depending on the type of the error.
  42. **
  43. **
  44. **
  45. *******************************************************************
  46. ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
  47. ** reserved. Copying or other reproduction of this program
  48. ** except for archival purposes is prohibited without prior
  49. ** written consent of Hewlett-Packard Company.
  50. ********************************************************************
  51. **
  52. **
  53. **
  54. *****************************************************************************
  55. *************************************<+>*************************************/
  56. #include <stdio.h>
  57. #ifdef _SUN_OS
  58. #include <string.h>
  59. #endif
  60. #include <X11/Intrinsic.h>
  61. #include <Dt/UserMsg.h>
  62. #include "Sm.h"
  63. #include "SmError.h"
  64. #include "SmGlobals.h"
  65. /*
  66. * Global variables
  67. */
  68. NlsStrings smNLS;
  69. /*
  70. * Local functions
  71. */
  72. static int LibError( Display *, XErrorEvent *) ;
  73. static int LibIOError( void ) ;
  74. static void ToolkitWarning( char *) ;
  75. static void ToolkitError( char *) ;
  76. /*************************************<->*************************************
  77. *
  78. * InitErrorHandler ()
  79. *
  80. *
  81. * Description:
  82. * -----------
  83. * Initialize all error handlers for use with the session manager
  84. * session manager should only exit on real severe conditions.
  85. * it should try to gracefully recover on the rest.
  86. *
  87. *
  88. * Inputs:
  89. * ------
  90. *
  91. *
  92. * Outputs:
  93. * -------
  94. *
  95. *
  96. * Comments:
  97. * --------
  98. *
  99. *************************************<->***********************************/
  100. void
  101. InitErrorHandler( void )
  102. {
  103. XSetErrorHandler(LibError);
  104. XSetIOErrorHandler( (IOErrorHandlerProc) LibIOError);
  105. XtSetWarningHandler(ToolkitWarning);
  106. XtSetErrorHandler(ToolkitError);
  107. }
  108. /*************************************<->*************************************
  109. *
  110. * LibError (display, errorEvent)
  111. *
  112. *
  113. * Description:
  114. * -----------
  115. * X error handler. Takes care of X errors so that the server will
  116. * not terminate the session manager on any error.
  117. *
  118. *
  119. * Inputs:
  120. * ------
  121. * errorEvent = pointer to error event returned by the server.
  122. *
  123. *
  124. * Outputs:
  125. * -------
  126. *
  127. * Comments:
  128. * --------
  129. *
  130. *************************************<->***********************************/
  131. static int
  132. LibError(
  133. Display *display,
  134. XErrorEvent *errorEvent )
  135. {
  136. #ifdef DEBUG
  137. switch (errorEvent->error_code)
  138. {
  139. case Success:
  140. break;
  141. case BadAccess:
  142. PrintError(DtError, BAD_ACCESS);
  143. break;
  144. case BadAtom:
  145. PrintError(DtError, BAD_ATOM);
  146. break;
  147. case BadDrawable:
  148. PrintError(DtError, BAD_DRAWABLE);
  149. break;
  150. case BadMatch:
  151. PrintError(DtError, BAD_MATCH);
  152. break;
  153. case BadValue:
  154. PrintError(DtError, BAD_VALUE);
  155. break;
  156. case BadWindow:
  157. PrintError(DtError, BAD_WINDOW);
  158. break;
  159. default:
  160. PrintError(DtError, DEFAULT_ERROR);
  161. break;
  162. }
  163. #endif /*DEBUG*/
  164. return 0;
  165. }
  166. /*************************************<->*************************************
  167. *
  168. * LibIOError ()
  169. *
  170. *
  171. * Description:
  172. * -----------
  173. * IO error handler. In charge of handling IO events from the
  174. * X server
  175. *
  176. *
  177. * Inputs:
  178. * ------
  179. *
  180. *
  181. * Outputs:
  182. * -------
  183. *
  184. * Comments:
  185. * --------
  186. *
  187. *************************************<->***********************************/
  188. static int
  189. LibIOError( void )
  190. {
  191. PrintError(DtError, GETMESSAGE(8, 1, "Connection to server lost - exiting."));
  192. SM_EXIT(-1);
  193. return 0;
  194. }
  195. /*************************************<->*************************************
  196. *
  197. * ToolkitWarning (message)
  198. *
  199. *
  200. * Description:
  201. * -----------
  202. * Handles all toolkit warnings
  203. *
  204. *
  205. * Inputs:
  206. * ------
  207. * message = error message sent by toolkit
  208. *
  209. *
  210. * Outputs:
  211. * -------
  212. *
  213. * Comments:
  214. * --------
  215. *
  216. *************************************<->***********************************/
  217. static void
  218. ToolkitWarning(
  219. char *message )
  220. {
  221. #ifdef DEBUG
  222. PrintError(DtError, message);
  223. #endif /*DEBUG*/
  224. }
  225. /*************************************<->*************************************
  226. *
  227. * ToolkitError (message)
  228. *
  229. *
  230. * Description:
  231. * -----------
  232. * Handles all toolkit errors
  233. *
  234. *
  235. * Inputs:
  236. * ------
  237. * message = error message sent by toolkit
  238. *
  239. *
  240. * Outputs:
  241. * -------
  242. *
  243. * Comments:
  244. * --------
  245. *
  246. * Xt assumes the client will exit when an XtError is generated
  247. * so we must exit since the state will be undefined if we
  248. * continue
  249. *
  250. *
  251. *************************************<->***********************************/
  252. static void
  253. ToolkitError(
  254. char *message )
  255. {
  256. PrintError(DtError, message);
  257. SM_EXIT(-1);
  258. }
  259. /*************************************<->*************************************
  260. *
  261. * PrintError (severity, help)
  262. *
  263. *
  264. * Description:
  265. * -----------
  266. * Handles the printing of all session manager errors using the dt API
  267. * These are simple errors that don't set errno
  268. *
  269. *
  270. * Inputs:
  271. * ------
  272. * severity = severity of the error
  273. * help = help message to user (what type of error)
  274. *
  275. *
  276. * Outputs:
  277. * -------
  278. *
  279. * Comments:
  280. * --------
  281. * WARNING: Currently the va_alist parameter is not used in the
  282. * DtSimpleError is not used
  283. *
  284. *************************************<->***********************************/
  285. void
  286. PrintError(
  287. DtSeverity severity,
  288. char *help )
  289. {
  290. _DtSimpleError(DtProgName, severity, NULL, "%.2000s", help);
  291. }
  292. /*************************************<->*************************************
  293. *
  294. * PrintErrnoError (severity, help)
  295. *
  296. *
  297. * Description:
  298. * -----------
  299. * Handles the printing of all session manager errors using the dt API
  300. * These are simple errors that set errno
  301. *
  302. *
  303. * Inputs:
  304. * ------
  305. * severity = severity of the error
  306. * help = help message to user (what type of error)
  307. *
  308. *
  309. * Outputs:
  310. * -------
  311. *
  312. * Comments:
  313. * --------
  314. * WARNING: Currently the va_alist parameter is not used in the
  315. * DtSimpleErrnoError is not used
  316. *
  317. *************************************<->***********************************/
  318. void
  319. PrintErrnoError(
  320. DtSeverity severity,
  321. char *help )
  322. {
  323. _DtSimpleErrnoError(DtProgName, severity, NULL, "%s", help);
  324. }