Comment on attachment 68712
Improved patch to save previous hibernation method
Review of attachment 68712:
-----------------------------------------------------------------
In do_hibernate() the attempt to save and restore the active mode in /sys/power/disk fails, causing "sh: I/O error" message in pm log (attempting to write something that isn't one of the modes in /sys/power/disk, namely an empty string). Instrumenting the function I found that HIBERNATE_MODE_SAVE was never set.
The characters [] are special in a shell pattern (which is what follows the ## and %% shell variable expansion modifiers) and have to be escaped: \[ \].
Although you could make the penultimate line as follows I don't recommend it because it would hide any problems like the escaping issue that could cause HIBERNATE_MODE_SAVE to be invalid:
Comment on attachment 68712
Improved patch to save previous hibernation method
Review of attachment 68712: ------- ------- ------- ------- ------- ------- ------- ------- --
-------
In do_hibernate() the attempt to save and restore the active mode in /sys/power/disk fails, causing "sh: I/O error" message in pm log (attempting to write something that isn't one of the modes in /sys/power/disk, namely an empty string). Instrumenting the function I found that HIBERNATE_MODE_SAVE was never set.
The characters [] are special in a shell pattern (which is what follows the ## and %% shell variable expansion modifiers) and have to be escaped: \[ \].
The following works as you intended:
do_hibernate() MODE_SAVE MODE_SAVE= $(cat /sys/power/disk) && \ MODE_SAVE= "${HIBERNATE_ MODE_SAVE# #*\[}" && \ MODE_SAVE= "${HIBERNATE_ MODE_SAVE% %\]*}" && \ MODE_SAVE" > /sys/power/disk
{
[ -n "${HIBERNATE_MODE}" ] && \
grep -qw "${HIBERNATE_MODE}" /sys/power/disk && \
#df 2016-02-07 Shell patterns have to be escaped \[ \]! Fixes sh: I/O error when -z $HIBERNATE_
HIBERNATE_
HIBERNATE_
HIBERNATE_
echo -n "${HIBERNATE_MODE}" > /sys/power/disk
echo -n "disk" > /sys/power/state
RET=$?
echo -n "$HIBERNATE_
return "$RET"
}
Although you could make the penultimate line as follows I don't recommend it because it would hide any problems like the escaping issue that could cause HIBERNATE_MODE_SAVE to be invalid:
[ -n "$HIBERNATE_ MODE_SAVE" ] && echo -n "$HIBERNATE_ MODE_SAVE" > /sys/power/disk