diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index e72b0588..95d42498 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include @@ -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); + } + return true; }