Home | History | Annotate | Line # | Download | only in src
      1 /*
      2 
      3 Copyright 1993, 1998  The Open Group
      4 
      5 Permission to use, copy, modify, distribute, and sell this software and its
      6 documentation for any purpose is hereby granted without fee, provided that
      7 the above copyright notice appear in all copies and that both that
      8 copyright notice and this permission notice appear in supporting
      9 documentation.
     10 
     11 The above copyright notice and this permission notice shall be included in
     12 all copies or substantial portions of the Software.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     20 
     21 Except as contained in this notice, the name of The Open Group shall not be
     22 used in advertising or otherwise to promote the sale, use or other dealings
     23 in this Software without prior written authorization from The Open Group.
     24 
     25 */
     26 
     27 /*
     28  * Author: Ralph Mor, X Consortium
     29  */
     30 
     31 #ifdef HAVE_CONFIG_H
     32 #include <config.h>
     33 #endif
     34 #include <X11/SM/SMlib.h>
     35 #include "SMlibint.h"
     36 #include <stdio.h>
     37 
     38 
     39 
     40 /*
     42  * Default Smc error handler.
     43  */
     44 
     45 void
     46 _SmcDefaultErrorHandler(SmcConn smcConn, Bool swap, int offendingMinorOpcode,
     47 			unsigned long offendingSequence, int errorClass,
     48 			int severity, SmPointer values)
     49 {
     50     char *pData = (char *) values;
     51     const char *str;
     52 
     53     switch (offendingMinorOpcode)
     54     {
     55         case SM_RegisterClient:
     56             str = "RegisterClient";
     57 	    break;
     58         case SM_InteractRequest:
     59             str = "InteractRequest";
     60 	    break;
     61         case SM_InteractDone:
     62             str = "InteractDone";
     63 	    break;
     64         case SM_SaveYourselfDone:
     65             str = "SaveYourselfDone";
     66 	    break;
     67         case SM_CloseConnection:
     68             str = "CloseConnection";
     69 	    break;
     70         case SM_SetProperties:
     71             str = "SetProperties";
     72 	    break;
     73         case SM_GetProperties:
     74             str = "GetProperties";
     75 	    break;
     76 	default:
     77 	    str = "";
     78 	}
     79 
     80     fprintf (stderr, "\n");
     81 
     82     fprintf (stderr, "XSMP error:  Offending minor opcode    = %d (%s)\n",
     83 	offendingMinorOpcode, str);
     84 
     85     fprintf (stderr, "             Offending sequence number = %ld\n",
     86 	offendingSequence);
     87 
     88     switch (errorClass)
     89     {
     90         case IceBadMinor:
     91             str = "BadMinor";
     92             break;
     93         case IceBadState:
     94             str = "BadState";
     95             break;
     96         case IceBadLength:
     97             str = "BadLength";
     98             break;
     99         case IceBadValue:
    100             str = "BadValue";
    101             break;
    102 	default:
    103 	    str = "???";
    104     }
    105 
    106     fprintf (stderr, "             Error class               = %s\n", str);
    107 
    108     if (severity == IceCanContinue)
    109 	str = "CanContinue";
    110     else if (severity == IceFatalToProtocol)
    111 	str = "FatalToProtocol";
    112     else if (severity == IceFatalToConnection)
    113 	str = "FatalToConnection";
    114     else
    115 	str = "???";
    116 
    117     fprintf (stderr, "             Severity                  = %s\n", str);
    118 
    119     switch (errorClass)
    120     {
    121         case IceBadValue:
    122         {
    123 	    unsigned int offset, length, val;
    124 
    125 	    EXTRACT_CARD32 (pData, swap, offset);
    126 	    EXTRACT_CARD32 (pData, swap, length);
    127 
    128 	    fprintf (stderr,
    129 		"             BadValue Offset           = %d\n", offset);
    130 	    fprintf (stderr,
    131 		"             BadValue Length           = %d\n", length);
    132 
    133 	    if (length <= 4)
    134 	    {
    135 		if (length == 1)
    136 		    val = (unsigned int) *pData;
    137 		else if (length == 2)
    138 		{
    139 		    EXTRACT_CARD16 (pData, swap, val);
    140 		}
    141 		else
    142 		{
    143 		    EXTRACT_CARD32 (pData, swap, val);
    144 		}
    145 
    146 		fprintf (stderr,
    147 	            "             BadValue                  = %d\n", val);
    148 	    }
    149             break;
    150 	}
    151 
    152 	default:
    153 	    break;
    154     }
    155 
    156     fprintf (stderr, "\n");
    157 
    158     if (severity != IceCanContinue)
    159 	exit (1);
    160 }
    161 
    162 
    163 
    164 /*
    166  * Default Sms error handler.
    167  */
    168 
    169 void
    170 _SmsDefaultErrorHandler(SmsConn smsConn, Bool swap, int offendingMinorOpcode,
    171 			unsigned long offendingSequence, int errorClass,
    172 			int severity, SmPointer values)
    173 {
    174     char *pData = (char *) values;
    175     const char *str;
    176 
    177     switch (offendingMinorOpcode)
    178     {
    179         case SM_SaveYourself:
    180             str = "SaveYourself";
    181 	    break;
    182         case SM_Interact:
    183             str = "Interact";
    184 	    break;
    185         case SM_Die:
    186             str = "Die";
    187 	    break;
    188         case SM_ShutdownCancelled:
    189             str = "ShutdownCancelled";
    190 	    break;
    191 	default:
    192 	    str = "";
    193 	}
    194 
    195     fprintf (stderr, "\n");
    196 
    197     fprintf (stderr, "XSMP error:  Offending minor opcode    = %d (%s)\n",
    198 	offendingMinorOpcode, str);
    199 
    200     fprintf (stderr, "             Offending sequence number = %ld\n",
    201 	offendingSequence);
    202 
    203     switch (errorClass)
    204     {
    205         case IceBadMinor:
    206             str = "BadMinor";
    207             break;
    208         case IceBadState:
    209             str = "BadState";
    210             break;
    211         case IceBadLength:
    212             str = "BadLength";
    213             break;
    214         case IceBadValue:
    215             str = "BadValue";
    216             break;
    217 	default:
    218 	    str = "???";
    219     }
    220 
    221     fprintf (stderr, "             Error class               = %s\n", str);
    222 
    223     if (severity == IceCanContinue)
    224 	str = "CanContinue";
    225     else if (severity == IceFatalToProtocol)
    226 	str = "FatalToProtocol";
    227     else if (severity == IceFatalToConnection)
    228 	str = "FatalToConnection";
    229     else
    230 	str = "???";
    231 
    232     fprintf (stderr, "             Severity                  = %s\n", str);
    233 
    234     switch (errorClass)
    235     {
    236         case IceBadValue:
    237         {
    238 	    unsigned int offset, length, val;
    239 
    240 	    EXTRACT_CARD32 (pData, swap, offset);
    241 	    EXTRACT_CARD32 (pData, swap, length);
    242 
    243 	    fprintf (stderr,
    244 		"             BadValue Offset           = %d\n", offset);
    245 	    fprintf (stderr,
    246 		"             BadValue Length           = %d\n", length);
    247 
    248 	    if (length <= 4)
    249 	    {
    250 		if (length == 1)
    251 		    val = (unsigned int) *pData;
    252 		else if (length == 2)
    253 		{
    254 		    EXTRACT_CARD16 (pData, swap, val);
    255 		}
    256 		else
    257 		{
    258 		    EXTRACT_CARD32 (pData, swap, val);
    259 		}
    260 
    261 		fprintf (stderr,
    262 	            "             BadValue                  = %d\n", val);
    263 	    }
    264             break;
    265 	}
    266 
    267 	default:
    268 	    break;
    269     }
    270 
    271     fprintf (stderr, "\n\n");
    272 
    273     /* don't exit() - that would kill the SM - pretty devastating */
    274 }
    275 
    276 
    277 
    278 /*
    280  * This procedure sets the Smc error handler to be the specified
    281  * routine.  If NULL is passed in the default error handler is restored.
    282  * The function's return value is the previous error handler.
    283  */
    284 
    285 SmcErrorHandler
    286 SmcSetErrorHandler(SmcErrorHandler handler)
    287 {
    288     SmcErrorHandler oldHandler = _SmcErrorHandler;
    289 
    290     if (handler != NULL)
    291 	_SmcErrorHandler = handler;
    292     else
    293 	_SmcErrorHandler = _SmcDefaultErrorHandler;
    294 
    295     return (oldHandler);
    296 }
    297 
    298 
    299 
    300 /*
    302  * This procedure sets the Sms error handler to be the specified
    303  * routine.  If NULL is passed in the default error handler is restored.
    304  * The function's return value is the previous error handler.
    305  */
    306 
    307 SmsErrorHandler
    308 SmsSetErrorHandler(SmsErrorHandler handler)
    309 {
    310     SmsErrorHandler oldHandler = _SmsErrorHandler;
    311 
    312     if (handler != NULL)
    313 	_SmsErrorHandler = handler;
    314     else
    315 	_SmsErrorHandler = _SmsDefaultErrorHandler;
    316 
    317     return (oldHandler);
    318 }
    319