def sandbox_summary(self, move_log=False): """if the instance is sandboxed, print the sandbox access summary""" if not os.path.exists(self.__sandbox_log): self.write("end_sandbox_summary") return 0 violations=portage_util.grabfile(self.__sandbox_log) if len(violations)==0: self.write("end_sandbox_summary") return 0 if not move_log: move_log=self.__sandbox_log elif move_log != self.__sandbox_log: myf=open(move_log) for x in violations: myf.write(x+"\n") myf.close() from output import red self.ebd_write.write(red("--------------------------- ACCESS VIOLATION SUMMARY ---------------------------")+"\n") self.ebd_write.write(red("LOG FILE = \"%s\"" % move_log)+"\n\n") for x in violations: self.ebd_write.write(x+"\n") self.write(red("--------------------------------------------------------------------------------")+"\n") self.write("end_sandbox_summary") try: os.remove(self.__sandbox_log) except (IOError, OSError), e: print "exception caught when cleansing sandbox_log=%s" % str(e)
def __init__(self, clone=None, mycpv=None, config_profile_path=portage_const.PROFILE_PATH, config_incrementals=None): self.already_in_regenerate = 0 self.locked = 0 self.mycpv = None self.puse = [] self.modifiedkeys = [] self.virtuals = {} self.v_count = 0 if clone: self.clone(clone) else: self.depcachedir = portage_const.DEPCACHE_PATH if not os.path.exists(config_profile_path): writemsg("config_profile_path not specified to class config\n") sys.exit(1) self.profile_path = config_profile_path if not config_incrementals: import traceback traceback.print_stack() writemsg("incrementals not specified to class config\n") writemsg("sayonara, sucker.\n") sys.exit(1) self.incrementals = copy.deepcopy(config_incrementals) self.module_priority = ["user", "default"] self.modules = {} self.modules["user"] = getconfig(portage_const.MODULES_FILE_PATH) if self.modules["user"] == None: self.modules["user"] = {} self.modules["default"] = { "portdbapi.metadbmodule": "cache.metadata.database", "portdbapi.auxdbmodule": "cache.flat_list.database", } self.usemask = [] self.configlist = [] self.backupenv = {} # back up our incremental variables: self.configdict = {} # configlist will contain: [ globals, defaults, conf, pkg, auto, backupenv (incrementals), origenv ] # The symlink might not exist or might not be a symlink. try: self.profiles = [abssymlink(self.profile_path)] except (OSError, IOError): self.profiles = [self.profile_path] mypath = self.profiles[0] while os.path.exists(mypath + "/parent"): mypath = os.path.normpath(mypath + "///" + grabfile(mypath + "/parent")[0]) if os.path.exists(mypath): self.profiles.insert(0, mypath) if os.environ.get("PORTAGE_CALLER", '') == "repoman": pass else: # XXX: This should depend on ROOT? if os.path.exists("/" + portage_const.CUSTOM_PROFILE_PATH): self.profiles.append("/" + portage_const.CUSTOM_PROFILE_PATH) self.packages_list = grab_multiple("packages", self.profiles, grabfile_package) self.packages = stack_lists(self.packages_list, incremental=1) del self.packages_list #self.packages = grab_stacked("packages", self.profiles, grabfile, incremental_lines=1) # revmaskdict self.prevmaskdict = {} for x in self.packages: mycatpkg = portage_dep.dep_getkey(x) if not self.prevmaskdict.has_key(mycatpkg): self.prevmaskdict[mycatpkg] = [x] else: self.prevmaskdict[mycatpkg].append(x) # get profile-masked use flags -- INCREMENTAL Child over parent usemask_lists = grab_multiple("use.mask", self.profiles, grabfile) self.usemask = stack_lists(usemask_lists, incremental=True) del usemask_lists use_defs_lists = grab_multiple("use.defaults", self.profiles, grabdict) self.use_defs = stack_dictlist(use_defs_lists, incremental=True) del use_defs_lists try: mygcfg_dlists = grab_multiple("make.globals", self.profiles + ["/etc"], getconfig) self.mygcfg = stack_dicts( mygcfg_dlists, incrementals=portage_const.INCREMENTALS, ignore_none=1) if self.mygcfg == None: self.mygcfg = {} except SystemExit, e: raise except Exception, e: writemsg("!!! %s\n" % (e)) writemsg( "!!! Incorrect multiline literals can cause this. Do not use them.\n" ) writemsg( "!!! Errors in this file should be reported on bugs.gentoo.org.\n" ) sys.exit(1)
self.configlist.append({}) self.configdict["auto"] = self.configlist[-1] #backup-env (for recording our calculated incremental variables:) self.backupenv = os.environ.copy() self.configlist.append(self.backupenv) # XXX Why though? self.configdict["backupenv"] = self.configlist[-1] self.configlist.append(os.environ.copy()) self.configdict["env"] = self.configlist[-1] # make lookuplist for loading package.* self.lookuplist = self.configlist[:] self.lookuplist.reverse() archlist = grabfile(self["PORTDIR"] + "/profiles/arch.list") self.configdict["conf"]["PORTAGE_ARCHLIST"] = ' '.join(archlist) if os.environ.get("PORTAGE_CALLER", '') == "repoman": # repoman shouldn't use local settings. locations = [self["PORTDIR"] + "/profiles"] self.pusedict = {} self.pkeywordsdict = {} self.punmaskdict = {} else: locations = [ self["PORTDIR"] + "/profiles", portage_const.USER_CONFIG_PATH ] # Never set anything in this. It's for non-originals.
def update_confcache(self,settings,logfile,new_confcache, confcache=portage_const.CONFCACHE_FILE, \ confcache_list=portage_const.CONFCACHE_LIST): """internal function called when a processor has finished a configure, and wishes its cache be transferred to the global cache This runs through the sandbox log, storing the md5 of files along with the list of files to check. Finally, it transfers the cache to the global location.""" if not self.__ebp: import traceback traceback.print_stack() print "err... no ebp, yet load_confcache called. invalid" sys.exit(1) import re from portage_checksum import perform_md5 if not (os.path.exists(logfile) and os.path.exists(new_confcache)) : # eh? wth? self.__ebp.write("failed") return 0 myfiles=portage_util.grabfile(logfile) filter=re.compile('^(%s|/tmp|/dev|.*/\.ccache)/' % os.path.normpath(settings["PORTAGE_TMPDIR"])) l=[] for x in myfiles: # get only read syscalls... if x[0:8] == "open_rd:": l.append(x.split()[1]) myfiles = portage_util.unique_array(l) l=[] for x in myfiles: if not os.path.exists(x): continue if not filter.match(x): l.append(x) del myfiles if not len(l): self.__ebp.write("updated") return 0 lock=portage_locks.lockfile(confcache_list,wantnewlockfile=1) # update phase. if not os.path.exists(confcache_list): prevmask=os.umask(0) myf=anydbm.open(confcache_list,"n",0664) os.umask(prevmask) else: myf=anydbm.open(confcache_list,"w",0664) for x in l: try: if not stat.S_ISDIR(os.stat(x).st_mode) and not myf.has_key(x): myf[x]=str(perform_md5(x,calc_prelink=1)) except (IOError, OSError): # exceptions are only possibly (ignoring anydbm horkage) from os.stat pass myf.close() from portage_data import portage_gid os.chown(confcache_list, -1, portage_gid) shutil.move(new_confcache, confcache) os.chown(confcache, -1, portage_gid) m=os.umask(0) os.chmod(confcache, 0664) os.chmod(confcache_list, 0664) os.umask(m) portage_locks.unlockfile(lock) self.__ebp.write("updated") return 0
def load_confcache(self,transfer_to,confcache=portage_const.CONFCACHE_FILE, confcache_list=portage_const.CONFCACHE_LIST): """verifys a requested conf cache, removing the global cache if it's stale. The handler should be the only one to call this""" from portage_checksum import perform_md5 from output import red if not self.__ebp: import traceback traceback.print_stack() print "err... no ebp, yet load_confcache called. invalid" raise Exception,"load_confcache called yet no running processor. bug?" valid=True lock=None if not os.path.exists(confcache_list): print "confcache file listing doesn't exist" valid=False elif not os.path.exists(confcache): print "confcache doesn't exist" valid=False else: lock=portage_locks.lockfile(confcache_list,wantnewlockfile=1) try: myf=anydbm.open(confcache_list, "r", 0664) for l in myf.keys(): # file, md5 if perform_md5(l,calc_prelink=1) != myf[l]: print red("***")+" confcache is stale: %s: recorded md5: %s: actual: %s:" % (l,myf[l],perform_md5(l,calc_prelink=1)) raise Exception("md5 didn't match") myf.close() # verify env now. new_cache=[] env_vars=[] # guessing on THOST. I'm sure it's wrong... env_translate={"build_alias":"CBUILD","host_alias":"CHOST","target_alias":"THOST"} cache=portage_util.grabfile(confcache) x=0 while x < len(cache): #ac_cv_env if cache[x][0:10] == "ac_cv_env_": f=cache[x][10:].find("_set") if f == -1 or f==11: cache.pop(x) continue env_vars.append(cache[x][10:10 + cache[x][10:].find("_set")]) x += 1 else: new_cache.append(cache[x]) x += 1 for x in env_vars: self.__ebp.write("request %s" % env_translate.get(x,x)) line=self.__ebp.read() if line[-1] == "\n": line=line[:-1] new_cache.append("ac_cv_env_%s_set=%s" % (x, line)) if line == "unset": new_cache.append("ac_cv_env_%s_value=" % x) else: line=self.__ebp.read() if line[-1] == "\n": line=line[:-1] if line.split()[0] != line: #quoting... XXX new_cache.append("ac_cv_env_%s_value='%s'" % (x,line)) else: new_cache.append("ac_cv_env_%s_value=%s" % (x,line)) myf=open(confcache,"w") for x in new_cache: myf.write(x+"\n") myf.close() except SystemExit, e: raise except Exception,e: print "caught exception: %s" % str(e) try: myf.close() except (IOError, OSError): pass valid=False