Skip to content

Commit

Permalink
honor --cwd for --shell
Browse files Browse the repository at this point in the history
Additionally change to `chroothome` when --shell.

Relates: #693
  • Loading branch information
xsuchy authored and praiskup committed May 21, 2021
1 parent f4af0ef commit 707da91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mock/docs/mock.1
Expand Up @@ -260,7 +260,7 @@ If a pkg fails to build, continue to the next one, default is to stop.
Works only with \fB\-\-chain\fR.
.TP
\fB\-\-cwd\fR=\fIDIR\fP
Change to the specified directory (relative to the chroot) before running command when using \-\-chroot
Change to the specified directory (relative to the chroot) before running command when using \-\-chroot or \-\-shell.
.TP
\fB\-D \fR"\fIMACRO EXPR\fP", \fB\-\-define\fR="\fIMACRO EXPR\fP"
Specify macro definitions used for the build. This option may be used multiple times, just as the rpmbuild \-\-define option can be. For example:
Expand Down
4 changes: 4 additions & 0 deletions mock/py/mockbuild/backend.py
Expand Up @@ -350,11 +350,15 @@ def shell(self, options, cmd=None):
else:
uid = 0
gid = 0
cwd = options.cwd
if not cwd:
cwd = self.config['chroothome']

try:
self.state.start("shell")
ret = util.doshell(chrootPath=self.buildroot.make_chroot_path(),
environ=self.buildroot.env, uid=uid, gid=gid,
cwd=cwd,

This comment has been minimized.

Copy link
@martinpitt

martinpitt Jun 28, 2021

This got uploaded to EPEL 7 and broke mock --shell there. Please see https://bugzilla.redhat.com/show_bug.cgi?id=1976702 for details.

nspawn_args=self._get_nspawn_args(),
unshare_net=self.private_network,
cmd=cmd)
Expand Down
5 changes: 3 additions & 2 deletions mock/py/mockbuild/util.py
Expand Up @@ -762,6 +762,7 @@ def _prepare_nspawn_command(chrootPath, user, cmd, nspawn_args=None, env=None,
return nspawn_argv + cmd

def doshell(chrootPath=None, environ=None, uid=None, gid=None, cmd=None,
cwd=None,
nspawn_args=None,
unshare_ipc=True,
unshare_net=False):
Expand All @@ -786,7 +787,7 @@ def doshell(chrootPath=None, environ=None, uid=None, gid=None, cmd=None,
elif isinstance(cmd, list):
cmd = ' '.join(cmd)

preexec = ChildPreExec(personality=None, chrootPath=chrootPath, cwd=None,
preexec = ChildPreExec(personality=None, chrootPath=chrootPath, cwd=cwd,
uid=uid, gid=gid, env=environ, shell=shell,
unshare_ipc=unshare_ipc, unshare_net=unshare_net,
no_setsid=no_setsid)
Expand All @@ -795,7 +796,7 @@ def doshell(chrootPath=None, environ=None, uid=None, gid=None, cmd=None,
# nspawn cannot set gid
log.debug("Using nspawn with args %s", nspawn_args)
cmd = _prepare_nspawn_command(chrootPath, uid, cmd, nspawn_args=nspawn_args, env=environ,
interactive=True)
interactive=True, cwd=cwd)
environ['SYSTEMD_NSPAWN_TMPFS_TMP'] = '0'
shell = False

Expand Down

0 comments on commit 707da91

Please sign in to comment.