package cmd
import (
+ "context"
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
+ "os/signal"
"regexp"
"strconv"
"strings"
+ "syscall"
"time"
"code.gitea.io/gitea/models"
verb = strings.Replace(verb, "-", " ", 1)
}
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ go func() {
+ // install notify
+ signalChannel := make(chan os.Signal, 1)
+
+ signal.Notify(
+ signalChannel,
+ syscall.SIGINT,
+ syscall.SIGTERM,
+ )
+ select {
+ case <-signalChannel:
+ case <-ctx.Done():
+ }
+ cancel()
+ signal.Reset()
+ }()
+
var gitcmd *exec.Cmd
verbs := strings.Split(verb, " ")
if len(verbs) == 2 {
- gitcmd = exec.Command(verbs[0], verbs[1], repoPath)
+ gitcmd = exec.CommandContext(ctx, verbs[0], verbs[1], repoPath)
} else {
- gitcmd = exec.Command(verb, repoPath)
+ gitcmd = exec.CommandContext(ctx, verb, repoPath)
}
gitcmd.Dir = setting.RepoRootPath
package external
import (
+ "context"
"fmt"
"io"
"io/ioutil"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
+ "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
)
args = append(args, f.Name())
}
- cmd := exec.Command(commands[0], args...)
+ processCtx, cancel := context.WithCancel(ctx.Ctx)
+ defer cancel()
+
+ pid := process.GetManager().Add(fmt.Sprintf("Render [%s] for %s", commands[0], ctx.URLPrefix), cancel)
+ defer process.GetManager().Remove(pid)
+
+ cmd := exec.CommandContext(processCtx, commands[0], args...)
cmd.Env = append(
os.Environ(),
"GITEA_PREFIX_SRC="+ctx.URLPrefix,
args := []string{"serv", "key-" + keyID, "--config=" + setting.CustomConf}
log.Trace("SSH: Arguments: %v", args)
- cmd := exec.Command(setting.AppPath, args...)
+ cmd := exec.CommandContext(session.Context(), setting.AppPath, args...)
cmd.Env = append(
os.Environ(),
"SSH_ORIGINAL_COMMAND="+command,