Skip to content

Commit

Permalink
pupnp: Log a warning if UPnP is already initialized
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AmnaSnene committed Aug 16, 2024
1 parent 5170f76 commit 7a33c7c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/upnp/protocol/pupnp/pupnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,16 @@ PUPnP::initUpnpLib()
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.
Expand Down

0 comments on commit 7a33c7c

Please sign in to comment.