Skip to content

Commit d44b0e3

Browse files
authored
Merge pull request #2878 from lifenjoiner/SIGHUP
Empty signal handler for Windows
2 parents c51e9dc + 60f8682 commit d44b0e3

3 files changed

Lines changed: 53 additions & 28 deletions

File tree

dnscrypt-proxy/hot_reload.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package main
22

33
import (
4-
"os"
5-
"os/signal"
6-
"syscall"
7-
84
"github.com/jedisct1/dlog"
95
)
106

117
// InitHotReload sets up hot-reloading for configuration files
128
func (proxy *Proxy) InitHotReload() error {
9+
// Check if hot reload is enabled and platform has SIGHUP
10+
if !proxy.enableHotReload && !HasSIGHUP {
11+
dlog.Notice("Hot reload is disabled")
12+
return nil
13+
}
14+
1315
// Find plugins that support hot-reloading
1416
plugins := []Plugin{}
1517

@@ -105,27 +107,3 @@ func (proxy *Proxy) InitHotReload() error {
105107

106108
return nil
107109
}
108-
109-
// setupSignalHandler sets up a SIGHUP handler to manually trigger reloads
110-
func setupSignalHandler(proxy *Proxy, plugins []Plugin) {
111-
sigChan := make(chan os.Signal, 1)
112-
signal.Notify(sigChan, syscall.SIGHUP)
113-
114-
go func() {
115-
for {
116-
sig := <-sigChan
117-
if sig == syscall.SIGHUP {
118-
dlog.Notice("Received SIGHUP signal, reloading configurations")
119-
120-
// Reload each plugin that supports hot-reloading
121-
for _, plugin := range plugins {
122-
if err := plugin.Reload(); err != nil {
123-
dlog.Errorf("Failed to reload plugin [%s]: %v", plugin.Name(), err)
124-
} else {
125-
dlog.Noticef("Successfully reloaded plugin [%s]", plugin.Name())
126-
}
127-
}
128-
}
129-
}
130-
}()
131-
}

dnscrypt-proxy/signal_others.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build windows || (js && wasm) || wasip1
2+
3+
package main
4+
5+
const HasSIGHUP = false
6+
7+
// setupSignalHandler sets up a SIGHUP handler to manually trigger reloads
8+
func setupSignalHandler(proxy *Proxy, plugins []Plugin) {
9+
return
10+
}

dnscrypt-proxy/signal_posix.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build unix && !(js && wasm) && !wasip1
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
10+
"github.com/jedisct1/dlog"
11+
)
12+
13+
const HasSIGHUP = true
14+
15+
// setupSignalHandler sets up a SIGHUP handler to manually trigger reloads
16+
func setupSignalHandler(proxy *Proxy, plugins []Plugin) {
17+
sigChan := make(chan os.Signal, 1)
18+
signal.Notify(sigChan, syscall.SIGHUP)
19+
20+
go func() {
21+
for {
22+
sig := <-sigChan
23+
if sig == syscall.SIGHUP {
24+
dlog.Notice("Received SIGHUP signal, reloading configurations")
25+
26+
// Reload each plugin that supports hot-reloading
27+
for _, plugin := range plugins {
28+
if err := plugin.Reload(); err != nil {
29+
dlog.Errorf("Failed to reload plugin [%s]: %v", plugin.Name(), err)
30+
} else {
31+
dlog.Noticef("Successfully reloaded plugin [%s]", plugin.Name())
32+
}
33+
}
34+
}
35+
}
36+
}()
37+
}

0 commit comments

Comments
 (0)