mirror of
https://github.com/fosrl/olm.git
synced 2026-02-07 21:46:40 +00:00
Handle cross platform close
Former-commit-id: 89932bb736c7f4b3eb9bb2384b0cf6bd27872c1c
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fosrl/newt/bind"
|
"github.com/fosrl/newt/bind"
|
||||||
@@ -576,7 +575,7 @@ func (o *Olm) Close() {
|
|||||||
// If we never created a device from the FD, close it explicitly
|
// If we never created a device from the FD, close it explicitly
|
||||||
// This can happen if tunnel is stopped during registration before handleConnect
|
// This can happen if tunnel is stopped during registration before handleConnect
|
||||||
logger.Debug("Closing unused TUN file descriptor %d", o.tunnelConfig.FileDescriptorTun)
|
logger.Debug("Closing unused TUN file descriptor %d", o.tunnelConfig.FileDescriptorTun)
|
||||||
if err := syscall.Close(int(o.tunnelConfig.FileDescriptorTun)); err != nil {
|
if err := closeFD(o.tunnelConfig.FileDescriptorTun); err != nil {
|
||||||
logger.Error("Failed to close TUN file descriptor: %v", err)
|
logger.Error("Failed to close TUN file descriptor: %v", err)
|
||||||
} else {
|
} else {
|
||||||
logger.Info("Closed unused TUN file descriptor")
|
logger.Info("Closed unused TUN file descriptor")
|
||||||
|
|||||||
10
olm/olm_unix.go
Normal file
10
olm/olm_unix.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package olm
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
// closeFD closes a file descriptor in a platform-specific way
|
||||||
|
func closeFD(fd uint32) error {
|
||||||
|
return syscall.Close(int(fd))
|
||||||
|
}
|
||||||
10
olm/olm_windows.go
Normal file
10
olm/olm_windows.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package olm
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
// closeFD closes a file descriptor in a platform-specific way
|
||||||
|
func closeFD(fd uint32) error {
|
||||||
|
return syscall.Close(syscall.Handle(fd))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user