mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Use loop instead of recursion
This fixes crash when clicking "screenshot" button in the top panel on postmarketOS. The reason for crash is that default thread stack size in musl libc is limited, and recursion in a function with a 4 Kb buffer consumes it all.
This commit is contained in:
parent
8f92f6b4d6
commit
036edc24cb
1 changed files with 15 additions and 13 deletions
|
|
@ -46,20 +46,22 @@ static int readData(int theFile, QByteArray &theDataOut)
|
|||
char lBuffer[4096];
|
||||
int lRetryCount = 0;
|
||||
ssize_t lBytesRead = 0;
|
||||
while (true) {
|
||||
lBytesRead = QT_READ(theFile, lBuffer, sizeof lBuffer);
|
||||
// give user 30 sec to click a window, afterwards considered as error
|
||||
if (lBytesRead == -1 && (errno == EAGAIN) && ++lRetryCount < 30000) {
|
||||
usleep(1000);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lBytesRead > 0) {
|
||||
theDataOut.append(lBuffer, lBytesRead);
|
||||
lBytesRead = readData(theFile, theDataOut);
|
||||
}
|
||||
do {
|
||||
// give user 30 sec to click a window, afterwards considered as error
|
||||
while (true) {
|
||||
lBytesRead = QT_READ(theFile, lBuffer, sizeof lBuffer);
|
||||
if (lBytesRead == -1 && (errno == EAGAIN) && ++lRetryCount < 30000) {
|
||||
usleep(1000);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lBytesRead > 0) {
|
||||
theDataOut.append(lBuffer, lBytesRead);
|
||||
}
|
||||
} while (lBytesRead > 0);
|
||||
return lBytesRead;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue