Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 90343 | Differences between
and this patch

Collapse All | Expand All

(-)portage-2.0.51.20.orig/bin/ebuild.sh (-1 / +16 lines)
Lines 1119-1130 Link Here
1119
	trap SIGINT SIGQUIT
1119
	trap SIGINT SIGQUIT
1120
}
1120
}
1121
1121
1122
iw_begin() {
1123
	export SANDBOX_ON="1"
1124
	export SANDBOX_WRITE="/"
1125
	export SANDBOX_DEBUG="1"
1126
	export SANDBOX_DEBUG_LOG="$INSTALLWATCHFILE"
1127
}
1128
1129
iw_end() {
1130
	export SANDBOX_ON="0"
1131
	unset SANDBOX_DEBUG SANDBOX_DEBUG_LOG INSTALLWATCHFILE
1132
}
1133
1122
dyn_preinst() {
1134
dyn_preinst() {
1123
	# set IMAGE depending if this is a binary or compile merge
1135
	# set IMAGE depending if this is a binary or compile merge
1124
	[ "${EMERGE_FROM}" == "binary" ] && IMAGE=${PKG_TMPDIR}/${PF}/bin \
1136
	[ "${EMERGE_FROM}" == "binary" ] && IMAGE=${PKG_TMPDIR}/${PF}/bin \
1125
					|| IMAGE=${D}
1137
					|| IMAGE=${D}
1126
1138
	[ -n "$INSTALLWATCHFILE" ] && iw_begin
1127
	pkg_preinst
1139
	pkg_preinst
1140
	[ -n "$INSTALLWATCHFILE" ] && iw_end
1128
1141
1129
	# hopefully this will someday allow us to get rid of the no* feature flags
1142
	# hopefully this will someday allow us to get rid of the no* feature flags
1130
	# we don't want globbing for initial expansion, but afterwards, we do
1143
	# we don't want globbing for initial expansion, but afterwards, we do
Lines 1749-1754 Link Here
1749
		;;
1762
		;;
1750
	prerm|postrm|postinst|config)
1763
	prerm|postrm|postinst|config)
1751
		export SANDBOX_ON="0"
1764
		export SANDBOX_ON="0"
1765
		[ -n "$INSTALLWATCHFILE" ] && iw_begin
1752
		if [ "$PORTAGE_DEBUG" != "1" ]; then
1766
		if [ "$PORTAGE_DEBUG" != "1" ]; then
1753
			pkg_${myarg}
1767
			pkg_${myarg}
1754
			#Allow non-zero return codes since they can be caused by &&
1768
			#Allow non-zero return codes since they can be caused by &&
Lines 1758-1763 Link Here
1758
			#Allow non-zero return codes since they can be caused by &&
1772
			#Allow non-zero return codes since they can be caused by &&
1759
			set +x
1773
			set +x
1760
		fi
1774
		fi
1775
		[ -n "$INSTALLWATCHFILE" ] && iw_end
1761
		;;
1776
		;;
1762
	unpack|compile|test|clean|install)
1777
	unpack|compile|test|clean|install)
1763
		if [ "${SANDBOX_DISABLED="0"}" == "0" ]; then
1778
		if [ "${SANDBOX_DISABLED="0"}" == "0" ]; then
(-)portage-2.0.51.20.orig/pym/portage_installwatch.py (+126 lines)
Line 0 Link Here
1
import errno
2
import os
3
import stat
4
import portage_checksum
5
6
def file_text_description(fullpath, root, delim):
7
	"""Create a string similar to portage CONTENTS format"""
8
	mystat=os.lstat(fullpath)
9
	mymode=mystat[stat.ST_MODE]
10
	mymtime=mystat[stat.ST_MTIME]
11
	
12
	path=fullpath
13
	if root!="/" and path[0:len(root)] == root:
14
		path=path[len(root)-1:]
15
	
16
	if stat.S_ISLNK(mymode):
17
		myto=os.readlink(fullpath)
18
		return "sym"+delim+path+delim+"->"+delim+myto+delim+str(mymtime)
19
	elif stat.S_ISDIR(mymode):
20
		return "dir"+delim+path
