improve and clarify exec functionality#4
Open
spotrh wants to merge 1 commit intoToddAtkins:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This was reported against swatch here: https://bugzilla.redhat.com/show_bug.cgi?id=1622187
Steps to Reproduce:
watchfor /something(\d*)/
exec echo $1$1
quit
Actual results:
(From step 4) output shown is 'Aug' (correct since the first part of the log file line begins with the date/time, but wrong in that the '$1' should appear twice. Adding '--dump-script' to the command-line shows that only one '$1' is substituted. Without the awk-field-syntax option, the correct output is shown.
(From step 5) The 'quit' should execute immediately. It does not because it is actually waiting on the 'tail' command pipe used for input. The wait does eventually time out, not sure what causes that though (tail, perl, exit?)
(From step 8) output shown is 'something64 Aug'. Because of the first colon (:), the $1 is not substituted correctly - it ends up displaying the last token of the log line ('something64'). The second $1 is again substituted correctly, but where have the colons gone? Without the awk-field-syntax, the correct output is shown.
(From step 12) The output is correct. However, if the '--awk-field-option' is removed, an error is shown indicating that '$* is no longer supported'. The output also shows ':./.swatchdog_script.30491 :'. The '$0' is being interpreted as the actual swatchdog script being run.
Expected results:
(From step 4) output should be 'AugAug' when awk-field-option used, and '3232' when it isn't.
(From step 5) The 'quit' should cause swatchdog to immediately exit cleanly.
(From step 8) output should be ':Aug Aug:' when awk field option used, and ':64 64:' when it isn't used.
(From step 12) With the awk fields option, the output should show the whole log line twice, separated by a space and beginning and ending with a colon. Without the awk fields option the output should be exactly the same.
Additional info:
The man page implies that with 'exec' $N variables can be used, but does not specify that their meaning is different depending on whether the '--awk-fields-syntax' option is used or not.
It also implies that '$0' and '$' will be substituted in all cases. This only happens when the awk fields option is used. However, since without the option these variables end up being interpreted by the shell, we will get the $0 interpreted as the swatchdog script name and $ as nothing (since no parameters are passed to the script). It is probably better, more user friendly, if$0 and $ * are substituted in all cases (regardless of the awk fields option).
There is no accounting taken for the fact that a variable may be escaped. Entering '$0' for example, should not be interpreted (regardless of any options).
Swatchdog currently calls 'exit' when the 'quit' action is seen. But this waits on the tail command to finish. It is better to call the 'goodbye' function already written into the script, and used to handle signals. This will then kill the tail pid, close any pipes and then exit. It happens immediately.
This PR resolves all the above problems, and rewrites most of the 'exec' part of the man page. In addition, all the variables are substituted - provided they are not escaped. Currently, as shown in test step 4 above, only the first variable is substituted. Any others are ignored (so never shown in the output).
It also fixes one typo in the man page.