Ejemplo n.º 1
0
func (s *Contester) setupSubprocess(request *contester_proto.LocalExecutionParameters, sandbox *Sandbox, doRedirects bool) (sub *subprocess.Subprocess, err error) {
	sub = subprocess.SubprocessCreate()

	sub.Cmd = &subprocess.CommandLine{
		ApplicationName: request.ApplicationName,
		CommandLine:     request.CommandLine,
		Parameters:      request.CommandLineParameters,
	}

	sub.CurrentDirectory = request.CurrentDirectory

	sub.TimeLimit = subprocess.DuFromMicros(request.GetTimeLimitMicros())
	sub.HardTimeLimit = subprocess.DuFromMicros(request.GetTimeLimitHardMicros())
	sub.MemoryLimit = request.GetMemoryLimit()
	sub.CheckIdleness = request.GetCheckIdleness()
	sub.RestrictUi = request.GetRestrictUi()
	sub.NoJob = request.GetNoJob()

	sub.Environment = fillEnv(request.Environment)

	if doRedirects {
		sub.StdIn = fillRedirect(request.StdIn)
		sub.StdOut = fillRedirect(request.StdOut)
	}

	if request.GetJoinStdoutStderr() {
		sub.JoinStdOutErr = true
	} else {
		sub.StdErr = fillRedirect(request.StdErr)
	}

	sub.Options = &subprocess.PlatformOptions{}

	if sandbox.Login != nil {
		sub.Login = sandbox.Login
	} else {
		if PLATFORM_ID == "linux" {
			sub.Login, err = subprocess.NewLoginInfo("compiler", "compiler")
			if err != nil {
				return
			}
		}
	}

	err = s.localPlatformSetup(sub, request)
	return
}
Ejemplo n.º 2
0
func SetupSubprocess(s *ProcessConfig, desktop *platform.ContesterDesktop, loadLibraryW uintptr) (*subprocess.Subprocess, error) {
	sub := subprocess.SubprocessCreate()

	sub.Cmd = &subprocess.CommandLine{}

	if s.ApplicationName != "" {
		sub.Cmd.ApplicationName = &s.ApplicationName
	}

	if s.CommandLine != "" {
		sub.Cmd.CommandLine = &s.CommandLine
	}

	if s.Parameters != nil {
		sub.Cmd.Parameters = s.Parameters
	}

	if s.CurrentDirectory != "" {
		sub.CurrentDirectory = &s.CurrentDirectory
	} else {
		if wd, err := os.Getwd(); err == nil && wd != "" {
			sub.CurrentDirectory = &wd
		}
	}

	sub.TimeLimit = subprocess.DuFromMicros(uint64(s.TimeLimit))
	if s.HardTimeLimit > 0 {
		sub.HardTimeLimit = subprocess.DuFromMicros(uint64(s.HardTimeLimit))
	}
	sub.MemoryLimit = uint64(s.MemoryLimit)
	sub.CheckIdleness = !s.NoIdleCheck
	sub.RestrictUi = !s.TrustedMode
	sub.ProcessAffinityMask = uint64(s.ProcessAffinity)
	sub.NoJob = s.NoJob

	if len(s.Environment) > 0 {
		sub.Environment = (*[]string)(&s.Environment)
	}

	sub.StdIn = fillRedirect(s.StdIn)
	sub.StdOut = fillRedirect(s.StdOut)
	if s.JoinStdOutErr {
		sub.JoinStdOutErr = true
	} else {
		sub.StdErr = fillRedirect(s.StdErr)
	}

	sub.Options = newPlatformOptions()

	var err error
	if s.NeedLogin() {
		sub.Login, err = subprocess.NewLoginInfo(s.LoginName, s.Password)
		if err != nil {
			return nil, err
		}
		setDesktop(sub.Options, desktop)
	}

	setInject(sub.Options, s.InjectDLL, loadLibraryW)
	return sub, nil
}