fix(tun): only create tun device if it does not exist

- do not create if it exists and is problematic
- wrap errors with a better context
This commit is contained in:
Quentin McGaw
2024-04-29 09:28:48 +00:00
parent c47858fdda
commit 7570a79ce6

View File

@@ -331,11 +331,15 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
}
const tunDevice = "/dev/net/tun"
if err := tun.Check(tunDevice); err != nil {
err = tun.Check(tunDevice)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("checking TUN device: %w (see the Wiki errors/tun page)", err)
}
logger.Info(err.Error() + "; creating it...")
err = tun.Create(tunDevice)
if err != nil {
return err
return fmt.Errorf("creating tun device: %w", err)
}
}