Skip to content

Commit

Permalink
replace popen call to xfs_quota with new runCommand function
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Jul 25, 2011
1 parent b2e3b5e commit 9c8231e
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions src/cpp/session/modules/SessionFilesQuotas.cpp
Expand Up @@ -13,8 +13,6 @@

#include "SessionFilesQuotas.hpp"

#include <stdio.h>

#include <iostream>

#include <boost/tokenizer.hpp>
Expand All @@ -26,6 +24,8 @@
#include <core/BoostErrors.hpp>
#include <core/Log.hpp>

#include <core/system/Process.hpp>

#include <r/RExec.hpp>

#include <session/SessionModuleContext.hpp>
Expand Down Expand Up @@ -169,36 +169,19 @@ void checkQuotaThread()
{
try
{
// start process
FILE* fp = ::popen("xfs_quota -c 'quota -N'", "r");
if (fp == NULL)
// run the command
using namespace core::system;
ProcessResult result;
Error error = runCommand("xfs_quota -c 'quota -N'", "", &result);
if (error)
{
LOG_ERROR(systemError(errno, ERROR_LOCATION));
LOG_ERROR(error);
return;
}

// collect output
std::string output;
const int kBuffSize = 1024;
char buffer[kBuffSize];
while (::fgets(buffer, kBuffSize, fp) != NULL)
output += buffer;

// log if an error terminated our output
if (::ferror(fp))
LOG_ERROR(systemError(errno, ERROR_LOCATION));

// close file
if (::pclose(fp) == -1)
{
// ECHILD expected if process was reaped elsewhere by wait or waitpid
if (errno != ECHILD)
LOG_ERROR(systemError(errno, ERROR_LOCATION));
}


// parse output
QuotaInfo quotaInfo;
Error error = parseQuotaInfo(output, &quotaInfo);
error = parseQuotaInfo(result.stdOut, &quotaInfo);
if (error)
{
LOG_ERROR(error);
Expand Down

0 comments on commit 9c8231e

Please sign in to comment.