Use File.SetUnixFileMode

This commit is contained in:
Bond_009 2022-10-13 18:19:11 +02:00
parent 71982c7297
commit 93fd462b58
1 changed files with 5 additions and 16 deletions

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -201,7 +202,7 @@ namespace Jellyfin.Server
{ {
await webHost.StartAsync(_tokenSource.Token).ConfigureAwait(false); 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); var socketPath = GetUnixSocketPath(startupConfig, appPaths);
@ -691,27 +692,15 @@ namespace Jellyfin.Server
return socketPath; return socketPath;
} }
[UnsupportedOSPlatform("windows")]
private static void SetUnixSocketPermissions(IConfiguration startupConfig, string socketPath) private static void SetUnixSocketPermissions(IConfiguration startupConfig, string socketPath)
{ {
var socketPerms = startupConfig.GetUnixSocketPermissions(); var socketPerms = startupConfig.GetUnixSocketPermissions();
if (!string.IsNullOrEmpty(socketPerms)) if (!string.IsNullOrEmpty(socketPerms))
{ {
#pragma warning disable SA1300 // Entrypoint is case sensitive. File.SetUnixFileMode(socketPath, (UnixFileMode)Convert.ToInt32(socketPerms, 8));
[DllImport("libc")] _logger.LogInformation("Kestrel unix socket permissions set to {SocketPerms}", socketPerms);
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);
}
} }
} }
} }