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 void
OsVendorVErrorF(const char * pszFormat,va_list va_args)40 OsVendorVErrorF(const char *pszFormat, va_list va_args)
41 {
42 /* make sure the clipboard and multiwindow threads do not interfere the
43 * main thread */
44 static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER;
45
46 /* Lock the printing mutex */
47 pthread_mutex_lock(&s_pmPrinting);
48
49 /* Print the error message to a log file, could be stderr */
50 LogVWrite(0, pszFormat, va_args);
51
52 /* Unlock the printing mutex */
53 pthread_mutex_unlock(&s_pmPrinting);
54 }
55 #endif
56
57 /*
58 * os/log.c:FatalError () calls our vendor ErrorF, so the message
59 * from a FatalError will be logged.
60 *
61 * Attempt to do last-ditch, safe, important cleanup here.
62 */
63 void
OsVendorFatalError(const char * f,va_list args)64 OsVendorFatalError(const char *f, va_list args)
65 {
66 char errormsg[1024] = "";
67
68 /* Don't give duplicate warning if UseMsg was called */
69 if (g_fSilentFatalError)
70 return;
71
72 if (!g_fLogInited) {
73 g_fLogInited = TRUE;
74 g_pszLogFile = LogInit(g_pszLogFile, ".old");
75 }
76 LogClose(EXIT_ERR_ABORT);
77
78 /* Format the error message */
79 vsnprintf(errormsg, sizeof(errormsg), f, args);
80
81 /*
82 Sometimes the error message needs a bit of cosmetic cleaning
83 up for use in a dialog box...
84 */
85 {
86 char *s;
87
88 while ((s = strstr(errormsg, "\n\t")) != NULL) {
89 s[0] = ' ';
90 s[1] = '\n';
91 }
92 }
93
94 winMessageBoxF("A fatal error has occurred and " PROJECT_NAME " will now exit.\n\n"
95 "%s\n\n"
96 "Please open %s for more information.\n",
97 MB_ICONERROR,
98 errormsg,
99 (g_pszLogFile ? g_pszLogFile : "the logfile"));
100 }
101
102 /*
103 * winMessageBoxF - Print a formatted error message in a useful
104 * message box.
105 */
106
107 void
winMessageBoxF(const char * pszError,UINT uType,...)108 winMessageBoxF(const char *pszError, UINT uType, ...)
109 {
110 char *pszErrorF = NULL;
111 char *pszMsgBox = NULL;
112 va_list args;
113 int size;
114
115 va_start(args, uType);
116 size = vasprintf(&pszErrorF, pszError, args);
117 va_end(args);
118 if (size == -1) {
119 pszErrorF = NULL;
120 goto winMessageBoxF_Cleanup;
121 }
122
123 #define MESSAGEBOXF \
124 "%s\n" \
125 "Vendor: %s\n" \
126 "Release: %d.%d.%d.%d\n" \
127 "Contact: %s\n" \
128 "%s\n\n" \
129 "XWin was started with the following command-line:\n\n" \
130 "%s\n"
131
132 size = asprintf(&pszMsgBox, MESSAGEBOXF,
133 pszErrorF, XVENDORNAME,
134 XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH,
135 XORG_VERSION_SNAP,
136 BUILDERADDR, BUILDERSTRING, g_pszCommandLine);
137
138 if (size == -1) {
139 pszMsgBox = NULL;
140 goto winMessageBoxF_Cleanup;
141 }
142
143 /* Display the message box string */
144 MessageBox(NULL, pszMsgBox, PROJECT_NAME, MB_OK | uType);
145
146 winMessageBoxF_Cleanup:
147 free(pszErrorF);
148 free(pszMsgBox);
149 #undef MESSAGEBOXF
150 }
151