mirror of
https://github.com/dreamstarsky/runbin.git
synced 2026-05-15 14:23:07 +00:00
add stdout/stderr/compilelog limit
This commit is contained in:
@@ -10,6 +10,7 @@ type LimitConfig struct {
|
|||||||
Cpu float32
|
Cpu float32
|
||||||
Memory int
|
Memory int
|
||||||
Time float32
|
Time float32
|
||||||
|
Size int
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorkerConfig struct {
|
type WorkerConfig struct {
|
||||||
@@ -28,6 +29,7 @@ func LoadWorker(configFile string) *WorkerConfig {
|
|||||||
v.SetDefault("limit.cpu", 1.0)
|
v.SetDefault("limit.cpu", 1.0)
|
||||||
v.SetDefault("limit.time", 10.0)
|
v.SetDefault("limit.time", 10.0)
|
||||||
v.SetDefault("limit.memory", 512*1024)
|
v.SetDefault("limit.memory", 512*1024)
|
||||||
|
v.SetDefault("limit.size", 1024)
|
||||||
v.SetDefault("process", 1)
|
v.SetDefault("process", 1)
|
||||||
v.SetDefault("name", "default name")
|
v.SetDefault("name", "default name")
|
||||||
v.SetDefault("compilerimage", "cpp_gcc-latest:latest")
|
v.SetDefault("compilerimage", "cpp_gcc-latest:latest")
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ func compileCpp(ctx context.Context, task *model.Paste, cli *client.Client, tmpD
|
|||||||
|
|
||||||
// Read compilation log
|
// Read compilation log
|
||||||
if logData, err := os.ReadFile(filepath.Join(tmpDir, "compile.txt")); err == nil {
|
if logData, err := os.ReadFile(filepath.Join(tmpDir, "compile.txt")); err == nil {
|
||||||
|
logData = logData[:min(len(logData), cfg.Limit.Size)]
|
||||||
task.CompileLog = string(logData)
|
task.CompileLog = string(logData)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,18 +145,20 @@ func runCpp(ctx context.Context, task *model.Paste, cli *client.Client, tmpDir s
|
|||||||
usagePath := filepath.Join(tmpDir, "usage.json")
|
usagePath := filepath.Join(tmpDir, "usage.json")
|
||||||
|
|
||||||
// Read program output
|
// Read program output
|
||||||
if outData, err := os.ReadFile(stdoutPath); err == nil {
|
if stdoutData, err := os.ReadFile(stdoutPath); err == nil {
|
||||||
task.Stdout = string(outData)
|
stdoutData = stdoutData[:min(len(stdoutData), cfg.Limit.Size)]
|
||||||
|
task.Stdout = string(stdoutData)
|
||||||
}
|
}
|
||||||
if outData, err := os.ReadFile(stderrPath); err == nil {
|
if stderrData, err := os.ReadFile(stderrPath); err == nil {
|
||||||
task.Stderr = string(outData)
|
stderrData = stderrData[:min(len(stderrData), cfg.Limit.Size)]
|
||||||
|
task.Stderr = string(stderrData)
|
||||||
}
|
}
|
||||||
if usageData, err := os.ReadFile(usagePath); err == nil {
|
if usageData, err := os.ReadFile(usagePath); err == nil {
|
||||||
var usage Usage
|
var usage Usage
|
||||||
fmt.Println(string(usageData))
|
fmt.Println(string(usageData))
|
||||||
fmt.Println(json.Unmarshal(usageData, &usage))
|
fmt.Println(json.Unmarshal(usageData, &usage))
|
||||||
task.MemoryUsageKb = int(usage.MaxMemory)
|
task.MemoryUsageKb = int(usage.MaxMemory)
|
||||||
task.ExecutionTimeMs = int(usage.RealTime * 1000)
|
task.ExecutionTimeMs = int(usage.RealTime * 1000)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user