From 4384320d416aabb86e30ce07b551704f6607807c Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Sat, 23 Jan 2016 02:19:34 -0500 Subject: [PATCH] Detect running instance and prevent loading second instance. --- src/main.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main.cc b/src/main.cc index c71f483592..91c48eb1fd 100644 --- a/src/main.cc +++ b/src/main.cc @@ -35,6 +35,8 @@ This file is part of the QGROUNDCONTROL project #include "QGCApplication.h" +#define SINGLE_INSTANCE_PORT 14499 + #ifndef __mobile__ #include "QGCSerialPortInfo.h" #endif @@ -119,6 +121,16 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) int main(int argc, char *argv[]) { +#ifndef __mobile__ + //-- Test for another instance already running. If that's the case, we simply exit. + QHostAddress host("127.0.0.1"); + QUdpSocket socket; + if(!socket.bind(host, SINGLE_INSTANCE_PORT, QAbstractSocket::DontShareAddress)) { + qWarning() << "Another instance already running. Exiting."; + exit(-1); + } +#endif + #ifdef Q_OS_MAC #ifndef __ios__ // Prevent Apple's app nap from screwing us over -- GitLab