This instance will be upgraded to Heptapod 0.20.1 on 2020-03-08 at 14:00 UTC+1 (10 minutes of downtime)

Commit 3d9011e7 authored by Gleb Popov's avatar Gleb Popov

Add support for logging messages via syslog.

Original patch by: Pau Amma <pauamma@gundo.com>
parent f84418710115
# Sample bsdisks syslog configuration file.
# Move to /usr/local/etc/syslog.d/bsdisks-newsyslog.conf and edit as necessary.
# See newsyslog.conf(5) for a description of this file's format.
/var/log/bsdisks.log 644 3 1000 * JC
# Sample bsdisks syslog configuration file.
# Move to /usr/local/etc/syslog.d/bsdisks-syslog.conf and edit as necessary,
# then run "service syslogd reload" as root.
# See syslog.conf(5) for a description of this file's format.
!bsdisks
*.* /var/log/bsdisks.log
!*
......@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd July 3, 2020
.Dd July 28, 2020
.Dt BSDISKS 8
.Os
.Sh NAME
......@@ -33,6 +33,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl -no-debug
.Op Fl -syslog-output
.Sh DESCRIPTION
The UDisks2 service provides interfaces to enumerate
and perform operations on disks and storage devices
......@@ -44,13 +45,26 @@ command is an implementation of the UDisks2 service for
The following option is available:
.Bl -tag -width indent
.It Fl -no-debug
Suppress debugging output (that is, do not output anything).
Suppress debugging output (that is, do not output anything) to standard output.
.It Fl -syslog-output
Copies all output to
.Xr syslog 3
regardless of the presence of
.Fl -no-debug
.El
.Sh FILES
.Bl -tag -width /var/run/devd.seqpacket.pipe -compact
.It Pa /usr/local/etc/bsdisks.conf
Configuration file for
.Nm
.It Pa /usr/local/etc/syslog.d/bsdisks-syslog.conf
.Nm
configuration file for
.Xr syslogd 8
.It Pa /usr/local/etc/newsyslog.d/bsdisks-newsyslog.conf
.Nm
configuration file for
.Xr newsyslog 8
.It Pa /var/run/devd.seqpacket.pipe
Pipe to read device and media events from
.Xr devd 8
......
......@@ -26,6 +26,10 @@
#include <QSet>
#include <stdarg.h>
#include <sysexits.h>
#include <syslog.h>
#include "bsdisks.h"
#include "manageradaptor.h"
#include "adaptors.h"
......@@ -45,6 +49,42 @@ BsdisksConfig& BsdisksConfig::get()
return config;
}
/* Initialized in main */
static QtMessageHandler old_message_handler = NULL;
static bool syslog_output;
static bool no_debug;
static void message_handler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if(syslog_output)
{
QByteArray local_msg = msg.toLocal8Bit();
switch (type)
{
case QtDebugMsg:
syslog(LOG_DEBUG | LOG_DAEMON, "%s\n", local_msg.constData());
break;
case QtInfoMsg:
syslog(LOG_INFO | LOG_DAEMON, "%s\n", local_msg.constData());
break;
case QtWarningMsg:
syslog(LOG_WARNING | LOG_DAEMON, "%s\n", local_msg.constData());
break;
case QtCriticalMsg:
/* Tone it down a bit here */
syslog(LOG_ERR | LOG_DAEMON, "%s\n", local_msg.constData());
break;
case QtFatalMsg:
/* Tone it down a bit here */
syslog(LOG_CRIT | LOG_DAEMON, "%s\n", local_msg.constData());
break;
}
}
if((old_message_handler != NULL) && !no_debug)
(*old_message_handler)(type, context, msg);
}
int main(int argc, char** argv)
{
qRegisterMetaType<Configuration>();
......@@ -92,18 +132,12 @@ int main(int argc, char** argv)
if(!QDBusConnection::systemBus().registerService("org.freedesktop.UDisks2"))
{
qCritical() << "Could not register UDisks2 service";
return -1;
return EX_UNAVAILABLE;
}
if(QCoreApplication::arguments().contains("--no-debug"))
{
qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Q_UNUSED(type);
Q_UNUSED(context);
Q_UNUSED(msg);
});
}
syslog_output = QCoreApplication::arguments().contains("--syslog-output");
no_debug = QCoreApplication::arguments().contains("--no-debug");
old_message_handler = qInstallMessageHandler(&message_handler);
new ObjectManagerAdaptor(&manager);
......
[D-BUS Service]
Name=org.freedesktop.UDisks2
Exec=@CMAKE_INSTALL_PREFIX@/bin/bsdisks --no-debug
Exec=@CMAKE_INSTALL_PREFIX@/bin/bsdisks --no-debug --syslog-output
User=root
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