1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-16 10:36:13 +01:00

osc chroot: also mount devpts

This is needed for running expect, for example.
This commit is contained in:
Andreas Schwab 2018-01-28 15:40:34 +01:00
parent 5e3fe8ba08
commit 50222810f0

View File

@ -6449,45 +6449,59 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if suwrapper.startswith('su '): if suwrapper.startswith('su '):
mntproc = [sucmd, '%s mount -n -tproc none %s/proc' % (suargs, buildroot)] mntproc = [sucmd, '%s mount -n -tproc none %s/proc' % (suargs, buildroot)]
mntsys = [sucmd, '%s mount -n -tsysfs none %s/sys' % (suargs, buildroot)] mntsys = [sucmd, '%s mount -n -tsysfs none %s/sys' % (suargs, buildroot)]
mntdevpts = [sucmd, '%s mount -n -tdevpts -omode=0620,gid=5 none %s/dev/pts' % (suargs, buildroot)]
umntproc = [sucmd, '%s umount %s/proc' % (suargs, buildroot)] umntproc = [sucmd, '%s umount %s/proc' % (suargs, buildroot)]
umntsys = [sucmd, '%s umount %s/sys' % (suargs, buildroot)] umntsys = [sucmd, '%s umount %s/sys' % (suargs, buildroot)]
umntdevpts = [sucmd, '%s umount %s/devpts' % (suargs, buildroot)]
cmd = [sucmd, '%s chroot "%s" su - %s' % (suargs, buildroot, user)] cmd = [sucmd, '%s chroot "%s" su - %s' % (suargs, buildroot, user)]
else: else:
mntproc = [sucmd, 'mount', '-n', '-tproc' , 'none', '%s/proc' % buildroot] mntproc = [sucmd, 'mount', '-n', '-tproc' , 'none', '%s/proc' % buildroot]
mntsys = [sucmd, 'mount', '-n', '-tsysfs' , 'none', '%s/sys' % buildroot] mntsys = [sucmd, 'mount', '-n', '-tsysfs' , 'none', '%s/sys' % buildroot]
mntdevpts = [sucmd, 'mount', '-n', '-tdevpts' , '-omode=0620,gid=5', 'none', '%s/dev/pts' % buildroot]
umntproc = [sucmd, 'umount', '%s/proc' % buildroot] umntproc = [sucmd, 'umount', '%s/proc' % buildroot]
umntsys = [sucmd, 'umount', '%s/sys' % buildroot] umntsys = [sucmd, 'umount', '%s/sys' % buildroot]
umntdevpts = [sucmd, 'umount', '%s/dev/pts' % buildroot]
cmd = [sucmd, 'chroot', buildroot, 'su', '-', user] cmd = [sucmd, 'chroot', buildroot, 'su', '-', user]
if suargs: if suargs:
mntproc[1:1] = suargs.split() mntproc[1:1] = suargs.split()
mntsys[1:1] = suargs.split()
mntdevpts[1:1] = suargs.split()
umntproc[1:1] = suargs.split() umntproc[1:1] = suargs.split()
umntsys[1:1] = suargs.split()
umntdevpts[1:1] = suargs.split()
cmd[1:1] = suargs.split() cmd[1:1] = suargs.split()
#signal handler for chroot procfs umount #signal handler for chroot procfs umount
def umount_handle(signum = None, frame = None, ret=1): def umount_handle(signum = None, frame = None, ret=1):
subprocess.call(umntproc) subprocess.call(umntproc)
subprocess.call(umntsys) subprocess.call(umntsys)
subprocess.call(umntdevpts)
sys.exit(ret) sys.exit(ret)
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]: for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
signal.signal(sig, umount_handle) signal.signal(sig, umount_handle)
print('mounting proc: %s' % ' '.join(mntproc)) print('mounting proc: %s' % ' '.join(mntproc))
print('mounting sys: %s' % ' '.join(mntsys)) print('mounting sys: %s' % ' '.join(mntsys))
print('mounting devpts: %s' % ' '.join(mntdevpts))
mount_err = -1 mount_err = -1
proc_mount_err = subprocess.call(mntproc) proc_mount_err = subprocess.call(mntproc)
sys_mount_err = subprocess.call(mntsys) sys_mount_err = subprocess.call(mntsys)
devpts_mount_err = subprocess.call(mntdevpts)
if proc_mount_err > 0: if proc_mount_err > 0:
print('There was an error mounting proc. Please check mountpoints in chroot') print('There was an error mounting proc. Please check mountpoints in chroot')
if sys_mount_err > 0: if sys_mount_err > 0:
print('There was an error mounting sys. Please check mountpoints in chroot') print('There was an error mounting sys. Please check mountpoints in chroot')
if devpts_mount_err > 0:
print('There was an error mounting devpts. Please check mountpoints in chroot')
print('running: %s' % ' '.join(cmd)) print('running: %s' % ' '.join(cmd))
retval = 0 retval = 0
try: try:
retval = subprocess.call(cmd) retval = subprocess.call(cmd)
finally: finally:
if ((not proc_mount_err or proc_mount_err == 32) and if ((not proc_mount_err or proc_mount_err == 32) and
(not sys_mount_err or sys_mount_err == 32)): (not sys_mount_err or sys_mount_err == 32) and
print('unmounting %s/proc and %s/sys ...' % (buildroot, buildroot)) (not devpts_mount_err or devpts_mount_err == 32)):
print('unmounting %s/proc and %s/sys and %s/dev/pts ...' % (buildroot, buildroot, buildroot))
umount_handle(ret=retval) umount_handle(ret=retval)