system_suspend: allow SystemSuspend to re-open the fd if found stale
Based on the BR it is evedent that when kernel fails to write any
wakeup reasons in /sys/kernel/wakeup_reasons/last_resume_reason, i.e.
if the file is read empty by system_suspend then the file descriptor
associated with that file becomes stale and cannot read the file
contents anymore, and all the subsequent attempts to read the
wakeup_reason returns empty which causes flurry of "unknown" wakeup
reasons.
Also, kernel only writes the wakeup reason in the sysfs node upon read()
call to the sysfs node, and hence it is not possible to know ahead of
time if the kernel is going to return empty file.
While we cannot prevent this error condition, we can certainly receover
re-opening the fd associated with "last_resume_reason" file.
Since it's main that opens all the files and pass their file descriptors
to SystemSuspend.cpp to do further file handling. This change will
re-open file for that stale fd using "/proc/self/fd/<fd>" when it
detects the failure condition, i.e. when an attempt to read
last_resume_reason file returns empty.
Bug:
192813633
Test: SystemSuspendV1_0UnitTest
Signed-off-by: Manish Varma <varmam@google.com>
Change-Id: I9e142f6526a1c0f836202725b593c624536c0f64