mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
add kill switch for errno 22 error to shut down if the error does not go away
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -70,9 +71,20 @@ func (i *Inotify) Watch(dir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errno22Counter = 0
|
||||||
|
|
||||||
func (i *Inotify) Read(buf []byte) (int, error) {
|
func (i *Inotify) Read(buf []byte) (int, error) {
|
||||||
n, errno := unix.Read(i.FD, buf)
|
n, errno := unix.Read(i.FD, buf)
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
|
if errno.Error() == "invalid argument" {
|
||||||
|
errno22Counter += 1
|
||||||
|
if errno22Counter > 20 {
|
||||||
|
fmt.Printf("Unrecoverable inotify error (%s, errno %d). Exiting program...\n", errno, errno)
|
||||||
|
os.Exit(22)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errno22Counter = 0
|
||||||
|
}
|
||||||
return n, fmt.Errorf("reading from inotify fd %d: errno: %d", i.FD, errno)
|
return n, fmt.Errorf("reading from inotify fd %d: errno: %d", i.FD, errno)
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user