aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Program.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2022-12-07 17:40:24 +0100
committerShadowghost <Ghost_of_Stone@web.de>2022-12-07 17:40:24 +0100
commit2c86bd1875e6e85d5867618e992d850453dae663 (patch)
tree671070fb246fd3821bf6f1e58a01c402a2f969d1 /Jellyfin.Server/Program.cs
parentdd5f90802e71083347b6095eb79a9de0b9d34615 (diff)
parent3cb7fe50127b1a8158186b390836ee25ae5a50fd (diff)
Merge branch 'master' into network-rewrite
Diffstat (limited to 'Jellyfin.Server/Program.cs')
-rw-r--r--Jellyfin.Server/Program.cs31
1 files changed, 10 insertions, 21 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 1e63b0204..8529a16d3 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -201,7 +202,7 @@ namespace Jellyfin.Server
{
await webHost.StartAsync(_tokenSource.Token).ConfigureAwait(false);
- if (startupConfig.UseUnixSocket() && Environment.OSVersion.Platform == PlatformID.Unix)
+ if (!OperatingSystem.IsWindows() && startupConfig.UseUnixSocket())
{
var socketPath = GetUnixSocketPath(startupConfig, appPaths);
@@ -234,7 +235,7 @@ namespace Jellyfin.Server
finally
{
// Don't throw additional exception if startup failed.
- if (appHost.ServiceProvider != null)
+ if (appHost.ServiceProvider is not null)
{
_logger.LogInformation("Running query planner optimizations in the database... This might take a while");
// Run before disposing the application
@@ -400,7 +401,7 @@ namespace Jellyfin.Server
if (string.IsNullOrEmpty(configDir))
{
- if (options.DataDir != null
+ if (options.DataDir is not null
|| Directory.Exists(Path.Combine(dataDir, "config"))
|| OperatingSystem.IsWindows())
{
@@ -575,7 +576,7 @@ namespace Jellyfin.Server
{
// Use the swagger API page as the default redirect path if not hosting the web client
var inMemoryDefaultConfig = ConfigurationOptions.DefaultConfiguration;
- if (startupConfig != null && !startupConfig.HostWebClient())
+ if (startupConfig is not null && !startupConfig.HostWebClient())
{
inMemoryDefaultConfig[DefaultRedirectKey] = "api-docs/swagger";
}
@@ -635,7 +636,7 @@ namespace Jellyfin.Server
}
string commandLineArgsString;
- if (options.RestartArgs != null)
+ if (options.RestartArgs is not null)
{
commandLineArgsString = options.RestartArgs;
}
@@ -670,7 +671,7 @@ namespace Jellyfin.Server
{
var xdgRuntimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR");
var socketFile = "jellyfin.sock";
- if (xdgRuntimeDir == null)
+ if (xdgRuntimeDir is null)
{
// Fall back to config dir
socketPath = Path.Join(appPaths.ConfigurationDirectoryPath, socketFile);
@@ -684,27 +685,15 @@ namespace Jellyfin.Server
return socketPath;
}
+ [UnsupportedOSPlatform("windows")]
private static void SetUnixSocketPermissions(IConfiguration startupConfig, string socketPath)
{
var socketPerms = startupConfig.GetUnixSocketPermissions();
if (!string.IsNullOrEmpty(socketPerms))
{
-#pragma warning disable SA1300 // Entrypoint is case sensitive.
- [DllImport("libc")]
- static extern int chmod(string pathname, int mode);
-#pragma warning restore SA1300
-
- var exitCode = chmod(socketPath, Convert.ToInt32(socketPerms, 8));
-
- if (exitCode < 0)
- {
- _logger.LogError("Failed to set Kestrel unix socket permissions to {SocketPerms}, return code: {ExitCode}", socketPerms, exitCode);
- }
- else
- {
- _logger.LogInformation("Kestrel unix socket permissions set to {SocketPerms}", socketPerms);
- }
+ File.SetUnixFileMode(socketPath, (UnixFileMode)Convert.ToInt32(socketPerms, 8));
+ _logger.LogInformation("Kestrel unix socket permissions set to {SocketPerms}", socketPerms);
}
}
}