added some dhcp4 packet functions and generic byte reading functions

This commit is contained in:
2025-09-17 19:31:37 +09:00
parent 67b3e9727b
commit 90365bfdd4
8 changed files with 394 additions and 65 deletions

69
cmd/signal.go Normal file
View File

@ -0,0 +1,69 @@
package main
import "haza"
import "sync"
import "os"
import "os/signal"
import "syscall"
type signal_handler struct {
svc haza.Service
}
func (sh *signal_handler) RunTask(wg *sync.WaitGroup) {
var sighup_chan chan os.Signal
var sigterm_chan chan os.Signal
var sig os.Signal
if wg != nil {
defer wg.Done()
}
sighup_chan = make(chan os.Signal, 1)
sigterm_chan = make(chan os.Signal, 1)
signal.Notify(sighup_chan, syscall.SIGHUP)
signal.Notify(sigterm_chan, syscall.SIGTERM, os.Interrupt)
chan_loop:
for {
select {
case <-sighup_chan:
sh.svc.FixServices()
case sig = <-sigterm_chan:
sh.svc.StopServices()
sh.svc.WriteLog ("", haza.LOG_INFO, "Received %s signal", sig)
break chan_loop
}
}
//signal.Reset(syscall.SIGHUP)
//signal.Reset(syscall.SIGTERM)
signal.Stop(sighup_chan)
signal.Stop(sigterm_chan)
}
func (sh *signal_handler) StartService(data interface{}) {
// this isn't actually used standalone..
// if we are to implement it, it must use the wait group for signal handler itself
// however, this service is run through another service.
// sh.wg.Add(1)
// go sh.RunTask(&sh.wg)
}
func (sh *signal_handler) StopServices() {
syscall.Kill(syscall.Getpid(), syscall.SIGTERM) // TODO: find a better to terminate the signal handler...
}
func (sh *signal_handler) FixServices() {
}
func (sh *signal_handler) WaitForTermination() {
// not implemented. see the comment in StartServices()
// sh.wg.Wait()
}
func (sh *signal_handler) WriteLog(id string, level haza.LogLevel, fmt string, args ...interface{}) {
sh.svc.WriteLog(id, level, fmt, args...)
}