From 538cd56a01b28b9294f3ac7d0c97214037d19e91 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 22 Jun 2024 21:29:19 +0500 Subject: [PATCH] code prettyfing --- main.go | 10 ++----- runner/runner.go | 57 +++++++++++++++++------------------- runner/runner_test.go | 24 +++++++-------- starter/starter.c | 68 +++++++++++++++++++++---------------------- 4 files changed, 75 insertions(+), 84 deletions(-) diff --git a/main.go b/main.go index d09b175..9870ef6 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,14 @@ package main import ( - //"os" - //"fmt" - //"log" - //exec "os/exec" runner "runner/runner" ) func main() { - err:=runner.Init() - if(err!=nil) { + err := runner.Init() + if(err != nil) { panic(err) } limits := runner.Limits{Core: 3,Memory: 10000000, Time: 1000} - runner.IsolatedRun([]string{"/bin/echo","123"},limits) + runner.IsolatedRun([]string{"/bin/echo", "123"}, limits) } diff --git a/runner/runner.go b/runner/runner.go index 33509fa..2be7f6f 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -1,7 +1,6 @@ package runner import ( - //"errors" "bytes" "io" "fmt" @@ -24,22 +23,22 @@ type Limits struct { } func extractNumbers(s string) (result []int) { - lastNumber,isNumber := false,false - var curNumber=0 - for _,char :=range s { - isNumber=(char>='0' && char<='9') + lastNumber, isNumber := false,false + var curNumber = 0 + for _, char := range s { + isNumber = (char >= '0' && char <= '9') if(isNumber) { - curNumber*=10 - curNumber+=int(char-'0') + curNumber *= 10 + curNumber += int(char - '0') } if(!isNumber && lastNumber) { - result=append(result,curNumber) - curNumber=0 + result = append(result, curNumber) + curNumber = 0 } - lastNumber=isNumber + lastNumber = isNumber } if(lastNumber) { - result=append(result,curNumber) + result = append(result, curNumber) } return } @@ -54,39 +53,35 @@ func Init() error { } //isolated cores initialisation: cmdlineBytes := make([]byte, 400) - cmdlineFile,_:=os.Open("/proc/cmdline"); - countCmdlineBytes,_:=cmdlineFile.Read(cmdlineBytes); - cmdline:=string(cmdlineBytes[:countCmdlineBytes]) - kernelParams:=strings.Split(cmdline," ") - for _,param := range kernelParams{ - if(len(param)>=9 && param[:9]=="isolcpus=") { - coresIsolated=append(coresIsolated, extractNumbers(param[9:])...) + cmdlineFile, _ := os.Open("/proc/cmdline"); + countCmdlineBytes, _ := cmdlineFile.Read(cmdlineBytes); + cmdline := string(cmdlineBytes[:countCmdlineBytes]) + kernelParams := strings.Split(cmdline," ") + for _, param := range kernelParams{ + if(len(param) >= 9 && param[:9] == "isolcpus=") { + coresIsolated = append(coresIsolated, extractNumbers(param[9:])...) } } - if(len(coresIsolated)==0) { + if(len(coresIsolated) == 0) { return fmt.Errorf("no free cores available")//TODO: trouble description } - log.Println("running on cores:",coresIsolated) + log.Println("running on cores:", coresIsolated) log.Println("Runner initialisation successful!") return nil } -func IsolatedRun(command []string,limits Limits) { +func IsolatedRun(command []string, limits Limits) { var runId string - for i:=0;itime/1000,((params->time)%1000)*1000000}; + struct timespec tw = {params -> time / 1000, ((params->time) % 1000) * 1000000}; struct timespec tr; - nanosleep(&tw,&tr); - kill(params->pid,SIGKILL); + nanosleep(&tw, &tr); + kill(params->pid, SIGKILL); } -//const size_t STACK_SIZE=1000000; #define STACK_SIZE 1000000 static char nmstack[STACK_SIZE]; static char killstack[STACK_SIZE]; @@ -59,30 +59,31 @@ static void parse_args(int argc, char **argv, struct params *params,struct limit puts("usage:\n starter