summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorradhitya <alif@radhitya.org>2026-06-22 20:11:01 +0700
committerradhitya <alif@radhitya.org>2026-06-22 20:11:01 +0700
commit7f57333518ba0905d4447f7cd679ab018bfa12a7 (patch)
tree79bf3904ffad2ddd129a026d4e9915c62c0f8f49
parent81661cc8deaacbff3497f0c9ef2625e98257ef76 (diff)
fix bug and makefile
-rw-r--r--.gitignore1
-rw-r--r--Makefile11
-rw-r--r--internal/server/server.go36
3 files changed, 27 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index f1469da..80dd8d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.opencode/
*.sh
build/
*.pem
diff --git a/Makefile b/Makefile
index bd66e11..dfbfbf3 100644
--- a/Makefile
+++ b/Makefile
@@ -32,13 +32,12 @@ run: build
./$(OUTPUT)
install:
- install -d $(DESTDIR)$(BINDIR)
- install -m 0755 $(OUTPUT) $(DESTDIR)$(BINDIR)/$(BINARY)
- install -d $(DESTDIR)/etc/linum/blocklist
+ mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)/etc/linum/blocklist
+ cp $(OUTPUT) $(DESTDIR)$(BINDIR)/$(BINARY)
install-service:
- install -d $(DESTDIR)$(SYSTEMD_DIR)
- install -m 0644 etc/linum.service $(DESTDIR)$(SYSTEMD_DIR)/linum.service
+ mkdir -p $(DESTDIR)$(SYSTEMD_DIR)
+ cp etc/linum.service $(DESTDIR)$(SYSTEMD_DIR)/linum.service
install-config:
install -d $(DESTDIR)/etc/linum
@@ -48,7 +47,7 @@ fuzz:
$(GO) test -fuzz=FuzzBuildResponse -fuzztime=30s ./internal/server/
build-linux:
- GOOS=linux GOARCH=amd64 $(GO) build $(LDFLAGS) -o build/$(BINARY)-linux-amd64 $(MAIN)
+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(LDFLAGS) -o build/$(BINARY)-linux-amd64 $(MAIN)
build-darwin:
GOOS=darwin GOARCH=amd64 $(GO) build $(LDFLAGS) -o build/$(BINARY)-darwin-amd64 $(MAIN)
diff --git a/internal/server/server.go b/internal/server/server.go
index 74add95..7bdc917 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -39,6 +39,7 @@ type Server struct {
upDoH bool
upDoT bool
cancel context.CancelFunc
+ closeOnce sync.Once
}
func (s *Server) Ready() bool {
@@ -180,12 +181,15 @@ func (s *Server) Run(ctx context.Context) error {
if s.udp != nil {
s.udp.Shutdown(shutdownCtx)
+ s.udp = nil
}
if s.tcp != nil {
s.tcp.Shutdown(shutdownCtx)
+ s.tcp = nil
}
if s.doh != nil {
s.doh.Shutdown(shutdownCtx)
+ s.doh = nil
}
return ctx.Err()
case err := <-errCh:
@@ -194,21 +198,23 @@ func (s *Server) Run(ctx context.Context) error {
}
func (s *Server) Close() error {
- if s.admin != nil {
- s.admin.Close()
- }
- if s.udp != nil {
- s.udp.Shutdown(context.Background())
- }
- if s.tcp != nil {
- s.tcp.Shutdown(context.Background())
- }
- if s.dot != nil {
- s.dot.Shutdown(context.Background())
- }
- if s.doh != nil {
- s.doh.Close()
- }
+ s.closeOnce.Do(func() {
+ if s.admin != nil {
+ s.admin.Close()
+ }
+ if s.udp != nil {
+ s.udp.Shutdown(context.Background())
+ }
+ if s.tcp != nil {
+ s.tcp.Shutdown(context.Background())
+ }
+ if s.dot != nil {
+ s.dot.Shutdown(context.Background())
+ }
+ if s.doh != nil {
+ s.doh.Close()
+ }
+ })
return nil
}