Rename EINTR_LOOP -> QT_EINTR_LOOP

This non-namespaced macro was defined in a header, and while that
header is private, we shouldn't define non-namespaced macros in our
headers.

The macro also clashed with one of the same name defined in forkfd.c,
which broke unity-builds including the forkfd_qt.cpp TU. This rename
fixes that, too, so we can now remove forkfd_qt.cpp from
NO_UNITY_BUILD_SOURCES.

Pick-to: 6.5
Change-Id: Ic4bb4e4d7a632ca87905e48913db788a7c202314
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit f96a17225f088a5790655c01eaab9578c81a19f2)
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-11-07 20:20:01 +01:00
parent 52cc586a65
commit 2923a29b59
16 changed files with 36 additions and 38 deletions

View File

@ -956,8 +956,6 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_process AND UNIX
SOURCES SOURCES
../3rdparty/forkfd/forkfd.h ../3rdparty/forkfd/forkfd.h
io/forkfd_qt.cpp io/forkfd_qt.cpp
NO_UNITY_BUILD_SOURCES
io/forkfd_qt.cpp # EINTR_LOOP macro clashes
INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES
../3rdparty/forkfd ../3rdparty/forkfd
) )

View File

@ -165,7 +165,7 @@ void QKqueueFileSystemWatcherEngine::readFromKqueue()
int r; int r;
struct kevent kev; struct kevent kev;
struct timespec ts = { 0, 0 }; // 0 ts, because we want to poll struct timespec ts = { 0, 0 }; // 0 ts, because we want to poll
EINTR_LOOP(r, kevent(kqfd, 0, 0, &kev, 1, &ts)); QT_EINTR_LOOP(r, kevent(kqfd, 0, 0, &kev, 1, &ts));
if (r < 0) { if (r < 0) {
perror("QKqueueFileSystemWatcherEngine: error during kevent wait"); perror("QKqueueFileSystemWatcherEngine: error during kevent wait");
return; return;

View File

@ -160,9 +160,9 @@ bool QFSFileEnginePrivate::nativeSyncToDisk()
Q_Q(QFSFileEngine); Q_Q(QFSFileEngine);
int ret; int ret;
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
EINTR_LOOP(ret, fdatasync(nativeHandle())); QT_EINTR_LOOP(ret, fdatasync(nativeHandle()));
#else #else
EINTR_LOOP(ret, fsync(nativeHandle())); QT_EINTR_LOOP(ret, fsync(nativeHandle()));
#endif #endif
if (ret != 0) if (ret != 0)
q->setError(QFile::WriteError, qt_error_string(errno)); q->setError(QFile::WriteError, qt_error_string(errno));

View File

@ -1107,7 +1107,7 @@ void QProcessPrivate::waitForDeadChild()
forkfd_info info = {}; // Silence -Wmaybe-uninitialized; Thiago says forkfd_wait cannot fail here forkfd_info info = {}; // Silence -Wmaybe-uninitialized; Thiago says forkfd_wait cannot fail here
// (QTBUG-119081) // (QTBUG-119081)
int ret; int ret;
EINTR_LOOP(ret, forkfd_wait(forkfd, &info, nullptr)); QT_EINTR_LOOP(ret, forkfd_wait(forkfd, &info, nullptr));
exitCode = info.status; exitCode = info.status;
exitStatus = info.code == CLD_EXITED ? QProcess::NormalExit : QProcess::CrashExit; exitStatus = info.code == CLD_EXITED ? QProcess::NormalExit : QProcess::CrashExit;
@ -1115,7 +1115,7 @@ void QProcessPrivate::waitForDeadChild()
delete stateNotifier; delete stateNotifier;
stateNotifier = nullptr; stateNotifier = nullptr;
EINTR_LOOP(ret, forkfd_close(forkfd)); QT_EINTR_LOOP(ret, forkfd_close(forkfd));
forkfd = -1; // Child is dead, don't try to kill it anymore forkfd = -1; // Child is dead, don't try to kill it anymore
#if defined QPROCESS_DEBUG #if defined QPROCESS_DEBUG

View File

@ -804,7 +804,7 @@ void QStorageInfoPrivate::retrieveVolumeInfo()
{ {
QT_STATFSBUF statfs_buf; QT_STATFSBUF statfs_buf;
int result; int result;
EINTR_LOOP(result, QT_STATFS(QFile::encodeName(rootPath).constData(), &statfs_buf)); QT_EINTR_LOOP(result, QT_STATFS(QFile::encodeName(rootPath).constData(), &statfs_buf));
if (result == 0) { if (result == 0) {
valid = true; valid = true;
ready = true; ready = true;

View File

@ -67,7 +67,7 @@ bool QSharedMemoryPosix::create(QSharedMemoryPrivate *self, qsizetype size)
const QByteArray shmName = QFile::encodeName(self->nativeKey.nativeKey()); const QByteArray shmName = QFile::encodeName(self->nativeKey.nativeKey());
int fd; int fd;
EINTR_LOOP(fd, ::shm_open(shmName.constData(), O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600)); QT_EINTR_LOOP(fd, ::shm_open(shmName.constData(), O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600));
if (fd == -1) { if (fd == -1) {
const int errorNumber = errno; const int errorNumber = errno;
const auto function = "QSharedMemory::attach (shm_open)"_L1; const auto function = "QSharedMemory::attach (shm_open)"_L1;
@ -84,7 +84,7 @@ bool QSharedMemoryPosix::create(QSharedMemoryPrivate *self, qsizetype size)
// the size may only be set once // the size may only be set once
int ret; int ret;
EINTR_LOOP(ret, QT_FTRUNCATE(fd, size)); QT_EINTR_LOOP(ret, QT_FTRUNCATE(fd, size));
if (ret == -1) { if (ret == -1) {
self->setUnixErrorString("QSharedMemory::create (ftruncate)"_L1); self->setUnixErrorString("QSharedMemory::create (ftruncate)"_L1);
qt_safe_close(fd); qt_safe_close(fd);
@ -103,7 +103,7 @@ bool QSharedMemoryPosix::attach(QSharedMemoryPrivate *self, QSharedMemory::Acces
const int oflag = (mode == QSharedMemory::ReadOnly ? O_RDONLY : O_RDWR); const int oflag = (mode == QSharedMemory::ReadOnly ? O_RDONLY : O_RDWR);
const mode_t omode = (mode == QSharedMemory::ReadOnly ? 0400 : 0600); const mode_t omode = (mode == QSharedMemory::ReadOnly ? 0400 : 0600);
EINTR_LOOP(hand, ::shm_open(shmName.constData(), oflag | O_CLOEXEC, omode)); QT_EINTR_LOOP(hand, ::shm_open(shmName.constData(), oflag | O_CLOEXEC, omode));
if (hand == -1) { if (hand == -1) {
const int errorNumber = errno; const int errorNumber = errno;
const auto function = "QSharedMemory::attach (shm_open)"_L1; const auto function = "QSharedMemory::attach (shm_open)"_L1;

View File

@ -20,9 +20,9 @@
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
# include "private/qcore_unix_p.h" # include "private/qcore_unix_p.h"
#else #else
#define EINTR_LOOP_VAL(var, val, cmd) \ # define QT_EINTR_LOOP_VAL(var, val, cmd) \
(void)var; var = cmd (void)var; var = cmd
#define EINTR_LOOP(var, cmd) EINTR_LOOP_VAL(var, -1, cmd) # define QT_EINTR_LOOP(var, cmd) QT_EINTR_LOOP_VAL(var, -1, cmd)
#endif #endif
// OpenBSD 4.2 doesn't define EIDRM, see BUGS section: // OpenBSD 4.2 doesn't define EIDRM, see BUGS section:
@ -133,7 +133,7 @@ bool QSystemSemaphorePosix::modifySemaphore(QSystemSemaphorePrivate *self, int c
// rollback changes to preserve the SysV semaphore behavior // rollback changes to preserve the SysV semaphore behavior
for ( ; cnt < count; ++cnt) { for ( ; cnt < count; ++cnt) {
int res; int res;
EINTR_LOOP(res, ::sem_wait(semaphore)); QT_EINTR_LOOP(res, ::sem_wait(semaphore));
} }
return false; return false;
} }
@ -141,7 +141,7 @@ bool QSystemSemaphorePosix::modifySemaphore(QSystemSemaphorePrivate *self, int c
} while (cnt > 0); } while (cnt > 0);
} else { } else {
int res; int res;
EINTR_LOOP(res, ::sem_wait(semaphore)); QT_EINTR_LOOP(res, ::sem_wait(semaphore));
if (res == -1) { if (res == -1) {
// If the semaphore was removed be nice and create it and then modifySemaphore again // If the semaphore was removed be nice and create it and then modifySemaphore again
if (errno == EINVAL || errno == EIDRM) { if (errno == EINVAL || errno == EIDRM) {

View File

@ -174,7 +174,7 @@ bool QSystemSemaphoreSystemV::modifySemaphore(QSystemSemaphorePrivate *self, int
operation.sem_flg = SEM_UNDO; operation.sem_flg = SEM_UNDO;
int res; int res;
EINTR_LOOP(res, semop(semaphore, &operation, 1)); QT_EINTR_LOOP(res, semop(semaphore, &operation, 1));
if (-1 == res) { if (-1 == res) {
// If the semaphore was removed be nice and create it and then modifySemaphore again // If the semaphore was removed be nice and create it and then modifySemaphore again
if (errno == EINVAL || errno == EIDRM) { if (errno == EINVAL || errno == EIDRM) {

View File

@ -146,7 +146,7 @@ int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout
if (!timeout_ts) { if (!timeout_ts) {
// no timeout -> block forever // no timeout -> block forever
int ret; int ret;
EINTR_LOOP(ret, qt_ppoll(fds, nfds, nullptr)); QT_EINTR_LOOP(ret, qt_ppoll(fds, nfds, nullptr));
return ret; return ret;
} }

View File

@ -60,7 +60,7 @@
struct sockaddr; struct sockaddr;
#define EINTR_LOOP(var, cmd) \ #define QT_EINTR_LOOP(var, cmd) \
do { \ do { \
var = cmd; \ var = cmd; \
} while (var == -1 && errno == EINTR) } while (var == -1 && errno == EINTR)
@ -216,7 +216,7 @@ static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 07
flags |= O_CLOEXEC; flags |= O_CLOEXEC;
#endif #endif
int fd; int fd;
EINTR_LOOP(fd, QT_OPEN(pathname, flags, mode)); QT_EINTR_LOOP(fd, QT_OPEN(pathname, flags, mode));
#ifndef O_CLOEXEC #ifndef O_CLOEXEC
if (fd != -1) if (fd != -1)
@ -288,10 +288,10 @@ static inline int qt_safe_dup2(int oldfd, int newfd, int flags = FD_CLOEXEC)
int ret; int ret;
#ifdef QT_THREADSAFE_CLOEXEC #ifdef QT_THREADSAFE_CLOEXEC
// use dup3 // use dup3
EINTR_LOOP(ret, ::dup3(oldfd, newfd, flags ? O_CLOEXEC : 0)); QT_EINTR_LOOP(ret, ::dup3(oldfd, newfd, flags ? O_CLOEXEC : 0));
return ret; return ret;
#else #else
EINTR_LOOP(ret, ::dup2(oldfd, newfd)); QT_EINTR_LOOP(ret, ::dup2(oldfd, newfd));
if (ret == -1) if (ret == -1)
return -1; return -1;
@ -304,7 +304,7 @@ static inline int qt_safe_dup2(int oldfd, int newfd, int flags = FD_CLOEXEC)
static inline qint64 qt_safe_read(int fd, void *data, qint64 maxlen) static inline qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
{ {
qint64 ret = 0; qint64 ret = 0;
EINTR_LOOP(ret, QT_READ(fd, data, maxlen)); QT_EINTR_LOOP(ret, QT_READ(fd, data, maxlen));
return ret; return ret;
} }
#undef QT_READ #undef QT_READ
@ -313,7 +313,7 @@ static inline qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static inline qint64 qt_safe_write(int fd, const void *data, qint64 len) static inline qint64 qt_safe_write(int fd, const void *data, qint64 len)
{ {
qint64 ret = 0; qint64 ret = 0;
EINTR_LOOP(ret, QT_WRITE(fd, data, len)); QT_EINTR_LOOP(ret, QT_WRITE(fd, data, len));
return ret; return ret;
} }
#undef QT_WRITE #undef QT_WRITE
@ -328,7 +328,7 @@ static inline qint64 qt_safe_write_nosignal(int fd, const void *data, qint64 len
static inline int qt_safe_close(int fd) static inline int qt_safe_close(int fd)
{ {
int ret; int ret;
EINTR_LOOP(ret, QT_CLOSE(fd)); QT_EINTR_LOOP(ret, QT_CLOSE(fd));
return ret; return ret;
} }
#undef QT_CLOSE #undef QT_CLOSE
@ -340,28 +340,28 @@ static inline int qt_safe_execve(const char *filename, char *const argv[],
char *const envp[]) char *const envp[])
{ {
int ret; int ret;
EINTR_LOOP(ret, ::execve(filename, argv, envp)); QT_EINTR_LOOP(ret, ::execve(filename, argv, envp));
return ret; return ret;
} }
static inline int qt_safe_execv(const char *path, char *const argv[]) static inline int qt_safe_execv(const char *path, char *const argv[])
{ {
int ret; int ret;
EINTR_LOOP(ret, ::execv(path, argv)); QT_EINTR_LOOP(ret, ::execv(path, argv));
return ret; return ret;
} }
static inline int qt_safe_execvp(const char *file, char *const argv[]) static inline int qt_safe_execvp(const char *file, char *const argv[])
{ {
int ret; int ret;
EINTR_LOOP(ret, ::execvp(file, argv)); QT_EINTR_LOOP(ret, ::execvp(file, argv));
return ret; return ret;
} }
static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options)
{ {
int ret; int ret;
EINTR_LOOP(ret, ::waitpid(pid, status, options)); QT_EINTR_LOOP(ret, ::waitpid(pid, status, options));
return ret; return ret;
} }
#endif // QT_CONFIG(process) #endif // QT_CONFIG(process)

View File

@ -142,7 +142,7 @@ void QThreadPipe::wakeUp()
// eventfd // eventfd
eventfd_t value = 1; eventfd_t value = 1;
int ret; int ret;
EINTR_LOOP(ret, eventfd_write(fds[0], value)); QT_EINTR_LOOP(ret, eventfd_write(fds[0], value));
return; return;
} }
#endif #endif

View File

@ -54,7 +54,7 @@ static inline void qt_poll_examine_ready_read(struct pollfd &pfd)
int res; int res;
char data; char data;
EINTR_LOOP(res, ::recv(pfd.fd, &data, sizeof(data), MSG_PEEK)); QT_EINTR_LOOP(res, ::recv(pfd.fd, &data, sizeof(data), MSG_PEEK));
const int error = (res < 0) ? errno : 0; const int error = (res < 0) ? errno : 0;
if (res == 0) { if (res == 0) {
@ -109,7 +109,7 @@ static inline bool qt_poll_is_bad_fd(int fd)
#endif #endif
int ret; int ret;
EINTR_LOOP(ret, fcntl(fd, F_GETFD)); QT_EINTR_LOOP(ret, fcntl(fd, F_GETFD));
return (ret == -1 && errno == EBADF); return (ret == -1 && errno == EBADF);
} }

View File

@ -502,7 +502,7 @@ static void qt_nanosleep(timespec amount)
// nanosleep is POSIX.1-1993 // nanosleep is POSIX.1-1993
int r; int r;
EINTR_LOOP(r, nanosleep(&amount, &amount)); QT_EINTR_LOOP(r, nanosleep(&amount, &amount));
} }
void QThread::sleep(unsigned long secs) void QThread::sleep(unsigned long secs)

View File

@ -806,7 +806,7 @@ bool QNativeSocketEnginePrivate::nativeHasPendingDatagrams() const
// Peek 1 bytes into the next message. // Peek 1 bytes into the next message.
ssize_t readBytes; ssize_t readBytes;
char c; char c;
EINTR_LOOP(readBytes, ::recv(socketDescriptor, &c, 1, MSG_PEEK)); QT_EINTR_LOOP(readBytes, ::recv(socketDescriptor, &c, 1, MSG_PEEK));
// If there's no error, or if our buffer was too small, there must be a // If there's no error, or if our buffer was too small, there must be a
// pending datagram. // pending datagram.
@ -825,7 +825,7 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
// Linux can return the actual datagram size if we use MSG_TRUNC // Linux can return the actual datagram size if we use MSG_TRUNC
char c; char c;
EINTR_LOOP(recvResult, ::recv(socketDescriptor, &c, 1, MSG_PEEK | MSG_TRUNC)); QT_EINTR_LOOP(recvResult, ::recv(socketDescriptor, &c, 1, MSG_PEEK | MSG_TRUNC));
#elif defined(SO_NREAD) #elif defined(SO_NREAD)
// macOS can return the actual datagram size if we use SO_NREAD // macOS can return the actual datagram size if we use SO_NREAD
int value; int value;

View File

@ -108,7 +108,7 @@ static inline int qt_safe_connect(int sockfd, const struct sockaddr *addr, QT_SO
{ {
int ret; int ret;
// Solaris e.g. expects a non-const 2nd parameter // Solaris e.g. expects a non-const 2nd parameter
EINTR_LOOP(ret, QT_SOCKET_CONNECT(sockfd, const_cast<struct sockaddr *>(addr), addrlen)); QT_EINTR_LOOP(ret, QT_SOCKET_CONNECT(sockfd, const_cast<struct sockaddr *>(addr), addrlen));
return ret; return ret;
} }
#undef QT_SOCKET_CONNECT #undef QT_SOCKET_CONNECT
@ -144,7 +144,7 @@ static inline int qt_safe_sendmsg(int sockfd, const struct msghdr *msg, int flag
#endif #endif
int ret; int ret;
EINTR_LOOP(ret, ::sendmsg(sockfd, msg, flags)); QT_EINTR_LOOP(ret, ::sendmsg(sockfd, msg, flags));
return ret; return ret;
} }
@ -152,7 +152,7 @@ static inline int qt_safe_recvmsg(int sockfd, struct msghdr *msg, int flags)
{ {
int ret; int ret;
EINTR_LOOP(ret, ::recvmsg(sockfd, msg, flags)); QT_EINTR_LOOP(ret, ::recvmsg(sockfd, msg, flags));
return ret; return ret;
} }

View File

@ -408,7 +408,7 @@ static void generateStackTrace()
writeToStderr("Failed to start debugger.\n"); writeToStderr("Failed to start debugger.\n");
} else { } else {
int ret; int ret;
EINTR_LOOP(ret, waitpid(pid, nullptr, 0)); QT_EINTR_LOOP(ret, waitpid(pid, nullptr, 0));
} }
writeToStderr("=== End of stack trace ===\n"); writeToStderr("=== End of stack trace ===\n");