1 mike 1.1.2.1 /*
2 //%2006////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
5 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
6 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
7 // IBM Corp.; EMC Corporation, The Open Group.
8 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
9 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
10 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
11 // EMC Corporation; VERITAS Software Corporation; The Open Group.
12 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
13 // EMC Corporation; Symantec Corporation; The Open Group.
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining a copy
16 // of this software and associated documentation files (the "Software"), to
17 // deal in the Software without restriction, including without limitation the
18 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19 // sell copies of the Software, and to permit persons to whom the Software is
20 // furnished to do so, subject to the following conditions:
21 //
22 mike 1.1.2.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
23 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
24 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
26 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31 //%/////////////////////////////////////////////////////////////////////////////
32 */
33 #include <stdarg.h>
34 #include <syslog.h>
35 #include <stdio.h>
36 #include "Fatal.h"
37 #include "Log.h"
38 #include "Exit.h"
|
39 mike 1.1.2.2 #include "Globals.h"
|
40 mike 1.1.2.4 #include "Strlcpy.h"
41 #include "Strlcat.h"
|
42 mike 1.1.2.1
43 /*
44 **==============================================================================
45 **
46 ** Fatal()
47 **
48 ** Report fatal errors. The callar set fatal_file and fatal_line before
49 ** calling this function. Note that since this is a single threaded
50 ** application, there is no attempt to synchronize access to these
51 ** globals.
52 **
53 **==============================================================================
54 */
55
56 void Fatal(const char* file, size_t line, const char* format, ...)
57 {
|
58 mike 1.1.2.5 char prefixedFormat[EXECUTOR_BUFFER_SIZE];
|
59 mike 1.1.2.4 char lineStr[32];
60
61 /* Prepend "__FILE__(__LINE__): FATAL: " to format. */
62
|
63 mike 1.1.2.5 Strlcpy(prefixedFormat, file, sizeof(prefixedFormat));
64 Strlcat(prefixedFormat, "(", sizeof(prefixedFormat));
|
65 mike 1.1.2.4 sprintf(lineStr, "%u", (unsigned int)line);
|
66 mike 1.1.2.5 Strlcat(prefixedFormat, lineStr, sizeof(prefixedFormat));
67 Strlcat(prefixedFormat, "): FATAL: ", sizeof(prefixedFormat));
68 Strlcat(prefixedFormat, format, sizeof(prefixedFormat));
|
69 mike 1.1.2.1
70 /* Print to syslog. */
71 {
72 va_list ap;
|
73 mike 1.1.2.5 char buffer[EXECUTOR_BUFFER_SIZE];
74
|
75 mike 1.1.2.1 va_start(ap, format);
|
76 mike 1.1.2.5 vsprintf(buffer, prefixedFormat, ap);
|
77 mike 1.1.2.1 va_end(ap);
|
78 mike 1.1.2.5
|
79 mike 1.1.2.6 syslog(LOG_CRIT, "%s", buffer);
|
80 mike 1.1.2.1 }
81
82 /* Print to stderr. */
83 {
84 va_list ap;
85
|
86 mike 1.1.2.4 fprintf(stderr, "%s: ", globals.argv[0]);
|
87 mike 1.1.2.1 va_start(ap, format);
88 /* Flawfinder: ignore */
|
89 mike 1.1.2.5 vfprintf(stderr, prefixedFormat, ap);
|
90 mike 1.1.2.1 va_end(ap);
91 fputc('\n', stderr);
92 }
93
94 Exit(1);
95 }
|