From 0fd908798e2dd06b41e2b7c9d1d4c2777dade0c0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 24 Oct 2016 18:27:57 +0200 Subject: [client] Create config dir before trying to create vnc password file inside --- src/client/vnc/vncserver.cpp | 39 +++++++++++++++++++++++------------- src/client/vnc/vncserver.h | 2 ++ src/server/mainwindow/mainwindow.cpp | 1 - 3 files changed, 27 insertions(+), 15 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 VncServer::createPwFile(const QDir& dir) +{ + QDir::root().mkpath(dir.absolutePath()); + QString str(dir.absoluteFilePath("vncpass")); + QSharedPointer file = QSharedPointer(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 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); diff --git a/src/client/vnc/vncserver.h b/src/client/vnc/vncserver.h index 61e6d21..4974946 100644 --- a/src/client/vnc/vncserver.h +++ b/src/client/vnc/vncserver.h @@ -9,6 +9,7 @@ #define VNCSERVER_H_ #include +#include class VncServer; @@ -25,6 +26,7 @@ private: VncServer(); virtual ~VncServer(); + QSharedPointer createPwFile(const QDir& dir); static VncServer *me; diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index c716849..6d9bdd3 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -806,7 +806,6 @@ void MainWindow::onButtonReloadRoomConfig() { connect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk())); connect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel())); - qDebug() << "in onButtonReloadRoomConfig!" << "size of room: " << serverApp->getRooms().size(); QList keyList = serverApp->getRooms().keys(); for (QList::iterator it = keyList.begin(); it != keyList.end() ; it++) { _reloadWindow->ui->roomList->addItem(*it); -- cgit v1.2.3-55-g7522