all repos

viye @ d764ee5

my shot at reimplementing xiki
1 files changed, 12 insertions(+), 2 deletions(-)
add shell timeout
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-07-23 12:27:11 +0300
Authored at: 2026-07-22 17:26:59 +0300
Change ID: qolsuuoutqnntorpvxqktsruvxmypllq
Parent: 0da3343
M internal/plumbing/shell/shell.go
···
        1
        1
         package shell

      
        2
        2
         

      
        3
        3
         import (

      
        
        4
        +	"context"

      
        4
        5
         	"fmt"

      
        5
        6
         	"os"

      
        6
        7
         	"os/exec"

      ···
        8
        9
         	"strconv"

      
        9
        10
         	"strings"

      
        10
        11
         	"syscall"

      
        
        12
        +	"time"

      
        11
        13
         

      
        12
        14
         	"github.com/olexsmir/viye/internal/viye"

      
        13
        15
         )

      ···
        22
        24
         func (Tool) Execute(ctx *viye.Context) (string, error) {

      
        23
        25
         	switch {

      
        24
        26
         	case isCmd(ctx):

      
        25
        
        -		cmd := exec.Command("sh", "-c", strings.Join(ctx.Args, " "))

      
        
        27
        +		ctxTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)

      
        
        28
        +		defer cancel()

      
        
        29
        +

      
        
        30
        +		cmd := exec.CommandContext(ctxTimeout, "sh", "-c", strings.Join(ctx.Args, " "))

      
        26
        31
         		cmd.Dir = ctx.Dir

      
        27
        
        -		out, _ := cmd.CombinedOutput()

      
        
        32
        +		out, err := cmd.CombinedOutput()

      
        
        33
        +		if err != nil {

      
        
        34
        +			if ctxTimeout.Err() == context.DeadlineExceeded {

      
        
        35
        +				return "", fmt.Errorf("timeout: command exceeded 5s")

      
        
        36
        +			}

      
        
        37
        +		}

      
        28
        38
         		return viye.Indent(string(out)), nil

      
        29
        39
         

      
        30
        40
         	case isBGCmd(ctx):