From 2d7fb4c06a500acc207c962330b1f73b04124b24 Mon Sep 17 00:00:00 2001 From: Naitik Shah Date: Mon, 6 Jan 2014 15:15:45 +0530 Subject: [PATCH] detect init started on startup rather than when necessary to avoid re-parenting issues. fixes #7 --- grace.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grace.go b/grace.go index 5032998..c470066 100644 --- a/grace.go +++ b/grace.go @@ -25,6 +25,11 @@ var ( // Time in the past to trigger immediate deadline. timeInPast = time.Now() + + // Test if init activated by checking ppid on startup since we will get + // re-parented once the old parent is killed and we will end up looking like + // we're init started. + initStarted = os.Getppid() == 1 ) const ( @@ -81,7 +86,7 @@ func (l *listener) Close() error { var err error // Init provided sockets dont actually close so we trigger Accept to return // by setting the deadline. - if os.Getppid() == 1 { + if initStarted { if ld, ok := l.Listener.(deadliner); ok { err = ld.SetDeadline(timeInPast) } else {