From 7570a79ce6b866493d5ef37cc637581320207cb4 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Mon, 29 Apr 2024 09:28:48 +0000 Subject: [PATCH] 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 --- cmd/gluetun/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index 5ee9694e..80a2ae3c 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -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) } }