Skip to content

Commit 9383e65

Browse files
committed
Add README and LICENSE
1 parent a9ea5c2 commit 9383e65

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 opcoder0
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Fanotify Library
2+
3+
Fanotify library for Go provides a simple API to monitor filesystem for specific events. The library attempts to simplify specifying events/actions to the watcher by providing valid flag combinations. The flag features are validated against the user's kernel version.
4+
5+
Many of the useful features provided by [fanotify](https://man7.org/linux/man-pages/man7/fanotify.7.html) are available from Linux kernel 5.1 onwards. Most of the useful features availabe through this library work best on kernels 5.1 or later.
6+
7+
## Example: Listener watching for file/directory accessed events
8+
9+
```
10+
package main
11+
12+
import (
13+
"flag"
14+
"fmt"
15+
"os"
16+
17+
"github.com/opcoder0/fanotify"
18+
)
19+
20+
func main() {
21+
var listenPath string
22+
23+
flag.StringVar(&listenPath, "listen-path", "", "path to watch events")
24+
flag.Parse()
25+
26+
if listenPath == "" {
27+
fmt.Println("missing listen path")
28+
os.Exit(1)
29+
}
30+
mountPoint := "/"
31+
listener, err := fanotify.NewListener(mountPoint, 4096, true)
32+
if err != nil {
33+
fmt.Println(err)
34+
os.Exit(1)
35+
}
36+
fmt.Println("Listening to events for:", listenPath)
37+
listener.AddWatch(listenPath, fanotify.FileOrDirectoryAccessed)
38+
go listener.Start()
39+
i := 1
40+
for event := range listener.Events {
41+
fmt.Println(event)
42+
if i == 5 {
43+
fmt.Println("Enough events. Stopping...")
44+
listener.Stop()
45+
break
46+
}
47+
i++
48+
}
49+
}
50+
```

0 commit comments

Comments
 (0)