summaryrefslogtreecommitdiffstats
path: root/src/Common/Backends
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Backends')
-rw-r--r--src/Common/Backends/SystemBackendPosix.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/Common/Backends/SystemBackendPosix.cpp b/src/Common/Backends/SystemBackendPosix.cpp
index ca8b440..acb6bb6 100644
--- a/src/Common/Backends/SystemBackendPosix.cpp
+++ b/src/Common/Backends/SystemBackendPosix.cpp
@@ -19,8 +19,10 @@
#include "SystemBackendPosix.h"
+#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <sstream>
#include <fcntl.h>
#include <signal.h>
@@ -62,9 +64,32 @@ SystemBackendPosix::~SystemBackendPosix() {
void SystemBackendPosix::fsInfoCallback(int, const std::string &output, const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
- // TODO Process df output
+ std::vector<FSInfo> ret;
+ std::istringstream stream(output);
+ std::string str;
- callback(std::vector<FSInfo>());
+ std::getline(stream, str); // ignore first line
+
+ while(!stream.eof()) {
+ std::getline(stream, str);
+
+ char *fsName = new char[str.length()+1];
+ char *mountedOn = new char[str.length()+1];
+
+ FSInfo info;
+
+ if(std::sscanf(str.c_str(), "%s %lld %lld %lld %*d%% %s", fsName, &info.total, &info.used, &info.available, mountedOn) == 5) {
+ info.fsName = fsName;
+ info.mountedOn = mountedOn;
+
+ ret.push_back(info);
+ }
+
+ delete [] fsName;
+ delete [] mountedOn;
+ }
+
+ callback(ret);
}
bool SystemBackendPosix::fsInfo(const sigc::slot<void, const std::vector<FSInfo>& > &callback) {
@@ -200,7 +225,7 @@ bool SystemBackendPosix::execWithOutput(const sigc::slot<void, int, const std::s
dup2(pipeHandles[1], STDOUT_FILENO); // set the new pipe as stdout
close(pipeHandles[1]);
- bool ret = (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0);
+ bool ret (posix_spawnp(&pid, filename.c_str(), 0, 0, args.first, args.second) == 0);
if(ret)
processesWithOutput.insert(std::make_pair(pid, std::make_pair(resultHandler, pipeHandles[0])));