int DockerAPI::rmi(const std::string &image, CondorError &err) { // First, try to remove the named image run_simple_docker_command("rmi", image, default_timeout, err, true); // That may have succeed or failed. It could have // failed if the image doesn't exist (anymore), or // if someone else deleted it outside of condor. // Check to see if the image still exists. If it // has been removed, return 0. ArgList args; if ( ! add_docker_arg(args)) return -1; args.AppendArg( "images" ); args.AppendArg( "-q" ); args.AppendArg( image ); MyString displayString; args.GetArgsStringForLogging( & displayString ); dprintf( D_FULLDEBUG, "Attempting to run: '%s'.\n", displayString.c_str() ); #if 1 MyPopenTimer pgm; if (pgm.start_program(args, true, NULL, false) < 0) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } int exitCode; if ( ! pgm.wait_for_exit(default_timeout, &exitCode) || exitCode != 0) { pgm.close_program(1); MyString line; line.readLine(pgm.output(), false); line.chomp(); dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, line.c_str()); return -3; } return pgm.output_size() > 0; #else FILE * dockerResults = my_popen( args, "r", 1 , 0, false); if( dockerResults == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } char buffer[1024]; std::vector< std::string > output; while( fgets( buffer, 1024, dockerResults ) != NULL ) { size_t end = strlen(buffer); if (end > 0 && buffer[end-1] == '\n') { buffer[end-1] = '\0'; } output.push_back( buffer ); } int exitCode = my_pclose( dockerResults ); if( exitCode != 0 ) { dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, output[0].c_str() ); return -3; } if (output.size() == 0) { return 0; } else { return 1; } #endif }
/** * merge_stderr_with_stdout is intended for clients of this function * that wish to have the old behavior, where stderr and stdout were * both added to the same StringList. */ int systemCommand( ArgList &args, priv_state priv, StringList *cmd_out, StringList * cmd_in, StringList *cmd_err, bool merge_stderr_with_stdout) { int result = 0; FILE *fp = NULL; FILE * fp_for_stdin = NULL; FILE * childerr = NULL; MyString line; char buff[1024]; StringList *my_cmd_out = cmd_out; priv_state prev = get_priv_state(); int stdout_pipes[2]; int stdin_pipes[2]; int pid; bool use_privsep = false; switch ( priv ) { case PRIV_ROOT: prev = set_root_priv(); break; case PRIV_USER: case PRIV_USER_FINAL: prev = set_user_priv(); #if !defined(WIN32) if ( privsep_enabled() && (job_user_uid != get_condor_uid()) ) { use_privsep = true; } #endif break; default: // Stay as Condor user, this should be a no-op prev = set_condor_priv(); } #if defined(WIN32) if((cmd_in != NULL) || (cmd_err != NULL)) { vmprintf(D_ALWAYS, "Invalid use of systemCommand() in Windows.\n"); set_priv( prev ); return -1; } //if ( use_privsep ) { // fp = privsep_popen(args, "r", want_stderr, job_user_uid); //} //else { fp = my_popen( args, "r", merge_stderr_with_stdout ? MY_POPEN_OPT_WANT_STDERR : 0 ); //} #else // The old way of doing things (and the Win32 way of doing // things) // fp = my_popen( args, "r", want_stderr ? MY_POPEN_OPT_WANT_STDERR : 0 ); if((cmd_err != NULL) && merge_stderr_with_stdout) { vmprintf(D_ALWAYS, "Invalid use of systemCommand().\n"); set_priv( prev ); return -1; } PrivSepForkExec psforkexec; char ** args_array = args.GetStringArray(); int error_pipe[2]; // AIX 5.2, Solaris 5.9, HPUX 11 don't have AF_LOCAL if(pipe(stdin_pipes) < 0) { vmprintf(D_ALWAYS, "Error creating pipe: %s\n", strerror(errno)); deleteStringArray( args_array ); set_priv( prev ); return -1; } if(pipe(stdout_pipes) < 0) { vmprintf(D_ALWAYS, "Error creating pipe: %s\n", strerror(errno)); close(stdin_pipes[0]); close(stdin_pipes[1]); deleteStringArray( args_array ); set_priv( prev ); return -1; } if ( use_privsep ) { if(!psforkexec.init()) { vmprintf(D_ALWAYS, "my_popenv failure on %s\n", args_array[0]); close(stdin_pipes[0]); close(stdin_pipes[1]); close(stdout_pipes[0]); close(stdout_pipes[1]); deleteStringArray( args_array ); set_priv( prev ); return -1; } } if(cmd_err != NULL) { if(pipe(error_pipe) < 0) { vmprintf(D_ALWAYS, "Could not open pipe for error output: %s\n", strerror(errno)); close(stdin_pipes[0]); close(stdin_pipes[1]); close(stdout_pipes[0]); close(stdout_pipes[1]); deleteStringArray( args_array ); set_priv( prev ); return -1; } } // Now fork and do what my_popen used to do pid = fork(); if(pid < 0) { vmprintf(D_ALWAYS, "Error forking: %s\n", strerror(errno)); close(stdin_pipes[0]); close(stdin_pipes[1]); close(stdout_pipes[0]); close(stdout_pipes[1]); if(cmd_err != NULL) { close(error_pipe[0]); close(error_pipe[1]); } deleteStringArray( args_array ); set_priv( prev ); return -1; } if(pid == 0) { close(stdout_pipes[0]); close(stdin_pipes[1]); dup2(stdout_pipes[1], STDOUT_FILENO); dup2(stdin_pipes[0], STDIN_FILENO); if(merge_stderr_with_stdout) dup2(stdout_pipes[1], STDERR_FILENO); else if(cmd_err != NULL) { close(error_pipe[0]); dup2(error_pipe[1], STDERR_FILENO); } /* to be safe, we want to switch our real uid/gid to our effective uid/gid (shedding any privledges we've got). we also want to drop any supplimental groups we're in. we want to run this popen()'ed thing as our effective uid/gid, dropping the real uid/gid. all of these calls will fail if we don't have a ruid of 0 (root), but that's harmless. also, note that we have to stash our effective uid, then switch our euid to 0 to be able to set our real uid/gid. We wrap some of the calls in if-statements to quiet some compilers that object to us not checking the return values. */ uid_t euid = geteuid(); gid_t egid = getegid(); if ( seteuid( 0 ) ) { } setgroups( 1, &egid ); if ( setgid( egid ) ) { } if ( setuid( euid ) ) _exit(ENOEXEC); // Unsafe? install_sig_handler(SIGPIPE, SIG_DFL); sigset_t sigs; sigfillset(&sigs); sigprocmask(SIG_UNBLOCK, &sigs, NULL); MyString cmd = args_array[0]; if ( use_privsep ) { ArgList al; psforkexec.in_child(cmd, al); deleteStringArray( args_array ); args_array = al.GetStringArray(); } execvp(cmd.Value(), args_array); vmprintf(D_ALWAYS, "Could not execute %s: %s\n", args_array[0], strerror(errno)); exit(-1); } close(stdin_pipes[0]); close(stdout_pipes[1]); fp_for_stdin = fdopen(stdin_pipes[1], "w"); fp = fdopen(stdout_pipes[0], "r"); if(cmd_err != NULL) { close(error_pipe[1]); childerr = fdopen(error_pipe[0],"r"); if(childerr == 0) { vmprintf(D_ALWAYS, "Could not open pipe for reading child error output: %s\n", strerror(errno)); close(error_pipe[0]); close(stdin_pipes[1]); close(stdout_pipes[0]); fclose(fp); fclose(fp_for_stdin); deleteStringArray( args_array ); set_priv( prev ); return -1; } } if ( use_privsep ) { FILE* _fp = psforkexec.parent_begin(); privsep_exec_set_uid(_fp, job_user_uid); privsep_exec_set_path(_fp, args_array[0]); privsep_exec_set_args(_fp, args); Env env; env.MergeFrom(environ); privsep_exec_set_env(_fp, env); privsep_exec_set_iwd(_fp, "."); privsep_exec_set_inherit_fd(_fp, 1); privsep_exec_set_inherit_fd(_fp, 2); privsep_exec_set_inherit_fd(_fp, 0); if (!psforkexec.parent_end()) { vmprintf(D_ALWAYS, "my_popenv failure on %s\n", args_array[0]); fclose(fp); fclose(fp_for_stdin); if (childerr) { fclose(childerr); } deleteStringArray( args_array ); set_priv( prev ); return -1; } } deleteStringArray( args_array ); #endif set_priv( prev ); if ( fp == NULL ) { MyString args_string; args.GetArgsStringForDisplay( &args_string, 0 ); vmprintf( D_ALWAYS, "Failed to execute command: %s\n", args_string.Value() ); if (childerr) fclose(childerr); return -1; } if(cmd_in != NULL) { cmd_in->rewind(); char * tmp; while((tmp = cmd_in->next()) != NULL) { fprintf(fp_for_stdin, "%s\n", tmp); fflush(fp_for_stdin); } } if (fp_for_stdin) { // So that we will not be waiting for output while the // script waits for stdin to be closed. fclose(fp_for_stdin); } if ( my_cmd_out == NULL ) { my_cmd_out = new StringList(); } while ( fgets( buff, sizeof(buff), fp ) != NULL ) { line += buff; if ( line.chomp() ) { my_cmd_out->append( line.Value() ); line = ""; } } if(cmd_err != NULL) { while(fgets(buff, sizeof(buff), childerr) != NULL) { line += buff; if(line.chomp()) { cmd_err->append(line.Value()); line = ""; } } fclose(childerr); } #if defined(WIN32) result = my_pclose( fp ); #else // Why close first? Just in case the child process is waiting // on a read, and we have nothing more to send it. It will // now receive a SIGPIPE. fclose(fp); if(waitpid(pid, &result, 0) < 0) { vmprintf(D_ALWAYS, "Unable to wait: %s\n", strerror(errno)); if ( cmd_out == NULL ) { delete my_cmd_out; } return -1; } #endif if( result != 0 ) { MyString args_string; args.GetArgsStringForDisplay(&args_string,0); vmprintf(D_ALWAYS, "Command returned non-zero: %s\n", args_string.Value()); my_cmd_out->rewind(); const char *next_line; while ( (next_line = my_cmd_out->next()) ) { vmprintf( D_ALWAYS, " %s\n", next_line ); } } if ( cmd_out == NULL ) { delete my_cmd_out; } return result; }
JSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsNumber(exec, floor(args.at(0).toNumber(exec))); }
JSValue JSSQLTransaction::executeSql(ExecState* exec, const ArgList& args) { if (args.isEmpty()) { setDOMException(exec, SYNTAX_ERR); return jsUndefined(); } String sqlStatement = args.at(0).toString(exec); if (exec->hadException()) return jsUndefined(); // Now assemble the list of SQL arguments Vector<SQLValue> sqlValues; if (!args.at(1).isUndefinedOrNull()) { JSObject* object = args.at(1).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } JSValue lengthValue = object->get(exec, exec->propertyNames().length); if (exec->hadException()) return jsUndefined(); unsigned length = lengthValue.toUInt32(exec); if (exec->hadException()) return jsUndefined(); for (unsigned i = 0 ; i < length; ++i) { JSValue value = object->get(exec, i); if (exec->hadException()) return jsUndefined(); if (value.isNull()) sqlValues.append(SQLValue()); else if (value.isNumber()) sqlValues.append(value.uncheckedGetNumber()); else { // Convert the argument to a string and append it sqlValues.append(value.toString(exec)); if (exec->hadException()) return jsUndefined(); } } } RefPtr<SQLStatementCallback> callback; if (!args.at(2).isUndefinedOrNull()) { JSObject* object = args.at(2).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } callback = JSCustomSQLStatementCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); } RefPtr<SQLStatementErrorCallback> errorCallback; if (!args.at(3).isUndefinedOrNull()) { JSObject* object = args.at(3).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } errorCallback = JSCustomSQLStatementErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); } ExceptionCode ec = 0; m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec); setDOMException(exec, ec); return jsUndefined(); }
// ECMA 15.6.1 static JSValue QT_FASTCALL callBooleanConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsBoolean(args.at(0).toBoolean(exec)); }
std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, types::ID InputType) const { switch (getTriple().getArch()) { default: return getTripleString(); case llvm::Triple::x86_64: { llvm::Triple Triple = getTriple(); if (!Triple.isOSBinFormatMachO()) return getTripleString(); if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { // x86_64h goes in the triple. Other -march options just use the // vanilla triple we already have. StringRef MArch = A->getValue(); if (MArch == "x86_64h") Triple.setArchName(MArch); } return Triple.getTriple(); } case llvm::Triple::aarch64: { llvm::Triple Triple = getTriple(); if (!Triple.isOSBinFormatMachO()) return getTripleString(); // FIXME: older versions of ld64 expect the "arm64" component in the actual // triple string and query it to determine whether an LTO file can be // handled. Remove this when we don't care any more. Triple.setArchName("arm64"); return Triple.getTriple(); } case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { // FIXME: Factor into subclasses. llvm::Triple Triple = getTriple(); bool IsBigEndian = getTriple().getArch() == llvm::Triple::armeb || getTriple().getArch() == llvm::Triple::thumbeb; // Handle pseudo-target flags '-mlittle-endian'/'-EL' and // '-mbig-endian'/'-EB'. if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, options::OPT_mbig_endian)) { IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian); } // Thumb2 is the default for V7 on Darwin. // // FIXME: Thumb should just be another -target-feaure, not in the triple. StringRef Suffix = Triple.isOSBinFormatMachO() ? tools::arm::getLLVMArchSuffixForARM(tools::arm::getARMCPUForMArch(Args, Triple)) : tools::arm::getLLVMArchSuffixForARM(tools::arm::getARMTargetCPU(Args, Triple)); bool ThumbDefault = Suffix.startswith("v6m") || Suffix.startswith("v7m") || Suffix.startswith("v7em") || (Suffix.startswith("v7") && getTriple().isOSBinFormatMachO()); // FIXME: this is invalid for WindowsCE if (getTriple().isOSWindows()) ThumbDefault = true; std::string ArchName; if (IsBigEndian) ArchName = "armeb"; else ArchName = "arm"; // Assembly files should start in ARM mode. if (InputType != types::TY_PP_Asm && Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault)) { if (IsBigEndian) ArchName = "thumbeb"; else ArchName = "thumb"; } Triple.setArchName(ArchName + Suffix.str()); return Triple.getTriple(); } } }
void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector<StringRef> &Features) { // If -march=native, autodetect the feature list. if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { if (StringRef(A->getValue()) == "native") { llvm::StringMap<bool> HostFeatures; if (llvm::sys::getHostCPUFeatures(HostFeatures)) for (auto &F : HostFeatures) Features.push_back( Args.MakeArgString((F.second ? "+" : "-") + F.first())); } } if (Triple.getArchName() == "x86_64h") { // x86_64h implies quite a few of the more modern subtarget features // for Haswell class CPUs, but not all of them. Opt-out of a few. Features.push_back("-rdrnd"); Features.push_back("-aes"); Features.push_back("-pclmul"); Features.push_back("-rtm"); Features.push_back("-fsgsbase"); } const llvm::Triple::ArchType ArchType = Triple.getArch(); // Add features to be compatible with gcc for Android. if (Triple.isAndroid()) { if (ArchType == llvm::Triple::x86_64) { Features.push_back("+sse4.2"); Features.push_back("+popcnt"); } else Features.push_back("+ssse3"); } // Set features according to the -arch flag on MSVC. if (Arg *A = Args.getLastArg(options::OPT__SLASH_arch)) { StringRef Arch = A->getValue(); bool ArchUsed = false; // First, look for flags that are shared in x86 and x86-64. if (ArchType == llvm::Triple::x86_64 || ArchType == llvm::Triple::x86) { if (Arch == "AVX" || Arch == "AVX2") { ArchUsed = true; Features.push_back(Args.MakeArgString("+" + Arch.lower())); } } // Then, look for x86-specific flags. if (ArchType == llvm::Triple::x86) { if (Arch == "IA32") { ArchUsed = true; } else if (Arch == "SSE" || Arch == "SSE2") { ArchUsed = true; Features.push_back(Args.MakeArgString("+" + Arch.lower())); } } if (!ArchUsed) D.Diag(clang::diag::warn_drv_unused_argument) << A->getAsString(Args); } // Now add any that the user explicitly requested on the command line, // which may override the defaults. handleTargetFeaturesGroup(Args, Features, options::OPT_m_x86_Features_Group); }
TiValue JSC_HOST_CALL functionDebug(TiExcState* exec, TiObject*, TiValue, const ArgList& args) { fprintf(stderr, "--> %s\n", args.at(0).toString(exec).UTF8String().c_str()); return jsUndefined(); }
int OsProc::StartJob(FamilyInfo* family_info, NetworkNamespaceManager * network_manager = NULL, FilesystemRemap* fs_remap=NULL) { int nice_inc = 0; bool has_wrapper = false; dprintf(D_FULLDEBUG,"in OsProc::StartJob()\n"); if ( !JobAd ) { dprintf ( D_ALWAYS, "No JobAd in OsProc::StartJob()!\n" ); return 0; } MyString JobName; if ( JobAd->LookupString( ATTR_JOB_CMD, JobName ) != 1 ) { dprintf( D_ALWAYS, "%s not found in JobAd. Aborting StartJob.\n", ATTR_JOB_CMD ); return 0; } const char* job_iwd = Starter->jic->jobRemoteIWD(); dprintf( D_ALWAYS, "IWD: %s\n", job_iwd ); // some operations below will require a PrivSepHelper if // PrivSep is enabled (if it's not, privsep_helper will be // NULL) PrivSepHelper* privsep_helper = Starter->privSepHelper(); // // // // // // // Arguments // // // // // // // prepend the full path to this name so that we // don't have to rely on the PATH inside the // USER_JOB_WRAPPER or for exec(). bool transfer_exe = false; if (!JobAd->LookupBool(ATTR_TRANSFER_EXECUTABLE, transfer_exe)) { transfer_exe = false; } bool preserve_rel = false; if (!JobAd->LookupBool(ATTR_PRESERVE_RELATIVE_EXECUTABLE, preserve_rel)) { preserve_rel = false; } bool relative_exe = is_relative_to_cwd(JobName.Value()); if (relative_exe && preserve_rel && !transfer_exe) { dprintf(D_ALWAYS, "Preserving relative executable path: %s\n", JobName.Value()); } else if ( strcmp(CONDOR_EXEC,JobName.Value()) == 0 ) { JobName.sprintf( "%s%c%s", Starter->GetWorkingDir(), DIR_DELIM_CHAR, CONDOR_EXEC ); } else if (relative_exe && job_iwd && *job_iwd) { MyString full_name; full_name.sprintf("%s%c%s", job_iwd, DIR_DELIM_CHAR, JobName.Value()); JobName = full_name; } if( Starter->isGridshell() ) { // if we're a gridshell, just try to chmod our job, since // globus probably transfered it for us and left it with // bad permissions... priv_state old_priv = set_user_priv(); int retval = chmod( JobName.Value(), S_IRWXU | S_IRWXO | S_IRWXG ); set_priv( old_priv ); if( retval < 0 ) { dprintf ( D_ALWAYS, "Failed to chmod %s!\n", JobName.Value() ); return 0; } } ArgList args; // Since we may be adding to the argument list, we may need to deal // with platform-specific arg syntax in the user's args in order // to successfully merge them with the additional wrapper args. args.SetArgV1SyntaxToCurrentPlatform(); // First, put "condor_exec" or whatever at the front of Args, // since that will become argv[0] of what we exec(), either // the wrapper or the actual job. if( !getArgv0() ) { args.AppendArg(JobName.Value()); } else { args.AppendArg(getArgv0()); } // Support USER_JOB_WRAPPER parameter... char *wrapper = NULL; if( (wrapper=param("USER_JOB_WRAPPER")) ) { // make certain this wrapper program exists and is executable if( access(wrapper,X_OK) < 0 ) { dprintf( D_ALWAYS, "Cannot find/execute USER_JOB_WRAPPER file %s\n", wrapper ); free( wrapper ); return 0; } has_wrapper = true; // Now, we've got a valid wrapper. We want that to become // "JobName" so we exec it directly, and we want to put // what was the JobName (with the full path) as the first // argument to the wrapper args.AppendArg(JobName.Value()); JobName = wrapper; free(wrapper); } // Support USE_PARROT bool use_parrot = false; if( JobAd->LookupBool( ATTR_USE_PARROT, use_parrot) ) { // Check for parrot executable char *parrot = NULL; if( (parrot=param("PARROT")) ) { if( access(parrot,X_OK) < 0 ) { dprintf( D_ALWAYS, "Unable to use parrot(Cannot find/execute " "at %s(%s)).\n", parrot, strerror(errno) ); free( parrot ); return 0; } else { args.AppendArg(JobName.Value()); JobName = parrot; free( parrot ); } } else { dprintf( D_ALWAYS, "Unable to use parrot(Undefined path in config" " file)" ); return 0; } } // Either way, we now have to add the user-specified args as // the rest of the Args string. MyString args_error; if(!args.AppendArgsFromClassAd(JobAd,&args_error)) { dprintf(D_ALWAYS, "Failed to read job arguments from JobAd. " "Aborting OsProc::StartJob: %s\n",args_error.Value()); return 0; } // // // // // // // Environment // // // // // // // Now, instantiate an Env object so we can manipulate the // environment as needed. Env job_env; MyString env_errors; if( !Starter->GetJobEnv(JobAd,&job_env,&env_errors) ) { dprintf( D_ALWAYS, "Aborting OSProc::StartJob: %s\n", env_errors.Value()); return 0; } // // // // // // // Standard Files // // // // // // // handle stdin, stdout, and stderr redirection int fds[3]; // initialize these to -2 to mean they're not specified. // -1 will be treated as an error. fds[0] = -2; fds[1] = -2; fds[2] = -2; // in order to open these files we must have the user's privs: priv_state priv; priv = set_user_priv(); // if we're in PrivSep mode, we won't necessarily be able to // open the files for the job. getStdFile will return us an // open FD in some situations, but otherwise will give us // a filename that we'll pass to the PrivSep Switchboard // bool stdin_ok; bool stdout_ok; bool stderr_ok; MyString privsep_stdin_name; MyString privsep_stdout_name; MyString privsep_stderr_name; if (privsep_helper != NULL) { stdin_ok = getStdFile(SFT_IN, NULL, true, "Input file", &fds[0], &privsep_stdin_name); stdout_ok = getStdFile(SFT_OUT, NULL, true, "Output file", &fds[1], &privsep_stdout_name); stderr_ok = getStdFile(SFT_ERR, NULL, true, "Error file", &fds[2], &privsep_stderr_name); } else { fds[0] = openStdFile( SFT_IN, NULL, true, "Input file"); stdin_ok = (fds[0] != -1); fds[1] = openStdFile( SFT_OUT, NULL, true, "Output file"); stdout_ok = (fds[1] != -1); fds[2] = openStdFile( SFT_ERR, NULL, true, "Error file"); stderr_ok = (fds[2] != -1); } /* Bail out if we couldn't open the std files correctly */ if( !stdin_ok || !stdout_ok || !stderr_ok ) { /* only close ones that had been opened correctly */ for ( int i = 0; i <= 2; i++ ) { if ( fds[i] >= 0 ) { daemonCore->Close_FD ( fds[i] ); } } dprintf(D_ALWAYS, "Failed to open some/all of the std files...\n"); dprintf(D_ALWAYS, "Aborting OsProc::StartJob.\n"); set_priv(priv); /* go back to original priv state before leaving */ return 0; } // // // // // // // Misc + Exec // // // // // // if( !ThisProcRunsAlongsideMainProc() ) { Starter->jic->notifyJobPreSpawn(); } // compute job's renice value by evaluating the machine's // JOB_RENICE_INCREMENT in the context of the job ad... char* ptmp = param( "JOB_RENICE_INCREMENT" ); if( ptmp ) { // insert renice expr into our copy of the job ad MyString reniceAttr = "Renice = "; reniceAttr += ptmp; if( !JobAd->Insert( reniceAttr.Value() ) ) { dprintf( D_ALWAYS, "ERROR: failed to insert JOB_RENICE_INCREMENT " "into job ad, Aborting OsProc::StartJob...\n" ); free( ptmp ); return 0; } // evaluate if( JobAd->EvalInteger( "Renice", NULL, nice_inc ) ) { dprintf( D_ALWAYS, "Renice expr \"%s\" evaluated to %d\n", ptmp, nice_inc ); } else { dprintf( D_ALWAYS, "WARNING: job renice expr (\"%s\") doesn't " "eval to int! Using default of 10...\n", ptmp ); nice_inc = 10; } // enforce valid ranges for nice_inc if( nice_inc < 0 ) { dprintf( D_FULLDEBUG, "WARNING: job renice value (%d) is too " "low: adjusted to 0\n", nice_inc ); nice_inc = 0; } else if( nice_inc > 19 ) { dprintf( D_FULLDEBUG, "WARNING: job renice value (%d) is too " "high: adjusted to 19\n", nice_inc ); nice_inc = 19; } ASSERT( ptmp ); free( ptmp ); ptmp = NULL; } else { // if JOB_RENICE_INCREMENT is undefined, default to 10 nice_inc = 10; } // in the below dprintfs, we want to skip past argv[0], which // is sometimes condor_exec, in the Args string. MyString args_string; args.GetArgsStringForDisplay(&args_string, 1); if( has_wrapper ) { // print out exactly what we're doing so folks can debug // it, if they need to. dprintf( D_ALWAYS, "Using wrapper %s to exec %s\n", JobName.Value(), args_string.Value() ); MyString wrapper_err; wrapper_err.sprintf("%s%c%s", Starter->GetWorkingDir(), DIR_DELIM_CHAR, JOB_WRAPPER_FAILURE_FILE); if( ! job_env.SetEnv("_CONDOR_WRAPPER_ERROR_FILE", wrapper_err.Value()) ) { dprintf( D_ALWAYS, "Failed to set _CONDOR_WRAPPER_ERROR_FILE environment variable\n"); } } else { dprintf( D_ALWAYS, "About to exec %s %s\n", JobName.Value(), args_string.Value() ); } MyString path; path.sprintf("%s%c%s", Starter->GetWorkingDir(), DIR_DELIM_CHAR, MACHINE_AD_FILENAME); if( ! job_env.SetEnv("_CONDOR_MACHINE_AD", path.Value()) ) { dprintf( D_ALWAYS, "Failed to set _CONDOR_MACHINE_AD environment variable\n"); } path.sprintf("%s%c%s", Starter->GetWorkingDir(), DIR_DELIM_CHAR, JOB_AD_FILENAME); if( ! job_env.SetEnv("_CONDOR_JOB_AD", path.Value()) ) { dprintf( D_ALWAYS, "Failed to set _CONDOR_JOB_AD environment variable\n"); } // Grab the full environment back out of the Env object if(IsFulldebug(D_FULLDEBUG)) { MyString env_string; job_env.getDelimitedStringForDisplay(&env_string); dprintf(D_FULLDEBUG, "Env = %s\n", env_string.Value()); } // Check to see if we need to start this process paused, and if // so, pass the right flag to DC::Create_Process(). int job_opt_mask = DCJOBOPT_NO_CONDOR_ENV_INHERIT; if (!param_boolean("JOB_INHERITS_STARTER_ENVIRONMENT",false)) { job_opt_mask |= DCJOBOPT_NO_ENV_INHERIT; } int suspend_job_at_exec = 0; JobAd->LookupBool( ATTR_SUSPEND_JOB_AT_EXEC, suspend_job_at_exec); if( suspend_job_at_exec ) { dprintf( D_FULLDEBUG, "OsProc::StartJob(): " "Job wants to be suspended at exec\n" ); job_opt_mask |= DCJOBOPT_SUSPEND_ON_EXEC; } // If there is a requested coresize for this job, enforce it. // It is truncated because you can't put an unsigned integer // into a classad. I could rewrite condor's use of ATTR_CORE_SIZE to // be a float, but then when that attribute is read/written to the // job queue log by/or shared between versions of Condor which view the // type of that attribute differently, calamity would arise. int core_size_truncated; size_t core_size; size_t *core_size_ptr = NULL; if ( JobAd->LookupInteger( ATTR_CORE_SIZE, core_size_truncated ) ) { core_size = (size_t)core_size_truncated; core_size_ptr = &core_size; } long rlimit_as_hard_limit = 0; char *rlimit_expr = param("STARTER_RLIMIT_AS"); if (rlimit_expr) { classad::ClassAdParser parser; classad::ExprTree *tree = parser.ParseExpression(rlimit_expr); if (tree) { classad::Value val; int result; if (EvalExprTree(tree, Starter->jic->machClassAd(), JobAd, val) && val.IsIntegerValue(result)) { rlimit_as_hard_limit = ((long)result) * 1024 * 1024; dprintf(D_ALWAYS, "Setting job's virtual memory rlimit to %ld megabytes\n", rlimit_as_hard_limit); } else { dprintf(D_ALWAYS, "Can't evaluate STARTER_RLIMIT_AS expression %s\n", rlimit_expr); } } else { dprintf(D_ALWAYS, "Can't parse STARTER_RLIMIT_AS expression: %s\n", rlimit_expr); } } int *affinity_mask = makeCpuAffinityMask(Starter->getMySlotNumber()); #if defined ( WIN32 ) owner_profile_.update (); /************************************************************* NOTE: We currently *ONLY* support loading slot-user profiles. This limitation will be addressed shortly, by allowing regular users to load their registry hive - Ben [2008-09-31] **************************************************************/ bool load_profile = false, run_as_owner = false; JobAd->LookupBool ( ATTR_JOB_LOAD_PROFILE, load_profile ); JobAd->LookupBool ( ATTR_JOB_RUNAS_OWNER, run_as_owner ); if ( load_profile && !run_as_owner ) { if ( owner_profile_.load () ) { /* publish the users environment into that of the main job's environment */ if ( !owner_profile_.environment ( job_env ) ) { dprintf ( D_ALWAYS, "OsProc::StartJob(): Failed to " "export owner's environment.\n" ); } } else { dprintf ( D_ALWAYS, "OsProc::StartJob(): Failed to load " "owner's profile.\n" ); } } #endif // While we are still in user priv, print out the username #if defined(LINUX) if( Starter->glexecPrivSepHelper() ) { // TODO: if there is some way to figure out the final username, // print it out here or after starting the job. dprintf(D_ALWAYS,"Running job via glexec\n"); } #else if( false ) { } #endif else { char const *username = NULL; char const *how = ""; CondorPrivSepHelper* cpsh = Starter->condorPrivSepHelper(); if( cpsh ) { username = cpsh->get_user_name(); how = "via privsep switchboard "; } else { username = get_real_username(); } if( !username ) { username = "******"; } dprintf(D_ALWAYS,"Running job %sas user %s\n",how,username); } set_priv ( priv ); // use this to return more detailed and reliable error message info // from create-process operation. MyString create_process_err_msg; if (privsep_helper != NULL) { const char* std_file_names[3] = { privsep_stdin_name.Value(), privsep_stdout_name.Value(), privsep_stderr_name.Value() }; JobPid = privsep_helper->create_process(JobName.Value(), args, job_env, job_iwd, fds, std_file_names, nice_inc, core_size_ptr, 1, job_opt_mask, family_info, affinity_mask, &create_process_err_msg); } else { JobPid = daemonCore->Create_Process( JobName.Value(), args, PRIV_USER_FINAL, 1, FALSE, &job_env, job_iwd, family_info, NULL, fds, NULL, nice_inc, NULL, job_opt_mask, core_size_ptr, affinity_mask, NULL, &create_process_err_msg, fs_remap, rlimit_as_hard_limit, network_manager); } // Create_Process() saves the errno for us if it is an "interesting" error. int create_process_errno = errno; // errno is 0 in the privsep case. This executes for the daemon core create-process logic if ((FALSE == JobPid) && (0 != create_process_errno)) { if (create_process_err_msg != "") create_process_err_msg += " "; MyString errbuf; errbuf.sprintf("(errno=%d: '%s')", create_process_errno, strerror(create_process_errno)); create_process_err_msg += errbuf; } // now close the descriptors in fds array. our child has inherited // them already, so we should close them so we do not leak descriptors. // NOTE, we want to use a special method to close the starter's // versions, if that's what we're using, so we don't think we've // still got those available in other parts of the code for any // reason. for ( int i = 0; i <= 2; i++ ) { if ( fds[i] >= 0 ) { daemonCore->Close_FD ( fds[i] ); } } if ( JobPid == FALSE ) { JobPid = -1; if(!create_process_err_msg.IsEmpty()) { // if the reason Create_Process failed was that registering // a family with the ProcD failed, it is indicative of a // problem regarding this execute machine, not the job. in // this case, we'll want to EXCEPT instead of telling the // Shadow to put the job on hold. there are probably other // error conditions where EXCEPTing would be more appropriate // as well... // if (create_process_errno == DaemonCore::ERRNO_REGISTRATION_FAILED) { EXCEPT("Create_Process failed to register the job with the ProcD"); } MyString err_msg = "Failed to execute '"; err_msg += JobName; err_msg += "'"; if(!args_string.IsEmpty()) { err_msg += " with arguments "; err_msg += args_string.Value(); } err_msg += ": "; err_msg += create_process_err_msg; if( !ThisProcRunsAlongsideMainProc() ) { Starter->jic->notifyStarterError( err_msg.Value(), true, CONDOR_HOLD_CODE_FailedToCreateProcess, create_process_errno ); } } dprintf(D_ALWAYS,"Create_Process(%s,%s, ...) failed: %s\n", JobName.Value(), args_string.Value(), create_process_err_msg.Value()); return 0; } num_pids++; dprintf(D_ALWAYS,"Create_Process succeeded, pid=%d\n",JobPid); job_start_time.getTime(); return 1; }
int DockerAPI::inspect( const std::string & containerID, ClassAd * dockerAd, CondorError & /* err */ ) { if( dockerAd == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "dockerAd is NULL.\n" ); return -2; } ArgList inspectArgs; if ( ! add_docker_arg(inspectArgs)) return -1; inspectArgs.AppendArg( "inspect" ); inspectArgs.AppendArg( "--format" ); StringList formatElements( "ContainerId=\"{{.Id}}\" " "Pid={{.State.Pid}} " "Name=\"{{.Name}}\" " "Running={{.State.Running}} " "ExitCode={{.State.ExitCode}} " "StartedAt=\"{{.State.StartedAt}}\" " "FinishedAt=\"{{.State.FinishedAt}}\" " "DockerError=\"{{.State.Error}}\" " "OOMKilled=\"{{.State.OOMKilled}}\" " ); char * formatArg = formatElements.print_to_delimed_string( "\n" ); inspectArgs.AppendArg( formatArg ); free( formatArg ); inspectArgs.AppendArg( containerID ); MyString displayString; inspectArgs.GetArgsStringForLogging( & displayString ); dprintf( D_FULLDEBUG, "Attempting to run: %s\n", displayString.c_str() ); #if 1 MyPopenTimer pgm; if (pgm.start_program(inspectArgs, true, NULL, false) < 0) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -6; } MyStringSource * src = NULL; if (pgm.wait_and_close(default_timeout)) { src = &pgm.output(); } int expected_rows = formatElements.number(); dprintf( D_FULLDEBUG, "exit_status=%d, error=%d, %d bytes. expecting %d lines\n", pgm.exit_status(), pgm.error_code(), pgm.output_size(), expected_rows ); // If the output isn't exactly formatElements.number() lines long, // something has gone wrong and we'll at least be able to print out // the error message(s). std::vector<std::string> correctOutput(expected_rows); if (src) { MyString line; int i=0; while (line.readLine(*src,false)) { line.chomp(); //dprintf( D_FULLDEBUG, "\t[%2d] %s\n", i, line.c_str() ); if (i >= expected_rows) { if (line.empty()) continue; correctOutput.push_back(line.c_str()); } else { correctOutput[i] = line.c_str(); } std::string::iterator first = std::find(correctOutput[i].begin(), correctOutput[i].end(), '\"'); if (first != correctOutput[i].end()) { std::replace(++first, --correctOutput[i].end(), '\"','\''); } //dprintf( D_FULLDEBUG, "\tfix: %s\n", correctOutput[i].c_str() ); ++i; } } #else FILE * dockerResults = my_popen( inspectArgs, "r", 1 , 0, false); if( dockerResults == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "Unable to run '%s'.\n", displayString.c_str() ); return -6; } // If the output isn't exactly formatElements.number() lines long, // something has gone wrong and we'll at least be able to print out // the error message(s). char buffer[1024]; std::vector<std::string> correctOutput(formatElements.number()); for( int i = 0; i < formatElements.number(); ++i ) { if( fgets( buffer, 1024, dockerResults ) != NULL ) { correctOutput[i] = buffer; std::string::iterator first = std::find(correctOutput[i].begin(), correctOutput[i].end(), '\"'); if (first != correctOutput[i].end()) { std::replace(++first, -- --correctOutput[i].end(), '\"','\''); } } } my_pclose( dockerResults ); #endif int attrCount = 0; for( int i = 0; i < formatElements.number(); ++i ) { if( correctOutput[i].empty() || dockerAd->Insert( correctOutput[i].c_str() ) == FALSE ) { break; } ++attrCount; } if( attrCount != formatElements.number() ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to create classad from Docker output (%d). Printing up to the first %d (nonblank) lines.\n", attrCount, formatElements.number() ); for( int i = 0; i < formatElements.number() && ! correctOutput[i].empty(); ++i ) { dprintf( D_ALWAYS | D_FAILURE, "%s", correctOutput[i].c_str() ); } return -4; } dprintf( D_FULLDEBUG, "docker inspect printed:\n" ); for( int i = 0; i < formatElements.number() && ! correctOutput[i].empty(); ++i ) { dprintf( D_FULLDEBUG, "\t%s\n", correctOutput[i].c_str() ); } return 0; }
int run_simple_docker_command(const std::string &command, const std::string &container, int timeout, CondorError &, bool ignore_output) { ArgList args; if ( ! add_docker_arg(args)) return -1; args.AppendArg( command ); args.AppendArg( container.c_str() ); MyString displayString; args.GetArgsStringForLogging( & displayString ); dprintf( D_FULLDEBUG, "Attempting to run: %s\n", displayString.c_str() ); #if 1 MyPopenTimer pgm; if (pgm.start_program( args, true, NULL, false ) < 0) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } if ( ! pgm.wait_and_close(timeout) || pgm.output_size() <= 0) { int error = pgm.error_code(); if( error ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), pgm.error_str(), error ); if (pgm.was_timeout()) { dprintf( D_ALWAYS | D_FAILURE, "Declaring a hung docker\n"); return DockerAPI::docker_hung; } } else { dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() ); } return -3; } // On a success, Docker writes the containerID back out. MyString line; line.readLine(pgm.output()); line.chomp(); line.trim(); if (!ignore_output && line != container.c_str()) { // Didn't get back the result I expected, report the error and check to see if docker is hung. dprintf( D_ALWAYS | D_FAILURE, "Docker %s failed, printing first few lines of output.\n", command.c_str()); for (int ii = 0; ii < 10; ++ii) { if ( ! line.readLine(pgm.output(), false)) break; dprintf( D_ALWAYS | D_FAILURE, "%s\n", line.c_str() ); } return -4; } #else // Read from Docker's combined output and error streams. FILE * dockerResults = my_popen( args, "r", 1 , 0, false); if( dockerResults == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } // On a success, Docker writes the containerID back out. char buffer[1024]; if( NULL == fgets( buffer, 1024, dockerResults ) ) { if( errno ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), strerror( errno ), errno ); } else { dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() ); } my_pclose( dockerResults ); return -3; } size_t length = strlen( buffer ); if (!ignore_output) { if( length < 1 || strncmp( buffer, container.c_str(), length - 1 ) != 0 ) { dprintf( D_ALWAYS | D_FAILURE, "Docker %s failed, printing first few lines of output.\n", command.c_str() ); dprintf( D_ALWAYS | D_FAILURE, "%s", buffer ); while( NULL != fgets( buffer, 1024, dockerResults ) ) { dprintf( D_ALWAYS | D_FAILURE, "%s", buffer ); } my_pclose( dockerResults ); return -4; } } my_pclose( dockerResults ); #endif return 0; }
// // FIXME: We have a lot of boilerplate code in this function and file. // int DockerAPI::version( std::string & version, CondorError & /* err */ ) { ArgList versionArgs; if ( ! add_docker_arg(versionArgs)) return -1; versionArgs.AppendArg( "-v" ); MyString displayString; versionArgs.GetArgsStringForLogging( & displayString ); dprintf( D_FULLDEBUG, "Attempting to run: '%s'.\n", displayString.c_str() ); #if 1 MyPopenTimer pgm; if (pgm.start_program(versionArgs, true, NULL, false) < 0) { // treat 'file not found' as not really error int d_level = (pgm.error_code() == ENOENT) ? D_FULLDEBUG : (D_ALWAYS | D_FAILURE); dprintf(d_level, "Failed to run '%s' errno=%d %s.\n", displayString.c_str(), pgm.error_code(), pgm.error_str() ); return -2; } int exitCode; if ( ! pgm.wait_for_exit(default_timeout, &exitCode)) { pgm.close_program(1); dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), pgm.error_str(), pgm.error_code() ); return -3; } if (pgm.output_size() <= 0) { dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() ); return -3; } MyStringSource * src = &pgm.output(); MyString line; if (line.readLine(*src, false)) { line.chomp(); bool jansens = strstr( line.c_str(), "Jansens" ) != NULL; bool bad_size = ! src->isEof() || line.size() > 1024 || line.size() < (int)sizeof("Docker version "); if (bad_size && ! jansens) { // check second line of output for the word Jansens also. MyString tmp; tmp.readLine(*src, false); jansens = strstr( tmp.c_str(), "Jansens" ) != NULL; } if (jansens) { dprintf( D_ALWAYS | D_FAILURE, "The DOCKER configuration setting appears to point to OpenBox's docker. If you want to use Docker.IO, please set DOCKER appropriately in your configuration.\n" ); return -5; } else if (bad_size) { dprintf( D_ALWAYS | D_FAILURE, "Read more than one line (or a very long line) from '%s', which we think means it's not Docker. The (first line of the) trailing text was '%s'.\n", displayString.c_str(), line.c_str() ); return -5; } } if( exitCode != 0 ) { dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, line.c_str() ); return -4; } version = line.c_str(); #else FILE * dockerResults = my_popen( versionArgs, "r", 1 , 0, false); if( dockerResults == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } char buffer[1024]; if( NULL == fgets( buffer, 1024, dockerResults ) ) { if( errno ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), strerror( errno ), errno ); } else { dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() ); } my_pclose( dockerResults ); return -3; } if( NULL != fgets( buffer, 1024, dockerResults ) ) { if( strstr( buffer, "Jansens" ) != NULL ) { dprintf( D_ALWAYS | D_FAILURE, "The DOCKER configuration setting appears to point to OpenBox's docker. If you want to use Docker.IO, please set DOCKER appropriately in your configuration.\n" ); } else { dprintf( D_ALWAYS | D_FAILURE, "Read more than one line (or a very long line) from '%s', which we think means it's not Docker. The (first line of the) trailing text was '%s'.\n", displayString.c_str(), buffer ); } my_pclose( dockerResults ); return -5; } int exitCode = my_pclose( dockerResults ); if( exitCode != 0 ) { dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, buffer ); return -4; } size_t end = strlen(buffer); if (end > 0 && buffer[end-1] == '\n') { buffer[end-1] = '\0'; } version = buffer; #endif sscanf(version.c_str(), "Docker version %d.%d", &DockerAPI::majorVersion, &DockerAPI::minorVersion); return 0; }
int DockerAPI::detect( CondorError & err ) { // FIXME: Remove ::version() as a public API and return it from here, // because there's no point in doing this twice. std::string version; int rval = DockerAPI::version( version, err ); if( rval != 0 ) { dprintf(D_ALWAYS, "DockerAPI::detect() failed to detect the Docker version; assuming absent.\n" ); return -4; } ArgList infoArgs; if ( ! add_docker_arg(infoArgs)) return -1; infoArgs.AppendArg( "info" ); MyString displayString; infoArgs.GetArgsStringForLogging( & displayString ); dprintf( D_FULLDEBUG, "Attempting to run: '%s'.\n", displayString.c_str() ); #if 1 MyPopenTimer pgm; if (pgm.start_program(infoArgs, true, NULL, false) < 0) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } int exitCode; if ( ! pgm.wait_for_exit(default_timeout, &exitCode) || exitCode != 0) { pgm.close_program(1); MyString line; line.readLine(pgm.output(), false); line.chomp(); dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, line.c_str()); return -3; } if (IsFulldebug(D_ALWAYS)) { MyString line; do { line.readLine(pgm.output(), false); line.chomp(); dprintf( D_FULLDEBUG, "[docker info] %s\n", line.c_str() ); } while (line.readLine(pgm.output(), false)); } #else FILE * dockerResults = my_popen( infoArgs, "r", 1 , 0, false); if( dockerResults == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } // Even if we don't care about the success output, the failure output // can be handy for debugging... char buffer[1024]; std::vector< std::string > output; while( fgets( buffer, 1024, dockerResults ) != NULL ) { size_t end = strlen(buffer); if (end > 0 && buffer[end-1] == '\n') { buffer[end-1] = '\0'; } output.push_back( buffer ); } for( unsigned i = 0; i < output.size(); ++i ) { dprintf( D_FULLDEBUG, "[docker info] %s\n", output[i].c_str() ); } int exitCode = my_pclose( dockerResults ); if( exitCode != 0 ) { dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, output[0].c_str() ); return -3; } #endif return 0; }
// // Because we fork before calling docker, we don't actually // care if the image is stored locally or not (except to the extent that // remote image pull violates the principle of least astonishment). // int DockerAPI::run( ClassAd &machineAd, ClassAd &jobAd, const std::string & containerName, const std::string & imageID, const std::string & command, const ArgList & args, const Env & env, const std::string & sandboxPath, const std::list<std::string> extraVolumes, int & pid, int * childFDs, CondorError & /* err */ ) { gc_image(imageID); // // We currently assume that the system has been configured so that // anyone (user) who can run an HTCondor job can also run docker. It's // also apparently a security worry to run Docker as root, so let's not. // ArgList runArgs; if ( ! add_docker_arg(runArgs)) return -1; runArgs.AppendArg( "run" ); // Write out a file with the container ID. // FIXME: The startd can check this to clean up after us. // This needs to go into a directory that condor user // can write to. /* std::string cidFileName = sandboxPath + "/.cidfile"; runArgs.AppendArg( "--cidfile=" + cidFileName ); */ // Configure resource limits. // First cpus int cpus; int cpuShare; if (machineAd.LookupInteger(ATTR_CPUS, cpus)) { cpuShare = 10 * cpus; } else { cpuShare = 10; } std::string cpuShareStr; formatstr(cpuShareStr, "--cpu-shares=%d", cpuShare); runArgs.AppendArg(cpuShareStr); // Now memory int memory; // in Megabytes if (machineAd.LookupInteger(ATTR_MEMORY, memory)) { std::string mem; formatstr(mem, "--memory=%dm", memory); runArgs.AppendArg(mem); } // drop unneeded Linux capabilities if (param_boolean("DOCKER_DROP_ALL_CAPABILITIES", true /*default*/, true /*do_log*/, &machineAd, &jobAd)) { runArgs.AppendArg("--cap-drop=all"); // --no-new-privileges flag appears in docker 1.11 if (DockerAPI::majorVersion > 1 || DockerAPI::minorVersion > 10) { runArgs.AppendArg("--no-new-privileges"); } } // Give the container a useful name std::string hname = makeHostname(&machineAd, &jobAd); runArgs.AppendArg("--hostname"); runArgs.AppendArg(hname.c_str()); // Now the container name runArgs.AppendArg( "--name" ); runArgs.AppendArg( containerName ); if ( ! add_env_to_args_for_docker(runArgs, env)) { dprintf( D_ALWAYS | D_FAILURE, "Failed to pass enviroment to docker.\n" ); return -8; } // Map the external sanbox to the internal sandbox. runArgs.AppendArg( "--volume" ); runArgs.AppendArg( sandboxPath + ":" + sandboxPath ); // Now any extra volumes for (std::list<std::string>::const_iterator it = extraVolumes.begin(); it != extraVolumes.end(); it++) { runArgs.AppendArg("--volume"); std::string volume = *it; runArgs.AppendArg(volume); } // Start in the sandbox. runArgs.AppendArg( "--workdir" ); runArgs.AppendArg( sandboxPath ); // Run with the uid that condor selects for the user // either a slot user or submitting user or nobody uid_t uid = 0; uid_t gid = 0; // Docker doesn't actually run on Windows, but we compile // on Windows because... #ifndef WIN32 uid = get_user_uid(); gid = get_user_gid(); #endif if ((uid == 0) || (gid == 0)) { dprintf(D_ALWAYS|D_FAILURE, "Failed to get userid to run docker job\n"); return -9; } runArgs.AppendArg("--user"); std::string uidgidarg; formatstr(uidgidarg, "%d:%d", uid, gid); runArgs.AppendArg(uidgidarg); // Run the command with its arguments in the image. runArgs.AppendArg( imageID ); // If no command given, the default command in the image will run if (command.length() > 0) { runArgs.AppendArg( command ); } runArgs.AppendArgsFromArgList( args ); MyString displayString; runArgs.GetArgsStringForLogging( & displayString ); dprintf( D_ALWAYS, "Attempting to run: %s\n", displayString.c_str() ); // // If we run Docker attached, we avoid a race condition where // 'docker logs --follow' returns before 'docker rm' knows that the // container is gone (and refuses to remove it). Of course, we // can't block, so we have a proxy process run attached for us. // FamilyInfo fi; fi.max_snapshot_interval = param_integer( "PID_SNAPSHOT_INTERVAL", 15 ); int childPID = daemonCore->Create_Process( runArgs.GetArg(0), runArgs, PRIV_CONDOR_FINAL, 1, FALSE, FALSE, NULL, "/", & fi, NULL, childFDs ); if( childPID == FALSE ) { dprintf( D_ALWAYS | D_FAILURE, "Create_Process() failed.\n" ); return -1; } pid = childPID; return 0; }
// Analysis_Timecorr::Setup() Analysis::RetType Analysis_Timecorr::Setup(ArgList& analyzeArgs, AnalysisSetup& setup, int debugIn) { // Get Vectors std::string vec1name = analyzeArgs.GetStringKey("vec1"); if (vec1name.empty()) { mprinterr("Error: no vec1 given, ignoring command\n"); return Analysis::ERR; } vinfo1_ = (DataSet_Vector*)setup.DSL().FindSetOfType( vec1name, DataSet::VECTOR ); if (vinfo1_==0) { mprinterr("Error: vec1: no vector with name %s found.\n", vec1name.c_str()); return Analysis::ERR; } std::string vec2name = analyzeArgs.GetStringKey("vec2"); if (!vec2name.empty()) { vinfo2_ = (DataSet_Vector*)setup.DSL().FindSetOfType( vec2name, DataSet::VECTOR ); if (vinfo2_==0) { mprinterr("Error: vec2: no vector with name %s found.\n", vec2name.c_str()); return Analysis::ERR; } } else vinfo2_ = 0; // Get output DataSet name std::string setname = analyzeArgs.GetStringKey("name"); if (setname.empty()) setname = setup.DSL().GenerateDefaultName("TC"); // Determine auto or cross correlation if (vinfo2_ == 0) mode_ = AUTOCORR; else mode_ = CROSSCORR; // Get dplr, norm, drct dplr_ = analyzeArgs.hasKey("dplr"); norm_ = analyzeArgs.hasKey("norm"); drct_ = analyzeArgs.hasKey("drct"); std::string dplrname = analyzeArgs.GetStringKey("dplrout"); // Get order for Legendre polynomial, tstep, and tcorr order_ = analyzeArgs.getKeyInt("order",2); if (order_ < 0 || order_ > 2) { mprintf("Warning: vector order out of bounds (should be 0, 1, or 2), resetting to 2.\n"); order_ = 2; } tstep_ = analyzeArgs.getKeyDouble("tstep", 1.0); tcorr_ = analyzeArgs.getKeyDouble("tcorr", 10000.0); // File output. For ptrajformat, time correlation functions and dipolar // are output to file specified by 'out'. Otherwise time correlation // functions are written to file specified by 'out' using DataFile // framework and dipolar output to 'dplrname'. ptrajformat_ = analyzeArgs.hasKey("ptrajformat"); std::string filename = analyzeArgs.GetStringKey("out"); if (ptrajformat_ && filename.empty()) { mprinterr("Error: No output file name given ('out <filename>'). Required for 'ptrajformat'.\n"); return Analysis::ERR; } DataFile* dataout = 0; if (!ptrajformat_) { dataout = setup.DFL().AddDataFile( filename, analyzeArgs ); if (dplr_) { if (!dplrname.empty() && dplrname == filename) { mprinterr("Error: 'dplrname' cannot be the same file as 'out' when 'ptrajformat' not specified.\n"); return Analysis::ERR; } outfile_ = setup.DFL().AddCpptrajFile( dplrname, "Timecorr dipolar", DataFileList::TEXT, true ); if (outfile_ == 0) return Analysis::ERR; } } else { outfile_ = setup.DFL().AddCpptrajFile( filename, "Timecorr output" ); if (outfile_ == 0) return Analysis::ERR; } // Set up output DataSets tc_p_ = setup.DSL().AddSet( DataSet::DOUBLE, MetaData(setname, "P")); if (tc_p_ == 0) return Analysis::ERR; tc_p_->SetLegend( Plegend_[order_] ); if (dataout != 0) dataout->AddDataSet( tc_p_ ); if (dplr_) { tc_c_ = setup.DSL().AddSet( DataSet::DOUBLE, MetaData(setname, "C")); tc_r3r3_ = setup.DSL().AddSet( DataSet::DOUBLE, MetaData(setname, "R3R3")); if (tc_c_ == 0 || tc_r3r3_ == 0) return Analysis::ERR; tc_c_->SetLegend("<C>"); tc_r3r3_->SetLegend( "<1/(r^3*r^3)>" ); if (dataout != 0) { dataout->AddDataSet( tc_c_ ); dataout->AddDataSet( tc_r3r3_ ); } } // Print Status mprintf(" TIMECORR: Calculating %s", ModeString[mode_]); if (mode_ == AUTOCORR) mprintf(" of vector %s\n", vinfo1_->legend()); else // CROSSCORR mprintf(" of vectors %s and %s\n", vinfo1_->legend(), vinfo2_->legend()); mprintf("\tCorrelation time %f, time step %f, order %i\n", tcorr_, tstep_, order_); mprintf("\tCorr. func. are"); if (dplr_) mprintf(" for dipolar interactions and"); if (norm_) mprintf(" normalized.\n"); else mprintf(" not normalized.\n"); mprintf("\tCorr. func. are calculated using the"); if (drct_) mprintf(" direct approach.\n"); else mprintf(" FFT approach.\n"); if (ptrajformat_) mprintf("\tResults are written to %s\n", outfile_->Filename().full()); else { if (dataout != 0) mprintf("\tTime correlation functions written to %s\n", dataout->DataFilename().full()); if (outfile_ != 0) mprintf("\tDipolar results written to %s\n", outfile_->Filename().full()); } return Analysis::OK; }
JSValuePtr JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args) { int i, count = args.size(); jvalue *jArgs; JSValuePtr resultValue; Method *method = 0; size_t numMethods = methodList.size(); // Try to find a good match for the overloaded method. The // fundamental problem is that JavaScript doesn have the // notion of method overloading and Java does. We could // get a bit more sophisticated and attempt to does some // type checking as we as checking the number of parameters. Method *aMethod; for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { aMethod = methodList[methodIndex]; if (aMethod->numParameters() == count) { method = aMethod; break; } } if (method == 0) { JS_LOG ("unable to find an appropiate method\n"); return jsUndefined(); } const JavaMethod *jMethod = static_cast<const JavaMethod*>(method); JS_LOG ("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), _instance->_instance); if (count > 0) { jArgs = (jvalue *)malloc (count * sizeof(jvalue)); } else jArgs = 0; for (i = 0; i < count; i++) { JavaParameter* aParameter = jMethod->parameterAt(i); jArgs[i] = convertValueToJValue(exec, args.at(exec, i), aParameter->getJNIType(), aParameter->type()); JS_LOG("arg[%d] = %s\n", i, args.at(exec, i).toString(exec).ascii()); } jvalue result; // Try to use the JNI abstraction first, otherwise fall back to // nornmal JNI. The JNI dispatch abstraction allows the Java plugin // to dispatch the call on the appropriate internal VM thread. RootObject* rootObject = this->rootObject(); if (!rootObject) return jsUndefined(); bool handled = false; if (rootObject->nativeHandle()) { jobject obj = _instance->_instance; JSValuePtr exceptionDescription = noValue(); const char *callingURL = 0; // FIXME, need to propagate calling URL to Java handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); if (exceptionDescription) { throwError(exec, GeneralError, exceptionDescription.toString(exec)); free (jArgs); return jsUndefined(); } } // The following code can be conditionally removed once we have a Tiger update that // contains the new Java plugin. It is needed for builds prior to Tiger. if (!handled) { jobject obj = _instance->_instance; switch (jMethod->JNIReturnType()){ case void_type: callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs); break; case object_type: result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs); break; case boolean_type: result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs); break; case byte_type: result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs); break; case char_type: result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs); break; case short_type: result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs); break; case int_type: result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs); break; case long_type: result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs); break; case float_type: result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs); break; case double_type: result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs); break; case invalid_type: default: break; } } switch (jMethod->JNIReturnType()){ case void_type: { resultValue = jsUndefined(); } break; case object_type: { if (result.l != 0) { const char *arrayType = jMethod->returnType(); if (arrayType[0] == '[') { resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); } else { resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); } } else { resultValue = jsUndefined(); } } break; case boolean_type: { resultValue = jsBoolean(result.z); } break; case byte_type: { resultValue = jsNumber(exec, result.b); } break; case char_type: { resultValue = jsNumber(exec, result.c); } break; case short_type: { resultValue = jsNumber(exec, result.s); } break; case int_type: { resultValue = jsNumber(exec, result.i); } break; case long_type: { resultValue = jsNumber(exec, result.j); } break; case float_type: { resultValue = jsNumber(exec, result.f); } break; case double_type: { resultValue = jsNumber(exec, result.d); } break; case invalid_type: default: { resultValue = jsUndefined(); } break; } free (jArgs); return resultValue; }
// Action_DihedralScan::Init() Action::RetType Action_DihedralScan::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { if (init.DSL().EnsembleNum() > -1) { mprinterr("Error: DIHEDRALSCAN currently cannot be used in ensemble mode.\n"); return Action::ERR; } TrajectoryFile::TrajFormatType outfmt = TrajectoryFile::UNKNOWN_TRAJ; Topology* outtop = 0; int iseed = -1; debug_ = debugIn; // Get Keywords - first determine mode if (actionArgs.hasKey("random")) mode_ = RANDOM; else if (actionArgs.hasKey("interval")) mode_ = INTERVAL; else mode_ = INTERVAL; // Get residue range resRange_.SetRange(actionArgs.GetStringKey("resrange")); if (!resRange_.Empty()) resRange_.ShiftBy(-1); // User res args start from 1 // Determine which angles to search for dihSearch_.SearchForArgs(actionArgs); // If nothing is enabled, enable all dihSearch_.SearchForAll(); // For interval, get value to shift by, set max rotations and set up // output trajectory. if ( mode_ == INTERVAL ) { interval_ = actionArgs.getNextDouble(60.0); maxVal_ = (int) (360.0 / interval_); if (maxVal_ < 0) maxVal_ = -maxVal_; outfilename_ = actionArgs.GetStringKey("outtraj"); if (!outfilename_.empty()) { outfmt = TrajectoryFile::GetFormatFromArg( actionArgs ); outtop = init.DSL().GetTopology( actionArgs ); if (outtop == 0) { mprinterr("Error: dihedralscan: No topology for output traj.\n"); return Action::ERR; } } } // Get 'random' args if (mode_ == RANDOM) { check_for_clashes_ = actionArgs.hasKey("check"); checkAllResidues_ = actionArgs.hasKey("checkallresidues"); cutoff_ = actionArgs.getKeyDouble("cutoff",0.8); rescutoff_ = actionArgs.getKeyDouble("rescutoff",10.0); backtrack_ = actionArgs.getKeyInt("backtrack",4); increment_ = actionArgs.getKeyInt("increment",1); max_factor_ = actionArgs.getKeyInt("maxfactor",2); // Check validity of args if (cutoff_ < Constants::SMALL) { mprinterr("Error: cutoff too small.\n"); return Action::ERR; } if (rescutoff_ < Constants::SMALL) { mprinterr("Error: rescutoff too small.\n"); return Action::ERR; } if (backtrack_ < 0) { mprinterr("Error: backtrack value must be >= 0\n"); return Action::ERR; } if ( increment_<1 || (360 % increment_)!=0 ) { mprinterr("Error: increment must be a factor of 360.\n"); return Action::ERR; } // Calculate max increment max_increment_ = 360 / increment_; // Seed random number gen iseed = actionArgs.getKeyInt("rseed",-1); RN_.rn_set( iseed ); } // Output file for # of problems DataFile* problemFile = init.DFL().AddDataFile(actionArgs.GetStringKey("out"), actionArgs); // Dataset to store number of problems number_of_problems_ = init.DSL().AddSet(DataSet::INTEGER, actionArgs.GetStringNext(),"Nprob"); if (number_of_problems_==0) return Action::ERR; // Add dataset to data file list if (problemFile != 0) problemFile->AddDataSet(number_of_problems_); mprintf(" DIHEDRALSCAN: Dihedrals in"); if (resRange_.Empty()) mprintf(" all solute residues.\n"); else mprintf(" residue range [%s]\n", resRange_.RangeArg()); switch (mode_) { case RANDOM: mprintf("\tDihedrals will be rotated to random values.\n"); if (iseed==-1) mprintf("\tRandom number generator will be seeded using time.\n"); else mprintf("\tRandom number generator will be seeded using %i\n",iseed); if (check_for_clashes_) { mprintf("\tWill attempt to recover from bad steric clashes.\n"); if (checkAllResidues_) mprintf("\tAll residues will be checked.\n"); else mprintf("\tResidues up to the currenly rotating dihedral will be checked.\n"); mprintf("\tAtom cutoff %.2f, residue cutoff %.2f, backtrack = %i\n", cutoff_, rescutoff_, backtrack_); mprintf("\tWhen clashes occur dihedral will be incremented by %i\n",increment_); mprintf("\tMax # attempted rotations = %i times number dihedrals.\n", max_factor_); } break; case INTERVAL: mprintf("\tDihedrals will be rotated at intervals of %.2f degrees.\n", interval_); if (!outfilename_.empty()) mprintf("\tCoordinates output to %s, format %s\n",outfilename_.c_str(), TrajectoryFile::FormatString(outfmt)); break; } // Setup output trajectory if (!outfilename_.empty()) { if (outtraj_.InitTrajWrite(outfilename_, ArgList(), outfmt)) return Action::ERR; outframe_ = 0; } // Square cutoffs to compare to dist^2 instead of dist cutoff_ *= cutoff_; rescutoff_ *= rescutoff_; // Increment backtrack by 1 since we need to skip over current res ++backtrack_; // Initialize CheckStructure if (checkStructure_.SeparateInit( false, "*", "", "", 0.8, 1.15, false, init.DFL() )) { mprinterr("Error: Could not set up structure check for DIHEDRALSCAN.\n"); return Action::ERR; } return Action::OK; }
// Analysis_TI::Setup() Analysis::RetType Analysis_TI::Setup(ArgList& analyzeArgs, DataSetList* datasetlist, DataFileList* DFLin, int debugIn) { int nq = analyzeArgs.getKeyInt("nq", 0); ArgList nskipArg(analyzeArgs.GetStringKey("nskip"), ","); // Comma-separated if (nskipArg.empty()) nskip_.resize(1, 0); else { nskip_.clear(); for (int i = 0; i != nskipArg.Nargs(); i++) { nskip_.push_back( nskipArg.getNextInteger(0) ); if (nskip_.back() < 0) nskip_.back() = 0; } } std::string setname = analyzeArgs.GetStringKey("name"); DataFile* outfile = DFLin->AddDataFile(analyzeArgs.GetStringKey("out"), analyzeArgs); DataFile* curveout = DFLin->AddDataFile(analyzeArgs.GetStringKey("curveout"), analyzeArgs); // Select datasets from remaining args if (input_dsets_.AddSetsFromArgs( analyzeArgs.RemainingArgs(), *datasetlist )) { mprinterr("Error: Could not add data sets.\n"); return Analysis::ERR; } if (input_dsets_.empty()) { mprinterr("Error: No input data sets.\n"); return Analysis::ERR; } if (SetQuadAndWeights(nq)) return Analysis::ERR; if (quad_.size() != input_dsets_.size()) { mprinterr("Error: Expected %zu data sets based on nq, got %zu\n", quad_.size(), input_dsets_.size()); return Analysis::ERR; } dAout_ = datasetlist->AddSet(DataSet::XYMESH, setname, "TI"); if (dAout_ == 0) return Analysis::ERR; if (outfile != 0) outfile->AddDataSet( dAout_ ); MetaData md(dAout_->Meta().Name(), "TIcurve"); for (Iarray::const_iterator it = nskip_.begin(); it != nskip_.end(); ++it) { md.SetIdx( *it ); DataSet* ds = datasetlist->AddSet(DataSet::XYMESH, md); if (ds == 0) return Analysis::ERR; ds->SetLegend( md.Name() + "_Skip" + integerToString(*it) ); if (curveout != 0) curveout->AddDataSet( ds ); curve_.push_back( ds ); } mprintf(" TI: Calculating TI using Gaussian quadrature with %zu points.\n", quad_.size()); mprintf("\t%6s %8s %8s %s\n", "Point", "Abscissa", "Weight", "SetName"); for (unsigned int i = 0; i != quad_.size(); i++) mprintf("\t%6i %8.5f %8.5f %s\n", i, quad_[i], wgt_[i], input_dsets_[i]->legend()); if (nskip_.front() > 0) { mprintf("\tSkipping first"); for (Iarray::const_iterator it = nskip_.begin(); it != nskip_.end(); ++it) mprintf(" %i", *it); mprintf(" data points for <DV/DL> calc.\n"); } mprintf("\tResults saved in set '%s'\n", dAout_->legend()); mprintf("\tTI curve(s) saved in set(s)"); for (DSarray::const_iterator ds = curve_.begin(); ds != curve_.end(); ++ds) mprintf(" '%s'", (*ds)->legend()); mprintf("\n"); if (outfile != 0) mprintf("\tResults written to '%s'\n", outfile->DataFilename().full()); if (curveout!= 0) mprintf("\tTI curve written to '%s'\n", curveout->DataFilename().full()); return Analysis::OK; }
/// \brief Utility function to add a system include directory with extern "C" /// semantics to CC1 arguments. /// /// Note that this should be used rarely, and only for directories that /// historically and for legacy reasons are treated as having implicit extern /// "C" semantics. These semantics are *ignored* by and large today, but its /// important to preserve the preprocessor changes resulting from the /// classification. /*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs, ArgStringList &CC1Args, const Twine &Path) { CC1Args.push_back("-internal-externc-isystem"); CC1Args.push_back(DriverArgs.MakeArgString(Path)); }
int Interpreter::call(const QStringList &argv, bool interactive) { QMutexLocker locker(&m_chirp->m_mutex); ChirpProc proc; ProcInfo info; int args[20]; int i, j, k, n, base, res; bool ok; uint type; ArgList list; // not allowed if (argv.size()<1) return -1; // a procedure needs extension info (arg info, etc) in order for us to call... if ((proc=m_chirp->getProc(argv[0].toLocal8Bit()))>=0 && m_chirp->getProcInfo(proc, &info)>=0) { memset(args, 0, sizeof(args)); // zero args getArgs(&info, &list); n = strlen((char *)info.argTypes); // if we have fewer args than required... if ((int)list.size()>argv.size()-1) { // if we're interactive, ask for values if (interactive && argv.size()>0) { QStringList cargv = argv; QString pstring, pstring2; for (i=cargv.size()-1; i<(int)list.size(); i++) { if (info.argTypes[i]==CRP_TYPE_HINT) { if (n>i+4) { type = *(uint *)&info.argTypes[i+1]; if (type==FOURCC('R','E','G','1')) { emit videoInput(VideoWidget::REGION); pstring2 = "(select region with mouse)"; } if (type==FOURCC('P','N','T','1')) { emit videoInput(VideoWidget::POINT); pstring2 = "(select point with mouse)"; } emit enableConsole(false); } } k = i; pstring = printArgType(&info.argTypes[i], i) + " " + list[k].first + (list[k].second=="" ? "?" : " (" + list[k].second + ")?") + " " + pstring2; emit prompt(pstring); m_mutexInput.lock(); m_waiting = true; m_waitInput.wait(&m_mutexInput); m_waiting = false; m_mutexInput.unlock(); emit enableConsole(true); if (m_key==Qt::Key_Escape) return -1; cargv << m_command.split(QRegExp("\\s+")); } // call ourselves again, now that we have all the args return call(cargv, true); } else { emit error("too few arguments.\n"); return -1; } } augmentProcInfo(&info); // if we have all the args we need, parse, put in args array for (i=0, j=0; m_argTypes[i]; i++) { if (argv.size()>i+1) { if (m_argTypes[i]==CRP_INT8 || m_argTypes[i]==CRP_INT16 || m_argTypes[i]==CRP_INT32) { args[j++] = m_argTypes[i]; if (argv[i+1].left(2)=="0x") base = 16; else base = 10; args[j++] = argv[i+1].toInt(&ok, base); if (!ok) { emit error("argument didn't parse.\n"); return -1; } } #if 0 else if (m_argTypes[i]==CRP_STRING) { args[j++] = m_argTypes[i]; // string goes where? can't cast pointer to int... } #endif else { // deal with non-integer types return -1; } } } #if 0 // print helpful chirp argument string if (interactive && argv.size()>1) { QString callString = "Chirp arguments for " + argv[0] + " (ChirpProc=" + QString::number(proc) + "): "; for (i=1; i<argv.size(); i++) { if (i>1) callString += ", "; j = i; callString += printArgType(&m_argTypes[i-1], i) + "(" + argv[j] + ")"; } emit textOut(callString + "\n"); } #endif // make chirp call res = m_chirp->callAsync(proc, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18], args[19], END_OUT_ARGS); // check for cable disconnect if (res<0 && !m_notified) //res==LIBUSB_ERROR_PIPE) { m_notified = true; emit connected(PIXY, false); return res; } // get response if we're not programming, save text if we are if (m_programming) addProgram(argv); else m_chirp->serviceChirp(); } else { emit error("procedure unsupported.\n"); return -1; } return 0; }
Analysis::RetType Analysis_State::Setup(ArgList& analyzeArgs, AnalysisSetup& setup, int debugIn) { debug_ = debugIn; masterDSL_ = setup.DslPtr(); DataFile* outfile = setup.DFL().AddDataFile( analyzeArgs.GetStringKey("out"), analyzeArgs ); curveOut_ = setup.DFL().AddDataFile( analyzeArgs.GetStringKey("curveout"), analyzeArgs ); stateOut_ = setup.DFL().AddCpptrajFile( analyzeArgs.GetStringKey("stateout"), "State Output", DataFileList::TEXT, true); transOut_ = setup.DFL().AddCpptrajFile( analyzeArgs.GetStringKey("transout"), "Transitions Output", DataFileList::TEXT, true); normalize_ = analyzeArgs.hasKey("norm"); // Get definitions of states if present. // Define states as 'state <#>,<dataset>,<min>,<max>' std::string state_arg = analyzeArgs.GetStringKey("state"); if (!state_arg.empty()) { while (!state_arg.empty()) { // Expect form <#>,<dataset> ArgList argtmp(state_arg, ","); if (argtmp.Nargs() != 4) { mprinterr("Error: Malformed state argument '%s': expect <ID>,<dataset>,<min>,<max>\n", state_arg.c_str()); return Analysis::ERR; } std::string state_id = argtmp.GetStringNext(); // TODO: Check duplicate names if (state_id.empty()) { mprinterr("Error: In state argument, could not get ID.\n"); return Analysis::ERR; } DataSet* ds = setup.DSL().GetDataSet( argtmp.GetStringNext() ); if (ds == 0) return Analysis::ERR; if (ds->Ndim() != 1) { mprinterr("Error: Only 1D data sets allowed.\n"); return Analysis::ERR; } double min = argtmp.getNextDouble(0.0); double max = argtmp.getNextDouble(0.0); if (max < min) { mprinterr("Error: max value cannot be less than min.\n"); return Analysis::ERR; } States_.push_back( StateType(state_id, (DataSet_1D*)ds, min, max) ); state_arg = analyzeArgs.GetStringKey("state"); } } if (States_.empty()) { mprinterr("Error: No states defined.\n"); return Analysis::ERR; } state_data_ = setup.DSL().AddSet(DataSet::INTEGER, analyzeArgs.GetStringKey("name"), "State"); if (state_data_ == 0) return Analysis::ERR; if (outfile != 0) outfile->AddDataSet( state_data_ ); mprintf(" STATE: The following states have been set up:\n"); for (StateArray::const_iterator state = States_.begin(); state != States_.end(); ++state) mprintf("\t%u: %20s %12.4f <= %-20s < %12.4f\n", state - States_.begin(), state->DS().legend(), state->Min(), state->id(), state->Max()); mprintf("\tState data set: %s\n", state_data_->legend()); if (outfile != 0) mprintf("\tStates vs time output to file '%s'\n", outfile->DataFilename().full()); if (curveOut_ != 0) mprintf("\tCurves output to file '%s'\n", curveOut_->DataFilename().full()); mprintf("\tState output to file '%s'\n", stateOut_->Filename().full()); mprintf("\tTransitions output to file '%s'\n", transOut_->Filename().full()); if (normalize_) mprintf("\tCurves will be normalized to 1.0\n"); return Analysis::OK; }
std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, types::ID InputType) const { switch (getTriple().getArch()) { default: return getTripleString(); case llvm::Triple::x86_64: { llvm::Triple Triple = getTriple(); if (!Triple.isOSBinFormatMachO()) return getTripleString(); if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { // x86_64h goes in the triple. Other -march options just use the // vanilla triple we already have. StringRef MArch = A->getValue(); if (MArch == "x86_64h") Triple.setArchName(MArch); } return Triple.getTriple(); } case llvm::Triple::aarch64: { llvm::Triple Triple = getTriple(); if (!Triple.isOSBinFormatMachO()) return getTripleString(); // FIXME: older versions of ld64 expect the "arm64" component in the actual // triple string and query it to determine whether an LTO file can be // handled. Remove this when we don't care any more. Triple.setArchName("arm64"); return Triple.getTriple(); } case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { // FIXME: Factor into subclasses. llvm::Triple Triple = getTriple(); bool IsBigEndian = getTriple().getArch() == llvm::Triple::armeb || getTriple().getArch() == llvm::Triple::thumbeb; // Handle pseudo-target flags '-mlittle-endian'/'-EL' and // '-mbig-endian'/'-EB'. if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, options::OPT_mbig_endian)) { IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian); } // Thumb2 is the default for V7 on Darwin. // // FIXME: Thumb should just be another -target-feaure, not in the triple. StringRef MCPU, MArch; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) MCPU = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) MArch = A->getValue(); std::string CPU = Triple.isOSBinFormatMachO() ? tools::arm::getARMCPUForMArch(MArch, Triple).str() : tools::arm::getARMTargetCPU(MCPU, MArch, Triple); StringRef Suffix = tools::arm::getLLVMArchSuffixForARM(CPU, MArch, Triple); bool IsMProfile = ARM::parseArchProfile(Suffix) == ARM::ProfileKind::M; bool ThumbDefault = IsMProfile || (ARM::parseArchVersion(Suffix) == 7 && getTriple().isOSBinFormatMachO()); // FIXME: this is invalid for WindowsCE if (getTriple().isOSWindows()) ThumbDefault = true; std::string ArchName; if (IsBigEndian) ArchName = "armeb"; else ArchName = "arm"; // Check if ARM ISA was explicitly selected (using -mno-thumb or -marm) for // M-Class CPUs/architecture variants, which is not supported. bool ARMModeRequested = !Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault); if (IsMProfile && ARMModeRequested) { if (!MCPU.empty()) getDriver().Diag(diag::err_cpu_unsupported_isa) << CPU << "ARM"; else getDriver().Diag(diag::err_arch_unsupported_isa) << tools::arm::getARMArch(MArch, getTriple()) << "ARM"; } // Check to see if an explicit choice to use thumb has been made via // -mthumb. For assembler files we must check for -mthumb in the options // passed to the assembler via -Wa or -Xassembler. bool IsThumb = false; if (InputType != types::TY_PP_Asm) IsThumb = Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault); else { // Ideally we would check for these flags in // CollectArgsForIntegratedAssembler but we can't change the ArchName at // that point. There is no assembler equivalent of -mno-thumb, -marm, or // -mno-arm. for (const auto *A : Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) { for (StringRef Value : A->getValues()) { if (Value == "-mthumb") IsThumb = true; } } } // Assembly files should start in ARM mode, unless arch is M-profile, or // -mthumb has been passed explicitly to the assembler. Windows is always // thumb. if (IsThumb || IsMProfile || getTriple().isOSWindows()) { if (IsBigEndian) ArchName = "thumbeb"; else ArchName = "thumb"; } Triple.setArchName(ArchName + Suffix.str()); return Triple.getTriple(); } } }
/** Usage: * mrt out <filename> ([autocorr <filename> [tcorr <time>] [toffset <time>]]) * [lower <dist>] [upper <dist>] [time <t>] [tstar <t>] [noimage] * ([solvent <mask> | solute <mask>]) * (siteatoms <mask> | onemol <mask> | <sitemask1> ... <sitemaskN>) */ Action::RetType Action_MRT::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { useImage_ = !(actionArgs.hasKey("noimage")); std::string filename = actionArgs.GetStringKey("out"); if (filename.empty()) { mprinterr("Error: MRT: No output filename specified 'out <filename>'\n"); return Action::ERR; } time_ = actionArgs.getKeyDouble("time", 1.0); // Time that water can be inside/outside without counting it as // having left/entered. double tstar = actionArgs.getKeyDouble("tstar", 0.0); tstar /= (time_ + 0.5); nStar_ = (int)tstar; // Lower and upper distance limits double lowerCutoff = actionArgs.getKeyDouble("lower", 0.01); double upperCutoff = actionArgs.getKeyDouble("upper", 3.50); lowerCutoff2_ = lowerCutoff * lowerCutoff; upperCutoff2_ = upperCutoff * upperCutoff; // If specified, filename for autocorrelation fn autoCorr_ = actionArgs.GetStringKey("autocorr"); // Autocorrelation parameters // NOTE: Needed if autoCorr empty? double wsize = actionArgs.getKeyDouble("tcorr", 400.0); wsize /= (time_ + 0.5); wSize_ = (int)wsize; double noffset = actionArgs.getKeyDouble("toffset", 10.0); noffset /= (time_ + 0.5); nOffset_ = (int)noffset; if (nOffset_ < 1 || nOffset_ > wSize_) { mprinterr("Error: MRT: toffset must be in the range from %8.3f to %8.3f.\n", time_, (double)wSize_ * time_); return Action::ERR; } if ( (wSize_ % nOffset_) != 0 ) { mprinterr("Error: MRT: tcorr must be multiple of toffset.\n"); return Action::ERR; } int nWin = wSize_ / nOffset_; idxMaxWin_ = nWin - 1; // Get solvent mask expression. // If it is a solute, mask will be used as a single site. solventmask_.SetMaskString( actionArgs.GetStringKey("solvent") ); // Check if MRT to another solute is requested solutemask_.SetMaskString( actionArgs.GetStringKey("solute") ); // Process reference sites. Currently: // 1) siteatoms <mask> which expands to mutliple sites per atom in mask // 2) onemol <mask> means a single // 3) <mask1>...<maskN> multiple sites, use center-of-mass return Action::OK; }
void ToolChain::AddFilePathLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { for (const auto &LibPath : getFilePaths()) if(LibPath.length() > 0) CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); }
// ECMA 8.6.2.2 void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) { ASSERT(value); ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); if (propertyName == exec->propertyNames().underscoreProto) { // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla. if (!value->isObject() && !value->isNull()) return; JSValuePtr nextPrototypeValue = value; while (nextPrototypeValue && nextPrototypeValue->isObject()) { JSObject* nextPrototype = asObject(nextPrototypeValue)->unwrappedObject(); if (nextPrototype == this) { throwError(exec, GeneralError, "cyclic __proto__ value"); return; } nextPrototypeValue = nextPrototype->prototype(); } setPrototype(value); return; } // Check if there are any setters or getters in the prototype chain JSValuePtr prototype; for (JSObject* obj = this; !obj->structure()->hasGetterSetterProperties(); obj = asObject(prototype)) { prototype = obj->prototype(); if (prototype->isNull()) { putDirect(propertyName, value, 0, true, slot); return; } } unsigned attributes; if ((m_structure->get(propertyName, attributes) != WTF::notFound) && attributes & ReadOnly) return; for (JSObject* obj = this; ; obj = asObject(prototype)) { if (JSValuePtr gs = obj->getDirect(propertyName)) { if (gs->isGetterSetter()) { JSObject* setterFunc = asGetterSetter(gs)->setter(); if (!setterFunc) { throwSetterError(exec); return; } CallData callData; CallType callType = setterFunc->getCallData(callData); ArgList args; args.append(value); call(exec, setterFunc, callType, callData, this, args); return; } // If there's an existing property on the object or one of its // prototypes it should be replaced, so break here. break; } prototype = obj->prototype(); if (prototype->isNull()) break; } putDirect(propertyName, value, 0, true, slot); return; }
static JSValue JSC_HOST_CALL stringFromCharCode(ExecState* exec, JSObject*, JSValue, const ArgList& args) { if (LIKELY(args.size() == 1)) return jsSingleCharacterString(exec, args.at(0).toUInt32(exec)); return stringFromCharCodeSlowCase(exec, args); }
void HttpRequestHandler::processRequest() { HttpRequest httpRequest(m_dataInput); httpRequest.readHeader(); StringStorage request; request.fromAnsiString(httpRequest.getRequest()); if (!httpRequest.parseHeader()) { Log::warning(_T("invalid http request from %s"), m_peerHost.getString()); return ; } request.replaceChar(_T('\n'), _T(' ')); request.replaceChar(_T('\t'), _T(' ')); Log::message(_T("\"%s\" from %s"), request.getString(), m_peerHost.getString()); HttpReply reply(m_dataOutput); bool pageFound = false; if (strcmp(httpRequest.getFilename(), "/") == 0) { CharString paramsString("\n"); bool isAppletArgsValid = true; bool paramsInUrlIsEnabled = Configurator::getInstance()->getServerConfig()->isAppletParamInUrlEnabled(); if (httpRequest.hasArguments() && paramsInUrlIsEnabled) { ArgList *args = httpRequest.getArguments(); for (size_t i = 0; i < args->getCount(); i++) { const char *key = args->getKey(i); AppletParameter parameter(key, args->getValue(key)); if (!parameter.isValid()) { isAppletArgsValid = false; break; } paramsString.format("%s%s", paramsString.getString(), parameter.getFormattedString()); } } reply.send200(); if (!isAppletArgsValid) { m_dataOutput->writeFully(HTTP_MSG_BADPARAMS, strlen(HTTP_MSG_BADPARAMS)); } else { CharString page; StringStorage computerName(_T("TightVNC Server")); Environment::getComputerName(&computerName); size_t computerNameANSILength = computerName.getLength() + 1; char *computerNameANSI = new char[computerNameANSILength]; computerName.toAnsiString(computerNameANSI, computerNameANSILength); page.format(HTTP_INDEX_PAGE_FORMAT, computerNameANSI, Configurator::getInstance()->getServerConfig()->getRfbPort(), paramsString.getString()); delete[] computerNameANSI; m_dataOutput->writeFully(page.getString(), page.getLength()); } pageFound = true; } else if ((strcmp(httpRequest.getFilename(), "/VncViewer.jar") == 0)) { reply.send200(); m_dataOutput->writeFully(VNC_VIEWER_JAR_BODY, sizeof(VNC_VIEWER_JAR_BODY)); pageFound = true; } if (!pageFound) { reply.send404(); } }
// ECMA 15.5.1 static JSValue JSC_HOST_CALL callStringConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { if (args.isEmpty()) return jsEmptyString(exec); return jsString(exec, args.at(0).toString(exec)); }
JSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsDoubleNumber(exec, sqrt(args.at(0).toNumber(exec))); }
int DockerAPI::rm( const std::string & containerID, CondorError & /* err */ ) { ArgList rmArgs; if ( ! add_docker_arg(rmArgs)) return -1; rmArgs.AppendArg( "rm" ); rmArgs.AppendArg( "-f" ); // if for some reason still running, kill first rmArgs.AppendArg( "-v" ); // also remove the volume rmArgs.AppendArg( containerID.c_str() ); MyString displayString; rmArgs.GetArgsStringForLogging( & displayString ); dprintf( D_FULLDEBUG, "Attempting to run: %s\n", displayString.c_str() ); // Read from Docker's combined output and error streams. #if 1 MyPopenTimer pgm; if (pgm.start_program( rmArgs, true, NULL, false ) < 0) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } const char * got_output = pgm.wait_and_close(default_timeout); // On a success, Docker writes the containerID back out. MyString line; if ( ! got_output || ! line.readLine(pgm.output(), false)) { int error = pgm.error_code(); if( error ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), pgm.error_str(), error ); if (pgm.was_timeout()) { dprintf( D_ALWAYS | D_FAILURE, "Declaring a hung docker\n"); return docker_hung; } } else { dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() ); } return -3; } line.chomp(); line.trim(); if (line != containerID.c_str()) { // Didn't get back the result I expected, report the error and check to see if docker is hung. return check_if_docker_offline(pgm, "Docker remove", -4); } #else FILE * dockerResults = my_popen( rmArgs, "r", 1 , 0, false); if( dockerResults == NULL ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() ); return -2; } // On a success, Docker writes the containerID back out. char buffer[1024]; if( NULL == fgets( buffer, 1024, dockerResults ) ) { if( errno ) { dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), strerror( errno ), errno ); } else { dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() ); } my_pclose( dockerResults ); return -3; } int length = strlen( buffer ); if( length < 1 || strncmp( buffer, containerID.c_str(), length - 1 ) != 0 ) { dprintf( D_ALWAYS | D_FAILURE, "Docker remove failed, printing first few lines of output.\n" ); dprintf( D_ALWAYS | D_FAILURE, "%s", buffer ); while( NULL != fgets( buffer, 1024, dockerResults ) ) { dprintf( D_ALWAYS | D_FAILURE, "%s", buffer ); } my_pclose( dockerResults ); return -4; } my_pclose( dockerResults ); #endif return 0; }