bundle-list: local bundle list should work without root

When we changed the init swupd function we stopped supporting bundle-list as root.
Adding this back on.
This commit is contained in:
Otavio Pontes
2019-05-31 19:35:33 +00:00
parent 230e3e5744
commit 1272040876
4 changed files with 16 additions and 3 deletions
+6 -2
View File
@@ -124,11 +124,15 @@ enum swupd_code bundle_list_main(int argc, char **argv)
}
progress_init_steps("bundle-list", steps_in_bundlelist);
ret = swupd_init(SWUPD_ALL);
if (cmdline_local && !is_root()) {
ret = swupd_init(SWUPD_NO_ROOT);
} else {
ret = swupd_init(SWUPD_ALL);
}
/* if swupd fails to initialize, the only list command we can still attempt is
* listing locally installed bundles (with the limitation of not showing what
* bundles are experimental) */
if (ret != 0 && !cmdline_local) {
if (ret != 0) {
error("Failed updater initialization. Exiting now\n");
goto finish;
}
+1 -1
View File
@@ -43,7 +43,7 @@
void check_root(void)
{
if (getuid() != 0) {
if (!is_root()) {
error("This program must be run as root..aborting.\n\n");
exit(EXIT_FAILURE);
}
+5
View File
@@ -316,3 +316,8 @@ char *sys_path_join(const char *prefix, const char *path)
return str_or_die("%.*s%c%s", len, prefix, PATH_SEPARATOR, path);
}
bool is_root(void)
{
return getuid() == 0;
}
+4
View File
@@ -162,6 +162,10 @@ char *sys_dirname(const char *path);
*/
char *sys_path_join(const char *prefix, const char *path);
/**
* @brief Check if current user is root.
*/
bool is_root(void);
/**
* @brief Run a systemctl command with the informed parameters.
*/