summaryrefslogtreecommitdiff
path: root/fsnotify.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-02-18 23:37:11 -0600
committerJeff Carr <[email protected]>2023-02-18 23:37:11 -0600
commit041e3a0c6ede6cd96308caf49b2230d5bcb58dac (patch)
tree9f0692843849ff034d981fe7ed72883c73719f3b /fsnotify.go
parent4c348438f3b43e3de5c85a5fc8064cd0914f1fa2 (diff)
v0.0.2 next step: acutally try to nsupdatev0.0.2
upto the point where DNS update is next. start displaying real AAAA & naming buttons add RFC 2136 defining nsupdate. Vixie et al in 1997 Personal thansk to Paul for meeting with me some years back ready to pull DNS records starting a checkDNS() function dampen output. actually track IPs poll every 2 seconds (netlink is not the right thing here) ready to start looking for changes screw everything about logging. I hate log.whatthefuck*(){} Do you know what I don't care about? log() You shouldn't care either. Ignore it until you need it that is what logging is for. building something that works. So, here you go. a damn log() function in one place Also, because I'm annoyed today sleep() and exit() Because, when I want you to sleep or exit, I don't want to go to the top of a file and declare stupid shit related to nanoseconds or add "import os.Exit" or whatever the hell stop wasting my time. life is short. if he sit tunnelbroker down add IsRealIP() and IsIPv6() need a netlink function to trigger on changes (nope) put the gui plugin's in the debian package for now set the window title build a .deb package Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'fsnotify.go')
-rw-r--r--fsnotify.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/fsnotify.go b/fsnotify.go
new file mode 100644
index 0000000..814c9c7
--- /dev/null
+++ b/fsnotify.go
@@ -0,0 +1,76 @@
+package main
+
+// Watches for changes to a directory. Works cross-platform
+
+import (
+ "github.com/fsnotify/fsnotify"
+)
+
+// This would be a really dumb way to watch for new network interfaces
+// since it then watches a linux only directory /sys/class/net for changes
+
+func watchSysClassNet() {
+ // Create new watcher.
+ watcher, err := fsnotify.NewWatcher()
+ if err != nil {
+ exit(err)
+ }
+ defer watcher.Close()
+
+ // Start listening for events.
+ go func() {
+ for {
+ select {
+ case event, ok := <-watcher.Events:
+ if !ok {
+ return
+ }
+ log("event:", event)
+ if event.Has(fsnotify.Write) {
+ log("modified file:", event.Name)
+ }
+ case err, ok := <-watcher.Errors:
+ if !ok {
+ return
+ }
+ log("error:", err)
+ }
+ }
+ }()
+
+ // Add a path.
+ err = watcher.Add("/tmp")
+ if err != nil {
+ exit(err)
+ }
+
+ // Block main goroutine forever.
+ <-make(chan struct{})
+}
+
+func fsnotifyNetworkInterfaceChanges() error {
+ watcher, err := fsnotify.NewWatcher()
+ if err != nil {
+ return err
+ }
+ defer watcher.Close()
+
+ // Watch for network interface changes
+ err = watcher.Add("/sys/class/net")
+ if err != nil {
+ return err
+ }
+ for {
+ select {
+ case event := <-watcher.Events:
+ log("fsnotifyNetworkInterfaceChanges() event =", event)
+ if event.Op&fsnotify.Create == fsnotify.Create {
+ // Do something on network interface creation
+ }
+ case err := <-watcher.Errors:
+ log("fsnotifyNetworkInterfaceChanges() event err =", err)
+ return err
+ }
+ }
+}
+