From 1959d9ec26f65de379b487d6a7c9fc4b60877c9b Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 12 Dec 2014 19:53:20 +0000 Subject: [PATCH] make huppend more fault-tolerant --- main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index de4f500..72a95aa 100644 --- a/main.go +++ b/main.go @@ -64,8 +64,7 @@ func writelines(f *fileOpener, c chan []byte) { } case <-hup: if err := f.Reopen(); err != nil { - f.Close() - bail(1, "unable to reopen file in writelines loop: %v", err) + fmt.Fprintf(os.Stderr, "unable to reopen file in writelines loop: %v\n", err) } case <-kill: return @@ -108,13 +107,13 @@ func (f *fileOpener) Open() error { // this once, and we do include the create flag, reopen will always create a // file if none exists) func (f *fileOpener) Reopen() error { - if err := f.Close(); err != nil { - return fmt.Errorf("fileOpener unable to reopen file: %v", err) - } - if err := f.Open(); err != nil { + f2, err := os.OpenFile(f.fname, f.flag, f.mode) + if err != nil { return fmt.Errorf("fileOpener unable to reopen file: %v", err) } - return nil + f1 := f.File + f.File = f2 + return f1.Close() // hmm, do we care if we failed to close this file handle? } func (f *fileOpener) Close() error {