Skip to content

Commit

Permalink
Make url resolver log to systemd journal, and use /tmp/ssu.log as fal…
Browse files Browse the repository at this point in the history
…lback
  • Loading branch information
Bernd Wachter committed Jan 29, 2013
1 parent 649f47c commit f67e76a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions rpm/ssu.changes
@@ -1,3 +1,6 @@
* Tue Jan 29 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.20
- Move ssu resolver log to systemd journal, with fallback in /tmp/ssu.log

* Tue Jan 29 2013 Bernd Wachter <bernd.wachter@jollamobile.com> - 0.19
- Use default domain values if no domain-specific values exist

Expand Down
3 changes: 2 additions & 1 deletion rpm/ssu.spec
@@ -1,5 +1,5 @@
Name: ssu
Version: 0.19
Version: 0.20
Release: 1
Summary: SSU enabler for RND
Group: System/Base
Expand All @@ -10,6 +10,7 @@ BuildRequires: pkgconfig(QtCore)
BuildRequires: pkgconfig(libzypp)
BuildRequires: pkgconfig(QtSystemInfo)
BuildRequires: pkgconfig(qt-boostable)
BuildRequires: pkgconfig(libsystemd-journal)
Requires(pre): shadow-utils
Requires(postun): shadow-utils
Requires: ssu-vendor-data
Expand Down
27 changes: 21 additions & 6 deletions ssuurlresolver/ssuurlresolver.cpp
Expand Up @@ -6,17 +6,31 @@
*/

#include <QCoreApplication>
#include <systemd/sd-journal.h>

#include "ssuurlresolver.h"

SsuUrlResolver::SsuUrlResolver(): QObject(){
logfile.setFileName("/var/log/ssu.log");
logfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
logstream.setDevice(&logfile);
QObject::connect(this,SIGNAL(done()),
QCoreApplication::instance(),SLOT(quit()),
Qt::QueuedConnection);
}

void SsuUrlResolver::printJournal(int priority, QString message){
QByteArray ba = message.toUtf8();
const char *ca = ba.constData();

if (sd_journal_print(LOG_INFO, "ssu: %s", ca) < 0){
QFile logfile;
QTextStream logstream;
logfile.setFileName("/tmp/ssu.log");
logfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
logstream.setDevice(&logfile);
logstream << message << "\n";
logstream.flush();
}
}

void SsuUrlResolver::run(){
QHash<QString, QString> repoParameters;
QString resolvedUrl, repo;
Expand All @@ -26,7 +40,7 @@ void SsuUrlResolver::run(){

if (in.headerEmpty()){
// FIXME, do something; we need at least repo header
logstream << "D'oh, received empty header list\n";
printJournal(LOG_WARNING, "Received empty header list. Most likely your ssu setup is broken");
}

PluginFrame::HeaderListIterator it;
Expand Down Expand Up @@ -72,7 +86,7 @@ void SsuUrlResolver::run(){

// TODO: check for credentials scope required for repository; check if the file exists;
// compare with configuration, and dump credentials to file if necessary
logstream << QString("Requesting credentials for '%1' with RND status %2...").arg(repo).arg(isRnd);
printJournal(LOG_DEBUG, QString("Requesting credentials for '%1' with RND status %2...").arg(repo).arg(isRnd));
QString credentialsScope = ssu.credentialsScope(repo, isRnd);
if (!credentialsScope.isEmpty()){
headerList.append(QString("credentials=%1").arg(credentialsScope));
Expand Down Expand Up @@ -100,7 +114,8 @@ void SsuUrlResolver::run(){
.arg(headerList.join("&"));
}

logstream << QString("resolved to %1\n").arg(resolvedUrl);
printJournal(LOG_INFO, QString("%1 resolved to %2").arg(repo).arg(resolvedUrl));

PluginFrame out("RESOLVEDURL");
out.setBody(resolvedUrl.toStdString());
out.writeTo(std::cout);
Expand Down
3 changes: 1 addition & 2 deletions ssuurlresolver/ssuurlresolver.h
Expand Up @@ -52,8 +52,7 @@ class SsuUrlResolver: public QObject {

private:
Ssu ssu;
QFile logfile;
QTextStream logstream;
void printJournal(int priority, QString message);

public slots:
void run();
Expand Down
2 changes: 1 addition & 1 deletion ssuurlresolver/ssuurlresolver.pro
Expand Up @@ -8,7 +8,7 @@ CONFIG -= app_bundle
CONFIG += console link_pkgconfig
QT -= gui
QT += network
PKGCONFIG += libzypp
PKGCONFIG += libzypp libsystemd-journal

unix:target.path = $${PREFIX}/usr/lib/zypp/plugins/urlresolver
INSTALLS += target
Expand Down

0 comments on commit f67e76a

Please sign in to comment.