(file) Return to Fatal.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

 1 kumpf 1.2 /*
 2 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
 3 martin 1.5 //
 4 martin 1.3 // Licensed to The Open Group (TOG) under one or more contributor license
 5            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 6            // this work for additional information regarding copyright ownership.
 7            // Each contributor licenses this file to you under the OpenPegasus Open
 8            // Source License; you may not use this file except in compliance with the
 9            // License.
10 martin 1.5 //
11 martin 1.3 // Permission is hereby granted, free of charge, to any person obtaining a
12            // copy of this software and associated documentation files (the "Software"),
13            // to deal in the Software without restriction, including without limitation
14            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15            // and/or sell copies of the Software, and to permit persons to whom the
16            // Software is furnished to do so, subject to the following conditions:
17 martin 1.5 //
18 martin 1.3 // The above copyright notice and this permission notice shall be included
19            // in all copies or substantial portions of the Software.
20 martin 1.5 //
21 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 martin 1.5 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 martin 1.3 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 martin 1.5 //
29 martin 1.3 //////////////////////////////////////////////////////////////////////////
30 martin 1.4 */
31 martin 1.3 
32 kumpf  1.2 #include <stdarg.h>
33            #include <syslog.h>
34            #include <stdio.h>
35            #include "Fatal.h"
36            #include "Log.h"
37            #include "Exit.h"
38            #include "Globals.h"
39            #include "Strlcpy.h"
40            #include "Strlcat.h"
41            
42            /*
43            **==============================================================================
44            **
45            ** Fatal()
46            **
47            **     Report fatal errors. The callar set fatal_file and fatal_line before
48            **     calling this function. Note that since this is a single threaded
49            **     application, there is no attempt to synchronize access to these
50            **     globals.
51            **
52            **==============================================================================
53 kumpf  1.2 */
54            
55            void Fatal(const char* file, size_t line, const char* format, ...)
56            {
57                char prefixedFormat[EXECUTOR_BUFFER_SIZE];
58            
59            #ifdef PEGASUS_DEBUG
60                /* Prepend "__FILE__(__LINE__): FATAL: " to format. */
61            
62 lawrence.luo 1.5.22.1     char lineStr[32];
63 kumpf        1.2          Strlcpy(prefixedFormat, file, sizeof(prefixedFormat));
64                           Strlcat(prefixedFormat, "(", sizeof(prefixedFormat));
65                           sprintf(lineStr, "%u", (unsigned int)line);
66                           Strlcat(prefixedFormat, lineStr, sizeof(prefixedFormat));
67                           Strlcat(prefixedFormat, "): FATAL: ", sizeof(prefixedFormat));
68                       #endif
69                       
70                           Strlcat(prefixedFormat, format, sizeof(prefixedFormat));
71                       
72                           /* Print to syslog. */
73                           {
74                               va_list ap;
75                               char buffer[EXECUTOR_BUFFER_SIZE];
76                       
77                               va_start(ap, format);
78                               /* Flawfinder: ignore */
79                               vsprintf(buffer, prefixedFormat, ap);
80                               va_end(ap);
81                       
82                               syslog(LOG_CRIT, "%s", buffer);
83                           }
84 kumpf        1.2      
85                           /* Print to stderr. */
86                           {
87                               va_list ap;
88                       
89                               fprintf(stderr, "%s: ", globals.argv[0]);
90                               va_start(ap, format);
91                               /* Flawfinder: ignore */
92                               vfprintf(stderr, prefixedFormat, ap);
93                               va_end(ap);
94                               fputc('\n', stderr);
95                           }
96                       
97                           Exit(1);
98                       }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2