Issue #223: Attempt to remove stale lock file. (dismine/valentina)

New issue 223: Attempt to remove stale lock file.

Roman Telezhinskyi:

The lock file uses a PID to check whether the application is active (through QLockFile), but that check is fragile. If the program doesn’t terminate normally and that PID is reused, it will refuse to start, and this is very confusing.

Guys from ricochet already reached this issue. We will try use same method for our similar issue.

Here example of his solution.


     if (!lock->tryLock()) {
         if (lock->error() == QLockFile::LockFailedError) {
            // This happens if a stale lock file exists and another process uses that PID.
            // Try removing the stale file, which will fail if a real process is holding a
            // file-level lock. A false error is more problematic than not locking properly
            // on corner-case systems.
            if (!lock->removeStaleLockFile() || !lock->tryLock()) {
                errorMessage = QStringLiteral("Configuration file is already in use");
                return false;
            } else
                qDebug() << "Removed stale lock file";
         } else {
             errorMessage = QStringLiteral("Cannot write configuration file (failed to acquire lock)");
            return false;
        return false;

Responsible: dismine