diff options
author | Simon Rettberg | 2016-10-24 18:27:57 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-10-24 18:27:57 +0200 |
commit | 0fd908798e2dd06b41e2b7c9d1d4c2777dade0c0 (patch) | |
tree | 2c333f08be3790d7dba0deafb659d9f54a117fca /src/client/vnc/vncserver.cpp | |
parent | [client] Fix "toogle vm/manager" button (copy&paste error..) (diff) | |
download | pvs2-0fd908798e2dd06b41e2b7c9d1d4c2777dade0c0.tar.gz pvs2-0fd908798e2dd06b41e2b7c9d1d4c2777dade0c0.tar.xz pvs2-0fd908798e2dd06b41e2b7c9d1d4c2777dade0c0.zip |
[client] Create config dir before trying to create vnc password file inside
Diffstat (limited to 'src/client/vnc/vncserver.cpp')
-rw-r--r-- | src/client/vnc/vncserver.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/client/vnc/vncserver.cpp b/src/client/vnc/vncserver.cpp index 9d647f0..496a84d 100644 --- a/src/client/vnc/vncserver.cpp +++ b/src/client/vnc/vncserver.cpp @@ -55,6 +55,18 @@ VncServer::VncServer() : _process(NULL), _port(0), _timerId(0) {} */ VncServer::~VncServer() {} +QSharedPointer<QFile> VncServer::createPwFile(const QDir& dir) +{ + QDir::root().mkpath(dir.absolutePath()); + QString str(dir.absoluteFilePath("vncpass")); + QSharedPointer<QFile> file = QSharedPointer<QFile>(new QFile(str)); + if (file->exists()) { + file->remove(); + } + file->open(QIODevice::WriteOnly); + return file; +} + /***************************************************************************//** * @brief VncServer::start */ @@ -70,22 +82,21 @@ void VncServer::start() _rwpass = makePassword(); _ropass = makePassword(); // Create new password file - QDir path = Util::settingsDir(); - QString pwfile(path.absoluteFilePath("vncpass")); - QFile pwhandle(pwfile); - if (pwhandle.exists()) - pwhandle.remove(); - if (!pwhandle.open(QIODevice::WriteOnly)) { - qDebug() << "Could not open " << pwfile << " for writing"; + QSharedPointer<QFile> pwhandle = createPwFile(Util::settingsDir()); + if (!pwhandle->isOpen()) { + pwhandle = createPwFile(QDir("/tmp")); + } + if (!pwhandle->isOpen()) { + qDebug() << "Could not open " << pwhandle->fileName() << " for writing"; emit started(0, _ropass, _rwpass); return; } - pwhandle.setPermissions(QFile::ReadOwner | QFile::WriteOwner); - pwhandle.write(_rwpass.toUtf8().constData()); - pwhandle.write("\n"); - pwhandle.write(_ropass.toUtf8().constData()); - pwhandle.write("\n"); - pwhandle.close(); + pwhandle->setPermissions(QFile::ReadOwner | QFile::WriteOwner); + pwhandle->write(_rwpass.toUtf8().constData()); + pwhandle->write("\n"); + pwhandle->write(_ropass.toUtf8().constData()); + pwhandle->write("\n"); + pwhandle->close(); // Create new process _process = new QProcess(this); connect(_process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStdOut())); @@ -96,7 +107,7 @@ void VncServer::start() QStringList args; args << "-forever"; args << "-display" << ":0"; - args << "-passwdfile" << (QString("rm:" + pwfile)); + args << "-passwdfile" << (QString("rm:" + pwhandle->fileName())); args << "-shared"; args << "-repeat"; args << "-autoport" << QString::number(54112); |