Skip to content

Commit 761c649

Browse files
committed
TerminalShell: better support for environment running with su
1 parent a2f576f commit 761c649

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/detection/terminalshell/terminalshell.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,22 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
455455
}
456456
}
457457

458+
termProgramVersion = getenv("LC_TERMINAL_VERSION");
459+
if(termProgramVersion)
460+
{
461+
const char* termProgram = getenv("LC_TERMINAL");
462+
if(termProgram)
463+
{
464+
if(ffStrbufStartsWithIgnCaseS(processName, termProgram) || // processName ends with `.exe` on Windows
465+
(ffStrEquals(termProgram, "vscode") && ffStrbufStartsWithIgnCaseS(processName, "code")) ||
466+
(ffStrStartsWith(termProgram, "iTerm") && ffStrbufStartsWithIgnCaseS(processName, "iTermServer-"))
467+
) {
468+
ffStrbufSetS(version, termProgramVersion);
469+
return true;
470+
}
471+
}
472+
}
473+
458474
#ifdef _WIN32
459475

460476
return getFileVersion(exe->chars, version);

src/detection/terminalshell/terminalshell_linux.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid)
139139
strcasecmp(name, "sshd") == 0 ||
140140
strcasecmp(name, "gdb") == 0 ||
141141
strcasecmp(name, "lldb") == 0 ||
142+
strcasecmp(name, "login") == 0 ||
142143
strcasecmp(name, "guake-wrapped") == 0 ||
143144
strcasestr(name, "debug") != NULL ||
144145
strcasestr(name, "command-not-found") != NULL ||
@@ -251,6 +252,9 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
251252
if(!ffStrSet(term))
252253
term = getenv("TERM_PROGRAM");
253254

255+
if(!ffStrSet(term))
256+
term = getenv("LC_TERMINAL");
257+
254258
//Normal Terminal
255259
if(!ffStrSet(term))
256260
term = getenv("TERM");

0 commit comments

Comments
 (0)