[BUG] Error when run as non-root and there is a pending reboot
When I've got a pending reboot (kernel update), running tracer as non-root reports an error:
[riehecky@testify ~]$ tracer -vv
You can't open package database due to insufficient permissions
You will probably need to run tracer as root
[riehecky@testify ~]$ tracer --show-resource system
Python: 3.9.21
Distribution: rhel
Package Manager: Dnf, Yum
Init system: systemd
Uptime: 5 days, 22:48:29
User: riehecky
Tracer version: 1.1
Rules: 30
Applications: 57
[riehecky@testify ~]$ rpm -qa |wc
2473 2473 86478
Can this be modified to run as non-root since I'm able to query the package database?
since I'm able to query the package database?
I don't think you are because we don't throw the exception preemptively, only when a database operation fails https://github.com/FrostyX/tracer/blob/edd31423b32f78b587c47424e262398d70d55386/tracer/packageManagers/rpm.py#L95-L96
The problem is that RPM and DNF have their own separate databases. You can access the RPM database but not the DNF one.
I'm showing world read on what I think is the dnf database:
[riehecky@testify ~]$ ls -l /var/lib/dnf/history.sqlite
-rw-r--r--. 1 root root 2428928 Jul 29 10:04 /var/lib/dnf/history.sqlite
Am I looking in the wrong place?
Oh, you are absolutely right. This is weird ... I put a debugger into the code I lined above:
[jkadlcik@hive tracer]$ PYTHONPATH=/home/jkadlcik/git/tracer/ ~/git/tracer/bin/tracer.py
> /home/jkadlcik/git/tracer/tracer/packageManagers/rpm.py(96)packages_newer_than()
-> breakpoint()
(Pdb) pp e
OperationalError('attempt to write a readonly database')
And the exception is thrown by cursor.execute(sql, [unix_time]).
This is only a problem for DNF4 https://github.com/FrostyX/tracer/blob/35a40c8138fe86581e41207f3537da013c7742dc/tracer/packageManagers/dnf.py#L31
The DNF5 class works without root permissions, so maybe the solution for the future will be dropping DNF4 support https://github.com/FrostyX/tracer/blob/35a40c8138fe86581e41207f3537da013c7742dc/tracer/packageManagers/dnf.py#L70
With RHEL10 still DNF4 based, there is a lot of time left in the DNF4 world.
Part of the fix seems to be:
conn = sqlite3.connect('file:' + sqlite + '?mode=ro', uri=True)
which puts sqlite in read-only mode (python 3.6+ required)