()
| 120 | } |
| 121 | |
| 122 | func inotifyNodes() (int, error) { |
| 123 | pid := os.Getpid() |
| 124 | |
| 125 | output, err := exec.Command("/bin/sh", "-c", fmt.Sprintf( |
| 126 | "find /proc/%d/fd -lname anon_inode:inotify -printf '%%hinfo/%%f\n' | xargs cat | grep -c '^inotify'", pid)).Output() |
| 127 | if err != nil { |
| 128 | return 0, fmt.Errorf("error running command to determine number of watched files: %w\n %s", err, output) |
| 129 | } |
| 130 | |
| 131 | n, err := strconv.Atoi(strings.TrimSpace(string(output))) |
| 132 | if err != nil { |
| 133 | return 0, fmt.Errorf("couldn't parse number of watched files: %w", err) |
| 134 | } |
| 135 | return n, nil |
| 136 | } |
| 137 | |
| 138 | func TestDontRecurseWhenWatchingParentsOfNonExistentFiles(t *testing.T) { |
| 139 | if runtime.GOOS != "linux" { |
no test coverage detected