From 6909e47e0fdbd3c67bd5d6db44cab5e35b059737 Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Tue, 28 Feb 2017 10:13:17 +0100 Subject: [PATCH] Fix empty registry file on machine crash (#3668) (#3684) Closes https://github.com/elastic/beats/issues/3537 (cherry picked from commit e2e58c00760662dbae8a52d3ef02122b329a127a) --- CHANGELOG.asciidoc | 1 + filebeat/registrar/registrar.go | 2 +- winlogbeat/checkpoint/file_unix.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) 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) }