From f5a3afdcae67938cf7e6040d01a1d51a51e40350 Mon Sep 17 00:00:00 2001 From: "Kent R. Spillner" Date: Sat, 10 Mar 2012 18:35:08 -0600 Subject: [PATCH 1/2] watch: exit cleanly when falling through main loop. Revert commit ffe5e0b08eb981b862bab8220f0b9fcf48b7fc4f. Restores clean exit when falling through main loop. Previously, watch only exited when there was an error or when interrupted by the user. Commit 81f64657ba183ee983ea98c7f97904296b2ce5aa 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. --- watch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/watch.c b/watch.c index e9ce7c01..e3066f6f 100644 --- a/watch.c +++ b/watch.c @@ -739,5 +739,7 @@ int main(int argc, char *argv[]) usleep(interval * 1000000); } while (!exit_early); - return EXIT_FAILURE; + endwin(); + + return EXIT_SUCCESS; } From ddfc402886eb215d34ce031a60a861e50e80a19a Mon Sep 17 00:00:00 2001 From: "Kent R. Spillner" Date: Sun, 11 Mar 2012 10:14:27 -0500 Subject: [PATCH 2/2] 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. --- watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watch.c b/watch.c index e3066f6f..6ce174ba 100644 --- a/watch.c +++ b/watch.c @@ -657,7 +657,7 @@ int main(int argc, char *argv[]) tabpending = 0; } move(y, x); - if (!exit_early && option_chgexit) { + if (!first_screen && !exit_early && option_chgexit) { #ifdef WITH_WATCH8BIT cchar_t oldc; in_wch(&oldc);