strang1ato/nhi

Output of commands not saved when vim is ran

Opened this issue · 4 comments

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:

nhi/daemon/src/nhi.bpf.c

Lines 393 to 404 in a3c65cc

} else if (write_event->output[i+7] == 'l') {
helper->omit_write = 0;
bpf_map_update_elem(&shells, &shell_index, helper, BPF_ANY);
write_event->output[i] = 0;
write_event->output[i+1] = 0;
write_event->output[i+2] = 0;
write_event->output[i+3] = 0;
write_event->output[i+4] = 0;
write_event->output[i+5] = 0;
write_event->output[i+6] = 0;
write_event->output[i+7] = 0;
}

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).

@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 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

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 (#14)

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

@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)