diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2020-09-03 12:07:45 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2020-09-03 13:32:06 +0200 |
| commit | cbb265cc889ba8014991688e7c8636f4b8032d29 (patch) | |
| tree | b6583b2874aaf369ac968f52c656c519f6f6c802 | |
| parent | e698721807cac35c04b2a54179144553df4656b9 (diff) | |
| download | mullvadvpn-cbb265cc889ba8014991688e7c8636f4b8032d29.tar.xz mullvadvpn-cbb265cc889ba8014991688e7c8636f4b8032d29.zip | |
Remove dup() call
| -rw-r--r-- | ios/PacketTunnel/WireguardDevice.swift | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/ios/PacketTunnel/WireguardDevice.swift b/ios/PacketTunnel/WireguardDevice.swift index e45cf6bd4b..6bf6cabfd2 100644 --- a/ios/PacketTunnel/WireguardDevice.swift +++ b/ios/PacketTunnel/WireguardDevice.swift @@ -21,10 +21,6 @@ class WireguardDevice { /// A failure to obtain the tunnel device file descriptor case cannotLocateSocketDescriptor - /// A failure to duplicate the socket descriptor. - /// The associated value contains the `errno` from a syscall to `dup` - case cannotDuplicateSocketDescriptor(Int32) - /// A failure to start the Wireguard backend case start(Int32) @@ -41,8 +37,6 @@ class WireguardDevice { switch self { case .cannotLocateSocketDescriptor: return "Cannot locate the socket file descriptor." - case .cannotDuplicateSocketDescriptor(let posixErrorCode): - return "Cannot duplicate the socket file descriptor. Errno: \(posixErrorCode)" case .start(let wgErrorCode): return "Failed to start Wireguard. Return code: \(wgErrorCode)" case .notStarted: @@ -244,28 +238,16 @@ class WireguardDevice { private func startWireguardBackend(resolvedConfiguration: WireguardConfiguration) -> Result<(), Error> { assert(self.wireguardHandle == nil) - // Duplicate the tunnel file descriptor to prevent `wgTurnOff` from closing it - let duplicateFileDescriptor = dup(self.tunnelFileDescriptor) - if duplicateFileDescriptor == -1 { - return .failure(.cannotDuplicateSocketDescriptor(errno)) - } - let handle = resolvedConfiguration .uapiConfiguration() .toRawWireguardConfigString() - .withCString { wgTurnOn($0, duplicateFileDescriptor) } + .withCString { wgTurnOn($0, self.tunnelFileDescriptor) } if handle >= 0 { self.wireguardHandle = handle return .success(()) } else { - // `wgTurnOn` does not cover all of the code paths and may leave the file descriptor - // open on failure - if close(duplicateFileDescriptor) == -1 { - self.logger.warning("Failed to close the duplicate tunnel file descriptor. Error: \(errno)") - } - return .failure(.start(handle)) } } |
