1// Copyright 2015 Keybase, Inc. All rights reserved. Use of 2// this source code is governed by the included BSD license. 3 4package libkb 5 6import ( 7 "os" 8) 9 10type LockPIDFile struct { 11 Contextified 12 name string 13 file *os.File 14} 15 16func NewLockPIDFile(g *GlobalContext, s string) *LockPIDFile { 17 return &LockPIDFile{Contextified: NewContextified(g), name: s} 18} 19 20func (f *LockPIDFile) Close() (err error) { 21 if f.file != nil { 22 if e1 := f.file.Close(); e1 != nil { 23 f.G().Log.Warning("Error closing pid file: %s\n", e1) 24 } 25 f.G().Log.Debug("Cleaning up pidfile %s", f.name) 26 if err = os.Remove(f.name); err != nil { 27 f.G().Log.Warning("Error removing pidfile: %s\n", err) 28 } 29 } 30 return 31} 32