Skip to content

Commit

Permalink
feat: add --stealth-stdout and --stealth-stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
speed47 committed Sep 15, 2023
1 parent a13ca74 commit c2e089c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- name: compile with zstd autodetection (none)
run: |
sudo apt-get remove --purge -y libzstd-dev
make clean && ./configure && make -j$(nproc) && ./ttyrec -V
if ./ttyrec -V | grep -qF 'zstd'; then
exit 1
Expand Down
3 changes: 2 additions & 1 deletion compress_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ size_t fwrite_wrapper_zstd(const void *ptr, size_t size, size_t nmemb, FILE *str
}

size_t written = 0;
ZSTD_inBuffer input = { ptr, size * nmemb, 0 };
ZSTD_inBuffer input = { ptr, size *nmemb, 0 };

while (input.pos < input.size)
{
ZSTD_outBuffer output = { buffOut, buffOutSize, 0 };
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ovh-ttyrec (1.1.7.0) master; urgency=medium

* feat: add --stealth-stdout and --stealth-stderr

-- Stéphane Lesimple (deb packages) <stephane.lesimple@corp.ovh.com> Fri, 15 Sep 2023 15:39:33 +0200

ovh-ttyrec (1.1.6.7) master; urgency=medium

* fix: rare interlocking on exit
Expand Down
5 changes: 4 additions & 1 deletion ovh-ttyrec.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Summary: Extended (but compatible) fork of ttyrec
Name: ovh-ttyrec
Version: 1.1.6.7
Version: 1.1.7.0
Release: 1
License: BSD
Group: Applications/System
Expand Down Expand Up @@ -55,6 +55,9 @@ rm -rf -- "$RPM_BUILD_ROOT"
%{_bindir}/ttyrec

%changelog
* Fri Sep 15 2023 Stéphane Lesimple (deb packages) <stephane.lesimple@corp.ovh.com> 1.1.7.0
- feat: add --stealth-stdout and --stealth-stderr

* Mon Mar 29 2021 Stéphane Lesimple (deb packages) <stephane.lesimple@corp.ovh.com> 1.1.6.7
- fix: rare interlocking on exit
- enh: default install prefix is now /usr/local
Expand Down
1 change: 1 addition & 0 deletions ttyplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ double ttywait(struct timeval prev, struct timeval cur, double speed)
* Save "diff" since select(2) may overwrite it to {0, 0}.
*/
struct timeval orig_diff = diff;

select(1, &readfs, NULL, NULL, &diff);
diff = orig_diff; /* Restore the original diff value. */
if (FD_ISSET(0, &readfs)) /* a user hits a character? */
Expand Down
40 changes: 37 additions & 3 deletions ttyrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static time_t locked_since = 0;
static int lock_warned = 0;
static int kill_warned = 0;

static const char version[] = "1.1.6.7";
static const char version[] = "1.1.7.0";

static FILE *fscript;
static int child;
Expand Down Expand Up @@ -250,6 +250,8 @@ static int opt_append = 0;
static int opt_debug = 0;
static int opt_count_bytes = 0;
static int opt_cheatcodes = 0;
static int opt_stealth_stdout = 0;
static int opt_stealth_stderr = 0;
static char *opt_custom_message = NULL;

static int use_tty = 1; // no=0, yes=1
Expand All @@ -274,6 +276,12 @@ int main(int argc, char **argv)
{
static struct option long_options[] =
{
/*
* "long-opt-name", a, b, c
* a: 1 if requires an arg, 0 otherwise
* b: always 0
* c: an optional char for the corresponding short-option, 0 otherwise
*/
{ "zstd", 0, 0, 0 },
{ "level", 1, 0, 'l' },
{ "verbose", 0, 0, 'v' },
Expand All @@ -290,6 +298,8 @@ int main(int argc, char **argv)
{ "msg", 1, 0, 's' },
{ "count-bytes", 0, 0, 'n' },
{ "term", 1, 0, 'T' },
{ "stealth-stdout", 0, 0, 0 },
{ "stealth-stderr", 0, 0, 0 },
{ "version", 0, 0, 'V' },
{ "help", 0, 0, 'h' },
{ "max-flush-time", 1, 0, 0 },
Expand Down Expand Up @@ -356,6 +366,14 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
}
else if (strcmp(long_options[option_index].name, "stealth-stdout") == 0)
{
opt_stealth_stdout = 1;
}
else if (strcmp(long_options[option_index].name, "stealth-stderr") == 0)
{
opt_stealth_stderr = 1;
}
else
{
fprintf(stderr, "Unknown long option %s\r\n", long_options[option_index].name);
Expand Down Expand Up @@ -1168,6 +1186,7 @@ void lock_session(int signal)

char hostname[BUFSIZ];
struct utsname name;

if (uname(&name))
{
hostname[0] = '\0';
Expand All @@ -1186,6 +1205,7 @@ void lock_session(int signal)
"Sincerely yours", "Take care",
"Cheers", "With deepest sympathy",
};

#define salute_len (sizeof(salute) / sizeof(const char *))

// save cursor pos, save buffer, clear screen, put cursor at home position, hide cursor
Expand Down Expand Up @@ -1322,6 +1342,7 @@ void dooutput(void)
for ( ; ;)
{
Header h;
int dont_write = 0;

// we have a tty
if (use_tty)
Expand Down Expand Up @@ -1388,13 +1409,21 @@ void dooutput(void)
current_fd_name = "stderr";
pipe_flag = &stderr_pipe_opened;
target_fd = 2; // stderr
if (opt_stealth_stderr)
{
dont_write = 1; // don't write buffer to ttyrec file, see below
}
}
else if (FD_ISSET(stdout_pipe[0], &rfds))
{
current_fd = stdout_pipe[0];
current_fd_name = "stdout";
pipe_flag = &stdout_pipe_opened;
target_fd = 1; // stdout
if (opt_stealth_stdout)
{
dont_write = 1; // don't write buffer to ttyrec file, see below
}
}
else
{
Expand Down Expand Up @@ -1450,8 +1479,11 @@ void dooutput(void)
break;
}
}
(void)write_header(fscript, &h);
(void)fwrite_wrapper(obuf, 1, cc, fscript);
if (!dont_write)
{
(void)write_header(fscript, &h);
(void)fwrite_wrapper(obuf, 1, cc, fscript);
}
bytes_out += cc;
last_activity = time(NULL);
lock_warned = 0;
Expand Down Expand Up @@ -2087,6 +2119,8 @@ void help(void)
" -T, --term MODE MODE can be either 'never' (never allocate a pseudotty, even if stdin is a tty, and use pipes to\n" \
" handle stdout/stderr instead), 'always' (always allocate a pseudotty, even if stdin is not a tty)\n" \
" or 'auto' (default, allocate a pseudotty if stdin is a tty, uses pipes otherwise)\n" \
" --stealth-stdout when no pseudotty is allocated, don't record stdout\n" \
" --stealth-stderr when no pseudotty is allocated, don't record stderr\n" \
" -v, --verbose verbose (debug) mode, use twice for more verbosity\n" \
" -V, --version show version information\n" \
" -e, --shell-cmd CMD enables legacy compatibility mode and specifies the command to be run under the user's $SHELL -c\n" \
Expand Down

0 comments on commit c2e089c

Please sign in to comment.