Skip to content

Commit 8d7d93a

Browse files
firewavedanmar
authored andcommitted
donate-cpu.py: improved error detection (cppcheck-opensource#1766)
* threadexecutor.cpp: streamlined error messages * donate-cpu.py: detect additional signals and exitcode != 0 as crash as well and (ab)use elapsedTime to make the errorcode visible in the output / also detect ThreadExecutor issues * donate-cpu.py: bumped version * donate-cpu.py: fixed detection of ThreadExecutor errors
1 parent 7d383d1 commit 8d7d93a

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

cli/threadexecutor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ int ThreadExecutor::handleRead(int rpipe, unsigned int &result)
9191
}
9292

9393
if (type != REPORT_OUT && type != REPORT_ERROR && type != REPORT_INFO && type != CHILD_END) {
94-
std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl;
94+
std::cerr << "#### ThreadExecutor::handleRead error, type was:" << type << std::endl;
9595
std::exit(0);
9696
}
9797

9898
unsigned int len = 0;
9999
if (read(rpipe, &len, sizeof(len)) <= 0) {
100-
std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl;
100+
std::cerr << "#### ThreadExecutor::handleRead error, type was:" << type << std::endl;
101101
std::exit(0);
102102
}
103103

@@ -106,7 +106,7 @@ int ThreadExecutor::handleRead(int rpipe, unsigned int &result)
106106
char *buf = new char[len + 1];
107107
const ssize_t readIntoBuf = read(rpipe, buf, len);
108108
if (readIntoBuf <= 0) {
109-
std::cerr << "#### You found a bug from cppcheck.\nThreadExecutor::handleRead error, type was:" << type << std::endl;
109+
std::cerr << "#### ThreadExecutor::handleRead error, type was:" << type << std::endl;
110110
std::exit(0);
111111
}
112112
buf[readIntoBuf] = 0;
@@ -183,25 +183,25 @@ unsigned int ThreadExecutor::check()
183183
if ((iFile != _files.end() || iFileSettings != _settings.project.fileSettings.end()) && nchildren < _settings.jobs && checkLoadAverage(nchildren)) {
184184
int pipes[2];
185185
if (pipe(pipes) == -1) {
186-
std::cerr << "pipe() failed: "<< std::strerror(errno) << std::endl;
186+
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
187187
std::exit(EXIT_FAILURE);
188188
}
189189

190190
int flags = 0;
191191
if ((flags = fcntl(pipes[0], F_GETFL, 0)) < 0) {
192-
std::cerr << "fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
192+
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
193193
std::exit(EXIT_FAILURE);
194194
}
195195

196196
if (fcntl(pipes[0], F_SETFL, flags | O_NONBLOCK) < 0) {
197-
std::cerr << "fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
197+
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
198198
std::exit(EXIT_FAILURE);
199199
}
200200

201201
pid_t pid = fork();
202202
if (pid < 0) {
203203
// Error
204-
std::cerr << "Failed to create child process: "<< std::strerror(errno) << std::endl;
204+
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
205205
std::exit(EXIT_FAILURE);
206206
} else if (pid == 0) {
207207
close(pipes[0]);
@@ -377,18 +377,18 @@ unsigned int ThreadExecutor::check()
377377
for (unsigned int i = 0; i < _settings.jobs; ++i) {
378378
threadHandles[i] = (HANDLE)_beginthreadex(nullptr, 0, threadProc, this, 0, nullptr);
379379
if (!threadHandles[i]) {
380-
std::cerr << "#### .\nThreadExecutor::check error, errno :" << errno << std::endl;
380+
std::cerr << "#### ThreadExecutor::check error, errno :" << errno << std::endl;
381381
exit(EXIT_FAILURE);
382382
}
383383
}
384384

385385
const DWORD waitResult = WaitForMultipleObjects(_settings.jobs, threadHandles, TRUE, INFINITE);
386386
if (waitResult != WAIT_OBJECT_0) {
387387
if (waitResult == WAIT_FAILED) {
388-
std::cerr << "#### .\nThreadExecutor::check wait failed, result: " << waitResult << " error: " << GetLastError() << std::endl;
388+
std::cerr << "#### ThreadExecutor::check wait failed, result: " << waitResult << " error: " << GetLastError() << std::endl;
389389
exit(EXIT_FAILURE);
390390
} else {
391-
std::cerr << "#### .\nThreadExecutor::check wait failed, result: " << waitResult << std::endl;
391+
std::cerr << "#### ThreadExecutor::check wait failed, result: " << waitResult << std::endl;
392392
exit(EXIT_FAILURE);
393393
}
394394
}
@@ -398,14 +398,14 @@ unsigned int ThreadExecutor::check()
398398
DWORD exitCode;
399399

400400
if (!GetExitCodeThread(threadHandles[i], &exitCode)) {
401-
std::cerr << "#### .\nThreadExecutor::check get exit code failed, error:" << GetLastError() << std::endl;
401+
std::cerr << "#### ThreadExecutor::check get exit code failed, error:" << GetLastError() << std::endl;
402402
exit(EXIT_FAILURE);
403403
}
404404

405405
result += exitCode;
406406

407407
if (!CloseHandle(threadHandles[i])) {
408-
std::cerr << "#### .\nThreadExecutor::check close handle failed, error:" << GetLastError() << std::endl;
408+
std::cerr << "#### ThreadExecutor::check close handle failed, error:" << GetLastError() << std::endl;
409409
exit(EXIT_FAILURE);
410410
}
411411
}

tools/donate-cpu.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
4040
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
4141
# changes)
42-
CLIENT_VERSION = "1.1.17"
42+
CLIENT_VERSION = "1.1.18"
4343

4444

4545
def checkRequirements():
@@ -274,8 +274,8 @@ def scanPackage(workPath, cppcheckPath, jobs):
274274
cppcheck_cmd = cppcheckPath + '/cppcheck' + ' ' + options
275275
cmd = 'nice ' + cppcheck_cmd
276276
returncode, stdout, stderr, elapsedTime = runCommand(cmd)
277+
print('cppcheck finished with ' + str(returncode))
277278
if returncode == -11 or stderr.find('Internal error: Child process crashed with signal 11 [cppcheckError]') > 0:
278-
# Crash!
279279
print('Crash!')
280280
stacktrace = ''
281281
if cppcheckPath == 'cppcheck':
@@ -289,7 +289,20 @@ def scanPackage(workPath, cppcheckPath, jobs):
289289
stacktrace = stdout[gdb_pos:]
290290
else:
291291
stacktrace = stdout[last_check_pos:]
292-
return -1, stacktrace, '', -1, options
292+
return -11, stacktrace, '', -11, options
293+
if returncode != 0:
294+
print('Error!')
295+
return returncode, '', '', returncode, options
296+
if stderr.find('Internal error: Child process crashed with signal ') > 0:
297+
print('Error!')
298+
s = 'Internal error: Child process crashed with signal '
299+
pos1 = stderr.find(s)
300+
pos2 = stderr.find(' [cppcheckError]', pos1)
301+
signr = int(stderr[pos1+len(s):pos2])
302+
return -signr, '', '', -signr, options
303+
if stderr.find('#### ThreadExecutor') > 0:
304+
print('Thread!')
305+
return -111, '', '', -111, options
293306
information_messages_list = []
294307
issue_messages_list = []
295308
count = 0

0 commit comments

Comments
 (0)