Use mutex when reloading file notifier

This commit is contained in:
Julien Riou 2018-06-11 21:05:34 +02:00
parent 3a89201a94
commit 9d72ce2201
No known key found for this signature in database
GPG key ID: BA3E15176E45E85D

View file

@ -4,6 +4,7 @@ import (
"github.com/jouir/pgterminate/base"
"log"
"os"
"sync"
"time"
)
@ -12,6 +13,7 @@ type File struct {
handle *os.File
name string
sessions chan base.Session
mutex sync.Mutex
}
// NewFile creates a file notifier
@ -43,6 +45,8 @@ func (f *File) open() {
// Reload closes and re-open the file to be compatible with logrotate
func (f *File) Reload() {
f.mutex.Lock()
defer f.mutex.Unlock()
log.Println("Re-opening log file", f.name)
f.handle.Close()
f.open()