From e4b201a271e796d98d35183bc710826bc0111065 Mon Sep 17 00:00:00 2001 From: Tim Emiola Date: Wed, 31 Jan 2024 16:01:38 +0900 Subject: [PATCH] Remove the check for root when no pids are specified --- ChangeLog.md | 7 +++++++ README.md | 21 ++++++++++++--------- src/System/MemInfo.hs | 10 +--------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index e886f27..d3a3077 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,13 @@ `mem-info` uses [PVP Versioning][1]. +## Unreleased -- 2024-01-31 + +- Remove the check for __root__ when no pids are specified + + - previously, an error occurred if no pids were specified without sudo + - after this, all processes of the current user are shown + ## 0.2.0.0 -- 2024-01-28 - Simplify the output when the -d (--discriminate-by-pid) flag is used diff --git a/README.md b/README.md index 19c5c9b..1444c03 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ re-implementation allows its behaviour to be used as library code in haskell programs. It provides an executable command `printmem`, that mimics `ps_mem` while adding -new features, and `mem-info`, a haskell library package. +[new features], and `mem-info`, a haskell library package. ## Rationale @@ -44,7 +44,7 @@ common per-process breakdown of the RAM measurements. You can download a pre-built binary from [releases]. It is a statically-linked executable that should run on most recent Linux distributions. -Download it, place it in a directory on your path and give it executable permissions + Download it, place it in a directory on your path and give it executable permissions E.g, the following commands should suffice @@ -84,19 +84,21 @@ Available options: ### Example output You can run `printmem` *without* filtering; this will try to display data for -all running processes, so sudo is required +all running processes accessible by the current user -```sudo printmem``` +```printmem``` -Usually, you'll want to filter the results. which is supported by the `-p ` -option. This can be specified multiple times to select multiple processes. [pgrep] is great companion tool for obtaining the specific sets of pids for filtering. +Often, you'll want to filter the results. which is supported by the `-p ` +option. This can be specified multiple times to select multiple processes. +[pgrep] is great companion tool for obtaining the specific sets of pids for +filtering. -#### Example: breakdown the memory use of the current user +#### Example: breakdown the memory use of a different user -To restrict output to the current $USER, you can obtain the user's process IDs using pgrep comme ca +To restrict output to the specific user, you can obtain the user's process IDs using pgrep comme ca ``` -sudo printmem -S -p $(pgrep -d' -p ' -u $USER) + sudo printmem -S -p $(pgrep -d' -p ' -u ) ``` giving output like this: @@ -220,3 +222,4 @@ main = monitorRamOf $ 96334 :| [96335]-- replace with your own process IDs [releases]: [nix]: [cabal]: +[new features]: diff --git a/src/System/MemInfo.hs b/src/System/MemInfo.hs index c906295..bafa585 100644 --- a/src/System/MemInfo.hs +++ b/src/System/MemInfo.hs @@ -95,7 +95,6 @@ import System.MemInfo.SysInfo ( fmtSwapFlaws, mkReportBud, ) -import System.Posix.User (getEffectiveUserID) {- | Print a report to @stdout@ displaying the memory usage of the programs @@ -324,7 +323,7 @@ verify' pidsMb = do thenMkBud = either (pure . Left) mkBud' case pidsMb of Just pids -> checkAllExist pids >>= thenMkBud - Nothing -> whenRoot $ allKnownProcs >>= thenMkBud + Nothing -> allKnownProcs >>= thenMkBud procRoot :: String @@ -335,13 +334,6 @@ pidPath :: String -> ProcessID -> FilePath pidPath base pid = "" +| procRoot |++| toInteger pid |+ "/" +| base |+ "" -whenRoot :: IO (Either NotRun a) -> IO (Either NotRun a) -whenRoot action = do - -- if choicePidsToShow is Nothing, must be running as root - isRoot' <- (== 0) <$> getEffectiveUserID - if isRoot' then action else pure $ Left NeedsRoot - - {- | pidExists returns false for any ProcessID that does not exist or cannot be accessed -}