mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-03 07:37:34 -04:00
windows/svc: make IsWindowsService handle parent exit
IsWindowsService fails when parent process has exited. This change makes IsWindowsService return false instead. Added a test to verify the change. Change-Id: Ibb2aa9478e8afd9e35011bbdc0985bdf8f0af9cc Reviewed-on: https://go-review.googlesource.com/c/sys/+/294729 TryBot-Result: Go Bot <gobot@golang.org> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Trust: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
@@ -96,6 +96,13 @@ func IsWindowsService() (bool, error) {
|
||||
var psid uint32
|
||||
err := windows.ProcessIdToSessionId(uint32(pbi[5]), &psid)
|
||||
if err != nil {
|
||||
if err == windows.ERROR_INVALID_PARAMETER {
|
||||
// This error happens when Windows cannot find process parent.
|
||||
// Perhaps process parent exited.
|
||||
// Assume we are not running in a service, because service
|
||||
// parent process (services.exe) cannot exit.
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if psid != 0 {
|
||||
|
||||
Reference in New Issue
Block a user