diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-30 17:32:26 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-30 17:32:47 +0200 |
commit | 25522af61f488a27fae7a24cdc7b2c949f442eed (patch) | |
tree | bc719392f4f98ba9787ab18ed73a82f4bb0e6339 /synchronizer/main.cpp | |
parent | 2a07a60b3a501e98b91e83b702a13d3dcbe66ed7 (diff) | |
download | sink-25522af61f488a27fae7a24cdc7b2c949f442eed.tar.gz sink-25522af61f488a27fae7a24cdc7b2c949f442eed.zip |
Moved lockfile into synchronizer
For better testability of listener.
Diffstat (limited to 'synchronizer/main.cpp')
-rw-r--r-- | synchronizer/main.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index 11fec25..2b0cfe3 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp | |||
@@ -18,6 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <QCoreApplication> | 20 | #include <QCoreApplication> |
21 | #include <QLockFile> | ||
21 | 22 | ||
22 | #include <signal.h> | 23 | #include <signal.h> |
23 | 24 | ||
@@ -41,7 +42,16 @@ int main(int argc, char *argv[]) | |||
41 | return app.exec(); | 42 | return app.exec(); |
42 | } | 43 | } |
43 | 44 | ||
44 | Listener *listener = new Listener(argv[1], &app); | 45 | const QByteArray instanceIdentifier = argv[1]; |
46 | |||
47 | QLockFile lockfile(instanceIdentifier + ".lock"); | ||
48 | lockfile.setStaleLockTime(0); | ||
49 | if (!lockfile.tryLock(0)) { | ||
50 | Warning() << "Failed to acquire exclusive lock on socket."; | ||
51 | return -1; | ||
52 | } | ||
53 | |||
54 | Listener *listener = new Listener(instanceIdentifier, &app); | ||
45 | 55 | ||
46 | QObject::connect(&app, &QCoreApplication::aboutToQuit, | 56 | QObject::connect(&app, &QCoreApplication::aboutToQuit, |
47 | listener, &Listener::closeAllConnections); | 57 | listener, &Listener::closeAllConnections); |