diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llerrorthread.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llerrorthread.cpp | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llerrorthread.cpp b/linden/indra/llcommon/llerrorthread.cpp new file mode 100644 index 0000000..b9bb605 --- /dev/null +++ b/linden/indra/llcommon/llerrorthread.cpp | |||
@@ -0,0 +1,208 @@ | |||
1 | /** | ||
2 | * @file llerrorthread.cpp | ||
3 | * | ||
4 | * Copyright (c) 2004-2007, Linden Research, Inc. | ||
5 | * | ||
6 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
7 | * to you under the terms of the GNU General Public License, version 2.0 | ||
8 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
9 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
10 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
11 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
12 | * | ||
13 | * There are special exceptions to the terms and conditions of the GPL as | ||
14 | * it is applied to this Source Code. View the full text of the exception | ||
15 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
16 | * online at http://secondlife.com/developers/opensource/flossexception | ||
17 | * | ||
18 | * By copying, modifying or distributing this software, you acknowledge | ||
19 | * that you have read and understood your obligations described above, | ||
20 | * and agree to abide by those obligations. | ||
21 | * | ||
22 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
23 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
24 | * COMPLETENESS OR PERFORMANCE. | ||
25 | */ | ||
26 | |||
27 | #include "linden_common.h" | ||
28 | #include "llerrorthread.h" | ||
29 | #include "llapp.h" | ||
30 | |||
31 | LLErrorThread::LLErrorThread() | ||
32 | : LLThread("Error"), | ||
33 | mUserDatap(NULL) | ||
34 | { | ||
35 | } | ||
36 | |||
37 | LLErrorThread::~LLErrorThread() | ||
38 | { | ||
39 | } | ||
40 | |||
41 | void LLErrorThread::setUserData(void* user_data) | ||
42 | { | ||
43 | mUserDatap = user_data; | ||
44 | } | ||
45 | |||
46 | |||
47 | void* LLErrorThread::getUserData() const | ||
48 | { | ||
49 | return mUserDatap; | ||
50 | } | ||
51 | |||
52 | #if !LL_WINDOWS | ||
53 | // | ||
54 | // Various signal/error handling functions that can't be put into the class | ||
55 | // | ||
56 | void get_child_status(const int waitpid_status, int &process_status, bool &exited, bool do_logging) | ||
57 | { | ||
58 | exited = false; | ||
59 | process_status = -1; | ||
60 | // The child process exited. Call its callback, and then clean it up | ||
61 | if (WIFEXITED(waitpid_status)) | ||
62 | { | ||
63 | process_status = WEXITSTATUS(waitpid_status); | ||
64 | exited = true; | ||
65 | if (do_logging) | ||
66 | { | ||
67 | llinfos << "get_child_status - Child exited cleanly with return of " << process_status << llendl; | ||
68 | } | ||
69 | return; | ||
70 | } | ||
71 | else if (WIFSIGNALED(waitpid_status)) | ||
72 | { | ||
73 | process_status = WTERMSIG(waitpid_status); | ||
74 | exited = true; | ||
75 | if (do_logging) | ||
76 | { | ||
77 | llinfos << "get_child_status - Child died because of uncaught signal " << process_status << llendl; | ||
78 | #ifdef WCOREDUMP | ||
79 | if (WCOREDUMP(waitpid_status)) | ||
80 | { | ||
81 | llinfos << "get_child_status - Child dumped core" << llendl; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | llinfos << "get_child_status - Child didn't dump core" << llendl; | ||
86 | } | ||
87 | #endif | ||
88 | } | ||
89 | return; | ||
90 | } | ||
91 | else if (do_logging) | ||
92 | { | ||
93 | // This is weird. I just dump the waitpid status into the status code, | ||
94 | // not that there's any way of telling what it is... | ||
95 | llinfos << "get_child_status - Got SIGCHILD but child didn't exit" << llendl; | ||
96 | process_status = waitpid_status; | ||
97 | } | ||
98 | |||
99 | } | ||
100 | #endif | ||
101 | |||
102 | void LLErrorThread::run() | ||
103 | { | ||
104 | LLApp::sErrorThreadRunning = TRUE; | ||
105 | // This thread sits and waits for the sole purpose | ||
106 | // of waiting for the signal/exception handlers to flag the | ||
107 | // application state as APP_STATUS_ERROR. | ||
108 | llinfos << "thread_error - Waiting for an error" << llendl; | ||
109 | |||
110 | S32 counter = 0; | ||
111 | #if !LL_WINDOWS | ||
112 | U32 last_sig_child_count = 0; | ||
113 | #endif | ||
114 | while (1) | ||
115 | { | ||
116 | if (LLApp::isError() || LLApp::isStopped()) | ||
117 | { | ||
118 | // The application has stopped running, time to take action (maybe) | ||
119 | break; | ||
120 | } | ||
121 | #if !LL_WINDOWS | ||
122 | // Check whether or not the main thread had a sig child we haven't handled. | ||
123 | U32 current_sig_child_count = LLApp::getSigChildCount(); | ||
124 | if (last_sig_child_count != current_sig_child_count) | ||
125 | { | ||
126 | int status = 0; | ||
127 | pid_t child_pid = 0; | ||
128 | last_sig_child_count = current_sig_child_count; | ||
129 | if (LLApp::sLogInSignal) | ||
130 | { | ||
131 | llinfos << "thread_error handling SIGCHLD #" << current_sig_child_count << llendl; | ||
132 | } | ||
133 | for (LLApp::child_map::iterator iter = LLApp::sChildMap.begin(); iter != LLApp::sChildMap.end();) | ||
134 | { | ||
135 | child_pid = iter->first; | ||
136 | LLChildInfo &child_info = iter->second; | ||
137 | // check the status of *all* children, in case we missed a signal | ||
138 | if (0 != waitpid(child_pid, &status, WNOHANG)) | ||
139 | { | ||
140 | bool exited = false; | ||
141 | int exit_status = -1; | ||
142 | get_child_status(status, exit_status, exited, LLApp::sLogInSignal); | ||
143 | |||
144 | if (child_info.mCallback) | ||
145 | { | ||
146 | if (LLApp::sLogInSignal) | ||
147 | { | ||
148 | llinfos << "Signal handler - Running child callback" << llendl; | ||
149 | } | ||
150 | child_info.mCallback(child_pid, exited, status); | ||
151 | } | ||
152 | LLApp::sChildMap.erase(iter++); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | // Child didn't terminate, yet we got a sigchild somewhere... | ||
157 | if (child_info.mGotSigChild && child_info.mCallback) | ||
158 | { | ||
159 | child_info.mCallback(child_pid, false, 0); | ||
160 | } | ||
161 | child_info.mGotSigChild = FALSE; | ||
162 | iter++; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | // check the status of *all* children, in case we missed a signal | ||
167 | // Same as above, but use the default child callback | ||
168 | while(0 < (child_pid = waitpid( -1, &status, WNOHANG ))) | ||
169 | { | ||
170 | if (0 != waitpid(child_pid, &status, WNOHANG)) | ||
171 | { | ||
172 | bool exited = false; | ||
173 | int exit_status = -1; | ||
174 | get_child_status(status, exit_status, exited, LLApp::sLogInSignal); | ||
175 | if (LLApp::sDefaultChildCallback) | ||
176 | { | ||
177 | if (LLApp::sLogInSignal) | ||
178 | { | ||
179 | llinfos << "Signal handler - Running default child callback" << llendl; | ||
180 | } | ||
181 | LLApp::sDefaultChildCallback(child_pid, true, status); | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | |||
188 | #endif | ||
189 | ms_sleep(10); | ||
190 | counter++; | ||
191 | } | ||
192 | if (LLApp::isError()) | ||
193 | { | ||
194 | // The app is in an error state, run the application's error handler. | ||
195 | //llinfos << "thread_error - An error has occurred, running error callback!" << llendl; | ||
196 | // Run the error handling callback | ||
197 | LLApp::runErrorHandler(); | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | // Everything is okay, a clean exit. | ||
202 | //llinfos << "thread_error - Application exited cleanly" << llendl; | ||
203 | } | ||
204 | |||
205 | //llinfos << "thread_error - Exiting" << llendl; | ||
206 | LLApp::sErrorThreadRunning = FALSE; | ||
207 | } | ||
208 | |||