105b261ecSmrg/* 205b261ecSmrg *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved. 305b261ecSmrg * 405b261ecSmrg *Permission is hereby granted, free of charge, to any person obtaining 505b261ecSmrg * a copy of this software and associated documentation files (the 605b261ecSmrg *"Software"), to deal in the Software without restriction, including 705b261ecSmrg *without limitation the rights to use, copy, modify, merge, publish, 805b261ecSmrg *distribute, sublicense, and/or sell copies of the Software, and to 905b261ecSmrg *permit persons to whom the Software is furnished to do so, subject to 1005b261ecSmrg *the following conditions: 1105b261ecSmrg * 1205b261ecSmrg *The above copyright notice and this permission notice shall be 1305b261ecSmrg *included in all copies or substantial portions of the Software. 1405b261ecSmrg * 1505b261ecSmrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1605b261ecSmrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1705b261ecSmrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 1805b261ecSmrg *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR 1905b261ecSmrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 2005b261ecSmrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2105b261ecSmrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2205b261ecSmrg * 2305b261ecSmrg *Except as contained in this notice, the name of Harold L Hunt II 2405b261ecSmrg *shall not be used in advertising or otherwise to promote the sale, use 2505b261ecSmrg *or other dealings in this Software without prior written authorization 2605b261ecSmrg *from Harold L Hunt II. 2705b261ecSmrg * 2805b261ecSmrg * Authors: Harold L Hunt II 2905b261ecSmrg */ 3005b261ecSmrg 3105b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H 3205b261ecSmrg#include <xwin-config.h> 3305b261ecSmrg#endif 3405b261ecSmrg 356747b715Smrg#include <../xfree86/common/xorgVersion.h> 3605b261ecSmrg#include "win.h" 3705b261ecSmrg 3805b261ecSmrg#ifdef DDXOSVERRORF 3905b261ecSmrgvoid 4035c4bbdfSmrgOsVendorVErrorF(const char *pszFormat, va_list va_args) 4105b261ecSmrg{ 4235c4bbdfSmrg /* make sure the clipboard and multiwindow threads do not interfere the 4335c4bbdfSmrg * main thread */ 4435c4bbdfSmrg static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER; 4505b261ecSmrg 4635c4bbdfSmrg /* Lock the printing mutex */ 4735c4bbdfSmrg pthread_mutex_lock(&s_pmPrinting); 4805b261ecSmrg 4935c4bbdfSmrg /* Print the error message to a log file, could be stderr */ 5035c4bbdfSmrg LogVWrite(0, pszFormat, va_args); 5105b261ecSmrg 5235c4bbdfSmrg /* Unlock the printing mutex */ 5335c4bbdfSmrg pthread_mutex_unlock(&s_pmPrinting); 5405b261ecSmrg} 5505b261ecSmrg#endif 5605b261ecSmrg 5705b261ecSmrg/* 5835c4bbdfSmrg * os/log.c:FatalError () calls our vendor ErrorF, so the message 5935c4bbdfSmrg * from a FatalError will be logged. 6005b261ecSmrg * 6105b261ecSmrg * Attempt to do last-ditch, safe, important cleanup here. 6205b261ecSmrg */ 6305b261ecSmrgvoid 6435c4bbdfSmrgOsVendorFatalError(const char *f, va_list args) 6505b261ecSmrg{ 6635c4bbdfSmrg char errormsg[1024] = ""; 6735c4bbdfSmrg 6835c4bbdfSmrg /* Don't give duplicate warning if UseMsg was called */ 6935c4bbdfSmrg if (g_fSilentFatalError) 7035c4bbdfSmrg return; 7135c4bbdfSmrg 7235c4bbdfSmrg if (!g_fLogInited) { 7335c4bbdfSmrg g_fLogInited = TRUE; 741b5d61b8Smrg g_pszLogFile = LogInit(g_pszLogFile, ".old"); 7535c4bbdfSmrg } 7635c4bbdfSmrg LogClose(EXIT_ERR_ABORT); 7735c4bbdfSmrg 7835c4bbdfSmrg /* Format the error message */ 7935c4bbdfSmrg vsnprintf(errormsg, sizeof(errormsg), f, args); 8035c4bbdfSmrg 8135c4bbdfSmrg /* 8235c4bbdfSmrg Sometimes the error message needs a bit of cosmetic cleaning 8335c4bbdfSmrg up for use in a dialog box... 8435c4bbdfSmrg */ 8535c4bbdfSmrg { 8635c4bbdfSmrg char *s; 8735c4bbdfSmrg 8835c4bbdfSmrg while ((s = strstr(errormsg, "\n\t")) != NULL) { 8935c4bbdfSmrg s[0] = ' '; 9035c4bbdfSmrg s[1] = '\n'; 9135c4bbdfSmrg } 9235c4bbdfSmrg } 9335c4bbdfSmrg 9435c4bbdfSmrg winMessageBoxF("A fatal error has occurred and " PROJECT_NAME " will now exit.\n\n" 9535c4bbdfSmrg "%s\n\n" 9635c4bbdfSmrg "Please open %s for more information.\n", 9735c4bbdfSmrg MB_ICONERROR, 9835c4bbdfSmrg errormsg, 9935c4bbdfSmrg (g_pszLogFile ? g_pszLogFile : "the logfile")); 10005b261ecSmrg} 10105b261ecSmrg 10205b261ecSmrg/* 10305b261ecSmrg * winMessageBoxF - Print a formatted error message in a useful 10405b261ecSmrg * message box. 10505b261ecSmrg */ 10605b261ecSmrg 10705b261ecSmrgvoid 10835c4bbdfSmrgwinMessageBoxF(const char *pszError, UINT uType, ...) 10905b261ecSmrg{ 11035c4bbdfSmrg char *pszErrorF = NULL; 11135c4bbdfSmrg char *pszMsgBox = NULL; 11235c4bbdfSmrg va_list args; 11335c4bbdfSmrg int size; 11435c4bbdfSmrg 11535c4bbdfSmrg va_start(args, uType); 11635c4bbdfSmrg size = vasprintf(&pszErrorF, pszError, args); 11735c4bbdfSmrg va_end(args); 11835c4bbdfSmrg if (size == -1) { 11935c4bbdfSmrg pszErrorF = NULL; 12035c4bbdfSmrg goto winMessageBoxF_Cleanup; 12135c4bbdfSmrg } 12205b261ecSmrg 12305b261ecSmrg#define MESSAGEBOXF \ 12405b261ecSmrg "%s\n" \ 12505b261ecSmrg "Vendor: %s\n" \ 12635c4bbdfSmrg "Release: %d.%d.%d.%d\n" \ 12705b261ecSmrg "Contact: %s\n" \ 1286747b715Smrg "%s\n\n" \ 12905b261ecSmrg "XWin was started with the following command-line:\n\n" \ 13005b261ecSmrg "%s\n" 13105b261ecSmrg 13235c4bbdfSmrg size = asprintf(&pszMsgBox, MESSAGEBOXF, 13335c4bbdfSmrg pszErrorF, XVENDORNAME, 13435c4bbdfSmrg XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, 13535c4bbdfSmrg XORG_VERSION_SNAP, 13635c4bbdfSmrg BUILDERADDR, BUILDERSTRING, g_pszCommandLine); 13735c4bbdfSmrg 13835c4bbdfSmrg if (size == -1) { 13935c4bbdfSmrg pszMsgBox = NULL; 14035c4bbdfSmrg goto winMessageBoxF_Cleanup; 14135c4bbdfSmrg } 14235c4bbdfSmrg 14335c4bbdfSmrg /* Display the message box string */ 14435c4bbdfSmrg MessageBox(NULL, pszMsgBox, PROJECT_NAME, MB_OK | uType); 14505b261ecSmrg 14605b261ecSmrg winMessageBoxF_Cleanup: 14735c4bbdfSmrg free(pszErrorF); 14835c4bbdfSmrg free(pszMsgBox); 14905b261ecSmrg#undef MESSAGEBOXF 15005b261ecSmrg} 151