return option_checker_.Init(argc, argv);
}
-void InitPkgDB::RunBackend(const std::string& pkgid,
+bool InitPkgDB::RunBackend(const std::string& pkgid,
const std::string& type, bool preload) {
bf::path backend_path(kBackendDirectoryPath);
backend_path /= type;
if (preload) {
if (option_checker_.GetUid() != kRootUserUid) {
std::cerr << "Preload request for non-root user" << std::endl;
- return;
+ return false;
}
params.emplace_back("--preload");
}
backend.RunWithArgs(params);
- backend.Wait();
+ if (!backend.Wait()) {
+ std::cerr << "Failed to run backend" << std::endl;
+ return false;
+ }
+
+ return true;
}
-void InitPkgDB::LoadDirectory(const std::string& path,
+bool InitPkgDB::LoadDirectory(const std::string& path,
bool preload) {
ManifestLoader manifest_loader(path);
std::list<ManifestInfo> manifest_list = manifest_loader.LoadManifest();
for (auto &manifest_info : manifest_list) {
std::cerr << "Manifest : " << std::get<0>(manifest_info) <<
(option_checker_.IsPartialRW() ? " (rw-only)":" (all)") << std::endl;
- RunBackend(std::get<1>(manifest_info), std::get<2>(manifest_info),
- preload);
+ if (!RunBackend(std::get<1>(manifest_info),
+ std::get<2>(manifest_info), preload))
+ return false;
}
+ return true;
}
bool InitPkgDB::Run() {
if (option_checker_.IsGlobal()) {
if (!option_checker_.IsRWOnly())
- LoadDirectory(tzplatform_getenv(TZ_SYS_RO_PACKAGES), true);
+ if (!LoadDirectory(tzplatform_getenv(TZ_SYS_RO_PACKAGES), true))
+ return false;
if (option_checker_.IsROOnly())
return true;
- LoadDirectory(tzplatform_getenv(TZ_SYS_RW_PACKAGES), false);
+ if (!LoadDirectory(tzplatform_getenv(TZ_SYS_RW_PACKAGES), false))
+ return false;
} else {
// Specified user location
tzplatform_set_user(option_checker_.GetUid());
std::string user_dir(tzplatform_getenv(TZ_USER_PACKAGES));
tzplatform_reset_user();
- LoadDirectory(user_dir, false);
+ if (!LoadDirectory(user_dir, false))
+ return false;
}
return true;
#include <sys/types.h>
#include <unistd.h>
+#include <fstream>
#include <iostream>
#include "pkg_initdb/init_pkg_db.h"
const uid_t kRootUserUid = 0;
+void AddErrorFlag() {
+ std::ofstream ofs("/tmp/.preload_install_error", std::ios::app);
+ ofs << "pkg_initdb error\n";
+ ofs.close();
+}
+
} // namespace
int main(int argc, char *argv[]) {
if (!init_pkg_db.Init(argc, argv))
return -1;
- if (!init_pkg_db.Run())
+ if (!init_pkg_db.Run()) {
+ AddErrorFlag();
return -1;
+ }
return 0;
}