#1391 PR merged: Redirect both stderr and stdout into the log file but use the original fds for actually intended user input/output

Labels: enhancement, cleanup, fixed / solved / done

jsmeix opened issue at 2017-06-22 10:49:

This is a precondition for https://github.com/rear/rear/issues/885

The very first step is some cleanup and enhancements
of the messages output functions in _input-output-functions.sh

Be patient - do not merge it yet - more needs to come here...

jsmeix commented at 2017-06-23 12:46:

Meanwhile it seems to look o.k. for me when I run

rear -d -D mkbackup 2>/dev/null

rear -d -D recover 2>/dev/null

i.e. what is missing is to fix all the old deprecated usage of '>&8'
cf. https://github.com/rear/rear/issues/885#issuecomment-310393496

jsmeix commented at 2017-06-26 10:04:

By meditating over the weekend how I could
fix all the old deprecated usage of '>&8'
I think now that I will fix it in two steps:

First setp (within this pull request)
I will simply convert all old usage of '>&8' into '>/dev/null'
because according to
https://github.com/rear/rear/pull/874#issuecomment-227135652
all old usage of '>&8' results the same as '>/dev/null'
so that converting all old usage of '>&8' into '>/dev/null'
does not change anything and I can proceed here
towards getting this pull request in a state where
it can be merged.

Second step via https://github.com/rear/rear/issues/887
As a second separated step I can step by step check
each usage of '>/dev/null' and clean it up or enhance it
as appropriate, i.e.:
usually things should go to the log file but sometimes
things should actually still go to /dev/null, cf.
https://github.com/rear/rear/issues/887#issue-161207988

jsmeix commented at 2017-06-26 12:08:

Manwhile this pull request has changed from my initial attempt to
"Use generic ReaR functions for actually intended user input/output"
to
"Redirect both stderr and stdout into the log file
but use the original fds for actually intended user input/output"
which means it already solves
https://github.com/rear/rear/issues/885
in a (relatively) simple way as follows:

In lib/_input-output-functions.sh I do (excerpts):

# Duplicate STDIN to fd6 ...
exec 6<&0
# Duplicate STDOUT to fd7 ...
exec 7>&1
# Duplicate STDERR to fd8 ...
exec 8>&2

that is sourced before I do in usr/sbin/rear

# Redirect both STDOUT and STDERR into the log file.
...
exec 2>>"$RUNTIME_LOGFILE"
...
exec 1>&2

In all user input/output functions and in all scripts
I use now fd6 for actually intended user input and
fd7 and fd8 for actually intended user output.

To keep backward compatible behaviour
all old usage of '>&8' was converted into '>/dev/null'
where /dev/null usage in general can be cleaned up
later via https://github.com/rear/rear/issues/887

jsmeix commented at 2017-06-26 12:20:

Because it works well for me and I did not change
real functionality but only whereto stdin and stdout goes
I think this change cannot cause severe issues so that I merge it
(of course if there are issues I will fix them).

jsmeix commented at 2017-06-26 12:39:

In https://github.com/rear/rear/wiki/Coding-Style
I explained "What to do with stdout and stderr" when
both stdout and stderr are redirected into ReaR's log file.

jsmeix commented at 2017-06-28 14:27:

In https://github.com/rear/rear/pull/1391#issuecomment-311043325
I falsely assumed this change cannot cause severe issues,
see https://github.com/rear/rear/issues/1398

schlomo commented at 2017-06-28 14:46:

So should we revert it?

jsmeix commented at 2017-06-29 07:39:

@schlomo
please have a look at the actual current code what really would
have to be reverted to get back the previous behaviour, cf.
https://github.com/rear/rear/issues/1398#issuecomment-311886920

From my point of view all the other changes in this pull request
are valuable enhancements and code cleanup, cf.
https://github.com/rear/rear/pull/1391#issuecomment-311040948
for an overview.


[Export of Github issue for rear/rear.]