From 7566f1396e04eea2ceba3b5ec8f57db94e093f0a Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 24 Mar 2016 08:58:29 -0400 Subject: [PATCH] Add a new "fast" mode to the sysadm-update check for updates (re-use previous update info), and setup the regular health check to report update information using this fast mode. --- src/server/EventWatcher.cpp | 6 +++++ src/server/library/sysadm-update.cpp | 38 ++++++++++++++++++++++------ src/server/library/sysadm-update.h | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/server/EventWatcher.cpp b/src/server/EventWatcher.cpp index 92d7bc8..4950c34 100644 --- a/src/server/EventWatcher.cpp +++ b/src/server/EventWatcher.cpp @@ -8,6 +8,7 @@ #include "globals.h" #include "library/sysadm-general.h" #include "library/sysadm-zfs.h" +#include "library/sysadm-update.h" // === PUBLIC === EventWatcher::EventWatcher(){ @@ -361,6 +362,11 @@ void EventWatcher::CheckSystemState(){ obj.insert("zpools", zpools ); } + //Next Check for Updates + QJsonObject updates = sysadm::Update::checkUpdates(true); //do the "fast" version of updates + if(!updates.isEmpty()){ + obj.insert("updates",updates); + } // Priority 0-10 obj.insert("priority", DisplayPriority(priority) ); diff --git a/src/server/library/sysadm-update.cpp b/src/server/library/sysadm-update.cpp index a0d6646..c5de5d8 100644 --- a/src/server/library/sysadm-update.cpp +++ b/src/server/library/sysadm-update.cpp @@ -10,28 +10,50 @@ #include "sysadm-global.h" #include "globals.h" +#define UP_PIDFILE "/tmp/.updateInProgress" +#define UP_RBFILE "/tmp/.rebootRequired" +#define UP_UPFILE "/tmp/.updatesAvailable" + using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h // Return a list of updates available -QJsonObject Update::checkUpdates() { +QJsonObject Update::checkUpdates(bool fast) { + //NOTE: The "fast" option should only be used for automated/timed checks (to prevent doing this long check too frequently) QJsonObject retObject; - if(QFile::exists("/tmp/.rebootRequired")){ - retObject.insert("status","rebootrequired"); + + //Quick check to ensure the tool is available + if(!QFile::exists("/usr/local/bin/pc-updatemanager")){ return retObject; } - if(QFile::exists("/tmp/.updateInProgress")){ + //Check if the system is waiting to reboot + if(QFile::exists(UP_RBFILE)){ + retObject.insert("status","rebootrequired"); + if(QFile::exists(UP_UPFILE)){ QFile::remove(UP_UPFILE); } //ensure the next fast update does a full check + return retObject; + } + //Check if an update is currently running + if(QFile::exists(UP_PIDFILE)){ //See if the process is actually running - if( General::RunQuickCommand("pgrep -F /tmp/.updateInProgress") ){ + if( General::RunQuickCommand(QString("pgrep -F ")+UP_PIDFILE) ){ //Success if return code == 0 retObject.insert("status","updaterunning"); + if(QFile::exists(UP_UPFILE)){ QFile::remove(UP_UPFILE); } //ensure the next fast update does a full check return retObject; } } - QStringList output = General::RunCommand("pc-updatemanager check").split("\n"); - output.append( General::RunCommand("pc-updatemanager pkgcheck").split("\n") ); - qDebug() << "pc-updatemanager checks:" << output; + //Get the list of deatils from the update checks (fast/full) + QStringList output; + if(fast && QFile::exists(UP_UPFILE) && (QFileInfo(UP_UPFILE).lastModified().addSecs(43200)