M gitsrht-update-hook/post-update.go => gitsrht-update-hook/post-update.go +23 -6
@@ 6,8 6,8 @@ import (
"fmt"
"log"
"os"
- "os/exec"
"strings"
+ "syscall"
goredis "github.com/go-redis/redis"
_ "github.com/lib/pq"
@@ 272,10 272,27 @@ func postUpdate() {
// Run stage 3 asyncronously - the last few tasks can be done without
// blocking the pusher's terminal.
- stage3 := exec.Command(hook, string(deliveriesJson), string(payloadBytes))
- stage3.Args[0] = "stage-3"
+ wd, err := os.Getwd()
+ if err != nil {
+ log.Fatalf("Failed to execute stage 3: %v", err)
+ }
+
+ procAttr := syscall.ProcAttr{
+ Dir: wd,
+ Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()},
+ Env: os.Environ(),
+ Sys: &syscall.SysProcAttr{
+ Foreground: false,
+ },
+ }
+ pid, err := syscall.ForkExec(hook, []string{
+ "hooks/stage-3", string(deliveriesJson), string(payloadBytes),
+ }, &procAttr)
+ if err != nil {
+ log.Fatalf("Failed to execute stage 3: %v", err)
+ }
+
logger.Printf("Executing stage 3 to record %d sync deliveries and make " +
- "%d async deliveries", len(deliveries), len(dbinfo.AsyncWebhooks))
- stage3.Start()
- stage3.Process.Release()
+ "%d async deliveries (pid %d)", len(deliveries),
+ len(dbinfo.AsyncWebhooks), pid)
}
M gitsrht-update-hook/stage-3.go => gitsrht-update-hook/stage-3.go +1 -1
@@ 73,7 73,7 @@ func stage3() {
subscription_id
) VALUES (
$1, NOW() AT TIME ZONE 'UTC', 'repo:post-update',
- $2, $3, $4, $5, $6, $7
+ $2, $3, $4, $5, $6, $7, $8
);
`, delivery.UUID, delivery.Url,
delivery.Payload, delivery.Headers,
M gitsrht-update-hook/webhooks.go => gitsrht-update-hook/webhooks.go +5 -1
@@ 145,7 145,11 @@ func deliverWebhooks(subs []WebhookSubscription,
delivery.ResponseStatus = resp.StatusCode
delivery.ResponseHeaders = responseHeaders.String()
- delivery.Response = string(respBody)[:65535]
+ if len(respBody) > 65535 {
+ delivery.Response = string(respBody)[:65535]
+ } else {
+ delivery.Response = string(respBody)
+ }
deliveries = append(deliveries, delivery)
}