Commit e9e7cf5e authored by spiiroin's avatar spiiroin

[sensord] Use systemd notify instead of forking a daemon. Fixes JB#36189

Using systemd specific startup notification is preferable over cusrom
daemon forks.

Add support for systemd-notify and use it instead of forking.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent bcf16ef1
......@@ -20,6 +20,7 @@ BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(libsystemd)
BuildRequires: doxygen
BuildRequires: systemd
BuildRequires: libudev-devel
......
......@@ -5,8 +5,8 @@ Requires=dbus.service
Conflicts=actdead.target
[Service]
Type=forking
ExecStart=/usr/sbin/sensorfwd -c=/etc/sensorfw/primaryuse.conf -d --log-level=warning --no-magnetometer-bg-calibration
Type=notify
ExecStart=/usr/sbin/sensorfwd -c=/etc/sensorfw/primaryuse.conf --systemd --log-level=warning --no-magnetometer-bg-calibration
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=1
......
......@@ -33,6 +33,8 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <systemd/sd-daemon.h>
#include <signal.h>
#include <iostream>
#include <errno.h>
......@@ -175,6 +177,11 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
if (parser.notifySystemd())
{
sd_notify(0, "READY=1");
}
int ret = app.exec();
sensordLogD() << "Exiting...";
Config::close();
......@@ -185,6 +192,7 @@ void printUsage()
{
qDebug() << "Usage: sensord [OPTIONS]";
qDebug() << " -d, --daemon Detach from terminal and run as daemon.\n";
qDebug() << " -s, --systemd Notify systemd when ready.\n";
qDebug() << " -l=N, --log-level=<level> Use given logging level. Messages are logged for";
qDebug() << " the given and higher priority levels. Level";
qDebug() << " can also be notched up by sending SIGUSR1 to";
......
......@@ -33,6 +33,7 @@ Parser::Parser(QStringList arguments) :
configFile_(false),
configDir_(false),
daemon_(false),
systemd_(false),
magnetometerCalibration_(true),
configFilePath_(""),
logLevel_(QtWarningMsg)
......@@ -81,7 +82,9 @@ void Parser::parsingCommandLine(QStringList arguments)
else if (opt.startsWith("--no-magnetometer-bg-calibration"))
magnetometerCalibration_ = false;
else if (opt.startsWith("-d") || opt.startsWith("--daemon"))
daemon_ = true;
daemon_ = true, systemd_ = false;
else if (opt.startsWith("-s") || opt.startsWith("--systemd"))
systemd_ = true, daemon_ = false;
else if (opt.startsWith("-h") || opt.startsWith("--help"))
printHelp_ = true;
else if (opt.startsWith("-"))
......@@ -134,3 +137,8 @@ bool Parser::createDaemon() const
return daemon_;
}
bool Parser::notifySystemd() const
{
return systemd_;
}
......@@ -48,6 +48,7 @@ public:
bool contextInfo() const;
bool magnetometerCalibration() const;
bool createDaemon() const;
bool notifySystemd() const;
private:
void parsingCommandLine(QStringList arguments);
......@@ -57,6 +58,7 @@ private:
bool configFile_;
bool configDir_;
bool daemon_;
bool systemd_;
bool magnetometerCalibration_;
QString configFilePath_;
......
......@@ -8,6 +8,8 @@ TARGET = sensorfwd
CONFIG += console \
link_pkgconfig
PKGCONFIG += libsystemd
SENSORFW_INCLUDEPATHS = .. \
../include \
../filters \
......
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