21
	elif stat.S_ISREG(mymode):
22
		mymd5=portage_checksum.perform_md5(fullpath,calc_prelink=1)
23
		return "obj"+delim+path+delim+mymd5+delim+str(mymtime)
24
	elif stat.S_ISFIFO(mymode):
25
		return "fif"+delim+path
26
	else:
27
		return "unk"+delim+path
28
29
def process_iw_log(sandbox_debug_file, output_file, root, delim):
30
	"""Convert sandbox_debug_file to Portage CONTENTS format.
31
	The output_file can be the same file as the input sandbox_debug_file
32
	The output_file will be automatically removed if there is no output
33
	Returns 0 on success, 1 if the input file does not exist or there is no output"""
34
	try:
35
		infile=open(sandbox_debug_file,"r")
36
	except EnvironmentError, e:
37
		if e.errno == errno.ENOENT:
38
			return 1
39
		else:
40
			raise e
41
	possible_file_creation=[
42
		"open_wr",
43
		"creat",
44
		"creat64",
45
		"mkdir",
46
		"mknod",
47
		"mkfifo",
48
		"link",
49
		"symlink",
50
		"rename"
51
	]
52
53
	unique_files=[]
54
	try:
55
		for line in infile:
56
			for prefix in possible_file_creation:
57
				if line.startswith(prefix):
58
					fullpath=line[11:-1]
59
					if fullpath not in unique_files:
60
						unique_files.append(fullpath)
61
					break
62
	except StopIteration, si:
63
		pass
64
	infile.close()
65
66
	unique_files.sort()
67
	outfile=open(output_file,"w")
68
	ignore_list=["/dev/null","/dev/tty"]
69
	for fullpath in unique_files:
70
		if fullpath not in ignore_list:
71
			try:
72
				outfile.write(file_text_description(fullpath, root, delim)+"\n")
73
			except EnvironmentError, e:
74
				if e.errno == errno.ENOENT:
75
					# These files don't necessarily exist
76
					pass
77
				else:
78
					raise e
79
	outfile.flush()
80
	outfile.close()
81
82
	if os.path.getsize(output_file)==0:
83
		os.unlink(output_file);
84
		return 1
85
86
	return 0
87
88
def read_contents(contents_file_path):
89
	"""Read a portage CONTENTS file and return a list of files"""
90
	files=[]
91
	myc=open(contents_file_path,"r")
92
	mylines=myc.readlines()
93
	myc.close()
94
	for line in mylines:
95
		mydat = line.split()
96
		files.append(mydat[1])
97
	return files
98
99
def remove_duplicates(primary, secondary):
100
	"""remove lines from secondary which alread occur in primary
101
	The secondary will be automatically removed if it contains no unique files
102
	Return 0 upon success or 1 if secodary does not exist"""
103
	infile=None
104
	try:
105
		infile=open(secondary,"r")
106
	except EnvironmentError, e:
107
		if e.errno == errno.ENOENT:
108
			return 1
109
		else:
110
			raise e
111
	secondary_lines=infile.readlines()
112
	infile.close()
113
	primary_files=read_contents(primary)
114
	
115
	outfile=open(secondary,"w")
116
	for line in secondary_lines:
117
		mydat = line.split()
118
		if mydat[1] not in primary_files:
119
			# line already ends with \n
120
			outfile.write(line)
121
	outfile.close()
122
	
123
	if os.path.getsize(secondary)==0:
124
		os.unlink(secondary);
125
	
126
	return 0
(-)portage-2.0.51.20.orig/pym/portage.py (-15 / +36 lines)
Lines 1564-1570 Link Here
1564
1564
1565
# XXX This would be to replace getstatusoutput completely.
1565
# XXX This would be to replace getstatusoutput completely.
1566
# XXX Issue: cannot block execution. Deadlock condition.
1566
# XXX Issue: cannot block execution. Deadlock condition.
1567
def spawn(mystring,mysettings,debug=0,free=0,droppriv=0,fd_pipes=None,**keywords):
1567
def spawn(mystring,mysettings,debug=0,free=0,droppriv=0,fd_pipes=None,iw_log=None,**keywords):
1568
	"""spawn a subprocess with optional sandbox protection, 
1568
	"""spawn a subprocess with optional sandbox protection, 
1569
	depending on whether sandbox is enabled.  The "free" argument,
1569
	depending on whether sandbox is enabled.  The "free" argument,
1570
	when set to 1, will disable sandboxing.  This allows us to 
1570
	when set to 1, will disable sandboxing.  This allows us to 
Lines 1589-1595 Link Here
1589
1589
1590
	if ("sandbox" in features) and (not free):
1590
	if ("sandbox" in features) and (not free):
1591
		keywords["opt_name"] += " sandbox"
1591
		keywords["opt_name"] += " sandbox"
1592
		if droppriv and portage_gid and portage_uid:
1592
		if iw_log:
1593
			env["INSTALLWATCHFILE"]=iw_log
1594
		elif droppriv and portage_gid and portage_uid:
1593
			keywords.update({"uid":portage_uid,"gid":portage_gid,"groups":[portage_gid],"umask":002})
1595
			keywords.update({"uid":portage_uid,"gid":portage_gid,"groups":[portage_gid],"umask":002})
1594
		return portage_exec.spawn_sandbox(mystring,env=env,**keywords)
1596
		return portage_exec.spawn_sandbox(mystring,env=env,**keywords)
1595
	else:
1597
	else:
Lines 2314-2320 Link Here
2314
				droppriv=actionmap[mydo]["args"][1],logfile=logfile)
2316
				droppriv=actionmap[mydo]["args"][1],logfile=logfile)
2315
	return retval
2317
	return retval
2316
2318
2317
def doebuild(myebuild,mydo,myroot,mysettings,debug=0,listonly=0,fetchonly=0,cleanup=0,dbkey=None,use_cache=1,fetchall=0,tree="porttree"):
2319
def doebuild(myebuild,mydo,myroot,mysettings,debug=0,listonly=0,fetchonly=0,cleanup=0,dbkey=None,use_cache=1,fetchall=0,tree="porttree",iw_log=None):
2318
	global db
2320
	global db
2319
	
2321
	
2320
	ebuild_path = os.path.abspath(myebuild)
2322
	ebuild_path = os.path.abspath(myebuild)
Lines 2595-2601 Link Here
2595
		return spawn(EBUILD_SH_BINARY+" "+mydo,mysettings,debug=debug,free=1,logfile=logfile)
2597
		return spawn(EBUILD_SH_BINARY+" "+mydo,mysettings,debug=debug,free=1,logfile=logfile)
2596
	elif mydo in ["prerm","postrm","preinst","postinst","config"]:
2598
	elif mydo in ["prerm","postrm","preinst","postinst","config"]:
2597
		mysettings.load_infodir(pkg_dir)
2599
		mysettings.load_infodir(pkg_dir)
2598
		return spawn(EBUILD_SH_BINARY+" "+mydo,mysettings,debug=debug,free=1,logfile=logfile)
2600
		free=1
2601
		if iw_log:
2602
			free=0
2603
		return spawn(EBUILD_SH_BINARY+" "+mydo,mysettings,debug=debug,free=free,logfile=logfile,iw_log=iw_log)
2599
	
2604
	
2600
	try: 
2605
	try: 
2601
		mysettings["SLOT"],mysettings["RESTRICT"] = db["/"]["porttree"].dbapi.aux_get(mycpv,["SLOT","RESTRICT"])
2606
		mysettings["SLOT"],mysettings["RESTRICT"] = db["/"]["porttree"].dbapi.aux_get(mycpv,["SLOT","RESTRICT"])
Lines 6428-6439 Link Here
6428
		print ">>> Merging",self.mycpv,"to",destroot
6433
		print ">>> Merging",self.mycpv,"to",destroot
6429
6434
6430
		# run preinst script
6435
		# run preinst script
6436
		iw_log=None
6437
		if "installwatch" in features:
6438
			iw_log=self.dbtmpdir+"/PREINST"
6431
		if myebuild:
6439
		if myebuild:
6432
			# if we are merging a new ebuild, use *its* pre/postinst rather than using the one in /var/db/pkg
