2019-07-21 11:46:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-12-01 15:47:28 +00:00
|
|
|
#include <AK/LogStream.h>
|
|
|
|
#include <AK/StdLibExtras.h>
|
2019-07-21 11:46:53 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
2019-12-01 15:47:28 +00:00
|
|
|
#include <unistd.h>
|
2019-07-21 11:46:53 +00:00
|
|
|
|
|
|
|
namespace CSyscallUtils {
|
|
|
|
|
2019-12-01 15:47:28 +00:00
|
|
|
template<typename Syscall, class... Args>
|
|
|
|
inline int safe_syscall(Syscall syscall, Args&&... args)
|
|
|
|
{
|
2019-07-21 11:46:53 +00:00
|
|
|
for (;;) {
|
|
|
|
int sysret = syscall(forward<Args>(args)...);
|
|
|
|
if (sysret == -1) {
|
2019-12-01 15:47:28 +00:00
|
|
|
int saved_errno = errno;
|
|
|
|
dbg() << "CSafeSyscall: " << sysret << " (" << saved_errno << ": " << strerror(saved_errno) << ")";
|
2019-07-21 11:46:53 +00:00
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
}
|
|
|
|
return sysret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|