1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27:45 +00:00

Userspace: Deal with select() returning EINTR on a signal interruption

Add a trivial CSafeSyscall template that calls a callback until it stops
returning EINTR, and use it everywhere we use select() now.

Thanks to Andreas for the suggestion of using a template parameter for
the syscall function to invoke.
This commit is contained in:
Robin Burchell 2019-07-21 13:46:53 +02:00 committed by Andreas Kling
parent a1eff3daba
commit f2c0e55070
5 changed files with 33 additions and 8 deletions

View file

@ -0,0 +1,25 @@
#pragma once
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <AK/StdLibExtras.h>
namespace CSyscallUtils {
template <typename Syscall, class... Args>
inline int safe_syscall(Syscall syscall, Args&& ... args) {
for (;;) {
int sysret = syscall(forward<Args>(args)...);
if (sysret == -1) {
dbgprintf("CSafeSyscall: %d (%d: %s)\n", sysret, errno, strerror(errno));
if (errno == EINTR)
continue;
ASSERT_NOT_REACHED();
}
return sysret;
}
}
}