IDEA-347916 IJent: bootstrap over shell runs IJent inside the default user shell

The bug existed because a child shell doesn't set the environment variable $SHELL.

```
$ echo $SHELL
/bin/bash
$ /bin/sh -c 'echo $SHELL'
/bin/bash
```

This behaviour is described in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html :

> SHELL
> This variable shall represent a pathname of the user's preferred command language interpreter.

I.e. it should be assumed that `$SHELL == $(getent passwd "$(whoami)" | cut -d: -f7)`

GitOrigin-RevId: dbf778a32e8198e542792e91d40e112ded2590c4
This commit is contained in:
Vladimir Lagunov
2024-03-01 21:34:23 +00:00
committed by intellij-monorepo-bot
parent 4698669667
commit a1b62ca724
@@ -209,7 +209,8 @@ private suspend fun doBootstrapOverShellSession(
val joinedCmd = getIjentGrpcArgv(remotePathToBinary, selfDeleteOnExit = true).joinToString(" ")
val commandLineArgs =
"""cd ${posixQuote(remotePathToBinary.substringBeforeLast('/'))}""" +
"""; exec "$(getent passwd "${'$'}(whoami)" | cut -d: -f7)" -c ${posixQuote(joinedCmd)}""" +
"""; export SHELL="${'$'}(getent passwd "${'$'}(whoami)" | cut -d: -f7)" """ +
"""; exec "${'$'}SHELL" -c ${posixQuote(joinedCmd)}""" +
"\n"
LOG.trace { "Executing IJent inside a shell: ${commandLineArgs.trimEnd()}" }