diff options
author | Andrew Stanley-Jones <andrew.stanley-jones@nokia.com> | 2012-06-25 16:25:33 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-25 08:34:02 +0200 |
commit | f54ac2657f8320ae7bd211c614df2d335b4ff3a1 (patch) | |
tree | efa6c640fa74f38edcdd5534e617d0bd827e113a /src/serviceframework | |
parent | a7d15b0bcd791d3aad42da578c840f88a7960d2a (diff) |
Remove left over defines and fix the unix backend
Change-Id: If491cb14a1829baf84769c8425144e7848604c37
Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/serviceframework')
-rw-r--r-- | src/serviceframework/ipc/instancemanager.cpp | 6 | ||||
-rw-r--r-- | src/serviceframework/ipc/ipc.pri | 2 | ||||
-rw-r--r-- | src/serviceframework/ipc/objectendpoint.cpp | 39 | ||||
-rw-r--r-- | src/serviceframework/ipc/qremoteserviceregister_unix_p.cpp | 163 | ||||
-rw-r--r-- | src/serviceframework/qserviceclientcredentials.cpp | 2 | ||||
-rw-r--r-- | src/serviceframework/qserviceinterfacedescriptor.cpp | 16 | ||||
-rw-r--r-- | src/serviceframework/qserviceinterfacedescriptor.h | 1 | ||||
-rw-r--r-- | src/serviceframework/serviceframework.pro | 4 |
8 files changed, 98 insertions, 135 deletions
diff --git a/src/serviceframework/ipc/instancemanager.cpp b/src/serviceframework/ipc/instancemanager.cpp index f439565a..a1a75774 100644 --- a/src/serviceframework/ipc/instancemanager.cpp +++ b/src/serviceframework/ipc/instancemanager.cpp @@ -152,9 +152,7 @@ QObject* InstanceManager::createObjectInstance(const QRemoteServiceRegister::Ent instanceId = descr.globalId; descr.globalRefCount++; if (!QMetaObject::invokeMethod(service, "verifyNewServiceClientCredentials", Q_ARG(QServiceClientCredentials*, &creds))){ -#ifdef QT_MTCLIENT_PRESENT qWarning() << "Unable to authenticate new client connection on shared object" << descr.entryData->meta->className(); -#endif } } else { bool hasSecureConstructor = false; @@ -169,9 +167,7 @@ QObject* InstanceManager::createObjectInstance(const QRemoteServiceRegister::Ent } } if (!hasSecureConstructor) { -#ifdef QT_MTCLIENT_PRESENT qWarning() << "caution SFW using constructor without security credentials" << descr.entryData->meta->className(); -#endif service = (*descr.entryData->cptr)(); } if (!service) @@ -194,9 +190,7 @@ QObject* InstanceManager::createObjectInstance(const QRemoteServiceRegister::Ent } } if (!hasSecureConstructor) { -#ifdef QT_MTCLIENT_PRESENT qWarning() << "caution SFW using constructor without security credentials" << descr.entryData->meta->className(); -#endif service = (*descr.entryData->cptr)(); } if (!service) diff --git a/src/serviceframework/ipc/ipc.pri b/src/serviceframework/ipc/ipc.pri index 7e42f332..8965db5d 100644 --- a/src/serviceframework/ipc/ipc.pri +++ b/src/serviceframework/ipc/ipc.pri @@ -18,6 +18,7 @@ isEmpty(SFW_BACKEND) { } equals(SFW_BACKEND,unix) { + DEFINES += SFW_USE_UNIX_BACKEND PRIVATE_HEADERS += ipc/qremoteserviceregister_unix_p.h \ ipc/objectendpoint_p.h SOURCES += ipc/qremoteserviceregister_unix_p.cpp \ @@ -33,6 +34,7 @@ equals(SFW_BACKEND,unix) { ipc/objectendpoint_dbus.cpp \ ipc/qservicemetaobject_dbus.cpp } else:equals(SFW_BACKEND,localsocket) { + DEFINES += SFW_USE_LOCALSOCKET_BACKEND QT += network PRIVATE_HEADERS += ipc/qremoteserviceregister_ls_p.h \ ipc/objectendpoint_p.h diff --git a/src/serviceframework/ipc/objectendpoint.cpp b/src/serviceframework/ipc/objectendpoint.cpp index df231a9e..a24be68f 100644 --- a/src/serviceframework/ipc/objectendpoint.cpp +++ b/src/serviceframework/ipc/objectendpoint.cpp @@ -197,7 +197,7 @@ ObjectEndPoint::ObjectEndPoint(Type type, QServiceIpcEndPoint* comm, QObject* pa d->endPointType = type; dispatch->setParent(this); -#ifdef QT_MTCLIENT_PRESENT +#ifdef SFW_USE_UNIX_BACKEND connect(dispatch, SIGNAL(readyRead()), this, SLOT(newPackageReady()), Qt::DirectConnection); connect(dispatch, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::DirectConnection); #else @@ -258,7 +258,14 @@ QObject* ObjectEndPoint::constructProxy(const QRemoteServiceRegister::Entry & en openRequests.insert(p.d->messageId, response); dispatch->writePackage(p); + qServiceLog() << "class" << "objectendpoint" + << "event" << "constructProxy" + << "progress" << "wait for result"; waitForResponse(p.d->messageId); + qServiceLog() << "class" << "objectendpoint" + << "event" << "constructProxy" + << "progress" << "got result"; + if (response->isFinished) { if (response->result == 0) @@ -437,35 +444,11 @@ void ObjectEndPoint::objectRequest(const QServicePackage& p) dispatch->getSecurityCredentials(creds); // not supported on windows at the moment -#ifdef QT_MTCLIENT_PRESENT -// if (!creds.isValid()) { -// disconnected(); -// return; -// } -// // default to reject all clients unless accepted -// creds.setClientAccepted(false); if (!creds.isValid()) { qWarning() << "SFW Unable to get socket credentials client asking for" << p.d->entry.interfaceName() << p.d->entry.serviceName() << "this may fail in the future"; disconnected(); return; } - QString testingdata = QLatin1Literal("/tmp/sfwtestdata/") + p.d->entry.interfaceName(); - qDebug() << "SFW Looking for false credentials in" << testingdata; - if (QFile::exists(testingdata)) { - QFile data(testingdata); - data.open(QIODevice::ReadOnly); - const QString line = QString::fromLatin1(data.readLine(128)).simplified(); - const QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts); - if (list.count() != 3) { - qWarning() << "File needs to be [pid] [uid] [gid]"; - } - else { - creds.d->pid = list.at(0).toInt(); - creds.d->uid = list.at(1).toInt(); - creds.d->gid = list.at(2).toInt(); - } - } -#endif //instantiate service object from type register service = m->createObjectInstance(p.d->entry, d->serviceInstanceId, creds); @@ -681,6 +664,9 @@ QVariant ObjectEndPoint::invokeRemoteProperty(int metaIndex, const QVariant& arg openRequests.insert(p.d->messageId, response); dispatch->writePackage(p); + qServiceLog() << "class" << "objectendpoint" + << "event" << "invokeRemoteProperty" + << "progress" << "wait for result"; waitForResponse(p.d->messageId); QVariant result; @@ -736,6 +722,9 @@ QVariant ObjectEndPoint::invokeRemote(int metaIndex, const QVariantList& args, i d->waitingOnReturnUuid = p.d->messageId; dispatch->writePackage(p); + qServiceLog() << "class" << "objectendpoint" + << "event" << "invokeRemote" + << "progress" << "wait for result"; waitForResponse(p.d->messageId); d->waitingOnReturnUuid = QUuid(); diff --git a/src/serviceframework/ipc/qremoteserviceregister_unix_p.cpp b/src/serviceframework/ipc/qremoteserviceregister_unix_p.cpp index 13361223..2c79401e 100644 --- a/src/serviceframework/ipc/qremoteserviceregister_unix_p.cpp +++ b/src/serviceframework/ipc/qremoteserviceregister_unix_p.cpp @@ -708,50 +708,6 @@ void UnixEndPoint::flushWriteBuffer() } } -class ServiceRequestWaiter : public QObject -{ - Q_OBJECT -public: - ServiceRequestWaiter(QObject *request, QObject *parent = 0) - : QObject(parent), receivedLaunched(false) - { - connect(request, SIGNAL(launched(QString)), this, SLOT(launched())); - connect(request, SIGNAL(failed(QString, QString)), this, SLOT(errorEvent(QString, QString))); - connect(request, SIGNAL(errorUnrecoverableIPCFault(QService::UnrecoverableIPCError)), - this, SLOT(ipcFault(QService::UnrecoverableIPCError))); - } - ~ServiceRequestWaiter() { } - - QString errorString; - bool receivedLaunched; - -Q_SIGNALS: - void ok(); - void error(); - -protected Q_SLOTS: - void errorEvent(const QString &, const QString& errorString) { - qDebug() << "Got error evernt"; - this->errorString = errorString; - emit error(); - } - - void ipcFault(QService::UnrecoverableIPCError) { - errorEvent(QString(), QStringLiteral("Unrecoverable IPC fault, unable to request service start")); - } - - void timeout() { - qWarning() << "SFW Timeout talking to the process manager?? exect failure"; - errorEvent(QString(), QStringLiteral("Timeout waiting for reply")); - } - - void launched() { - qWarning() << "SFW got laucnhed from PM"; - receivedLaunched = true; - emit ok(); - } -}; - QRemoteServiceRegisterUnixPrivate::QRemoteServiceRegisterUnixPrivate(QObject* parent) : QRemoteServiceRegisterPrivate(parent), server_fd(-1), server_notifier(0) { @@ -943,6 +899,10 @@ int doStart(const QString &location) { QTime total_time; total_time.start(); + qServiceLog() << "class" << "doStart" + << "event" << "start" + << "location" << location; + #ifndef Q_OS_MAC int fd = ::inotify_init1(IN_NONBLOCK|IN_CLOEXEC); int wd = ::inotify_add_watch(fd, "/tmp/", IN_MOVED_TO|IN_CREATE); @@ -991,6 +951,10 @@ int doStart(const QString &location) { QTime e; e.start(); + qServiceLog() << "class" << "doStart" + << "event" << "found process" + << "location" << location; + while ((e.elapsed() < 5000) && !w->done) { UnixEndPoint::runLocalEventLoop(); } @@ -1017,48 +981,96 @@ int doStart(const QString &location) { qWarning() << QTime::currentTime().toString(fmt) << "SFW unable to connect to service, trying to start it." << ret << qt_error_string(errno); - if (location == QStringLiteral("com.nokia.mt.processmanager.ServiceRequest") || - location == QStringLiteral("com.nokia.mt.processmanager.ServiceRequestSocket")) { + QString path = location; + // If we have autotests enable, check for the service in . +#ifdef QT_BUILD_INTERNAL + QFile filei(QStringLiteral("./") + path); + if (filei.exists()){ + path.prepend(QStringLiteral("./")); + qServiceLog() << "class" << "doStart" + << "event" << "found daemon in ." + << "location" << path; + } +#endif /* QT_BUILD_INTERNAL */ + + + int pipefd[2]; + + if (-1 == (pipe2(pipefd, O_CLOEXEC))) { + qWarning("pipe2 failed: %s", ::strerror(errno)); #ifndef Q_OS_MAC ::inotify_rm_watch(fd, wd); ::close(fd); #endif delete w; delete w_inotify; - close(socketfd); - return -1; + return socketfd; } - QVariantMap map; - map.insert(QStringLiteral("interfaceName"), QStringLiteral("com.nokia.mt.processmanager.ServiceRequest")); - map.insert(QStringLiteral("serviceName"), QStringLiteral("com.nokia.mt.processmanager")); - map.insert(QStringLiteral("major"), 1); - map.insert(QStringLiteral("minor"), 0); - map.insert(QStringLiteral("Location"), QStringLiteral("com.nokia.mt.processmanager.ServiceRequestSocket")); - map.insert(QStringLiteral("ServiceType"), QService::InterProcess); + qint64 pid = 0; - QServiceInterfaceDescriptor desc(map); - QServiceManager manager; - QObject *serviceRequest = manager.loadInterface(desc); + // Start the service as a detached process + if (!(pid = fork())) { + char buffer[] = "FAIL"; + close(pipefd[0]); - qWarning() << QTime::currentTime().toString(fmt) - << "SFW Called loadinterface" << serviceRequest; + qServiceLog() << "class" << "doStart" + << "event" << "client starting" + << "location" << path; + + // child, move it away from the parent + if (-1 == (setsid())) { + qWarning("setsit failed: %s", ::strerror(errno)); + write(pipefd[1], buffer, 5); + exit(-1); + } + + setpgid(getpid(), getpid()); + + execlp(path.toLatin1(), path.toLatin1(), NULL); + + qWarning("exec of process %s failed: %s", path.toLatin1(), ::strerror(errno)); - if (!serviceRequest) { - qWarning() << "Failed to initiate communications with Process manager, can't start service" << location; + qServiceLog() << "class" << "doStart" + << "event" << "failed start" + << "error" << ::strerror(errno); + + write(pipefd[1], buffer, 5); + exit(-1); + } + + if (pid == -1) { + close(pipefd[0]); + close(pipefd[1]); + qWarning("process start failed %s", ::strerror(errno)); #ifndef Q_OS_MAC ::inotify_rm_watch(fd, wd); ::close(fd); #endif delete w; delete w_inotify; - close(socketfd); - return -1; + return socketfd; } - ServiceRequestWaiter waiter(serviceRequest); + close(pipefd[1]); - QMetaObject::invokeMethod(serviceRequest, "startService", Qt::DirectConnection, Q_ARG(QString, location)); + char buffer[5]; + if (read(pipefd[0], buffer, 5) > 0) { + qServiceLog() << "class" << "doStart" + << "event" << "ddeamon error reported"; + qWarning("process start failed"); +#ifndef Q_OS_MAC + ::inotify_rm_watch(fd, wd); + ::close(fd); +#endif + delete w; + delete w_inotify; + return socketfd; + } + close(pipefd[0]); + + qServiceLog() << "class" << "doStart" + << "event" << "deamon started"; QFileInfo file(QStringLiteral("/tmp/") + location); qWarning() << QTime::currentTime().toString(fmt) @@ -1100,9 +1112,6 @@ int doStart(const QString &location) { << "errno" << qt_error_string(errno); if (ret == 0 || (ret == -1 && errno == EISCONN)) { - if (!waiter.receivedLaunched) { - qWarning() << "SFW asked the PM for a start, PM never replied, application started...something appears broken"; - } success = true; break; } else if (ret == -1 && errno == EINPROGRESS) { @@ -1110,28 +1119,17 @@ int doStart(const QString &location) { } else { w->setEnabled(false); } - - if (!waiter.errorString.isEmpty()) { - qWarning() << "SFW Error talking to PM" << socketfd << waiter.errorString; - qServiceLog() << "func" << __FUNCTION__ - << "event" << "error from waiter" - << "error" << waiter.errorString; - success = false; - break; - } } qServiceLog() << "func" << __FUNCTION__ << "event" << "connect done" << "time" << total_time.elapsed() - << "fd" << socketfd - << "pm_reply" << waiter.receivedLaunched; + << "fd" << socketfd; qWarning() << QTime::currentTime().toString(fmt) << "SFW doStart done. Total time" << total_time.elapsed() << "Socket exists:" << file.exists() << - "isSocketValid" << socketfd << - "pm reply" << waiter.receivedLaunched; + "isSocketValid" << socketfd; if (success == false) { ::close(socketfd); @@ -1140,7 +1138,6 @@ int doStart(const QString &location) { delete w; delete w_inotify; - delete serviceRequest; #ifndef Q_OS_MAC ::inotify_rm_watch(fd, wd); ::close(fd); diff --git a/src/serviceframework/qserviceclientcredentials.cpp b/src/serviceframework/qserviceclientcredentials.cpp index 3d12793a..a584f82c 100644 --- a/src/serviceframework/qserviceclientcredentials.cpp +++ b/src/serviceframework/qserviceclientcredentials.cpp @@ -127,11 +127,9 @@ void QServiceClientCredentials::setClientAccepted(bool isAccepted) */ bool QServiceClientCredentials::isClientAccepted() const { -#ifdef QT_MTCLIENT_PRESENT if (!d->acceptedSet) { qWarning() << "SFW credentials were queried, but service never called setClientAccepted(bool). Returning default accepted. This will break in the furture."; } -#endif return d->accepted; } diff --git a/src/serviceframework/qserviceinterfacedescriptor.cpp b/src/serviceframework/qserviceinterfacedescriptor.cpp index 4273dc45..aacc1faf 100644 --- a/src/serviceframework/qserviceinterfacedescriptor.cpp +++ b/src/serviceframework/qserviceinterfacedescriptor.cpp @@ -136,22 +136,6 @@ QServiceInterfaceDescriptor::QServiceInterfaceDescriptor(const QServiceInterface } /*! - Create a minimum QServiceInterfaceDescriptor from a hard coded serivce. Useful - if no database/metadata storage is available. Different platforms may have different - requirements -*/ -QServiceInterfaceDescriptor::QServiceInterfaceDescriptor(const QVariantMap &map) -{ - d = new QServiceInterfaceDescriptorPrivate; - d->interfaceName = map.value(QStringLiteral("interfaceName")).toString(); - d->serviceName = map.value(QStringLiteral("serviceName")).toString(); - d->major = map.value(QStringLiteral("major")).toInt(); - d->minor = map.value(QStringLiteral("minor")).toInt(); - d->attributes[QServiceInterfaceDescriptor::Location] = map.value(QStringLiteral("Location")).toString(); - d->attributes[QServiceInterfaceDescriptor::ServiceType] = map.value(QStringLiteral("ServiceType")).toString(); -} - -/*! \fn QServiceInterfaceDescriptor& QServiceInterfaceDescriptor::operator=(const QServiceInterfaceDescriptor& other) Copies the content of the QServiceInterfaceDescriptor object contained diff --git a/src/serviceframework/qserviceinterfacedescriptor.h b/src/serviceframework/qserviceinterfacedescriptor.h index 2ac787c1..39a4fff8 100644 --- a/src/serviceframework/qserviceinterfacedescriptor.h +++ b/src/serviceframework/qserviceinterfacedescriptor.h @@ -77,7 +77,6 @@ public: QServiceInterfaceDescriptor(); QServiceInterfaceDescriptor(const QServiceInterfaceDescriptor& other); - QServiceInterfaceDescriptor(const QVariantMap &map); ~QServiceInterfaceDescriptor(); QServiceInterfaceDescriptor& operator=(const QServiceInterfaceDescriptor& other); diff --git a/src/serviceframework/serviceframework.pro b/src/serviceframework/serviceframework.pro index cfe2628d..56153673 100644 --- a/src/serviceframework/serviceframework.pro +++ b/src/serviceframework/serviceframework.pro @@ -11,13 +11,13 @@ DEFINES += QT_BUILD_SFW_LIB QT_MAKEDLL load(qt_module_config) -sfwdebug: { +sfwdebug { DEFINES += QT_SFW_IPC_DEBUG QT += network } jsondb { - DEFINES += QT_NO_DBUS QT_ADDON_JSONDB_LIB QT_MTCLIENT_PRESENT + DEFINES += QT_NO_DBUS QT_ADDON_JSONDB_LIB QT += jsondb } |