From b862202396883a0ecfe96d14d07ce8cc6295a6d5 Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Mon, 26 Feb 2024 13:23:46 +0330 Subject: [PATCH] Frontend.XF.GTK: different exitCode on root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An error occurs when geewallet is run with root permissions, thus it’s necessary to restrict users from running it as root: ``` mkdir: cannot create directory ‘/run/user/0’: Permission denied realpath: '': No such file or directory realpath: '': No such file or directory realpath: '': No such file or directory realpath: '': No such file or directory realpath: '': No such file or directory realpath: '': No such file or directory realpath: '': No such file or directory realpath: '': No such file or directory Authorization required, but no authorization protocol specified (geewallet:5797): Gtk-WARNING **: 09:01:13.760: cannot open display: :0 ``` --- src/GWallet.Backend/Config.fs | 3 +++ src/GWallet.Frontend.XF.Gtk/Program.fs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/GWallet.Backend/Config.fs b/src/GWallet.Backend/Config.fs index 5bbf6a92c..ccdf01755 100644 --- a/src/GWallet.Backend/Config.fs +++ b/src/GWallet.Backend/Config.fs @@ -47,6 +47,9 @@ module Config = let IsMacPlatform() = RuntimeInformation.IsOSPlatform OSPlatform.OSX + let IsLinuxPlatform() = + RuntimeInformation.IsOSPlatform OSPlatform.Linux + let GetMonoVersion(): Option = FSharpUtil.option { // this gives None on MS.NET (e.g. UWP/WPF) diff --git a/src/GWallet.Frontend.XF.Gtk/Program.fs b/src/GWallet.Frontend.XF.Gtk/Program.fs index 771c6a2fa..f3f06ee62 100644 --- a/src/GWallet.Frontend.XF.Gtk/Program.fs +++ b/src/GWallet.Frontend.XF.Gtk/Program.fs @@ -39,6 +39,10 @@ module Main = let main argv = match argv.Length with | 0 -> + if GWallet.Backend.Config.IsLinuxPlatform() && Environment.UserName = "root" then + Console.Error.WriteLine "Running the GTK GUI as root is not supported" + Environment.Exit 1 + NormalStartWithNoParameters() | 1 when argv.[0] = "--version" -> Console.WriteLine (SPrintF1 "geewallet v%s" VersionHelper.CURRENT_VERSION)