Commits

Michał Górny  committed 0020370

Explicitly handle SIGCHLD.

The os.kill() is performed with root privileges, so it's unacceptable to
kill a random PID.

  • Participants
  • Parent commits 3911841

Comments (0)

Files changed (1)

File smartliverebuild/core.py

 		out.err('The argument to --jobs option must be a positive integer.')
 		raise SLRFailure('')
 
+	global childpid
 	childpid = None
 	commpipe = None
 	superuser = (os.geteuid() == 0)
 		portage_gid = pm_conf.userpriv_gid
 		if portage_uid and portage_gid:
 			if superuser:
+				def chld_handler(sig, frame):
+					global childpid
+					if os.wait()[0] == childpid:
+						childpid = None
+
 				out.s1('Forking to drop superuser privileges ...')
+				old_chld = signal.signal(signal.SIGCHLD, chld_handler)
 				commpipe = os.pipe()
 				childpid = os.fork()
+
+				if childpid == 0:
+					signal.signal(signal.SIGCHLD, old_chld)
 		else:
 			out.err("setuid requested but there's no 'portage' user in the system")
 			return 1
 			out.result('Found %s%d%s packages to rebuild.' % (out.white, len(packages), out.s1reset))
 	finally:
 		if childpid: # make sure that we leave no orphans
-			try:
-				os.kill(childpid, signal.SIGTERM)
-			except OSError:
-				pass
+			os.kill(childpid, signal.SIGTERM)
 
 	return packages