1/* 2 *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. 3 * 4 *Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 *"Software"), to deal in the Software without restriction, including 7 *without limitation the rights to use, copy, modify, merge, publish, 8 *distribute, sublicense, and/or sell copies of the Software, and to 9 *permit persons to whom the Software is furnished to do so, subject to 10 *the following conditions: 11 * 12 *The above copyright notice and this permission notice shall be 13 *included in all copies or substantial portions of the Software. 14 * 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR 19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 *Except as contained in this notice, the name of Harold L Hunt II 24 *shall not be used in advertising or otherwise to promote the sale, use 25 *or other dealings in this Software without prior written authorization 26 *from Harold L Hunt II. 27 * 28 * Authors: Harold L Hunt II 29 */ 30 31#ifdef HAVE_XWIN_CONFIG_H 32#include <xwin-config.h> 33#endif 34 35#include <../xfree86/common/xorgVersion.h> 36#include "win.h" 37 38#ifdef DDXOSVERRORF 39/* Prototype */ 40void 41OsVendorVErrorF (const char *pszFormat, va_list va_args); 42 43void 44OsVendorVErrorF (const char *pszFormat, va_list va_args) 45{ 46#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW) 47 /* make sure the clipboard and multiwindow threads do not interfere the 48 * main thread */ 49 static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER; 50 51 /* Lock the printing mutex */ 52 pthread_mutex_lock (&s_pmPrinting); 53#endif 54 55 /* Print the error message to a log file, could be stderr */ 56 LogVWrite (0, pszFormat, va_args); 57 58#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW) 59 /* Unlock the printing mutex */ 60 pthread_mutex_unlock (&s_pmPrinting); 61#endif 62} 63#endif 64 65 66/* 67 * os/util.c/FatalError () calls our vendor ErrorF, so the message 68 * from a FatalError will be logged. Thus, the message for the 69 * fatal error is not passed to this function. 70 * 71 * Attempt to do last-ditch, safe, important cleanup here. 72 */ 73void 74OsVendorFatalError (void) 75{ 76 /* Don't give duplicate warning if UseMsg was called */ 77 if (g_fSilentFatalError) 78 return; 79 80 if (!g_fLogInited) { 81 g_fLogInited = TRUE; 82 g_pszLogFile = LogInit (g_pszLogFile, NULL); 83 } 84 LogClose (); 85 86 winMessageBoxF ( 87 "A fatal error has occurred and " PROJECT_NAME " will now exit.\n" \ 88 "Please open %s for more information.\n", 89 MB_ICONERROR, (g_pszLogFile?g_pszLogFile:"the logfile")); 90} 91 92 93/* 94 * winMessageBoxF - Print a formatted error message in a useful 95 * message box. 96 */ 97 98void 99winMessageBoxF (const char *pszError, UINT uType, ...) 100{ 101 char * pszErrorF = NULL; 102 char * pszMsgBox = NULL; 103 va_list args; 104 int size; 105 106 va_start(args, uType); 107 size = vasprintf (&pszErrorF, pszError, args); 108 va_end(args); 109 if (size == -1) { 110 pszErrorF = NULL; 111 goto winMessageBoxF_Cleanup; 112 } 113 114#define MESSAGEBOXF \ 115 "%s\n" \ 116 "Vendor: %s\n" \ 117 "Release: %d.%d.%d.%d (%d)\n" \ 118 "Contact: %s\n" \ 119 "%s\n\n" \ 120 "XWin was started with the following command-line:\n\n" \ 121 "%s\n" 122 123 size = asprintf (&pszMsgBox, MESSAGEBOXF, 124 pszErrorF, XVENDORNAME, 125 XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, 126 XORG_VERSION_SNAP, XORG_VERSION_CURRENT, 127 BUILDERADDR, 128 BUILDERSTRING, 129 g_pszCommandLine); 130 131 if (size == -1) { 132 pszMsgBox = NULL; 133 goto winMessageBoxF_Cleanup; 134 } 135 136 /* Display the message box string */ 137 MessageBox (NULL, 138 pszMsgBox, 139 PROJECT_NAME, 140 MB_OK | uType); 141 142 winMessageBoxF_Cleanup: 143 free(pszErrorF); 144 free(pszMsgBox); 145#undef MESSAGEBOXF 146} 147