tracer icon indicating copy to clipboard operation
tracer copied to clipboard

[BUG] Error when run as non-root and there is a pending reboot

Open jcpunk opened this issue 5 months ago • 5 comments

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?

jcpunk avatar Jul 24 '25 18:07 jcpunk

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.

FrostyX avatar Jul 29 '25 14:07 FrostyX

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?

jcpunk avatar Jul 29 '25 15:07 jcpunk

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

FrostyX avatar Jul 29 '25 15:07 FrostyX

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

FrostyX avatar Jul 29 '25 15:07 FrostyX

With RHEL10 still DNF4 based, there is a lot of time left in the DNF4 world.

jcpunk avatar Jul 29 '25 15:07 jcpunk

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)

jcpunk avatar Dec 02 '25 21:12 jcpunk