Skip to content

Commit df2e645

Browse files
committed
core: fix flock/sendfile() on fbsd
1 parent 41828c4 commit df2e645

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

src/core/logging.cpp

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727
#include <qtmetamacros.h>
2828
#include <qtypes.h>
2929
#include <sys/mman.h>
30+
31+
#ifdef __FreeBSD__
32+
#include <sys/socket.h>
33+
#include <sys/types.h>
34+
#include <sys/uio.h>
35+
#else
3036
#include <sys/sendfile.h>
37+
#endif
3138

3239
#include "instanceinfo.hpp"
3340
#include "logcat.hpp"
@@ -392,13 +399,12 @@ void ThreadLogging::initFs() {
392399
delete detailedFile;
393400
detailedFile = nullptr;
394401
} else {
395-
auto lock = flock {
396-
.l_type = F_WRLCK,
397-
.l_whence = SEEK_SET,
398-
.l_start = 0,
399-
.l_len = 0,
400-
.l_pid = 0,
401-
};
402+
struct flock lock = {};
403+
lock.l_type = F_WRLCK;
404+
lock.l_whence = SEEK_SET;
405+
lock.l_start = 0;
406+
lock.l_len = 0;
407+
lock.l_pid = 0;
402408

403409
if (fcntl(detailedFile->handle(), F_SETLK, &lock) != 0) { // NOLINT
404410
qCWarning(logLogging) << "Unable to set lock marker on detailed log file. --follow from "
@@ -414,7 +420,14 @@ void ThreadLogging::initFs() {
414420
auto* oldFile = this->file;
415421
if (oldFile) {
416422
oldFile->seek(0);
423+
// clang-format off
424+
#ifdef __FreeBSD__
425+
off_t sent = 0;
426+
sendfile(file->handle(), oldFile->handle(), 0, oldFile->size(), nullptr, &sent, 0);
427+
#else
417428
sendfile(file->handle(), oldFile->handle(), nullptr, oldFile->size());
429+
#endif
430+
// clang-format on
418431
}
419432

420433
this->file = file;
@@ -426,7 +439,14 @@ void ThreadLogging::initFs() {
426439
auto* oldFile = this->detailedFile;
427440
if (oldFile) {
428441
oldFile->seek(0);
442+
// clang-format off
443+
#ifdef __FreeBSD__
444+
off_t sent = 0;
445+
sendfile(detailedFile->handle(), oldFile->handle(), 0, oldFile->size(), nullptr, &sent, 0);
446+
#else
429447
sendfile(detailedFile->handle(), oldFile->handle(), nullptr, oldFile->size());
448+
#endif
449+
// clang-format on
430450
}
431451

432452
crash::CrashInfo::INSTANCE.logFd = detailedFile->handle();
@@ -889,13 +909,12 @@ bool LogReader::continueReading() {
889909
}
890910

891911
void LogFollower::FcntlWaitThread::run() {
892-
auto lock = flock {
893-
.l_type = F_RDLCK, // won't block other read locks when we take it
894-
.l_whence = SEEK_SET,
895-
.l_start = 0,
896-
.l_len = 0,
897-
.l_pid = 0,
898-
};
912+
struct flock lock = {};
913+
lock.l_type = F_RDLCK; // won't block other read locks when we take it
914+
lock.l_whence = SEEK_SET;
915+
lock.l_start = 0;
916+
lock.l_len = 0;
917+
lock.l_pid = 0;
899918

900919
auto r = fcntl(this->follower->reader->file->handle(), F_SETLKW, &lock); // NOLINT
901920

src/core/paths.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,12 @@ void QsPaths::createLock() {
361361
return;
362362
}
363363

364-
auto lock = flock {
365-
.l_type = F_WRLCK,
366-
.l_whence = SEEK_SET,
367-
.l_start = 0,
368-
.l_len = 0,
369-
.l_pid = 0,
370-
};
364+
struct flock lock = {};
365+
lock.l_type = F_WRLCK;
366+
lock.l_whence = SEEK_SET;
367+
lock.l_start = 0;
368+
lock.l_len = 0;
369+
lock.l_pid = 0;
371370

372371
if (fcntl(file->handle(), F_SETLK, &lock) != 0) { // NOLINT
373372
qCCritical(logPaths).nospace() << "Could not lock instance lock at " << path
@@ -389,13 +388,12 @@ bool QsPaths::checkLock(const QString& path, InstanceLockInfo* info, bool allowD
389388
auto file = QFile(QDir(path).filePath("instance.lock"));
390389
if (!file.open(QFile::ReadOnly)) return false;
391390

392-
auto lock = flock {
393-
.l_type = F_WRLCK,
394-
.l_whence = SEEK_SET,
395-
.l_start = 0,
396-
.l_len = 0,
397-
.l_pid = 0,
398-
};
391+
struct flock lock = {};
392+
lock.l_type = F_WRLCK;
393+
lock.l_whence = SEEK_SET;
394+
lock.l_start = 0;
395+
lock.l_len = 0;
396+
lock.l_pid = 0;
399397

400398
fcntl(file.handle(), F_GETLK, &lock); // NOLINT
401399
auto isLocked = lock.l_type != F_UNLCK;

src/core/toolsupport.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ bool QmlToolingSupport::lockTooling() {
5454
return false;
5555
}
5656

57-
auto lock = flock {
58-
.l_type = F_WRLCK,
59-
.l_whence = SEEK_SET, // NOLINT (fcntl.h??)
60-
.l_start = 0,
61-
.l_len = 0,
62-
.l_pid = 0,
63-
};
57+
struct flock lock = {};
58+
lock.l_type = F_WRLCK;
59+
lock.l_whence = SEEK_SET; // NOLINT (fcntl.h??)
60+
lock.l_start = 0;
61+
lock.l_len = 0;
62+
lock.l_pid = 0;
6463

6564
if (fcntl(file->handle(), F_SETLK, &lock) == 0) {
6665
qCInfo(logTooling) << "Acquired tooling support lock";

0 commit comments

Comments
 (0)