diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 37c036b2e4d..721426b8b3b 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -41,6 +41,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff] *Filebeat* - Always use absolute path for event and registry. {pull}3328[3328] +- Fix empty registry file on machine crash. {issue}3537[3537] *Heartbeat* diff --git a/filebeat/registrar/registrar.go b/filebeat/registrar/registrar.go index 452dfa844dc..d08d252131a 100644 --- a/filebeat/registrar/registrar.go +++ b/filebeat/registrar/registrar.go @@ -298,7 +298,7 @@ func (r *Registrar) writeRegistry() error { logp.Debug("registrar", "Write registry file: %s", r.registryFile) tempfile := r.registryFile + ".new" - f, err := os.OpenFile(tempfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + f, err := os.OpenFile(tempfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0600) if err != nil { logp.Err("Failed to create tempfile (%s) for writing: %s", tempfile, err) return err diff --git a/winlogbeat/checkpoint/file_unix.go b/winlogbeat/checkpoint/file_unix.go index 8e6e76c8d74..5eb2b0d4ca5 100644 --- a/winlogbeat/checkpoint/file_unix.go +++ b/winlogbeat/checkpoint/file_unix.go @@ -5,5 +5,5 @@ package checkpoint import "os" func create(path string) (*os.File, error) { - return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0600) }