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:
@@ -331,11 +331,15 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tunDevice = "/dev/net/tun"
|
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...")
|
logger.Info(err.Error() + "; creating it...")
|
||||||
err = tun.Create(tunDevice)
|
err = tun.Create(tunDevice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("creating tun device: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user