strang1ato / nhi

:tv: Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism
GNU General Public License v3.0
295 stars 11 forks source link

Output of commands not saved when vim is ran #18

Open syn-lw opened 1 year ago

syn-lw commented 1 year ago

Hello,

Thank you, this project is really cool!

However, my commands are not logged after running commands such as vim:

vagrant@bullseye:~$ nhi fetch {-1}
vagrant@bullseye:~$ echo test
test
vagrant@bullseye:~$ vim
vagrant@bullseye:~$ echo test
(nothing here)

This issue seems to come from here: https://github.com/strang1ato/nhi/blob/a3c65ccf4a7600d5dea264eba924afd234191e06/daemon/src/nhi.bpf.c#L393-L404

Looking in the database (at /var/nhi/db), I can see:

echo test
b'\xfftest\n'
vim
b'\xff\x1b[?1000h\xff\x1b[34h\x1b[?25h\x00\x00\x00\x00\x00\x00\x00\x00'
echo test
b''

The last 8 bytes are set to \x00 which should mean that omit_write is set to zero, but I do not understand why it still refuses to log the next commands.

On another note, it would be nice to remove the null bytes and the rest of what was logged (\x1b[?1000h\xff\x1b[34h\x1b[?25h), it messes up my terminal after executing nhi fetch (which makes me have to execute reset to clean my terminal).

strang1ato commented 1 year ago

@syn-lw What terminal are you using? Also, can you share here content of /tmp/nhi.log file (if exists)

I see that you are using vagrant so you are using ssh, there might be a possibility that this is the cause of the problem. I have not tested how terminal behaviour changes (if changes) while using ssh.

On another note, it would be nice to remove the null bytes and the rest of what was logged (\x1b[?1000h\xff\x1b[34h\x1b[?25h), it messes up my terminal after executing nhi fetch (which makes me have to execute reset to clean my terminal).

That's a nice idea worth another github issue

syn-lw commented 1 year ago

@syn-lw What terminal are you using?

I am using Alacritty with tmux and connecting to my virtual machine using SSH (with nhi being installed in said virtual machine, not on my host).

It seems that the problem comes from tmux (it sets $TERM=screen).

Without tmux:

echo test1
b'\xfftest1\n'
vim
b'\xff\x1b[?12l\x1b[?25h\x00\x00\x00\x00\x00\x00\x00\x00\x1b[23;0;0t'
echo test2
b'\xfftest2\n'

With tmux:

echo test5
b'\xfftest5\n'
vim
b'\xff\x1b[?1000h\xff\x1b[34h\x1b[?25h\x00\x00\x00\x00\x00\x00\x00\x00'
echo test4
b''

Also, can you share here content of /tmp/nhi.log file (if exists)

The file does not exist

strang1ato commented 1 year ago

It seems that the problem comes from tmux (it sets $TERM=screen).

Nhi doesn't currently support tmux. There are other issues with tmux as well (https://github.com/strang1ato/nhi/issues/14)

I will gather information and create proper issue about adding support for tmux

strang1ato commented 1 year ago

@syn-lw Hi, could you share your tmux config. I struggle to reproduce the issue.

(Sorry for bothering after couple of months since opening this issue, but I was pretty busy with life)