Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit warning when root is needed to upgrade DB #1908

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tigergao99
Copy link
Contributor

Prints an explicit warning when errmsg has the substring "readonly".
Fixes #1771

@ceri
Copy link

ceri commented Nov 24, 2020

Could this also check that pkg isn't running as root, otherwise it's possible that this may give a misleading error explanation (if the filesystem is read-only, for example).

@tigergao99
Copy link
Contributor Author

Thanks for the catch. Now using geteuid() to check if user is root.

@bapt
Copy link
Member

bapt commented Dec 2, 2020

You should also check for "install as user" concept

@grahamperrin
Copy link
Contributor

Context:

% pkg update -f
pkg: Insufficient privileges to update the repository catalogue.
% pkg query %v pkg
1.18.4
% 

@kevemueller
Copy link

This looks misplaced. The SQL can err for a thousand reasons, not being able to write to the database is just one. Also the repetition does not look nice.

I believe the intention is to catch having a read-only database, which is a possible niche scenario, so not invalid per-se.

IMO the best place for this code fragment is in the error-handler that is invoked by many of the SQLite function call sites. It is located in libpkg/private/utils.h and called ERROR_SQLITE and ERROR_STMT_SQLITE.
The error condition is available and you can give more precise error messages that are pointing in the right direction for the pkg use of SQLite.
E.g. you would switch on SQLITE_IOERR, potentionally further narrow with SQLITE_IOERR_WRITE (778), perform your geteuid test and have the proper explanation in the error message.

Would that be a possible way forward for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'pkg which' attempts to write in the SQLite database
5 participants