mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-26 23:28:08 +03:00
* control: safely restart DHCP server
* control: use mutex in all POST,PUT,DELETE handlers
This commit is contained in:
parent
67014c40f7
commit
6f69fb73af
3 changed files with 15 additions and 6 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsforward"
|
"github.com/AdguardTeam/AdGuardHome/dnsforward"
|
||||||
|
@ -36,6 +37,8 @@ var client = &http.Client{
|
||||||
Timeout: time.Second * 30,
|
Timeout: time.Second * 30,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var controlLock sync.Mutex
|
||||||
|
|
||||||
// ----------------
|
// ----------------
|
||||||
// helper functions
|
// helper functions
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
12
dhcp.go
12
dhcp.go
|
@ -50,6 +50,11 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = dhcpServer.Stop()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to stop the DHCP server: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if newconfig.Enabled {
|
if newconfig.Enabled {
|
||||||
err := dhcpServer.Start(&newconfig)
|
err := dhcpServer.Start(&newconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,12 +62,7 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !newconfig.Enabled {
|
|
||||||
err := dhcpServer.Stop()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to stop the DHCP server: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config.DHCP = newconfig
|
config.DHCP = newconfig
|
||||||
httpUpdateConfigReloadDNSReturnOK(w, r)
|
httpUpdateConfigReloadDNSReturnOK(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,12 @@ func ensure(method string, handler func(http.ResponseWriter, *http.Request)) fun
|
||||||
http.Error(w, "This request must be "+method, http.StatusMethodNotAllowed)
|
http.Error(w, "This request must be "+method, http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if method == "POST" || method == "PUT" || method == "DELETE" {
|
||||||
|
controlLock.Lock()
|
||||||
|
defer controlLock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
handler(w, r)
|
handler(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue