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

`nhi` doesn't record commands #12

Closed crides closed 2 years ago

crides commented 2 years ago

Installed from release 0.2.1, nhi fetch shows only the creation of sessions, no commands have been logged, nor the finish of sessions. Same result from within and without tmux

$ uname -a
Linux Aostro-5468 5.14.16-arch1-1 #1 SMP PREEMPT Tue, 02 Nov 2021 22:22:59 +0000 x86_64 GNU/Linux

$ zsh --version
zsh 5.8 (x86_64-pc-linux-gnu)
strang1ato commented 2 years ago

@crides Can you show me the content of /tmp/nhi.log file (this file is created if error occurs, if it doesn't exist that's okay. You need root access to access that file).

and can you run this command and send me the output:

getent group tty

And check if source /etc/nhi/nhi.bash is added to the end of .bashrc or source /etc/nhi/nhi.zsh to the end of .zshrc, accordingly to your shell of choice

crides commented 2 years ago

Contents of /tmp/nhi.log:

2021-11-13 22:28:52 | process_vm_readv failed at get_shell_environ
2021-11-13 22:28:52 | no such table: 0
2021-11-13 22:28:53 | process_vm_readv failed at get_shell_environ
2021-11-13 22:28:53 | no such table: 0
2021-11-13 22:28:57 | process_vm_readv failed at get_shell_environ
2021-11-13 22:28:57 | no such table: 0
2021-11-13 22:29:02 | process_vm_readv failed at get_shell_environ
2021-11-13 22:29:02 | no such table: 0
2021-11-13 22:29:05 | process_vm_readv failed at get_shell_environ
2021-11-13 22:29:05 | no such table: 0
2021-11-13 22:29:08 | process_vm_readv failed at get_shell_environ
2021-11-13 22:29:08 | no such table: 0
2021-11-13 22:29:12 | process_vm_readv failed at get_shell_environ
2021-11-13 22:29:12 | no such table: 0
2021-11-13 22:29:16 | process_vm_readv failed at get_shell_environ
2021-11-13 22:29:16 | no such table: 0
2021-11-13 22:54:52 | process_vm_readv failed at get_shell_environ
2021-11-13 22:54:52 | no such table: 0
2021-11-13 22:55:00 | process_vm_readv failed at get_shell_environ
2021-11-13 22:55:00 | no such table: 0
2021-11-13 22:55:02 | process_vm_readv failed at get_shell_environ
2021-11-13 22:55:02 | no such table: 0
2021-11-13 22:56:31 | process_vm_readv failed at get_shell_environ
2021-11-13 22:56:31 | no such table: 0
2021-11-13 22:58:12 | process_vm_readv failed at get_shell_environ
2021-11-13 22:58:12 | no such table: 0
2021-11-13 22:58:13 | process_vm_readv failed at get_shell_environ
2021-11-13 22:58:13 | no such table: 0
2021-11-13 22:59:56 | process_vm_readv failed at get_shell_environ
2021-11-13 22:59:56 | no such table: 0
2021-11-13 23:00:38 | process_vm_readv failed at get_shell_environ
2021-11-13 23:00:38 | no such table: 0
$getent group tty
tty:x:5:brltty

And yes, I do have source /etc/nhi/nhi.zsh in .zshrc

strang1ato commented 2 years ago

Can you execute one last command: objdump -T $(which zsh) | awk -v sym=environ ' $NF == sym && $4 == ".bss" { print $1; exit }' and also post here the output

crides commented 2 years ago

Output is: 00000000000d4da0

strang1ato commented 2 years ago

I think that I need to replicate this bug myself, what distro are you using?

crides commented 2 years ago

Arch. And just in case terminal matters for some reason, it's Alacritty

Thanks for the fast responses by the way.

strang1ato commented 2 years ago

I will install Alacritty on my arch device and will let you know how it went.

Also, can you temporarly comment out everything besides source /etc/nhi/nhi.zsh from you .zshrc and restart your terminal and see if nhi works?

crides commented 2 years ago

Hmm it does, but only outside of tmux.

And I might bisect the .zshrc later, but it's here if you want to see it. I do have some local changes not yet commited but those are just aliases and functions.

strang1ato commented 2 years ago

So without tmux everything works fine? Keep in mind that some shell builtins are not being traced yet, however everything else is traced.

crides commented 2 years ago

Without tmux and without my .zshrc that is. And I'm testing using the finish time in nhi log

strang1ato commented 2 years ago

But does without tmux and with your zshrc everything works?

crides commented 2 years ago

No

strang1ato commented 2 years ago

@crides Okay I found why nhi wasn't working with your .zshrc and how to fix that. For now I found only "dirty fix", but it works. I will try to fix and patch repository in a few days. (You will need to replace current nhid binary (and maybe nhi.bpf.o file) with new/future one)

(I did not test it on tmux though)

crides commented 2 years ago

Thanks! I'll checkout the commit later (after it happens)

strang1ato commented 2 years ago

@crides I will let you know when it will be done, in this issue, and create a new release with the patch

strang1ato commented 2 years ago

@crides Should be fixed :+1: in your case download nhid only (from v0.2.2 release) and replace it in the place of old nhid in /usr/bin and give 755 permission to the new nhid and restart your computer.

crides commented 2 years ago

Yep that works with tmux + my .zshrc for saving command outputs, but doesn't seem to catch the finish of the sessions (that won't matter to me much, but may be something for you to look into).

Thanks for the help!

strang1ato commented 2 years ago

tmux may break some stuff, but if it works that's good. For now I make sure that nhi supports bash and zsh (without multiplexers and stuff like that).