diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..de356d6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tasks"] + path = tasks + url = https://github.com/mhogomchungu/tasks.git diff --git a/LICENSE b/COPYING similarity index 100% rename from LICENSE rename to COPYING diff --git a/task.h b/task.h new file mode 120000 index 0000000..7366c4e --- /dev/null +++ b/task.h @@ -0,0 +1 @@ +tasks/task.h \ No newline at end of file diff --git a/taskadds.cpp b/taskadds.cpp new file mode 100644 index 0000000..1c27c0f --- /dev/null +++ b/taskadds.cpp @@ -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 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; + }); +} diff --git a/taskadds.h b/taskadds.h new file mode 100644 index 0000000..392e135 --- /dev/null +++ b/taskadds.h @@ -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 +#include + +#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 */ diff --git a/tasks b/tasks new file mode 160000 index 0000000..f78c18d --- /dev/null +++ b/tasks @@ -0,0 +1 @@ +Subproject commit f78c18d38156e8f7dd0d342d9f8779bed8b7f84e