Commit Graph

35 Commits

Author SHA1 Message Date
Jan Alexander Steffens (heftig)
91e5879228
free: Clean up scale_size and fix free -h --si
- Simplify control flow a bit. We don't need two loop variables, either.
- Consistently use %lld for bytes.
- Fix the base handling for human-readable output. The code used to
  calculate *mebibytes* first, then scale that to the required exponent
  with the selected base, which is patently wrong.

Fixes https://gitlab.com/procps-ng/procps/-/issues/133
2021-06-15 21:42:51 +02:00
Craig Small
cb13448179 free,slabtop,uptime: complain about extra ops
free, slabtop and uptime would happily take extra command line
arguments and doing nothing about them. The programs now check
optind after option processing and will give you usage screen
if there is anything extra.

References:
 procps-ng/procps#181
2020-10-19 22:36:06 +11:00
Craig Small
91a396d76e free: Adjust space to really use 9 chars
@steffhip found that while the translation hint said use 9 characters in
the free headers, it really was only 7.

Currently each line is constructed with the following (in non wide format):
Header + 6 Columns.  The header takes 7 characters and each column is 11
characters wide and prefixed with one space. Thus we have
7 + (1 + 11) * 6 = 79 characters for each line

By dropping the leading space for the first column after the header -the
header is already terminated by a colon- one could indeed provide the needed
9 letters for the header and thus have 9 + 11 * 1 + (1 + 11) * 5 = 80 Chars
per line which would fit into one line.
2020-04-24 17:42:58 +10:00
Craig Small
58bff862fc free: fix scaling on 32-bit systems
Systems that have a 32-bit long would give incorrect results in free.

References:
 Issue #89
 https://www.freelists.org/post/procps/frees-scale-size-broken-with-32bit-long
2018-04-10 21:20:25 +10:00
Craig Small
e82dd07b3b free: Update tests and fix for previous patch
The previous two patches updated free, but needed a tweak and the tests
also needed to be updated. I've hand-calculated the results using bc and
both the testsuite and bc results equal what free prints out.

References:
 commit 9365be7633
 procps-ng/procps#45
2018-01-13 16:09:54 +11:00
getzze
9365be7633 free.c - name correctly the binary multiples in the human-readable case 2018-01-13 15:40:35 +11:00
getzze
27d0b400de free.c - correct conversion to decimal multiples 2018-01-13 15:38:59 +11:00
Jim Warner
629fa81b57 misc: eliminate all those remaining gcc -Wall warnings
Reference(s):
proc/readproc.c: In function 'statm2proc'
proc/readproc.c:627:9: warning: variable 'num' set but not used [-Wunused-but-set-variable]

ps/output.c: In function 'pr_context':
ps/output.c:1273:14: warning: unused variable 'tried_load' [-Wunused-variable]
ps/output.c:1272:16: warning: unused variable 'ps_is_selinux_enabled' [-Wunused-variable]
ps/output.c:1272:16: warning: 'ps_is_selinux_enabled' defined but not used [-Wunused-variable]
ps/output.c:1273:14: warning: 'tried_load' defined but not used [-Wunused-variable]
ps/output.c:1837:18: warning: 'shortsort_array_count' defined but not used [-Wunused-const-variable=]
ps/output.c:1803:18: warning: 'aix_array_count' defined but not used [-Wunused-const-variable=]

ps/parser.c: In function 'arg_type':
ps/parser.c:1098:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
ps/parser.c:1099:34: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'

ps/sortformat.c: In function 'format_parse':
ps/sortformat.c:241:1: warning: label 'out' defined but not used [-Wunused-label]

ps/stacktrace.c:176:13: warning: 'stack_trace_sigsegv' defined but not used [-Wunused-function]

watch.c: In function 'process_ansi':
watch.c:234:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
watch.c:237:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:32 +10:00
Craig Small
1310a76848 watch,free: interpet intervals in non-locale way
Both watch and free used the locale to determine the required delay
interval for subsequent updates. It's preferable to not care about
locale and accept both 12.34 and 12,34 as meaning 12 seconds and
340 microseconds.

References:
 https://bugs.debian.org/692113

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-07-03 16:14:36 +10:00
Craig Small
97cde50b35 free: use correct end sentinel
When scaling values, the last item was integer 0 but the loop checked
for character '0'.

This was reported by 付腾桂 Thanks for the report and patch.
2015-10-24 13:17:36 +11:00
Craig Small
fd007d6d1d free: Parse -s option correctly.
If the -s option was the first option on the command line, free
would report seconds argument failed. This only appeared on the
Debian free, not the one in git.

Closer examination revealed that if a valid float string is
given to strtof() it doesn't set errno to 0, but just leaves it
alone. As we are explicitly testing errno for overflows, this
means the previous errno change is picked up here.

The simple answer is to set errno to 0 before calling strtof().

References:
 https://bugs.debian/org/733758
 https://enc.com.au/2015/08/08/be-careful-with-errno/
2015-08-08 21:04:01 +10:00
Craig Small
f8e98b65ae free: Use IEC units
Free always used 1024 based units but used the confusing old style
kilo,mega etc.

This change changes the names to kibi,mebi for 1024 based divisors
and kilo,mega for 1000 based divisors or IEC units.

It also checks if you try to set two units, e.g free -k -m
Petabyte and Pebibyte have been added.

If you used to use the long options such as --mega these will now
actually print megabytes (they previously printed mebibytes).
The short options are being used on the IEC units

