Commit Graph

85 Commits

Author SHA1 Message Date
Craig Small
d3e0ff5a0a Merge branch 'awesomeclaw/procps-master'
References:
 procps-ng/procps!62

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2020-05-12 19:22:48 +10:00
Harry Wagstaff
c1214a56a6 Add ability to specify watch interval using environment variable WATCH_INTERVAL 2020-05-12 19:12:21 +10:00
Craig Small
bdce977a4e watch: fix unsetting of COLOR flag
watch used to check if COLOR was required, check if color was
possible then.. set the flag again.

It should have been cleared after failing to get colors out of
ncurses.

References:
 procps-ng/procps#143
2019-09-21 16:03:28 +10:00
Craig Small
d4a9a1e5d4 watch: use sysconf() for hostname length
Hurd doesn't have HOST_NAME_MAX, neither does Solaris.
An early fix just checked for this value and used 64 instead.
This change uses sysconf which is the correct method, possibly until
this compiles on some mis-behaving OS which doesn't have this value.

References:
 commit e564ddcb01
 procps-ng/procps#54
2018-03-03 18:36:44 +11:00
Craig Small
f9bef2b2c3 watch: Support ANSI 39,49 reset sequences
ANSI colour sequences 39 and 49 reset the foreground and background
colours respectively. This feature was missing from watch using the
colour "-c" option.

References:
 Fixes #73
 https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
2017-12-20 22:09:41 +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
Gustavo Zacarias
58559a5b64 configure.ac: use pkg-config to get ncursesw header location
Don't assume ncursesw headers are in ../usr/include/ncursesw/..
On a pure build/system without legacy ncurses that may not be true.
Since we're using pkg-config let it provide the correct include path.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2016-08-07 11:36:10 +02:00
Craig Small
e564ddcb01 watch: define HOST_NAME_MAX
Those infernal arches of kfreebsd-i386 (not -amd64) don't define
HOST_NAME_MAX. This patch is a work-around for those systems with
lacking include files.
2016-07-11 08:41:21 +10:00
Craig Small
9115ad7655 watch: fix process_ansi typo
When I had to apply Josh's ansi fix a few commits below I put the
return before the setattr

References:
 commit 261c571aca
