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