sm_error.c revision 3c15da26
1126a8a12Smrg/* 2126a8a12Smrg 3126a8a12SmrgCopyright 1993, 1998 The Open Group 4126a8a12Smrg 5126a8a12SmrgPermission to use, copy, modify, distribute, and sell this software and its 6126a8a12Smrgdocumentation for any purpose is hereby granted without fee, provided that 7126a8a12Smrgthe above copyright notice appear in all copies and that both that 8126a8a12Smrgcopyright notice and this permission notice appear in supporting 9126a8a12Smrgdocumentation. 10126a8a12Smrg 11126a8a12SmrgThe above copyright notice and this permission notice shall be included in 12126a8a12Smrgall copies or substantial portions of the Software. 13126a8a12Smrg 14126a8a12SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15126a8a12SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16126a8a12SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17126a8a12SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18126a8a12SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19126a8a12SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20126a8a12Smrg 21126a8a12SmrgExcept as contained in this notice, the name of The Open Group shall not be 22126a8a12Smrgused in advertising or otherwise to promote the sale, use or other dealings 23126a8a12Smrgin this Software without prior written authorization from The Open Group. 24126a8a12Smrg 25126a8a12Smrg*/ 26126a8a12Smrg 27126a8a12Smrg/* 28126a8a12Smrg * Author: Ralph Mor, X Consortium 29126a8a12Smrg */ 30126a8a12Smrg 31126a8a12Smrg#ifdef HAVE_CONFIG_H 32126a8a12Smrg#include <config.h> 33126a8a12Smrg#endif 34126a8a12Smrg#include <X11/SM/SMlib.h> 35126a8a12Smrg#include "SMlibint.h" 36126a8a12Smrg#include <stdio.h> 37126a8a12Smrg 38126a8a12Smrg 39126a8a12Smrg 40126a8a12Smrg/* 41126a8a12Smrg * Default Smc error handler. 42126a8a12Smrg */ 43126a8a12Smrg 44126a8a12Smrgvoid 45d656433aSmrg_SmcDefaultErrorHandler(SmcConn smcConn, Bool swap, int offendingMinorOpcode, 46d656433aSmrg unsigned long offendingSequence, int errorClass, 47d656433aSmrg int severity, SmPointer values) 48126a8a12Smrg{ 49126a8a12Smrg char *pData = (char *) values; 50126a8a12Smrg const char *str; 51126a8a12Smrg 52126a8a12Smrg switch (offendingMinorOpcode) 53126a8a12Smrg { 54126a8a12Smrg case SM_RegisterClient: 55126a8a12Smrg str = "RegisterClient"; 56126a8a12Smrg break; 57126a8a12Smrg case SM_InteractRequest: 58126a8a12Smrg str = "InteractRequest"; 59126a8a12Smrg break; 60126a8a12Smrg case SM_InteractDone: 61126a8a12Smrg str = "InteractDone"; 62126a8a12Smrg break; 63126a8a12Smrg case SM_SaveYourselfDone: 64126a8a12Smrg str = "SaveYourselfDone"; 65126a8a12Smrg break; 66126a8a12Smrg case SM_CloseConnection: 67126a8a12Smrg str = "CloseConnection"; 68126a8a12Smrg break; 69126a8a12Smrg case SM_SetProperties: 70126a8a12Smrg str = "SetProperties"; 71126a8a12Smrg break; 72126a8a12Smrg case SM_GetProperties: 73126a8a12Smrg str = "GetProperties"; 74126a8a12Smrg break; 75126a8a12Smrg default: 76126a8a12Smrg str = ""; 77126a8a12Smrg } 78126a8a12Smrg 79126a8a12Smrg fprintf (stderr, "\n"); 80126a8a12Smrg 81126a8a12Smrg fprintf (stderr, "XSMP error: Offending minor opcode = %d (%s)\n", 82126a8a12Smrg offendingMinorOpcode, str); 83126a8a12Smrg 84126a8a12Smrg fprintf (stderr, " Offending sequence number = %ld\n", 85126a8a12Smrg offendingSequence); 86126a8a12Smrg 87126a8a12Smrg switch (errorClass) 88126a8a12Smrg { 89126a8a12Smrg case IceBadMinor: 90126a8a12Smrg str = "BadMinor"; 91126a8a12Smrg break; 92126a8a12Smrg case IceBadState: 93126a8a12Smrg str = "BadState"; 94126a8a12Smrg break; 95126a8a12Smrg case IceBadLength: 96126a8a12Smrg str = "BadLength"; 97126a8a12Smrg break; 98126a8a12Smrg case IceBadValue: 99126a8a12Smrg str = "BadValue"; 100126a8a12Smrg break; 101126a8a12Smrg default: 102126a8a12Smrg str = "???"; 103126a8a12Smrg } 104126a8a12Smrg 105126a8a12Smrg fprintf (stderr, " Error class = %s\n", str); 106126a8a12Smrg 107126a8a12Smrg if (severity == IceCanContinue) 108126a8a12Smrg str = "CanContinue"; 109126a8a12Smrg else if (severity == IceFatalToProtocol) 110126a8a12Smrg str = "FatalToProtocol"; 111126a8a12Smrg else if (severity == IceFatalToConnection) 112126a8a12Smrg str = "FatalToConnection"; 113126a8a12Smrg else 114126a8a12Smrg str = "???"; 115126a8a12Smrg 116126a8a12Smrg fprintf (stderr, " Severity = %s\n", str); 117126a8a12Smrg 118126a8a12Smrg switch (errorClass) 119126a8a12Smrg { 120126a8a12Smrg case IceBadValue: 121126a8a12Smrg { 122126a8a12Smrg int offset, length, val; 123126a8a12Smrg 124126a8a12Smrg EXTRACT_CARD32 (pData, swap, offset); 125126a8a12Smrg EXTRACT_CARD32 (pData, swap, length); 126126a8a12Smrg 127126a8a12Smrg fprintf (stderr, 128126a8a12Smrg " BadValue Offset = %d\n", offset); 129126a8a12Smrg fprintf (stderr, 130126a8a12Smrg " BadValue Length = %d\n", length); 131126a8a12Smrg 132126a8a12Smrg if (length <= 4) 133126a8a12Smrg { 134126a8a12Smrg if (length == 1) 135126a8a12Smrg val = (int) *pData; 136126a8a12Smrg else if (length == 2) 137126a8a12Smrg { 138126a8a12Smrg EXTRACT_CARD16 (pData, swap, val); 139126a8a12Smrg } 140126a8a12Smrg else 141126a8a12Smrg { 142126a8a12Smrg EXTRACT_CARD32 (pData, swap, val); 143126a8a12Smrg } 144126a8a12Smrg 145126a8a12Smrg fprintf (stderr, 146126a8a12Smrg " BadValue = %d\n", val); 147126a8a12Smrg } 148126a8a12Smrg break; 149126a8a12Smrg } 150126a8a12Smrg 151126a8a12Smrg default: 152126a8a12Smrg break; 153126a8a12Smrg } 154126a8a12Smrg 155126a8a12Smrg fprintf (stderr, "\n"); 156126a8a12Smrg 157126a8a12Smrg if (severity != IceCanContinue) 158126a8a12Smrg exit (1); 159126a8a12Smrg} 160126a8a12Smrg 161126a8a12Smrg 162126a8a12Smrg 163126a8a12Smrg/* 164126a8a12Smrg * Default Sms error handler. 165126a8a12Smrg */ 166126a8a12Smrg 167126a8a12Smrgvoid 168d656433aSmrg_SmsDefaultErrorHandler(SmsConn smsConn, Bool swap, int offendingMinorOpcode, 169d656433aSmrg unsigned long offendingSequence, int errorClass, 170d656433aSmrg int severity, SmPointer values) 171126a8a12Smrg{ 172126a8a12Smrg char *pData = (char *) values; 173126a8a12Smrg const char *str; 174126a8a12Smrg 175126a8a12Smrg switch (offendingMinorOpcode) 176126a8a12Smrg { 177126a8a12Smrg case SM_SaveYourself: 178126a8a12Smrg str = "SaveYourself"; 179126a8a12Smrg break; 180126a8a12Smrg case SM_Interact: 181126a8a12Smrg str = "Interact"; 182126a8a12Smrg break; 183126a8a12Smrg case SM_Die: 184126a8a12Smrg str = "Die"; 185126a8a12Smrg break; 186126a8a12Smrg case SM_ShutdownCancelled: 187126a8a12Smrg str = "ShutdownCancelled"; 188126a8a12Smrg break; 189126a8a12Smrg default: 190126a8a12Smrg str = ""; 191126a8a12Smrg } 192126a8a12Smrg 193126a8a12Smrg fprintf (stderr, "\n"); 194126a8a12Smrg 195126a8a12Smrg fprintf (stderr, "XSMP error: Offending minor opcode = %d (%s)\n", 196126a8a12Smrg offendingMinorOpcode, str); 197126a8a12Smrg 198126a8a12Smrg fprintf (stderr, " Offending sequence number = %ld\n", 199126a8a12Smrg offendingSequence); 200126a8a12Smrg 201126a8a12Smrg switch (errorClass) 202126a8a12Smrg { 203126a8a12Smrg case IceBadMinor: 204126a8a12Smrg str = "BadMinor"; 205126a8a12Smrg break; 206126a8a12Smrg case IceBadState: 207126a8a12Smrg str = "BadState"; 208126a8a12Smrg break; 209126a8a12Smrg case IceBadLength: 210126a8a12Smrg str = "BadLength"; 211126a8a12Smrg break; 212126a8a12Smrg case IceBadValue: 213126a8a12Smrg str = "BadValue"; 214126a8a12Smrg break; 215126a8a12Smrg default: 216126a8a12Smrg str = "???"; 217126a8a12Smrg } 218126a8a12Smrg 219126a8a12Smrg fprintf (stderr, " Error class = %s\n", str); 220126a8a12Smrg 221126a8a12Smrg if (severity == IceCanContinue) 222126a8a12Smrg str = "CanContinue"; 223126a8a12Smrg else if (severity == IceFatalToProtocol) 224126a8a12Smrg str = "FatalToProtocol"; 225126a8a12Smrg else if (severity == IceFatalToConnection) 226126a8a12Smrg str = "FatalToConnection"; 227126a8a12Smrg else 228126a8a12Smrg str = "???"; 229126a8a12Smrg 230126a8a12Smrg fprintf (stderr, " Severity = %s\n", str); 231126a8a12Smrg 232126a8a12Smrg switch (errorClass) 233126a8a12Smrg { 234126a8a12Smrg case IceBadValue: 235126a8a12Smrg { 236126a8a12Smrg int offset, length, val; 237126a8a12Smrg 238126a8a12Smrg EXTRACT_CARD32 (pData, swap, offset); 239126a8a12Smrg EXTRACT_CARD32 (pData, swap, length); 240126a8a12Smrg 241126a8a12Smrg fprintf (stderr, 242126a8a12Smrg " BadValue Offset = %d\n", offset); 243126a8a12Smrg fprintf (stderr, 244126a8a12Smrg " BadValue Length = %d\n", length); 245126a8a12Smrg 246126a8a12Smrg if (length <= 4) 247126a8a12Smrg { 248126a8a12Smrg if (length == 1) 249126a8a12Smrg val = (int) *pData; 250126a8a12Smrg else if (length == 2) 251126a8a12Smrg { 252126a8a12Smrg EXTRACT_CARD16 (pData, swap, val); 253126a8a12Smrg } 254126a8a12Smrg else 255126a8a12Smrg { 256126a8a12Smrg EXTRACT_CARD32 (pData, swap, val); 257126a8a12Smrg } 258126a8a12Smrg 259126a8a12Smrg fprintf (stderr, 260126a8a12Smrg " BadValue = %d\n", val); 261126a8a12Smrg } 262126a8a12Smrg break; 263126a8a12Smrg } 264126a8a12Smrg 265126a8a12Smrg default: 266126a8a12Smrg break; 267126a8a12Smrg } 268126a8a12Smrg 269126a8a12Smrg fprintf (stderr, "\n\n"); 270126a8a12Smrg 271126a8a12Smrg /* don't exit() - that would kill the SM - pretty devastating */ 272126a8a12Smrg} 273126a8a12Smrg 274126a8a12Smrg 275126a8a12Smrg 2763c15da26Smrg/* 277126a8a12Smrg * This procedure sets the Smc error handler to be the specified 278126a8a12Smrg * routine. If NULL is passed in the default error handler is restored. 279126a8a12Smrg * The function's return value is the previous error handler. 280126a8a12Smrg */ 2813c15da26Smrg 282126a8a12SmrgSmcErrorHandler 283d656433aSmrgSmcSetErrorHandler(SmcErrorHandler handler) 284126a8a12Smrg{ 285126a8a12Smrg SmcErrorHandler oldHandler = _SmcErrorHandler; 286126a8a12Smrg 287126a8a12Smrg if (handler != NULL) 288126a8a12Smrg _SmcErrorHandler = handler; 289126a8a12Smrg else 290126a8a12Smrg _SmcErrorHandler = _SmcDefaultErrorHandler; 291126a8a12Smrg 292126a8a12Smrg return (oldHandler); 293126a8a12Smrg} 294126a8a12Smrg 295126a8a12Smrg 296126a8a12Smrg 2973c15da26Smrg/* 298126a8a12Smrg * This procedure sets the Sms error handler to be the specified 299126a8a12Smrg * routine. If NULL is passed in the default error handler is restored. 300126a8a12Smrg * The function's return value is the previous error handler. 301126a8a12Smrg */ 3023c15da26Smrg 303126a8a12SmrgSmsErrorHandler 304d656433aSmrgSmsSetErrorHandler(SmsErrorHandler handler) 305126a8a12Smrg{ 306126a8a12Smrg SmsErrorHandler oldHandler = _SmsErrorHandler; 307126a8a12Smrg 308126a8a12Smrg if (handler != NULL) 309126a8a12Smrg _SmsErrorHandler = handler; 310126a8a12Smrg else 311126a8a12Smrg _SmsErrorHandler = _SmsDefaultErrorHandler; 312126a8a12Smrg 313126a8a12Smrg return (oldHandler); 314126a8a12Smrg} 315