diff --git a/internal/cmd/rc.go b/internal/cmd/rc.go index 8a2049b60..47b0dfcde 100644 --- a/internal/cmd/rc.go +++ b/internal/cmd/rc.go @@ -151,6 +151,15 @@ func (rc *RC) Load(previousEnv Env) (newEnv Env, err error) { return } + // Allow RC loads to be canceled with SIGINT + ctx, cancel := context.WithCancel(context.Background()) + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + go func() { + <-c + cancel() + }() + // check what type of RC we're processing // use different exec method for each fn := "source_env" @@ -171,15 +180,6 @@ func (rc *RC) Load(previousEnv Env) (newEnv Env, err error) { rc.Path(), ) - // Allow RC loads to be canceled with SIGINT - ctx, cancel := context.WithCancel(context.Background()) - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - go func() { - <-c - cancel() - }() - // G204: Subprocess launched with function call as argument or cmd arguments // #nosec cmd := exec.CommandContext(ctx, config.BashPath, "--noprofile", "--norc", "-c", arg)