-
-
Notifications
You must be signed in to change notification settings - Fork 268
Have stdout and stderr also in non-debug modes #2633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In non-debug modes (in particular also in verbose mode) stdout and stderr are redirected to a temporary file STDOUT_STDERR_FILE="$TMP_DIR/rear.$WORKFLOW.stdout_stderr so in non-debug modes stdout and stderr of all programs is still available for the Error function to extract some latest messages cf. #2623
Let the Error function is search for latest stdout and stderr messages both in RUNTIME_LOGFILE and in STDOUT_STDERR_FILE and show all what is found (usually it should be only in one file).
Provide the "Including relative/path/to/script.sh" info both in RUNTIME_LOGFILE and STDOUT_STDERR_FILE because the Error function is searching for 'Including .*$script_basename' in both files.
To do chmod u=rw,go=- "$LOGFILE" it must exist
Be safe and do cat /dev/null >"$LOGFILE" before chmod u=rw,go=- "$LOGFILE" and then cat "$RUNTIME_LOGFILE" > "$LOGFILE"
|
To test how error out behaves I get this results: Neither verbose nor debug mode: Verbose mode: Debug mode Debugscript mode Because there is nothing in the log about the error in non-debug modes |
When stdout and stderr are redirected to STDOUT_STDERR_FILE messages of the last called programs cannot be in the log have the extracted messages also stored in the log. Furthermore show some generic info about debugging.
|
I decided against copying all lines in STDOUT_STDERR_FILE So I decided to copy only the extracted lines from STDOUT_STDERR_FILE I implemented that via With that I get in non-debug modes in the log |
Prepend temporary working area (BUILD_DIR) removal exit task (via "QuietAddExitTask cleanup_build_area_and_end_program") directly after "source usr/share/rear/lib/_input-output-functions.sh" so it gets executed directly before the generic exit tasks that are set in usr/share/rear/lib/_input-output-functions.sh This must be done before the first possible call of the 'Error' function otherwise we may error out but leave the build area behind.
|
Now things work well for me as far as I currently see. @rear/contributors |
In cleanup_build_area_and_end_program() when KEEP_BUILD_DIR is true show LogPrintError when there is something mounted within the build area and what is mounted there so the user is informed that he must manually umount it before he can (also manually) remove the build area.
|
With a7cd1eb In init/default/030_update_recovery_system.sh I added so during "rear mkrescue" I have and then Ignoring the manual umount is still safe with the shown 'rm' command: It removes all in the build area except the mounted things and their mountpoints. |
In cleanup_build_area_and_end_program() when KEEP_BUILD_DIR is not true use '--one-file-system' to be safe against also deleting by accident all mounted things below mountpoints in TMP_DIR or ROOTFS_DIR cf. #2633 (comment)
|
And 61646a6 |
In cleanup_build_area_and_end_program() also when KEEP_BUILD_DIR is not true show LogPrintError when there still exists something in the build area in particular when there is something mounted in the build area and what is mounted there so the user is informed that he must manually umount it before he can (also manually) remove the build area
Make multi-line Log() output appear aligned with the content of the first line: The first line is prefixed with MESSAGE_PREFIX and timestamp as it was before but now all subsequent lines are also prefixed with as many blanks as there are printable characters in the MESSAGE_PREFIX plus timestamp prefix so that the content of the subsequent lines gets properly indented to make their contents appear aligned with the content of the first line
|
With 42f78db I get and this log (excerpts) versus in debug mode (excerpts) and its log (excerpts) |
|
Because now all looks good to me |
Move the cleanup_build_area_and_end_program() function from lib/framework-functions.sh to lib/_input-output-functions.sh which is specifically sourced early in usr/sbin/rear to have cleanup_build_area_and_end_program() available for early Error() exits in usr/sbin/rear and make cleanup_build_area_and_end_program() and also the Error() function work fail-safe against not yet existing log files and not yet sourced functions in case of early Error() exits in usr/sbin/rear
Removed cleanup_build_area_and_end_program() from lib/framework-functions.sh because it is now with some more fail-safe conditions in lib/_input-output-functions.sh
|
I did 82c505e revealed that Error() hung up because it calls |
Some more minor fixes for early Error() in usr/sbin/rear
|
Phew! |
This code probably has not worked since commit 0022063 (PR rear#2633), because rescue.conf is sourced only when the build area has been already created by invoking mktemp. It is also unneeded, because since that commit, setting TMPDIR in local.conf (which was the initial concern that motivated this code) does not work anyway, as discussed in rear#2654.
This code probably has not worked since commit 0022063 (PR rear#2633), because rescue.conf is sourced only when the build area has been already created by invoking mktemp. It is also unneeded, because since that commit, setting TMPDIR in local.conf (which was the initial concern that motivated this code) does not work anyway, as discussed in rear#2654.
Type: Enhancement
Impact: High
Reference to related issue (URL):
Suppressing stderr by default decreases usability #2623
Redirect stdout and stderr to the log only in debug modes - normally discard them to /dev/null #2416
How was this pull request tested?
Only some "rear mkrescue" tests by me.
Brief description of the changes in this pull request:
In non-debug modes (in particular also in verbose mode)
stdout and stderr are redirected to a temporary file
STDOUT_STDERR_FILE="$TMP_DIR/rear.$WORKFLOW.stdout_stderr
so in non-debug modes stdout and stderr of all programs is still available
for the Error function to extract some latest messages,
cf. at the end of
#2627 (comment)
Furthermore the log files and the stdout/stderr file can now only read by root
because they may contain sensitive information
so we do now in usr/sbin/rear
cf. #2416 (comment)
I hope this makes it sufficiently secure for how ReaR is meant to be used
(at least it should now be more secure than before)
but I am not a security expert.