2016-07-09 15:57:11 +10:00
Craig Small
2f5e0da5bb watch: Remove second [m check
With the previous watch fixes, there is no need for the second
[m check as these are covered in previous checks.
2016-07-09 15:16:57 +10:00
Josh Triplett
0236d278f2 watch: Don't attempt to ungetc parts of unknown ANSI escape sequences
If process_ansi encountered an unknown character when processing an ANSI
escape sequence, it would ungetc all the characters read so far, except
for the character just read, and the opening '\033['.  ungetting the
middle of the escape sequence does not produce useful results, and also
relies on the unportable assumption that ungetc works on multiple
characters (which glibc does not support).  Discard the characters
instead.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
2016-07-09 14:56:29 +10:00
Josh Triplett
f9a4fef6a9 watch: Fix ANSI escape sequence termination
process_ansi stopped processing an ANSI escape sequence if
(c < '0' && c > '9' && c != ';'), which will never happen.  Fix the
range check to use || instead.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
2016-07-09 14:55:11 +10:00
Josh Triplett
261c571aca watch: Don't process additional numbers in unknown ANSI color escapes
process_ansi assumed all numbers in a color control sequence correspond
to colors or attributes, which breaks badly if it encounters a
ISO-8613-3 escape sequence (such as for truecolor RGB).  For instance,
the sequence "\x1b[38;2;10;20;30m" sets the foreground color to
rgb(10,20,30), but watch will interpret all five numbers in the sequence
as colors or attributes themselves.

Stop processing the entire escape sequence if watch encounters any
number it doesn't understand, as that number may change the meaning of
the rest of the sequence.
2016-07-09 14:52:54 +10:00
Craig Small
3ead0207ae watch: fix 8bit regression
As part of the fix to truncate the command in non-8bit, watch had
the function for output_header changed (much for scope cleanliness
and cohesiveness than anything; so I'm going to blame Meyer)...

Anyhow the 8bit enabled version did not have that update which
meant watch failed to compile. Thanks to @asavah for issue #37
and the patch.

References:
 commit 5a40c7970d
2016-07-09 13:27:23 +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
5a40c7970d watch: truncate command in non-8 bit mode
When the screen width is not long enough to display the entire
command, watch puts three dots ... like elipses at the end of
the truncated line.

It's been like that for years, perhaps noone uses non 8-bit
watch?

References:
 commit 367b8bb616

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-07-02 16:07:56 +10:00
Jesse Hathaway
94054e7e96 watch: Add hostname to the header
watch has the hostname added to the header so you know what device
if you have many it is running on.

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-07-02 15:45:36 +10:00
Craig Small
6fcb690099 watch: interpret esc[m sequence
Commit 99fa7f removed watch crashing from having the null ANSI
sequence. However it just ignored that sequence instead of fixing it.

This change correctly checks buf (not undefined endptr) and sends
the reset attribute if found.

Closes: #12
2015-11-18 22:48:09 +11:00
Craig Small
99fa7f9f57 watch: Correctly process [m Remove lib dependency
The commit referenced below made the ANSI sequence
[m be interpreted as [0m However this change was put
in the incorrect place and would reference an undefined
pointer, causing a crash. Thanks to Jimmy Theis for the
second heads-up.

watch doesn't need any libprocps functions so it is no
longer linked to them.

References:
 commit a5937e4e94
 https://www.freelists.org/post/procps/watch-crashes-but-its-not-the-latest-commit-fault
 https://www.freelists.org/post/procps/Segmentation-fault-in-watch-3311
2015-09-01 21:28:07 +10:00
Andrew Wilcox
c4318389ac Add _XOPEN_SOURCE_EXTENDED definition in WATCH8BIT
This is required for POSIX correctness (see
http://lists.gnu.org/archive/html/bug-ncurses/2011-07/msg00004.html),
and additionally is required for building procps against the musl C
library.
2015-07-05 14:37:48 -05:00
Jaromir Capik
a5937e4e94 watch: treat <ESC>[m as <ESC>[0m
Known terminals call reset in case of empty ANSI sequence.
We should do the same, even when this is not defined by the
ANSI standard.
2015-02-25 18:40:53 +01:00
Jaromir Capik
eae9b671c0 watch: avoid ansi manipulations in non-ansi mode 2014-09-08 18:28:08 +02:00
Jaromir Capik
578cce6730 watch: fixing uninitialized variable 2014-09-08 18:24:28 +02:00
Jaromir Capik
e428a27af9 watch: fixing default color handling
Previously the default background color was expected
to be always black and the default foreground color
was expected to be always white. This commit extends
the group of color pairs with pairs containing default
colors.
2014-09-08 15:50:24 +02:00
Jaromir Capik
0160bdb559 watch: fixing future italic support 2014-09-06 10:54:34 +02:00
Jaromir Capik
b3e36c552b watch: enhancing ANSI color & style support
This commit adds support for background colors
and additional ANSI styles (faint, italic,
underlined, blinking, inversed).
2014-09-06 10:52:38 +02:00
Jaromir Capik
29b27fb282 watch: fixing uninitialized endptr in the previous commit
And increasing the ANSI buffer size from 10 to 100.
2014-08-20 19:14:13 +02:00
Sean Silva
469cac00ff watch: Fix handling of ANSI color escapes for -c
The previous code assumed that there would be 1 or 2 attributes to
apply. In fact, there can in general be any number (but typically
between 1 and 3). This commit generalizes the existing code to read
arbitrarily many attributes from the escape sequence.
2014-08-20 19:13:20 +02:00
Josh Stone
835b6294d1 watch: Don't leak extra fds to the child
Once the write side of the pipe has been duped to stdout for the child,
the original pipefd is no longer needed, so it can be closed to avoid
leaking to the child.

The leak can easily be seen with "watch ls -l /proc/self/fd", but I
found this due to "watch lvs" diagnosing itself:

    File descriptor 4 (pipe:[3163616]) leaked on lvs invocation.

Signed-off-by: Josh Stone <jistone@redhat.com>
2014-02-04 19:23:59 +01:00
Craig Small
8a38cd5eb4 Split help lines to help translators
To assist translators, the help lines are split so that each translation
chunk has one option. This gives bonus of if we add or change an option,
only that option remains untranslated rather than the entire help block.

Reference:
  http://www.freelists.org/post/procps/procpsng-for-Translation-Project,1

Signed-off-by: Craig Small <csmall@enc.com.au>
2013-12-28 09:25:39 +11:00
Craig Small
764e27a4dd Increase watch interval.
watch would only use an interval of up to 4294 seconds and silently
change to this limit. The 4294 seconds is 2^32/10^6 or how many
microseconds fit into unsigned int.

This change increases the limit to 2^32 seconds which is
approximately 136 years. This should be ok for now. Anything above
the old limit now uses sleep() instead of usleep() which only uses
integers (so 9999.123 seconds will be 9999 seconds)

This bug was first reported in 2006 and included a patch by
Stephen Kratzer. The patch was updated to fit the current source.

Bug-Debian: http://bugs.debian.org/720445
References: http://sourceforge.net/mailarchive/message.php?msg_id=4335929

Signed-off-by: Craig Small <csmall@enc.com.au>
2013-08-25 17:43:20 +10:00
Rainer Müller
538bd978a4 watch: Remove unused header
No declaration from proc/procps.h is actually used for watch.
2013-03-20 16:32:06 +01: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
Sami Kerola
58713dbcc8 watch: fix compiler warnings
watch.c:255:14: warning: no previous declaration for 'get_time_usec' [-Wmissing-declarations]
watch.c:303:6: warning: no previous declaration for 'output_header' [-Wmissing-declarations]
watch.c:364:5: warning: no previous declaration for 'run_command' [-Wmissing-declarations]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:30:02 +11:00
Sami Kerola
6b0bb82b99 watch: fix to backporting error, and other wide character issues
The commit 8967f0fca3 has an typo like
error, which I must have done.  The Bug-Debian 240989 did not have 12
but 128.  Rest of the fixes are from Bug-Debian 675069 e.g. missing
include added, and usage of iswprint().

Bug-Debian: http://bugs.debian.org/240989
Bug-Debian: http://bugs.debian.org/675069
Reported-by: "Dr. David Alan Gilbert" <dave@treblig.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-05-30 22:03:31 +10:00
Craig Small
ff3ab9d52d watch compiles with 8bit enabled
watch wouldn't compile with --enable-watch8bit as some variables were
missing.  This changes fixes it.
2012-05-20 17:08:29 +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
85e0a23347 watch: refactor code, add output_header() and run_command()
The main() was starting to be quite long with deep indents.  Both
signs of clean up being welcome change.

FIXME: The comment also changes -g option to exit immediately,
when screen contents change.  This should be separated commit,
e.g. the stuff is not ready to be merged.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-16 14:32:49 +01:00
Sami Kerola
dbedc905fe watch: remove arbitrary terminal size restriction
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-16 13:18:57 +01:00
Sami Kerola
94fa402d4b slabtop, vmstat, watch: remove file descriptor constants
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-16 13:18:43 +01:00
Kent R. Spillner
ddfc402886 Don't check if output changed on first screen.
When invoked with the --chgexit/-g options wait until we have at
least one screen of output before checking if the output changed.
Otherwise, we're comparing the initial screen of output to all
spaces, which usually isn't what we want.
2012-03-11 10:14:27 -05:00
Kent R. Spillner
f5a3afdcae watch: exit cleanly when falling through main loop.
Revert commit ffe5e0b08e.  Restores
clean exit when falling through main loop.

Previously, watch only exited when there was an error or when
interrupted by the user.  Commit 81f64657ba
added another exit condition when the watched command's output
changes, causing execution to fall out of the main loop.

With this change, watch correctly restores the terminal and returns
an exit code indicating success when invoked with the --chgexit/-g
options.
2012-03-10 18:35:08 -06: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
703e1e0486 watch: remove unused variables
watch.c:281:43: warning: unused variable 'option_version' [-Wunused-variable]
watch.c:281:26: warning: unused variable 'option_help' [-Wunused-variable]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>

Conflicts:

	watch.c
2012-03-03 18:31:13 +11:00
Craig Small
35d6960b5a Merge commit 'refs/merge-requests/1' of git://gitorious.org/procps/procps 2012-03-03 14:39:43 +11:00
Sami Kerola
529fa2e615 watch: inform about optional argument for -d switch
The -d, --differences switch(s) can use optional argument that was
not documented earlier.

Reported-By: Marian Sigler <m@qjym.de>
Bug-Debian: http://bugs.debian.org/597021
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-11 21:43:28 +01:00
Sami Kerola
ffe5e0b08e watch: remove unreachable code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-05 20:48:33 +01:00
Kent R. Spillner
81f64657ba watch: exit when command output changes.
Add new flags to watch (-g/--chgexit) so that it exits when the
output changes.  This is useful in builds and shell scripts, for
example when deploying webapps to block the remainder of the
deployment steps until after the webapp starts.

e.g. watch --chgexit curl http://foo/bar
2012-01-26 08:42:37 -06:00
Mike Frysinger
13d8cc0681 watch: include sys/wait.h for waitpid
Fixes build warning:
	watch.c:682:3: warning: implicit declaration of
		function 'waitpid' [-Wimplicit-function-declaration]

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-01-24 08:55:05 +01:00
Sami Kerola
79ceb30b5c ps: unify cases and remove trailing dots in messages
Strings with lower caps & no trailing dots have greater change to
have multiple occurences, meaning less effort for translators, than
strings with them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-15 20:52:58 +01:00