References: https://www.gitorious.org/procps/procps/merge_requests/38

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-04-03 19:18:58 +11:00
Jaromir Capik
c9908b5971 free: fixing the layout broken with the -w introduction
For some reason I thought the columns are left justified
and consequently modified the header incorrectly when
implementing the -w/--wide feature.
With this commit the column width was increased by 1
so that the default layout is 79 characters wide
and allows to display 11 digits per column.
2014-08-20 13:21:22 +02:00
Jaromir Capik
f47001c9e9 free: remove -/+ buffers/cache
With introduction of the 'available' column
and with the latest changes in the 'used' evaluation
the -/+ buffers/cache line became redundant.
The first value duplicates the 'used'
column and the second value has a more accurate
brother called 'available'.
2014-07-31 15:10:42 +02:00
Jaromir Capik
5a0b972ca0 free: replace -a/--available with -w/--wide
This renames the --available switch
to the --wide switch and changes the default
layout so that it includes the 'available'
column and joins buffers and cache into
a common column called 'buff/cache'.
2014-07-31 15:10:42 +02:00
Jaromir Capik
ba6396f886 free: support for MemAvailable
This commit adds a new switch -a/--available that
appends a new column called 'available' to the
output. The column displays an estimation
of how much memory is available for starting
new applications, without swapping. Unlike the data
provided by the 'cached' or 'free' fields, this
field takes into account page cache and also that
not all reclaimable memory slabs will be reclaimed
due to items being in use.
2014-07-11 22:34:06 +02:00
Benno Schulenberg
099bf9a26a Update free text to help translators
Split up the free options so that each option has its own
gettext field, for ease of translating.

Signed-off-by: Craig Small <csmall@enc.com.au>
2013-10-10 09:56:44 +11:00
Rainer Müller
042776e04c configure: check for program_invocation_name
For portabiliy, check for program_invocation_name during configure and
define HAVE_PROGRAM_INVOCATION_NAME accordingly. Use of this symbol is
now enclosed with the appropriate #ifdef block.

The symbol program_invocation_name is only used for error message
handling using error(), so it's safe to omit this if it is not
available.
2013-03-20 16:32:06 +01:00
Adam Sampson
ecc265492f Show sizes > 4G correctly in bytes on 32-bit machines.
size is a long; this needs to be a 64-bit multiplication.
2012-06-27 06:47:38 +10:00
Sami Kerola
52269d22f3 all: check stdout and stderr status at exit
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code.  The uptime is just an
example same was true with all commands of the project.

$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-23 15:57:53 +01:00
Sami Kerola
ce61089059 docs: clarification to license headers in files
Add license header to all files.  The summary of licensing is below,
taken from Craig Small's email which is referred in commit message
tail.

sysctl and pgrep are GPL 2+
The rest is LGPL 2.1+

Reference: http://www.freelists.org/post/procps/Incorrect-FSF-address-in-the-license-files,8
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=797962
CC: Craig Small <csmall@enc.com.au>
CC: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:41:11 +11:00
Sami Kerola
a3544b00f8 free: remove redundant boundary check
The strtol_or_err() already check argument is not larger than
LONG_MAX. This commit also removes clang warning.

free.c:262:55: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
                        if (args.repeat_counter < 1 || args.repeat_counter > ULONG_MAX/2)
                                                       ~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:36:29 +11:00
Craig Small
c84675241d For free -b make the variable a long long
Bug-Debian: http://bugs.debian.org/654368

On systems with very large amonut of RAM when they use the -b or --bytes
option on free you get overflow and free shows a negative amount of
memory, which is obviously wrong.
2012-01-05 09:46:39 +11:00
Craig Small
5219a9c453 Check for 0 repeat count and tests in free
free checks for -c 0 now too.
testsuite has new checks for the checks.
2012-01-04 10:07:31 +11:00
Craig Small
223c95c95d free -c option uses strutils
The handling of the -c (count) option in free uses the standard string
handling and error utils.  The program also checks for negative counts
and errors on these.
2012-01-04 09:53:51 +11:00
Craig Small
fb11e1fe0a Changed the err and warns to macros
err and warn are BSD format but they are not recommended by library
developers.  However their consiseness is useful!

The solution is to use some macros that create xerr etc which then
just map to the error() function.  The next problem is error() uses
program_invocation_name so we set this to program_invovation_short_name

This is a global set but seems to be the convention (or at least errors
are on the short name only) used everywhere else.
2012-01-03 18:48:43 +11:00
Sami Kerola
c3405fab1a translations: group usage texts
Reference: http://www.freelists.org/post/procps/backporting,5
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-02 16:29:03 +11:00
Sami Kerola
0022b6ec5d nls: improve translations and provide translator help comments
Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:54 +01:00
Jim Warner
7b9b0c8d18 free: added remaining missing nls support 2011-12-20 17:30:51 +01:00
Sami Kerola
10db451038 free: add gettext support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:03 +01:00
Sami Kerola
e1bfc779f4 free: do not mix declarations and code [smatch scan]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:02 +01:00
Sami Kerola
71d10d3a49 name change: procps -> procps-ng
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-04 20:50:12 +02:00
Sami Kerola
d13fbc34a7 free: great modernization
Support long options, use program_invocation_short_name, print
version up on request, new giga & tera byte sizes switches, exit
when numeric arguments has garbage... and for rest see the diff.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-04-28 10:10:02 +02:00
albert
4ab5a6c8c3 merge with procps2 free 2004-01-30 04:47:14 +00:00
csmall
03a9b5a30f procps 010114 2002-02-01 22:47:29 +00:00