6440
			# if we are merging a new ebuild, use *its* pre/postinst rather than using the one in /var/db/pkg
6433
			# (if any).
6441
			# (if any).
6434
			a=doebuild(myebuild,"preinst",root,self.settings,cleanup=cleanup,use_cache=0)
6442
			a=doebuild(myebuild,"preinst",root,self.settings,cleanup=cleanup,use_cache=0,iw_log=iw_log)
6435
		else:
6443
		else:
6436
			a=doebuild(inforoot+"/"+self.pkg+".ebuild","preinst",root,self.settings,cleanup=cleanup,use_cache=0)
6444
			a=doebuild(inforoot+"/"+self.pkg+".ebuild","preinst",root,self.settings,cleanup=cleanup,use_cache=0,iw_log=iw_log)
6445
6446
		if iw_log:
6447
			import portage_installwatch
6448
			portage_installwatch.process_iw_log(iw_log, iw_log, root, " ")
6437
6449
6438
		# XXX: Decide how to handle failures here.
6450
		# XXX: Decide how to handle failures here.
6439
		if a != 0:
6451
		if a != 0:
Lines 6514-6526 Link Here
6514
			self.dbdir = self.dbtmpdir
6526
			self.dbdir = self.dbtmpdir
6515
			print ">>> original instance of package unmerged safely."	
6527
			print ">>> original instance of package unmerged safely."	
6516
6528
6517
		# We hold both directory locks.
6518
		self.dbdir = self.dbpkgdir
6519
		self.delete()
6520
		movefile(self.dbtmpdir, self.dbpkgdir, mysettings=self.settings)
6521
6522
		self.unlockdb()
6523
6524
		#write out our collection of md5sums
6529
		#write out our collection of md5sums
6525
		if cfgfiledict.has_key("IGNORE"):
6530
		if cfgfiledict.has_key("IGNORE"):
6526
			del cfgfiledict["IGNORE"]
6531
			del cfgfiledict["IGNORE"]
Lines 6545-6556 Link Here
6545
		portage_locks.unlockfile(mylock)
6550
		portage_locks.unlockfile(mylock)
6546
		
6551
		
6547
		#do postinst script
6552
		#do postinst script
6553
		iw_log=None
6554
		if "installwatch" in features:
6555
			iw_log=self.dbtmpdir+"/POSTINST"
6548
		if myebuild:
6556
		if myebuild:
6549
			# if we are merging a new ebuild, use *its* pre/postinst rather than using the one in /var/db/pkg 
6557
			# if we are merging a new ebuild, use *its* pre/postinst rather than using the one in /var/db/pkg 
6550
			# (if any).
6558
			# (if any).
6551
			a=doebuild(myebuild,"postinst",root,self.settings,use_cache=0)
6559
			a=doebuild(myebuild,"postinst",root,self.settings,use_cache=0,iw_log=iw_log)
6552
		else:
6560
		else:
6553
			a=doebuild(inforoot+"/"+self.pkg+".ebuild","postinst",root,self.settings,use_cache=0)
6561
			a=doebuild(inforoot+"/"+self.pkg+".ebuild","postinst",root,self.settings,use_cache=0,iw_log=iw_log)
6562
6563
		if iw_log:
6564
			import portage_installwatch
6565
			portage_installwatch.process_iw_log(iw_log, iw_log, root, " ")
6566
			portage_installwatch.remove_duplicates(self.dbtmpdir+"/CONTENTS", self.dbtmpdir+"/POSTINST")
6567
			portage_installwatch.remove_duplicates(self.dbtmpdir+"/CONTENTS", self.dbtmpdir+"/PREINST")
6568
6569
		# We hold both directory locks.
6570
		self.dbdir = self.dbpkgdir
6571
		self.delete()
6572
		movefile(self.dbtmpdir, self.dbpkgdir, mysettings=self.settings)
6573
6574
		self.unlockdb()
6554
6575
6555
		# XXX: Decide how to handle failures here.
6576
		# XXX: Decide how to handle failures here.
6556
		if a != 0:
6577
		if a != 0:

Return to bug 90343