This commit is contained in:
arcan1s 2014-08-26 13:35:24 +04:00
parent da5cbdb320
commit 51334a6d40
6 changed files with 96 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tasks"]
path = tasks
url = https://github.com/mhogomchungu/tasks.git

View File

1
task.h Symbolic link
View File

@ -0,0 +1 @@
tasks/task.h

44
taskadds.cpp Normal file
View File

@ -0,0 +1,44 @@
/***************************************************************************
* Copyright (C) 2014 Evgeniy Alekseev *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 3.0 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
***************************************************************************/
#include "taskadds.h"
TaskResult runTask(const QString cmd, const bool useSuid)
{
return Task::await<TaskResult>( [ & ]() {
TaskResult r;
if (useSuid) {
RootProcess command;
command.start(cmd);
command.waitForFinished(-1);
r.exitCode = command.exitCode();
r.output = command.readAllStandardOutput();
r.error = command.readAllStandardError();
} else {
QProcess command;
command.start(cmd);
command.waitForFinished(-1);
r.exitCode = command.exitCode();
r.output = command.readAllStandardOutput();
r.error = command.readAllStandardError();
}
return r;
});
}

47
taskadds.h Normal file
View File

@ -0,0 +1,47 @@
/***************************************************************************
* Copyright (C) 2014 Evgeniy Alekseev *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 3.0 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
***************************************************************************/
#ifndef TASKADDS_H
#define TASKADDS_H
#include <QProcess>
#include <unistd.h>
#include "task.h"
class RootProcess : public QProcess
{
protected:
void setupChildProcess()
{
::setuid(0);
};
};
struct TaskResult
{
int exitCode;
QByteArray error;
QByteArray output;
};
TaskResult runTask(const QString cmd, const bool useSuid = true);
#endif /* TASKADDS_H */

1
tasks Submodule

@ -0,0 +1 @@
Subproject commit f78c18d38156e8f7dd0d342d9f8779bed8b7f84e