aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs25
-rw-r--r--src/web/src/components/Search/Response.js2
2 files changed, 25 insertions, 2 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index dc3054dc..5414fccf 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -32,6 +32,7 @@ namespace slskd
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
+ using System.Threading;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
@@ -261,7 +262,29 @@ namespace slskd
return;
}
-
+ var reqInitialOwnership = false;
+ using(var mutex = new Mutex(reqInitialOwnership, AppName))
+ {
+ var hasHandle = false;
+ try{
+ try{
+ if(!mutex.WaitOne(0, false)){
+ Console.WriteLine("Another instance of this program is running");
+ Environment.Exit(0);
+ }
+ }
+ catch (AbandonedMutexException)
+ {
+ hasHandle=true;
+ }
+ }
+ finally
+ {
+ if(hasHandle)
+ mutex.ReleaseMutex();
+ }
+ }
+
if (GenerateCertificate)
{
GenerateX509Certificate(password: Cryptography.Random.GetBytes(16).ToBase62String(), filename: $"{AppName}.pfx");
diff --git a/src/web/src/components/Search/Response.js b/src/web/src/components/Search/Response.js
index 1e3dfcbd..6493393f 100644
--- a/src/web/src/components/Search/Response.js
+++ b/src/web/src/components/Search/Response.js
@@ -138,4 +138,4 @@ class Response extends Component {
};
}
-export default Response;
+export default Response; \ No newline at end of file