From e08161a3021236d8249a3b426967666b916f7d1e Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 28 Feb 2017 22:58:52 -0500 Subject: hook: fix can’t be executed while run as service on Windows (#4207) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/hook.go | 6 +- gogs.go | 2 +- templates/.VERSION | 2 +- vendor/github.com/gogits/minwinsvc/LICENSE | 20 ++++++ vendor/github.com/gogits/minwinsvc/README.md | 18 ++++++ vendor/github.com/gogits/minwinsvc/minwinsvc.go | 18 ++++++ vendor/github.com/gogits/minwinsvc/svc_other.go | 11 ++++ vendor/github.com/gogits/minwinsvc/svc_windows.go | 72 ++++++++++++++++++++++ vendor/github.com/kardianos/minwinsvc/LICENSE | 20 ------ vendor/github.com/kardianos/minwinsvc/README.md | 18 ------ vendor/github.com/kardianos/minwinsvc/minwinsvc.go | 18 ------ vendor/github.com/kardianos/minwinsvc/svc_other.go | 11 ---- .../github.com/kardianos/minwinsvc/svc_windows.go | 70 --------------------- vendor/vendor.json | 12 ++-- 14 files changed, 152 insertions(+), 146 deletions(-) create mode 100644 vendor/github.com/gogits/minwinsvc/LICENSE create mode 100644 vendor/github.com/gogits/minwinsvc/README.md create mode 100644 vendor/github.com/gogits/minwinsvc/minwinsvc.go create mode 100644 vendor/github.com/gogits/minwinsvc/svc_other.go create mode 100644 vendor/github.com/gogits/minwinsvc/svc_windows.go delete mode 100644 vendor/github.com/kardianos/minwinsvc/LICENSE delete mode 100644 vendor/github.com/kardianos/minwinsvc/README.md delete mode 100644 vendor/github.com/kardianos/minwinsvc/minwinsvc.go delete mode 100644 vendor/github.com/kardianos/minwinsvc/svc_other.go delete mode 100644 vendor/github.com/kardianos/minwinsvc/svc_windows.go diff --git a/cmd/hook.go b/cmd/hook.go index fede8649..95db18f0 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -117,7 +117,8 @@ func runHookPreReceive(c *cli.Context) error { } // Check force push - output, err := git.NewCommand("rev-list", oldCommitID, "^"+newCommitID).Run() + output, err := git.NewCommand("rev-list", oldCommitID, "^"+newCommitID). + RunInDir(models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME))) if err != nil { fail("Internal error", "Fail to detect force push: %v", err) } else if len(output) > 0 { @@ -131,6 +132,7 @@ func runHookPreReceive(c *cli.Context) error { } hookCmd := exec.Command(customHooksPath) + hookCmd.Dir = models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME)) hookCmd.Stdout = os.Stdout hookCmd.Stdin = buf hookCmd.Stderr = os.Stderr @@ -159,6 +161,7 @@ func runHookUpdate(c *cli.Context) error { } hookCmd := exec.Command(customHooksPath, args...) + hookCmd.Dir = models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME)) hookCmd.Stdout = os.Stdout hookCmd.Stdin = os.Stdin hookCmd.Stderr = os.Stderr @@ -231,6 +234,7 @@ func runHookPostReceive(c *cli.Context) error { } hookCmd := exec.Command(customHooksPath) + hookCmd.Dir = models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME)) hookCmd.Stdout = os.Stdout hookCmd.Stdin = buf hookCmd.Stderr = os.Stderr diff --git a/gogs.go b/gogs.go index 1882895f..0d81503e 100644 --- a/gogs.go +++ b/gogs.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.10.2.0228" +const APP_VER = "0.10.3.0228" func init() { setting.AppVer = APP_VER diff --git a/templates/.VERSION b/templates/.VERSION index 3762da78..59bae7e5 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.10.2.0228 \ No newline at end of file +0.10.3.0228 \ No newline at end of file diff --git a/vendor/github.com/gogits/minwinsvc/LICENSE b/vendor/github.com/gogits/minwinsvc/LICENSE new file mode 100644 index 00000000..fce91b4e --- /dev/null +++ b/vendor/github.com/gogits/minwinsvc/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2015 Daniel Theophanes + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. diff --git a/vendor/github.com/gogits/minwinsvc/README.md b/vendor/github.com/gogits/minwinsvc/README.md new file mode 100644 index 00000000..260dceea --- /dev/null +++ b/vendor/github.com/gogits/minwinsvc/README.md @@ -0,0 +1,18 @@ +### Minimal windows service stub + +Programs designed to run from most *nix style operating systems +can import this package to enable running programs as services without modifying +them. + +``` +import _ "github.com/kardianos/minwinsvc" +``` + +If you need more control over the exit behavior, set +``` +minwinsvc.SetOnExit(func() { + // Do something. + // Within 10 seconds call: + os.Exit(0) +}) +``` diff --git a/vendor/github.com/gogits/minwinsvc/minwinsvc.go b/vendor/github.com/gogits/minwinsvc/minwinsvc.go new file mode 100644 index 00000000..057ba7f9 --- /dev/null +++ b/vendor/github.com/gogits/minwinsvc/minwinsvc.go @@ -0,0 +1,18 @@ +// Copyright 2015 Daniel Theophanes. +// Use of this source code is governed by a zlib-style +// license that can be found in the LICENSE file.package service + +// Minimal non-invasive windows only service stub. +// +// Import to allow running as a windows service. +// import _ "github.com/kardianos/minwinsvc" +// This will detect if running as a windows service +// and install required callbacks for windows. +package minwinsvc + +// SetOnExit sets the function to be called when the windows service +// requests an exit. If this is not called, or if it is called where +// f == nil, then it defaults to calling "os.Exit(0)". +func SetOnExit(f func()) { + setOnExit(f) +} diff --git a/vendor/github.com/gogits/minwinsvc/svc_other.go b/vendor/github.com/gogits/minwinsvc/svc_other.go new file mode 100644 index 00000000..197d3002 --- /dev/null +++ b/vendor/github.com/gogits/minwinsvc/svc_other.go @@ -0,0 +1,11 @@ +// Copyright 2015 Daniel Theophanes. +// Use of this source code is governed by a zlib-style +// license that can be found in the LICENSE file.package service + +//+build !windows + +package minwinsvc + +func setOnExit(f func()) { + // Nothing. +} diff --git a/vendor/github.com/gogits/minwinsvc/svc_windows.go b/vendor/github.com/gogits/minwinsvc/svc_windows.go new file mode 100644 index 00000000..e79755fa --- /dev/null +++ b/vendor/github.com/gogits/minwinsvc/svc_windows.go @@ -0,0 +1,72 @@ +// Copyright 2015 Daniel Theophanes. +// Use of this source code is governed by a zlib-style +// license that can be found in the LICENSE file.package service + +//+build windows + +package minwinsvc + +import ( + "os" + "sync" + + "golang.org/x/sys/windows/svc" +) + +var ( + onExit func() + guard sync.Mutex +) + +func init() { + interactive, err := svc.IsAnInteractiveSession() + if err != nil { + panic(err) + } + // While run as Windows service, it is not an interactive session, + // but we don't want hook execute to be treated as service, e.g. gogs.exe hook pre-receive. + if interactive || len(os.Getenv("SSH_ORIGINAL_COMMAND")) > 0 { + return + } + go func() { + _ = svc.Run("", runner{}) + + guard.Lock() + f := onExit + guard.Unlock() + + // Don't hold this lock in user code. + if f != nil { + f() + } + // Make sure we exit. + os.Exit(0) + }() +} + +func setOnExit(f func()) { + guard.Lock() + onExit = f + guard.Unlock() +} + +type runner struct{} + +func (runner) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { + const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown + changes <- svc.Status{State: svc.StartPending} + + changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} + for { + c := <-r + switch c.Cmd { + case svc.Interrogate: + changes <- c.CurrentStatus + case svc.Stop, svc.Shutdown: + changes <- svc.Status{State: svc.StopPending} + return false, 0 + } + } + + return false, 0 +} diff --git a/vendor/github.com/kardianos/minwinsvc/LICENSE b/vendor/github.com/kardianos/minwinsvc/LICENSE deleted file mode 100644 index fce91b4e..00000000 --- a/vendor/github.com/kardianos/minwinsvc/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2015 Daniel Theophanes - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. diff --git a/vendor/github.com/kardianos/minwinsvc/README.md b/vendor/github.com/kardianos/minwinsvc/README.md deleted file mode 100644 index 260dceea..00000000 --- a/vendor/github.com/kardianos/minwinsvc/README.md +++ /dev/null @@ -1,18 +0,0 @@ -### Minimal windows service stub - -Programs designed to run from most *nix style operating systems -can import this package to enable running programs as services without modifying -them. - -``` -import _ "github.com/kardianos/minwinsvc" -``` - -If you need more control over the exit behavior, set -``` -minwinsvc.SetOnExit(func() { - // Do something. - // Within 10 seconds call: - os.Exit(0) -}) -``` diff --git a/vendor/github.com/kardianos/minwinsvc/minwinsvc.go b/vendor/github.com/kardianos/minwinsvc/minwinsvc.go deleted file mode 100644 index 057ba7f9..00000000 --- a/vendor/github.com/kardianos/minwinsvc/minwinsvc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -// Minimal non-invasive windows only service stub. -// -// Import to allow running as a windows service. -// import _ "github.com/kardianos/minwinsvc" -// This will detect if running as a windows service -// and install required callbacks for windows. -package minwinsvc - -// SetOnExit sets the function to be called when the windows service -// requests an exit. If this is not called, or if it is called where -// f == nil, then it defaults to calling "os.Exit(0)". -func SetOnExit(f func()) { - setOnExit(f) -} diff --git a/vendor/github.com/kardianos/minwinsvc/svc_other.go b/vendor/github.com/kardianos/minwinsvc/svc_other.go deleted file mode 100644 index 197d3002..00000000 --- a/vendor/github.com/kardianos/minwinsvc/svc_other.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -//+build !windows - -package minwinsvc - -func setOnExit(f func()) { - // Nothing. -} diff --git a/vendor/github.com/kardianos/minwinsvc/svc_windows.go b/vendor/github.com/kardianos/minwinsvc/svc_windows.go deleted file mode 100644 index 91e2b6a4..00000000 --- a/vendor/github.com/kardianos/minwinsvc/svc_windows.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -//+build windows - -package minwinsvc - -import ( - "os" - "sync" - - "golang.org/x/sys/windows/svc" -) - -var ( - onExit func() - guard sync.Mutex -) - -func init() { - interactive, err := svc.IsAnInteractiveSession() - if err != nil { - panic(err) - } - if interactive { - return - } - go func() { - _ = svc.Run("", runner{}) - - guard.Lock() - f := onExit - guard.Unlock() - - // Don't hold this lock in user code. - if f != nil { - f() - } - // Make sure we exit. - os.Exit(0) - }() -} - -func setOnExit(f func()) { - guard.Lock() - onExit = f - guard.Unlock() -} - -type runner struct{} - -func (runner) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { - const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown - changes <- svc.Status{State: svc.StartPending} - - changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} - for { - c := <-r - switch c.Cmd { - case svc.Interrogate: - changes <- c.CurrentStatus - case svc.Stop, svc.Shutdown: - changes <- svc.Status{State: svc.StopPending} - return false, 0 - } - } - - return false, 0 -} diff --git a/vendor/vendor.json b/vendor/vendor.json index 32b0465a..0e4cf311 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -176,6 +176,12 @@ "revision": "cd1abbd55d09b793672732a7a1dfdaa12a40dfd0", "revisionTime": "2016-11-20T02:51:54Z" }, + { + "checksumSHA1": "cccKtXG5TiCiCT9JA85slbJokfw=", + "path": "github.com/gogits/minwinsvc", + "revision": "95be6356811a6fbd4c2981713236971a3ccbb33a", + "revisionTime": "2017-03-01T03:54:11Z" + }, { "checksumSHA1": "MLO0PyrK2MUO6A7Z9PxWuu43C/A=", "path": "github.com/issue9/identicon", @@ -194,12 +200,6 @@ "revision": "8ddce2a84170772b95dd5d576c48d517b22cac63", "revisionTime": "2016-01-05T22:08:40Z" }, - { - "checksumSHA1": "/dBJ2h8Jo359deiC5GQ8ZYzX8M8=", - "path": "github.com/kardianos/minwinsvc", - "revision": "cad6b2b879b0970e4245a20ebf1a81a756e2bb70", - "revisionTime": "2015-11-22T16:33:09Z" - }, { "checksumSHA1": "vfzz7zTL9TZLpFO7NC1H6/Du3+s=", "path": "github.com/klauspost/compress/flate", -- cgit v1.2.3