pupnp: Log a warning if UPnP is already initialized
Currently, any flag other than UPNP_E_SUCCESS terminates UPnP during initialization. However, the UPNP_E_INIT flag (indicating UPnP is already initialized) should not cause termination. NAT-PMP has no equivalent flag.
Change-Id: Ia40508a4c07a141dbd5e2effe5f11dff05607d7c
diff --git a/src/upnp/protocol/pupnp/pupnp.cpp b/src/upnp/protocol/pupnp/pupnp.cpp
index 1df8219..c5a54e6 100644
--- a/src/upnp/protocol/pupnp/pupnp.cpp
+++ b/src/upnp/protocol/pupnp/pupnp.cpp
@@ -114,10 +114,16 @@
auto hostinfo = ip_utils::getHostName();
int upnp_err = UpnpInit2(hostinfo.interface.empty() ? nullptr : hostinfo.interface.c_str(), 0);
if (upnp_err != UPNP_E_SUCCESS) {
- if (logger_) logger_->error("PUPnP: Can't initialize libupnp: {}", UpnpGetErrorMessage(upnp_err));
- UpnpFinish();
- initialized_ = false;
- return;
+ if (upnp_err == UPNP_E_INIT) {
+ if (logger_) logger_->warn("PUPnP: libupnp already initialized");
+ initialized_ = true;
+ return;
+ }else {
+ if (logger_) logger_->error("PUPnP: Can't initialize libupnp: {}", UpnpGetErrorMessage(upnp_err));
+ UpnpFinish();
+ initialized_ = false;
+ return;
+ }
}
// Disable embedded WebServer if any.