Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/dbus/applicationservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
#include <QUrl>
#include <QUuid>
#include <algorithm>
#include <fcntl.h>
#include <new>
#include <qcontainerfwd.h>
#include <qdbuserror.h>
#include <qfileinfo.h>
#include <qlogging.h>
#include <qnamespace.h>
#include <qtmetamacros.h>
#include <unistd.h>
#include <utility>
#include <wordexp.h>

Expand Down Expand Up @@ -1037,6 +1039,23 @@ bool ApplicationService::saveAutostartEntry(const QString &fileName, const Deskt
return false;
}

// Ensure file content is flushed to physical disk so the autostart entry
// survives a hard reboot (BUG-375555).
if (autostartFile.handle() != -1) {
if (::fsync(autostartFile.handle()) != 0) {
qWarning() << "fsync autostart file failed:" << fileName;
}
}

// Sync the parent directory so the directory entry of a newly created file
// is also persisted to disk.
const QByteArray parentDirPath = autostartFileInfo.absolutePath().toLocal8Bit();
int dirFd = ::open(parentDirPath.constData(), O_RDONLY | O_DIRECTORY);
if (dirFd != -1) {
::fsync(dirFd);
::close(dirFd);
Comment on lines +1053 to +1056

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Failures from opening or syncing the parent directory are ignored, so saveAutostartEntry returns true even when the directory entry was not persisted and a newly created autostart file can still disappear after a hard reboot.

Triggers: When the parent directory cannot be opened or ::fsync(dirFd) fails, such as on a filesystem that does not support directory syncing or after an interrupted system call.

Suggested fix: Log failures from both ::open and ::fsync, and decide whether saveAutostartEntry should report directory-sync failure instead of claiming the write succeeded.

}

return true;
}

Expand Down
Loading