From aa6b6e3849e8f92802c1a2acab2baacf50ad32d5 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 8 Oct 2024 17:40:25 +0800 Subject: [PATCH] Remove Mono.Posix.NETStandard --- v2rayN/ServiceLib/Common/Utils.cs | 31 +++++++++++++++++++++++++++-- v2rayN/ServiceLib/ServiceLib.csproj | 1 - 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index d78a52c1..1fbe830f 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -1,4 +1,6 @@ -using System.Collections.Specialized; +using CliWrap; +using CliWrap.Buffered; +using System.Collections.Specialized; using System.Diagnostics; using System.IO.Compression; using System.Net; @@ -863,7 +865,32 @@ namespace ServiceLib.Common } else { - return Mono.Unix.Native.Syscall.geteuid() == 0; + var id = GetLinuxUserId().Result ?? "1000"; + if (int.TryParse(id, out int userId)) + { + return userId == 0; + } + else + { + return false; + } + } + } + + private static async Task GetLinuxUserId() + { + try + { + var result = await Cli.Wrap("/bin/bash") + .WithArguments(["-c", "id -u"]) + .WithValidation(CommandResultValidation.None) + .ExecuteBufferedAsync(); + + return result.StandardOutput.ToString(); + } + catch + { + return null; } } diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index ab44a0c9..3a598909 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -9,7 +9,6 @@ -