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