Commit Graph

76 Commits

Author SHA1 Message Date
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
Jim Warner
f865ccbff9 watch: correct differences option, eliminate duplicate help text 2012-01-05 10:07:08 +11:00
Sami Kerola
7ac61b3fa1 watch: halt screen at exit on error
This change allows user to see what was the last message before exit
on error, and when where the last update.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-05 09:58:24 +11:00
Sami Kerola
21b5980f82 watch: include strutils.h
Without the header strtod_or_err() returned random value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-05 09:58:19 +11:00
Craig Small
f776e59123 fixed e and x options in watch
The -e option would print a confusing error message. This is because
most error messages in watch are one word.  This fix makes a more
sensible message about what went wrong.

The -x option exited before the endwin() function was called, so if the
child process died the terminal was left in a funky state. endwin is now
called just before the exit(8) for the -x option.
2012-01-04 09:18:16 +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
5862f47b96 watch: use strtod_or_err() to validate user input
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:55 +01: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
Sami Kerola
c862a4caa5 nls: add functions which take translations to be used
Add the following three functions to most of the commands.

setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);

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:53 +01:00