void Init_CWD(GMC_ARG_VOID) { tp_Str Home, PWD; boolean Abort; tps_Str RawCWDirName; GetWorkingDir(&Abort, RawCWDirName); if (Abort) { SystemError("Current working directory name too long.\n"); Exit(1); }/*if*/; Do_Alias(OdinDirName, FALSE); Home = GetHome(""); if (Home == NIL) Home = GetEnv("HOME"); if (Home != NIL) Do_Alias(Home, FALSE); PWD = GetEnv("PWD"); if (PWD == NIL) PWD = GetEnv("cwd"); if (PWD != NIL && strncmp(PWD, RawCWDirName, strlen(PWD)) != 0) { Do_Alias(PWD, FALSE); }/*if*/; Get_Alias(CWDirName, RawCWDirName); Set_CWD(CWDirName); }/*Init_CWD*/
GeoVector AbortTask::GetHomeVector(const AircraftState &state) const { const Waypoint *home_waypoint = GetHome(); if (home_waypoint) return GeoVector(state.location, home_waypoint->location); return GeoVector(fixed_zero); }
std::string Config::Expand(std::string file) { auto pos = file.find('~'); if(pos != std::string::npos) { file.erase(pos,1); file.insert(pos, GetHome()); } return file; }
void InitializeGA(int argc,char *argv[]) { int seed,force = false; struct stat statbuf,sb; unsigned char s[16]; char vbuff[CF_BUFSIZE]; char ebuff[CF_EXPANDSIZE]; SHORT_CFENGINEPORT = htons((unsigned short)5308); snprintf(STR_CFENGINEPORT,15,"5308"); NewClass("any"); #if defined HAVE_CONSTELLATION NewClass("constellation_edition"); #elif defined HAVE_NOVA NewClass("nova_edition"); #else NewClass("community_edition"); #endif strcpy(VPREFIX,GetConsolePrefix()); if (VERBOSE) { NewClass("verbose_mode"); } if (INFORM) { NewClass("inform_mode"); } if (DEBUG) { NewClass("debug_mode"); } CfOut(cf_verbose,"","Cfengine - autonomous configuration engine - commence self-diagnostic prelude\n"); CfOut(cf_verbose,"","------------------------------------------------------------------------\n"); /* Define trusted directories */ #ifdef MINGW if(NovaWin_GetProgDir(CFWORKDIR, CF_BUFSIZE - sizeof("Cfengine"))) { strcat(CFWORKDIR, "\\Cfengine"); } else { CfOut(cf_error, "", "!! Could not get CFWORKDIR from Windows environment variable, falling back to compile time dir (%s)", WORKDIR); strcpy(CFWORKDIR,WORKDIR); } Debug("Setting CFWORKDIR=%s\n", CFWORKDIR); #elif defined(CFCYG) strcpy(CFWORKDIR,WORKDIR); MapName(CFWORKDIR); #else if (getuid() > 0) { strncpy(CFWORKDIR,GetHome(getuid()),CF_BUFSIZE-10); strcat(CFWORKDIR,"/.cfagent"); if (strlen(CFWORKDIR) > CF_BUFSIZE/2) { FatalError("Suspicious looking home directory. The path is too long and will lead to problems."); } } else { strcpy(CFWORKDIR,WORKDIR); } #endif /* On windows, use 'binary mode' as default for files */ #ifdef MINGW _fmode = _O_BINARY; #endif strcpy(SYSLOGHOST,"localhost"); SYSLOGPORT = htons(514); Cf3OpenLog(LOG_USER); if (!LOOKUP) /* cf-know should not do this in lookup mode */ { CfOut(cf_verbose,"","Work directory is %s\n",CFWORKDIR); snprintf(HASHDB,CF_BUFSIZE-1,"%s%c%s",CFWORKDIR,FILE_SEPARATOR,CF_CHKDB); snprintf(vbuff,CF_BUFSIZE,"%s%cinputs%cupdate.conf",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); MakeParentDirectory(vbuff,force); snprintf(vbuff,CF_BUFSIZE,"%s%cbin%ccf-agent -D from_cfexecd",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); MakeParentDirectory(vbuff,force); snprintf(vbuff,CF_BUFSIZE,"%s%coutputs%cspooled_reports",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); MakeParentDirectory(vbuff,force); snprintf(vbuff,CF_BUFSIZE,"%s%clastseen%cintermittencies",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); MakeParentDirectory(vbuff,force); snprintf(vbuff,CF_BUFSIZE,"%s%creports%cvarious",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); MakeParentDirectory(vbuff,force); snprintf(vbuff,CF_BUFSIZE,"%s%cinputs",CFWORKDIR,FILE_SEPARATOR); if (cfstat(vbuff,&sb) == -1) { FatalError(" !!! No access to WORKSPACE/inputs dir"); } else { cf_chmod(vbuff,sb.st_mode | 0700); } snprintf(vbuff,CF_BUFSIZE,"%s%coutputs",CFWORKDIR,FILE_SEPARATOR); if (cfstat(vbuff,&sb) == -1) { FatalError(" !!! No access to WORKSPACE/outputs dir"); } else { cf_chmod(vbuff,sb.st_mode | 0700); } sprintf(ebuff,"%s%cstate%ccf_procs",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); MakeParentDirectory(ebuff,force); if (cfstat(ebuff,&statbuf) == -1) { CreateEmptyFile(ebuff); } sprintf(ebuff,"%s%cstate%ccf_rootprocs",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); if (cfstat(ebuff,&statbuf) == -1) { CreateEmptyFile(ebuff); } sprintf(ebuff,"%s%cstate%ccf_otherprocs",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); if (cfstat(ebuff,&statbuf) == -1) { CreateEmptyFile(ebuff); } } OpenNetwork(); /* Init crypto stuff */ OpenSSL_add_all_algorithms(); OpenSSL_add_all_digests(); ERR_load_crypto_strings(); if(!LOOKUP) { CheckWorkingDirectories(); } RandomSeed(); RAND_bytes(s,16); s[15] = '\0'; seed = ElfHash(s); srand48((long)seed); LoadSecretKeys(); /* CheckOpts(argc,argv); - MacOS can't handle this back reference */ if (!MINUSF) { snprintf(VINPUTFILE,CF_BUFSIZE-1,"promises.cf"); } AUDITDBP = NULL; DetermineCfenginePort(); VIFELAPSED = 1; VEXPIREAFTER = 1; setlinebuf(stdout); if (BOOTSTRAP) { snprintf(vbuff,CF_BUFSIZE,"%s%cinputs%cfailsafe.cf",CFWORKDIR,FILE_SEPARATOR,FILE_SEPARATOR); if (!IsEnterprise() && cfstat(vbuff,&statbuf) == -1) { snprintf(VINPUTFILE,CF_BUFSIZE-1,".%cfailsafe.cf",FILE_SEPARATOR); } else { strncpy(VINPUTFILE,vbuff,CF_BUFSIZE-1); } } }