7801bcb65ccd5546156b470ac317b69f2497f142
[oweals/cde.git] / SmError.c
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
57 #include <stdio.h>
58 #ifdef _SUN_OS
59 #include <string.h>
60 #endif
61 #include <X11/Intrinsic.h>
62 #include <Dt/UserMsg.h>
63 #include "Sm.h"
64 #include "SmError.h"
65 #include "SmGlobals.h"
66
67
68 /*
69  * Global variables
70  */
71 NlsStrings              smNLS;
72
73 /*
74  * Local functions
75  */
76
77 static int LibError( Display *, XErrorEvent *) ;
78 static int LibIOError( void ) ;
79 static void ToolkitWarning( char *) ;
80 static void ToolkitError( char *) ;
81
82
83 \f
84 /*************************************<->*************************************
85  *
86  *  InitErrorHandler ()
87  *
88  *
89  *  Description:
90  *  -----------
91  *  Initialize all error handlers for use with the session manager
92  *  session manager should only exit on real severe conditions.
93  *  it should try to gracefully recover on the rest.
94  *
95  *
96  *  Inputs:
97  *  ------
98  *
99  * 
100  *  Outputs:
101  *  -------
102  *
103  *
104  *  Comments:
105  *  --------
106  * 
107  *************************************<->***********************************/
108 void 
109 InitErrorHandler( void )
110 {
111     XSetErrorHandler(LibError);
112     XSetIOErrorHandler( (IOErrorHandlerProc) LibIOError);
113     XtSetWarningHandler(ToolkitWarning);
114     XtSetErrorHandler(ToolkitError);
115 }
116
117 \f
118 /*************************************<->*************************************
119  *
120  *  LibError (display, errorEvent)
121  *
122  *
123  *  Description:
124  *  -----------
125  *  X error handler.  Takes care of X errors so that the server will
126  *  not terminate the session manager on any error.
127  *
128  *
129  *  Inputs:
130  *  ------
131  *  errorEvent = pointer to error event returned by the server.
132  *
133  * 
134  *  Outputs:
135  *  -------
136  *
137  *  Comments:
138  *  --------
139  * 
140  *************************************<->***********************************/
141 static int 
142 LibError(
143         Display *display,
144         XErrorEvent *errorEvent )
145 {
146 #ifdef DEBUG
147     switch (errorEvent->error_code)
148     {
149       case Success:
150         break;
151       case BadAccess:
152         PrintError(DtError, BAD_ACCESS);
153         break;
154       case BadAtom:
155         PrintError(DtError, BAD_ATOM);  
156         break;
157       case BadDrawable:
158         PrintError(DtError, BAD_DRAWABLE);
159         break;
160       case BadMatch:
161         PrintError(DtError, BAD_MATCH);
162         break;
163       case BadValue:
164         PrintError(DtError, BAD_VALUE);
165         break;
166       case BadWindow:
167         PrintError(DtError, BAD_WINDOW);
168         break;
169       default:
170         PrintError(DtError, DEFAULT_ERROR);
171         break;
172     }
173 #endif /*DEBUG*/
174     return 0;
175 }
176
177 \f
178 /*************************************<->*************************************
179  *
180  *  LibIOError ()
181  *
182  *
183  *  Description:
184  *  -----------
185  *  IO error handler.  In charge of handling IO events from the
186  *  X server
187  *
188  *
189  *  Inputs:
190  *  ------
191  *
192  * 
193  *  Outputs:
194  *  -------
195  *
196  *  Comments:
197  *  --------
198  * 
199  *************************************<->***********************************/
200 static int 
201 LibIOError( void )
202 {
203     PrintError(DtError, GETMESSAGE(8, 1, "Connection to server lost - exiting."));
204     SM_EXIT(-1);
205     return 0;
206 }
207
208 \f
209 /*************************************<->*************************************
210  *
211  *  ToolkitWarning (message)
212  *
213  *
214  *  Description:
215  *  -----------
216  *  Handles all toolkit warnings
217  *
218  *
219  *  Inputs:
220  *  ------
221  *  message = error message sent by toolkit
222  *
223  * 
224  *  Outputs:
225  *  -------
226  *
227  *  Comments:
228  *  --------
229  * 
230  *************************************<->***********************************/
231 static void 
232 ToolkitWarning(
233         char *message )
234 {
235 #ifdef DEBUG
236     PrintError(DtError, message);
237 #endif /*DEBUG*/    
238 }
239
240
241 \f
242 /*************************************<->*************************************
243  *
244  *  ToolkitError (message)
245  *
246  *
247  *  Description:
248  *  -----------
249  *  Handles all toolkit errors
250  *
251  *
252  *  Inputs:
253  *  ------
254  *  message = error message sent by toolkit
255  *
256  * 
257  *  Outputs:
258  *  -------
259  *
260  *  Comments:
261  *  --------
262  * 
263  *  Xt assumes the client will exit when an XtError is generated
264  *  so we must exit since the state will be undefined if we
265  *  continue
266  * 
267  * 
268  *************************************<->***********************************/
269 static void 
270 ToolkitError(
271         char *message )
272 {
273
274     PrintError(DtError, message);
275     SM_EXIT(-1);
276 }
277
278 \f
279 /*************************************<->*************************************
280  *
281  *  PrintError (severity, help)
282  *
283  *
284  *  Description:
285  *  -----------
286  *  Handles the printing of all session manager errors using the dt API
287  *  These are simple errors that don't set errno
288  *
289  *
290  *  Inputs:
291  *  ------
292  *  severity = severity of the error
293  *  help = help message to user (what type of error)
294  *
295  * 
296  *  Outputs:
297  *  -------
298  *
299  *  Comments:
300  *  --------
301  *  WARNING: Currently the va_alist parameter is not used in the
302  *  DtSimpleError is not used
303  * 
304  *************************************<->***********************************/
305 void 
306 PrintError(
307         DtSeverity severity,
308         char *help )
309 {
310     _DtSimpleError(DtProgName, severity, NULL, "%.2000s", help);
311 }
312
313 \f
314 /*************************************<->*************************************
315  *
316  *  PrintErrnoError (severity, help)
317  *
318  *
319  *  Description:
320  *  -----------
321  *  Handles the printing of all session manager errors using the dt API
322  *  These are simple errors that set errno
323  *
324  *
325  *  Inputs:
326  *  ------
327  *  severity = severity of the error
328  *  help = help message to user (what type of error)
329  *
330  * 
331  *  Outputs:
332  *  -------
333  *
334  *  Comments:
335  *  --------
336  *  WARNING: Currently the va_alist parameter is not used in the
337  *  DtSimpleErrnoError is not used
338  * 
339  *************************************<->***********************************/
340 void 
341 PrintErrnoError(
342         DtSeverity severity,
343         char *help )
344 {
345     _DtSimpleErrnoError(DtProgName, severity, NULL, "%s", help);
346 }