Commit 07d66670 authored by Fabian Kosmale's avatar Fabian Kosmale Committed by Fabian Kosmale

fix clazy warning: non-pod-global-static

parent d938cc91
......@@ -18,6 +18,7 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDebug>
#include <QGlobalStatic>
#include <syslog.h>
#include <iostream>
......@@ -28,14 +29,14 @@
*/
namespace {
/* Necessary when polkit isn't involved */
static std::ofstream logStream;
Q_GLOBAL_STATIC(std::ofstream, logStream);
static bool isSyslog( false );
static QString pathToFile;
Q_GLOBAL_STATIC(QString, pathToFile);
/* Whether the init occurred correctly */
static bool systemInitialized( false );
static QString __msg_prefix[] = { "", "Warning: ", "Critical: " };
static QLatin1String __msg_prefix[] = { QLatin1String(""), QLatin1String("Warning: "), QLatin1String("Critical: ") };
static int __msg_priority[] = { LOG_INFO, LOG_WARNING, LOG_CRIT };
/*
......@@ -46,7 +47,7 @@ namespace {
*/
static bool permissionsNeeded()
{
Akabei::Helpers::Permissions access = Akabei::Helpers::permissionsOfPath(pathToFile);
Akabei::Helpers::Permissions access = Akabei::Helpers::permissionsOfPath(*pathToFile);
return (!isSyslog && !access.testFlag(Akabei::Helpers::WritePermission));
}
}
......@@ -87,10 +88,10 @@ public:
#pragma clang diagnostic pop
#endif
} else {
logStream << data.toStdString() << std::endl;
logStream.flush();
*logStream << data.toStdString() << std::endl;
logStream->flush();
if (logStream.bad()) {
if (logStream->bad()) {
qDebug() << "Log error: I/O error while writing";
}
}
......@@ -123,7 +124,7 @@ public:
void AkabeiLogLine::initialize(bool syslog, const QString& filename)
{
pathToFile = filename;
*pathToFile = filename;
isSyslog = syslog;
if ( !permissionsNeeded() ) {
......@@ -132,10 +133,10 @@ void AkabeiLogLine::initialize(bool syslog, const QString& filename)
openlog("akabei", LOG_PID | LOG_CONS, LOG_USER); /* open connection for a generic user service */
systemInitialized = true;
} else {
pathToFile = filename;
logStream.open(filename.toUtf8().constData(), std::ios::app);
*pathToFile = filename;
logStream->open(filename.toUtf8().constData(), std::ios::app);
if (!logStream.is_open()) {
if (!logStream->is_open()) {
std::cerr << "Log error: couldn't open log file \"" << filename.toUtf8().constData() << "\" for writing." << std::endl;
} else {
systemInitialized = true;
......@@ -318,14 +319,14 @@ QString readLoggedActions(const QString &filter)
if (isSyslog)
return QString();
if (pathToFile.isEmpty()) {
if (pathToFile->isEmpty()) {
std::cerr << "Log error: logging system not initialized correctly. Cannot read from log." << std::endl;
return QString();
}
QString result;
QFile file(pathToFile);
QFile file(*pathToFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
......
This diff is collapsed.
......@@ -19,48 +19,48 @@ namespace InputValidator
void validate(const QStringList &args)
{
if (args.at(1) == "--help") {
out << QObject::tr("Usage: akabei-create-db [action] [database] [targets]") << endl;
(*out) << QObject::tr("Usage: akabei-create-db [action] [database] [targets]") << endl;
exit(0);
} else {
if (args.count() < 3) {
out << QObject::tr("Not enough input arguments!") << endl;
out << QObject::tr("Usage: akabei-create-db [action] [database] [targets]") << endl;
(*out) << QObject::tr("Not enough input arguments!") << endl;
(*out) << QObject::tr("Usage: akabei-create-db [action] [database] [targets]") << endl;
exit(1);
}
}
if (args.at(1) == "generate") {
if (!isValidDatabase(args.at(2))) {
out << QObject::tr("%1 is not a valid database filename. Examples: core.db or core.db.tar.xz").arg(args.at(2)) << endl;
(*out) << QObject::tr("%1 is not a valid database filename. Examples: core.db or core.db.tar.xz").arg(args.at(2)) << endl;
exit(1);
}
if (QFile::exists(args.at(2))) {
out << QObject::tr("%1 already exists. Do you want to overwrite it? [y/N]").arg(args.at(2)) << endl;
QString answer = in.readLine();
(*out) << QObject::tr("%1 already exists. Do you want to overwrite it? [y/N]").arg(args.at(2)) << endl;
QString answer = in->readLine();
if ((answer.isEmpty()) || ((answer != "y") && (answer != "Y"))) {
out << QObject::tr("Not overwriting. Exiting.") << endl;
(*out) << QObject::tr("Not overwriting. Exiting.") << endl;
exit(0);
}
}
} else if (args.at(1) == "remove") {
if (!isValidDatabase(args.at(2))) {
out << QObject::tr("%1 is not a valid database filename. Examples: core.db or core.db.tar.xz").arg(args.at(2)) << endl;
(*out) << QObject::tr("%1 is not a valid database filename. Examples: core.db or core.db.tar.xz").arg(args.at(2)) << endl;
exit(1);
}
if (!QFile::exists(args.at(2))) {
out << QObject::tr("%1 could not be found").arg(args.at(2)) << endl;
(*out) << QObject::tr("%1 could not be found").arg(args.at(2)) << endl;
exit(1);
}
} else if (args.at(1) == "add") {
if (!isValidDatabase(args.at(2))) {
out << QObject::tr("%1 is not a valid database filename. Examples: core.db or core.db.tar.xz").arg(args.at(2)) << endl;
(*out) << QObject::tr("%1 is not a valid database filename. Examples: core.db or core.db.tar.xz").arg(args.at(2)) << endl;
exit(1);
}
if (!QFile::exists(args.at(2))) {
out << QObject::tr("%1 does not exist. Exiting.").arg(args.at(2)) << endl;
(*out) << QObject::tr("%1 does not exist. Exiting.").arg(args.at(2)) << endl;
exit(1);
}
} else {
out << QObject::tr("%1 is not a valid action. Valid actions: generate, add, remove.").arg(args.at(2)) << endl;
(*out) << QObject::tr("%1 is not a valid action. Valid actions: generate, add, remove.").arg(args.at(2)) << endl;
exit(1);
}
}
......
......@@ -8,8 +8,13 @@
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEI_IO_H
#define AKABEI_IO_H
#include <stdio.h>
#include <QTextStream>
#include <QGlobalStatic>
static QTextStream out(stdout);
static QTextStream in(stdin);
Q_GLOBAL_STATIC_WITH_ARGS(QTextStream, out, (stdout));
Q_GLOBAL_STATIC_WITH_ARGS(QTextStream, in, (stdin));
#endif
......@@ -16,6 +16,7 @@
#include <sys/syslog.h>
#include <iostream>
#include <QGlobalStatic>
#include <QDebug>
#include <QDBusConnection>
#include <qdbusconnectioninterface.h>
......@@ -25,8 +26,8 @@
* Information needed through different invocations
*/
namespace {
static std::ofstream logStream;
static QString filename;
Q_GLOBAL_STATIC(std::ofstream, logStream);
Q_GLOBAL_STATIC(QString, filename);
}
LogHelper::LogHelper(QObject* parent)
......@@ -47,10 +48,10 @@ void LogHelper::init(const QString& fn)
return;
}
filename = fn;
logStream.open(filename.toUtf8().constData(), std::ios::app);
*filename = fn;
logStream->open(filename->toUtf8().constData(), std::ios::app);
if (!logStream.is_open()) {
if (!logStream->is_open()) {
qDebug() << "Log error: couldn't open log file" << filename << "for writing.";
}
}
......@@ -66,10 +67,10 @@ void LogHelper::log(const QString& data)
return;
}
logStream << data.toStdString() << std::endl;
logStream.flush();
*logStream << data.toStdString() << std::endl;
logStream->flush();
if (logStream.bad()) {
if (logStream->bad()) {
qDebug() << "Log error: I/O error while writing";
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment