| 181 | } |
| 182 | |
| 183 | void SingleApplicationPrivate::startPrimary() |
| 184 | { |
| 185 | // Reset the number of connections |
| 186 | auto *inst = static_cast <InstancesInfo*>( memory->data() ); |
| 187 | |
| 188 | inst->primary = true; |
| 189 | inst->primaryPid = QCoreApplication::applicationPid(); |
| 190 | qstrncpy( inst->primaryUser, getUsername().toUtf8().data(), sizeof(inst->primaryUser) ); |
| 191 | inst->checksum = blockChecksum(); |
| 192 | instanceNumber = 0; |
| 193 | // Successful creation means that no main process exists |
| 194 | // So we start a QLocalServer to listen for connections |
| 195 | QLocalServer::removeServer( blockServerName ); |
| 196 | server = new QLocalServer(); |
| 197 | |
| 198 | // Restrict access to the socket according to the |
| 199 | // SingleApplication::Mode::User flag on User level or no restrictions |
| 200 | if( options & SingleApplication::Mode::User ){ |
| 201 | server->setSocketOptions( QLocalServer::UserAccessOption ); |
| 202 | } else { |
| 203 | server->setSocketOptions( QLocalServer::WorldAccessOption ); |
| 204 | } |
| 205 | |
| 206 | server->listen( blockServerName ); |
| 207 | QObject::connect( |
| 208 | server, |
| 209 | &QLocalServer::newConnection, |
| 210 | this, |
| 211 | &SingleApplicationPrivate::slotConnectionEstablished |
| 212 | ); |
| 213 | } |
| 214 | |
| 215 | void SingleApplicationPrivate::startSecondary() |
| 216 | { |