From a1b62ca72458efe656052969a05775fbda65fd22 Mon Sep 17 00:00:00 2001 From: Vladimir Lagunov Date: Thu, 29 Feb 2024 18:14:47 +0100 Subject: [PATCH] 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 --- .../src/com/intellij/platform/ijent/IjentSessionProvider.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/ijent/src/com/intellij/platform/ijent/IjentSessionProvider.kt b/platform/ijent/src/com/intellij/platform/ijent/IjentSessionProvider.kt index 5455850e68bf..1578f1ce15ea 100644 --- a/platform/ijent/src/com/intellij/platform/ijent/IjentSessionProvider.kt +++ b/platform/ijent/src/com/intellij/platform/ijent/IjentSessionProvider.kt @@ -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()}" }