Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/nested task #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/calloc/calloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type GlobalVariables struct {
user *user.User
cwd string
shellPath string
taskId uint32

globalCtx context.Context
globalCtxCancel context.CancelFunc
Expand Down Expand Up @@ -107,7 +108,6 @@ func StartCallocStream(task *protos.TaskToCtld) {
var replyChannel chan ReplyReceiveItem

var request *protos.StreamCallocRequest
var taskId uint32

terminalExitChannel := make(chan bool, 1)
cancelRequestChannel := make(chan bool, 1)
Expand Down Expand Up @@ -168,8 +168,8 @@ CallocStateMachineLoop:
payload := cforedReply.GetPayloadTaskIdReply()

if payload.Ok {
taskId = payload.TaskId
fmt.Printf("Task id allocated: %d\n", taskId)
gVars.taskId = payload.TaskId
fmt.Printf("Task id allocated: %d\n", gVars.taskId)

state = WaitRes
} else {
Expand Down Expand Up @@ -216,7 +216,7 @@ CallocStateMachineLoop:
Type: protos.StreamCallocRequest_TASK_COMPLETION_REQUEST,
Payload: &protos.StreamCallocRequest_PayloadTaskCompleteReq{
PayloadTaskCompleteReq: &protos.StreamCallocRequest_TaskCompleteReq{
TaskId: taskId,
TaskId: gVars.taskId,
Status: protos.TaskStatus_Completed,
},
},
Expand Down Expand Up @@ -263,7 +263,7 @@ CallocStateMachineLoop:
Type: protos.StreamCallocRequest_TASK_COMPLETION_REQUEST,
Payload: &protos.StreamCallocRequest_PayloadTaskCompleteReq{
PayloadTaskCompleteReq: &protos.StreamCallocRequest_TaskCompleteReq{
TaskId: taskId,
TaskId: gVars.taskId,
Status: protos.TaskStatus_Cancelled,
},
},
Expand Down
19 changes: 18 additions & 1 deletion internal/calloc/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package calloc

import (
"CraneFrontEnd/internal/util"
"fmt"
"github.com/pkg/term/termios"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"os"
"os/exec"
"os/signal"
"strconv"
"strings"
"sync"
"syscall"
)
Expand Down Expand Up @@ -67,7 +70,21 @@ func StartTerminal(shellPath string,
Ctty: 0,
Foreground: true,
}
process.Env = os.Environ()

env := os.Environ()
envMap := make(map[string]string, len(env))
for _, envVar := range env {
parts := strings.SplitN(envVar, "=", 2)
if len(parts) == 2 {
envMap[parts[0]] = parts[1]
}
}
envMap["CRANE_JOB_ID"] = strconv.Itoa(int(gVars.taskId))
processEnv := make([]string, 0, len(envMap))
for key, value := range envMap {
processEnv = append(processEnv, fmt.Sprintf("%s=%s", key, value))
}
process.Env = processEnv

err = process.Start()
if err != nil {
Expand Down
Loading