davidedmundson added a comment.
I think I didn't explain myself properly. There's a way to do a version that has no race conditions. Order of events needs to be 1. We try to register our service name with the queued flag 2. We see if we succeeded to register it immediately 3. If it fails, we send a non-blocking quit method to whoever currently owns that name 4. and then wait for our application to be given the service name we've already requested all except 3 exist already. INLINE COMMENTS > kdbusservice.cpp:171 > > - if (options & KDBusService::Unique) { > + if (options & KDBusService::Replace && > QDBusConnection::sessionBus().interface()->isServiceRegistered(d->serviceName)) > { > + auto message = QDBusMessage::createMethodCall(d->serviceName, This is still racey > kdbusservice.cpp:181 > + QEventLoop unregistrationLoop; > + connect(bus, &QDBusConnectionInterface::serviceUnregistered, > + this, [&unregistrationLoop, this](const QString > &service) { QDBusConnectionInterface::serviceUnregistered is very different to QDBusServiceWatcher::serviceUnregistered QDBusConnectionInterface::serviceUnregistered will be called when our process loses the service name it had. Our process hasn't even requested a service name yet, so this won't happen. REPOSITORY R271 KDBusAddons REVISION DETAIL https://phabricator.kde.org/D22946 To: apol, #frameworks, davidedmundson Cc: davidedmundson, broulik, kossebau, kde-frameworks-devel, LeGast00n, GB_2, michaelh, ngraham, bruns