mirror of
https://gitlab.com/Syping/mayu
synced 2024-11-25 05:20:23 +01:00
stream now with qCritical()
This commit is contained in:
parent
15e7a40fa6
commit
4afa8935aa
3 changed files with 24 additions and 10 deletions
4
main.cpp
4
main.cpp
|
@ -29,9 +29,7 @@ int main(int argc, char *argv[])
|
|||
arguments.removeAt(0);
|
||||
|
||||
if (arguments.length() >= 2) {
|
||||
mayu a_mayu;
|
||||
a_mayu.setHostsFile(arguments.at(0));
|
||||
a_mayu.setJsonFile(arguments.at(1));
|
||||
mayu a_mayu(arguments.at(0), arguments.at(1));
|
||||
a_mayu.work();
|
||||
return a_mayu.getResult();
|
||||
}
|
||||
|
|
26
mayu.cpp
26
mayu.cpp
|
@ -30,10 +30,14 @@ extern "C" {
|
|||
#include "oping.h"
|
||||
}
|
||||
|
||||
mayu::mayu(QObject *parent) : QObject(parent)
|
||||
mayu::mayu(const QString &hostsFile, const QString &jsonFile, int tries, QObject *parent) : QObject(parent)
|
||||
{
|
||||
p_return = -1;
|
||||
p_tries = 4;
|
||||
p_tries = tries;
|
||||
if (!hostsFile.isEmpty())
|
||||
setHostsFile(hostsFile);
|
||||
if (!jsonFile.isEmpty())
|
||||
setJsonFile(jsonFile);
|
||||
}
|
||||
|
||||
void mayu::setHostsFile(const QString &fileName)
|
||||
|
@ -53,6 +57,11 @@ void mayu::setJsonFile(const QString &fileName)
|
|||
p_jsonFile = fileName;
|
||||
}
|
||||
|
||||
void mayu::setMaxTries(int tries)
|
||||
{
|
||||
p_tries = tries;
|
||||
}
|
||||
|
||||
const QString mayu::getHostsFile()
|
||||
{
|
||||
return p_hostsFile;
|
||||
|
@ -68,6 +77,11 @@ const QString mayu::getJsonFile()
|
|||
return p_jsonFile;
|
||||
}
|
||||
|
||||
int mayu::getMaxTries()
|
||||
{
|
||||
return p_tries;
|
||||
}
|
||||
|
||||
int mayu::getResult()
|
||||
{
|
||||
return p_return;
|
||||
|
@ -196,7 +210,7 @@ void mayu::parse_hosts()
|
|||
}
|
||||
else
|
||||
{
|
||||
cerr << "Failed read hosts from " << p_hostsFile.toStdString().c_str();
|
||||
qCritical() << "Failed read hosts from" << p_hostsFile;
|
||||
}
|
||||
if (!regainPrivileges()) {
|
||||
p_return = 3;
|
||||
|
@ -225,7 +239,7 @@ void mayu::work()
|
|||
if (jsonFile.open(QSaveFile::WriteOnly)) {
|
||||
jsonFile.write(jsonArray);
|
||||
if (!jsonFile.commit()) {
|
||||
cerr << "Failed save result to " << p_jsonFile.toStdString().c_str();
|
||||
qCritical() << "Failed save result to" << p_jsonFile;
|
||||
p_return = 1;
|
||||
}
|
||||
}
|
||||
|
@ -242,7 +256,7 @@ bool mayu::dropPrivileges()
|
|||
p_uid = geteuid();
|
||||
int status = seteuid(getuid());
|
||||
if (status != 0) {
|
||||
cerr << "Dropping of privileges has failed!";
|
||||
qCritical() << "Dropping of privileges has failed!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -256,7 +270,7 @@ bool mayu::regainPrivileges()
|
|||
#if _POSIX_SAVED_IDS
|
||||
int status = seteuid(p_uid);
|
||||
if (status != 0) {
|
||||
cerr << "Regaining of privileges has failed!";
|
||||
qCritical() << "Regaining of privileges has failed!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
4
mayu.h
4
mayu.h
|
@ -27,13 +27,15 @@ class mayu : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit mayu(QObject *parent = nullptr);
|
||||
explicit mayu(const QString &hostsFile = QString(), const QString &jsonFile = QString(), int tries = 4, QObject *parent = nullptr);
|
||||
void setHostsFile(const QString &fileName);
|
||||
void setHosts(const QStringList &hostsList);
|
||||
void setJsonFile(const QString &fileName);
|
||||
void setMaxTries(int tries);
|
||||
const QString getHostsFile();
|
||||
const QStringList getHosts();
|
||||
const QString getJsonFile();
|
||||
int getMaxTries();
|
||||
int getResult();
|
||||
static double ping(const QString &host, int tries, double timeout = 2.5);
|
||||
|
||||
|
|
Loading…
Reference in a new issue