mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 03:25:35 +00:00
001f482aca
Run an inotify goroutine and watch if another program takes over /etc/inotify.conf. Log if so. For now this only logs. In the future I want to wire it up into the health system to warn (visible in "tailscale status", etc) about the situation, with a short URL to more info about how you should really be using systemd-resolved if you want programs to not fight over your DNS files on Linux. Updates #4254 etc etc Change-Id: I86ad9125717d266d0e3822d4d847d88da6a0daaa Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package dns
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/illarion/gonotify"
|
|
)
|
|
|
|
func (m *directManager) runFileWatcher() {
|
|
in, err := gonotify.NewInotify()
|
|
if err != nil {
|
|
// Oh well, we tried. This is all best effort for now, to
|
|
// surface warnings to users.
|
|
m.logf("dns: inotify new: %v", err)
|
|
return
|
|
}
|
|
ctx, cancel := context.WithCancel(m.ctx)
|
|
defer cancel()
|
|
go m.closeInotifyOnDone(ctx, in)
|
|
|
|
const events = gonotify.IN_ATTRIB |
|
|
gonotify.IN_CLOSE_WRITE |
|
|
gonotify.IN_CREATE |
|
|
gonotify.IN_DELETE |
|
|
gonotify.IN_MODIFY |
|
|
gonotify.IN_MOVE
|
|
|
|
if err := in.AddWatch("/etc/", events); err != nil {
|
|
m.logf("dns: inotify addwatch: %v", err)
|
|
return
|
|
}
|
|
for {
|
|
events, err := in.Read()
|
|
if ctx.Err() != nil {
|
|
return
|
|
}
|
|
if err != nil {
|
|
m.logf("dns: inotify read: %v", err)
|
|
return
|
|
}
|
|
var match bool
|
|
for _, ev := range events {
|
|
if ev.Name == resolvConf {
|
|
match = true
|
|
break
|
|
}
|
|
}
|
|
if !match {
|
|
continue
|
|
}
|
|
m.checkForFileTrample()
|
|
}
|
|
}
|
|
|
|
func (m *directManager) closeInotifyOnDone(ctx context.Context, in *gonotify.Inotify) {
|
|
<-ctx.Done()
|
|
in.Close()
|
|
}
|