diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-06 18:01:30 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-06 18:01:30 -0500 |
| commit | de3389852fa4e85d914e789007d98010784d3f9a (patch) | |
| tree | e684ac785f9458fae25c219f44eb03031984d9f4 /src | |
| parent | fb6350e107bd5f850a13c8c2065e341241967ab2 (diff) | |
| parent | 9fc05648a75b1c8022e3f034ff2abca47cdeaaf2 (diff) | |
| download | slskd-de3389852fa4e85d914e789007d98010784d3f9a.tar.gz | |
Merge pull request #680 from skar07/mutex-implementation
Mutex implementation to check single instance
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Program.cs | 25 | ||||
| -rw-r--r-- | src/web/src/components/Search/Response.js | 2 |
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 |
