1 martin 1.14 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.15 //
|
3 martin 1.14 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.15 //
|
10 martin 1.14 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.15 //
|
17 martin 1.14 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.15 //
|
20 martin 1.14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.15 //
|
28 martin 1.14 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #if defined(PEGASUS_OS_VMS)
33 # include <fcntl.h>
34 #endif
35 #include <Pegasus/Common/System.h>
36 #include <Pegasus/Common/TraceFileHandler.h>
37 #include <Pegasus/Common/Mutex.h>
|
38 ashok.pathak 1.21 #include <Pegasus/Common/StringConversion.h>
|
39 mike 1.2
40 PEGASUS_USING_STD;
41
|
42 kumpf 1.5 PEGASUS_NAMESPACE_BEGIN
43
44 static Mutex writeMutex;
45 PEGASUS_FORK_SAFE_MUTEX(writeMutex)
|
46 mike 1.2
47 ///////////////////////////////////////////////////////////////////////////////
48 // Writes message to file. Locks the file before writing to it
49 // Implementation of this function is platform specific
50 ///////////////////////////////////////////////////////////////////////////////
51
|
52 marek 1.8
53 void TraceFileHandler::handleMessage(
54 const char *message,
|
55 marek 1.20 Uint32,
|
56 marek 1.8 const char *fmt, va_list argList)
57 {
|
58 amit99shah 1.23
|
59 thilo.boehm 1.13 if (_configHasChanged)
60 {
61 _reConfigure();
62 }
63
|
64 marek 1.8 if (!_fileHandle)
65 {
66 // The trace file is not open, which means an earlier fopen() was
67 // unsuccessful. Stop now to avoid logging duplicate error messages.
68 return;
69 }
70
|
71 amit99shah 1.23
|
72 marek 1.8 // Do not add Trace calls in the Critical section
73 // ---- BEGIN CRITICAL SECTION
74 AutoMutex writeLock(writeMutex);
|
75 mike 1.2
|
76 amit99shah 1.24 if(!_fileExists(_fileName))
77 {
78 return;
79 }
80
|
81 mike 1.2 // Write the message to the file
82 fprintf(_fileHandle, "%s", message);
83 vfprintf(_fileHandle, fmt, argList);
84 fprintf(_fileHandle, "\n");
|
85 john.eisenbraun 1.19
86 #if defined(PEGASUS_OS_VMS)
87 if (0 == fsync(fileno(_fileHandle)))
88 #else
|
89 marek 1.17 if (0 == fflush(_fileHandle))
|
90 john.eisenbraun 1.19 #endif
|
91 marek 1.17 {
92 // trace message successful written, reset error log messages
93 // thus allow writing of errors to log again
94 _logErrorBitField = 0;
95 }
96
|
97 marek 1.8 // ---- END CRITICAL SECTION
98 }
99
|
100 marek 1.20 void TraceFileHandler::handleMessage(const char *message, Uint32)
|
101 marek 1.8 {
|
102 amit99shah 1.23
|
103 thilo.boehm 1.13 if (_configHasChanged)
104 {
|
105 amit99shah 1.23 _reConfigure();
|
106 thilo.boehm 1.13 }
107
|
108 marek 1.8 if (!_fileHandle)
109 {
110 // The trace file is not open, which means an earlier fopen() was
111 // unsuccessful. Stop now to avoid logging duplicate error messages.
112 return;
113 }
114
|
115 amit99shah 1.24 // Do not add Trace calls in the Critical section
116 // ---- BEGIN CRITICAL SECTION
117 AutoMutex writeLock(writeMutex);
118
|
119 amit99shah 1.23 if(!_fileExists(_fileName))
120 {
121 return;
122 }
123
|
124 amit99shah 1.24
|
125 amit99shah 1.23 // Write the message to the file
|
126 marek 1.8 fprintf(_fileHandle, "%s\n", message);
|
127 john.eisenbraun 1.19 #if defined(PEGASUS_OS_VMS)
128 if (0 == fsync(fileno(_fileHandle)))
129 #else
|
130 marek 1.17 if (0 == fflush(_fileHandle))
|
131 john.eisenbraun 1.19 #endif
|
132 marek 1.17 {
133 // trace message successful written, reset error log messages
134 // thus allow writing of errors to log again
135 _logErrorBitField = 0;
136 }
|
137 marek 1.8 // ---- END CRITICAL SECTION
|
138 mike 1.2 }
139
140 PEGASUS_NAMESPACE_END
|