libct/cgroups/fscommon.WriteFile: use errors.Unwrap
Tested that the EINTR is still being detected: > $ go1.14 test -c # 1.14 is needed for EINTR to happen > $ sudo ./fscommon.test > INFO[0000] interrupted while writing 1063068 to /sys/fs/cgroup/memory/test-eint-89293785/memory.limit_in_bytes > PASS Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
66778b3c28
commit
e4e35b8de8
|
@ -41,20 +41,10 @@ func ReadFile(dir, file string) (string, error) {
|
|||
func retryingWriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
for {
|
||||
err := ioutil.WriteFile(filename, data, perm)
|
||||
if isInterruptedWriteFile(err) {
|
||||
if errors.Unwrap(err) == syscall.EINTR {
|
||||
logrus.Infof("interrupted while writing %s to %s", string(data), filename)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func isInterruptedWriteFile(err error) bool {
|
||||
if patherr, ok := err.(*os.PathError); ok {
|
||||
errno, ok2 := patherr.Err.(syscall.Errno)
|
||||
if ok2 && errno == syscall.EINTR {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue