mirror of
https://github.com/arcan1s/qtadds-taskadds-qprocess.git
synced 2025-04-24 15:37:18 +00:00
update
This commit is contained in:
parent
da5cbdb320
commit
51334a6d40
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "tasks"]
|
||||||
|
path = tasks
|
||||||
|
url = https://github.com/mhogomchungu/tasks.git
|
44
taskadds.cpp
Normal file
44
taskadds.cpp
Normal 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
47
taskadds.h
Normal 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
1
tasks
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f78c18d38156e8f7dd0d342d9f8779bed8b7f84e
|
Loading…
Reference in New Issue
Block a user