OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 NICTA | 3 * Copyright (c) 2010 NICTA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 FlushStreams (void) | 149 FlushStreams (void) |
150 { | 150 { |
151 NS_LOG_FUNCTION_NOARGS (); | 151 NS_LOG_FUNCTION_NOARGS (); |
152 std::list<std::ostream*> **pl = PeekStreamList (); | 152 std::list<std::ostream*> **pl = PeekStreamList (); |
153 if (*pl == 0) | 153 if (*pl == 0) |
154 { | 154 { |
155 return; | 155 return; |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 /* Override default SIGSEGV handler - will flush subsequent | 159 /* Override default SIGSEGV handler - will flush subsequent |
160 * streams even if one of the stream pointers is bad. | 160 * streams even if one of the stream pointers is bad. |
161 * The SIGSEGV override should only be active for the | 161 * The SIGSEGV override should only be active for the |
162 * duration of this function. */ | 162 * duration of this function. */ |
| 163 #ifndef _WIN32 |
163 struct sigaction hdl; | 164 struct sigaction hdl; |
164 hdl.sa_handler=sigHandler; | 165 hdl.sa_handler=sigHandler; |
165 sigaction (SIGSEGV, &hdl, 0); | 166 sigaction (SIGSEGV, &hdl, 0); |
| 167 #else |
| 168 typedef void(*SignalHandlerPointer) (int); |
| 169 SignalHandlerPointer previousHandler = signal(SIGSEGV, sigHandler); |
| 170 #endif |
166 | 171 |
167 std::list<std::ostream*> *l = *pl; | 172 std::list<std::ostream*> *l = *pl; |
168 | 173 |
169 /* Need to do it this way in case any of the ostream* causes SIGSEGV */ | 174 /* Need to do it this way in case any of the ostream* causes SIGSEGV */ |
170 while (!l->empty ()) | 175 while (!l->empty ()) |
171 { | 176 { |
172 std::ostream* s (l->front ()); | 177 std::ostream* s (l->front ()); |
173 l->pop_front (); | 178 l->pop_front (); |
174 s->flush (); | 179 s->flush (); |
175 } | 180 } |
176 | 181 |
| 182 #ifndef _WIN32 |
177 /* Restore default SIGSEGV handler (Not that it matters anyway) */ | 183 /* Restore default SIGSEGV handler (Not that it matters anyway) */ |
178 hdl.sa_handler=SIG_DFL; | 184 hdl.sa_handler=SIG_DFL; |
179 sigaction (SIGSEGV, &hdl, 0); | 185 sigaction (SIGSEGV, &hdl, 0); |
| 186 #else |
| 187 /* Restore default SIGSEGV handler (Not that it matters anyway) */ |
| 188 signal(SIGSEGV, previousHandler); |
| 189 #endif |
180 | 190 |
181 /* Flush all opened FILE* */ | 191 /* Flush all opened FILE* */ |
182 std::fflush (0); | 192 std::fflush (0); |
183 | 193 |
184 /* Flush stdandard streams - shouldn't be required (except for clog) */ | 194 /* Flush stdandard streams - shouldn't be required (except for clog) */ |
185 std::cout.flush (); | 195 std::cout.flush (); |
186 std::cerr.flush (); | 196 std::cerr.flush (); |
187 std::clog.flush (); | 197 std::clog.flush (); |
188 | 198 |
189 delete l; | 199 delete l; |
190 *pl = 0; | 200 *pl = 0; |
191 } | 201 } |
192 | 202 |
193 } // namespace FatalImpl | 203 } // namespace FatalImpl |
194 ·· | 204 ·· |
195 } // namespace ns3 | 205 } // namespace ns3 |
OLD | NEW |