Skip to content

Commit 79b7b15

Browse files
committed
Terminal: detect tty name
Fix #738
1 parent 111f711 commit 79b7b15

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/detection/terminalshell/terminalshell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef struct FFTerminalResult
2323
const char* exeName; //pointer to a char in exe
2424
FFstrbuf exePath; //Full real path to executable file
2525
FFstrbuf version;
26+
FFstrbuf tty;
2627
uint32_t pid;
2728
uint32_t ppid;
2829
} FFTerminalResult;

src/detection/terminalshell/terminalshell_linux.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ const FFTerminalResult* ffDetectTerminal()
571571
result.exeName = result.exe.chars;
572572
ffStrbufInit(&result.exePath);
573573
ffStrbufInit(&result.version);
574+
ffStrbufInitS(&result.tty, ttyname(STDOUT_FILENO));
574575
result.pid = 0;
575576
result.ppid = 0;
576577

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ const FFShellResult* ffDetectShell(void)
369369
ffStrbufInit(&result.exePath);
370370
ffStrbufInit(&result.prettyName);
371371
ffStrbufInit(&result.version);
372+
ffStrbufInit(&result.tty);
372373
result.pid = 0;
373374
result.ppid = 0;
374375
result.tty = -1;

src/modules/terminal/terminal.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <string.h>
88

9-
#define FF_TERMINAL_NUM_FORMAT_ARGS 7
9+
#define FF_TERMINAL_NUM_FORMAT_ARGS 8
1010

1111
void ffPrintTerminal(FFTerminalOptions* options)
1212
{
@@ -37,6 +37,7 @@ void ffPrintTerminal(FFTerminalOptions* options)
3737
{FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName},
3838
{FF_FORMAT_ARG_TYPE_STRBUF, &result->version},
3939
{FF_FORMAT_ARG_TYPE_STRBUF, &result->exePath},
40+
{FF_FORMAT_ARG_TYPE_STRBUF, &result->tty},
4041
});
4142
}
4243
}
@@ -95,6 +96,7 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy
9596
yyjson_mut_obj_add_uint(doc, obj, "ppid", result->ppid);
9697
yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->prettyName);
9798
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->version);
99+
yyjson_mut_obj_add_strbuf(doc, obj, "tty", &result->tty);
98100
}
99101

100102
void ffPrintTerminalHelpFormat(void)
@@ -107,6 +109,7 @@ void ffPrintTerminalHelpFormat(void)
107109
"Terminal pretty name",
108110
"Terminal version",
109111
"Terminal full exe path",
112+
"Terminal tty / pts used",
110113
});
111114
}
112115

0 commit comments

Comments
 (0)