diff options
author | Runxi Yu <me@runxiyu.org> | 2025-01-04 22:04:06 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-01-04 22:04:06 +0800 |
commit | ca92770b428709f3c8f577ea81b8944802394b85 (patch) | |
tree | ac497a4e2d820d3b5d5f3b23a2f9d42dce2e09a4 | |
parent | Use Open_file_at instead of Open (diff) | |
download | maild-ca92770b428709f3c8f577ea81b8944802394b85.tar.gz maild-ca92770b428709f3c8f577ea81b8944802394b85.tar.zst maild-ca92770b428709f3c8f577ea81b8944802394b85.zip |
Clean up directory file descriptors
-rw-r--r-- | config.go | 17 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | main.go | 1 |
4 files changed, 21 insertions, 3 deletions
@@ -3,6 +3,7 @@ package main import ( "bufio" "os" + "reflect" "sync" "go.lindenii.runxiyu.org/lindenii-common/misc" @@ -50,3 +51,19 @@ func prepare_dirs() error { } return nil } + +// clean_up_dirs closes all directories. It should only be called before +// program exit. +func clean_up_dirs() { + directories_mutex.Lock() + defer directories_mutex.Unlock() + directories_rv := reflect.ValueOf(directories) + directories_rt := directories_rv.Type() + for i := range directories_rt.NumField() { + dir, ok := directories_rv.Field(i).Interface().(misc.Dir_t) + if !ok { + panic("directories contains a field that's not misc.Dir_t") + } + dir.Close() + } +} @@ -2,4 +2,4 @@ module go.lindenii.runxiyu.org/maild go 1.23.4 -require go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250104131426-7a480ad159b9 +require go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250104140324-f57ba68adb4d @@ -1,2 +1,2 @@ -go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250104131426-7a480ad159b9 h1:9H+rOwTeOYBoi11NSXn4IN4j0/3zo5nT8HA2Ktrdur0= -go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250104131426-7a480ad159b9/go.mod h1:bOxuuGXA3UpbLb1lKohr2j2MVcGGLcqfAprGx9VCkMA= +go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250104140324-f57ba68adb4d h1:ilNgswXXIKwDK/8xvV0UH6FNZ1XpZHxm3s381xz2icM= +go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250104140324-f57ba68adb4d/go.mod h1:bOxuuGXA3UpbLb1lKohr2j2MVcGGLcqfAprGx9VCkMA= @@ -23,6 +23,7 @@ func main() { if err != nil { panic(err) } + defer clean_up_dirs() listener, err := net.Listen("tcp", ":25") if err != nil { |