From 646b025efada0b9bb1b3680d2a8e264b28cdb820 Mon Sep 17 00:00:00 2001
From: Hrvoje Senjan <hrvoje.senjan@gmail.com>
Date: Sat, 2 Sep 2017 11:09:51 +0200
Subject: [PATCH] Write the daemon's PID to a file on startup

openSUSE's generic display-manager service doesn't know what to do
without a pid file. drop the patch as soon as that sick dinosaur is killed.
---
 src/common/Constants.h.in |  1 +
 src/daemon/DaemonApp.cpp  | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/src/common/Constants.h.in b/src/common/Constants.h.in
index 405da5e..7b2669e 100644
--- a/src/common/Constants.h.in
+++ b/src/common/Constants.h.in
@@ -38,6 +38,7 @@
 #define SYSTEM_CONFIG_DIR           "@SYSTEM_CONFIG_DIR@"
 
 #define LOG_FILE                    "@LOG_FILE@"
+#define PID_FILE                    "@PID_FILE@"
 
 #define UID_MIN                     @UID_MIN@
 #define UID_MAX                     @UID_MAX@
diff --git a/src/daemon/DaemonApp.cpp b/src/daemon/DaemonApp.cpp
index 490068e..2b6777a 100644
--- a/src/daemon/DaemonApp.cpp
+++ b/src/daemon/DaemonApp.cpp
@@ -32,6 +32,7 @@
 #include <QDebug>
 #include <QHostInfo>
 #include <QTimer>
+#include <QFile>
 
 #include <iostream>
 
@@ -47,6 +48,16 @@ namespace SDDM {
         // log message
         qDebug() << "Initializing...";
 
+        // Write PID File
+        if ( ! QString(QStringLiteral(PID_FILE)).isEmpty() ) {
+            QFile pidFile(QStringLiteral(PID_FILE));
+            QString pid = QString::number(QCoreApplication::applicationPid());
+            if ( pidFile.open(QIODevice::WriteOnly | QIODevice::Text) ) {
+                pidFile.write(pid.toLatin1().data(), qstrlen(pid.toLatin1().data()));
+                pidFile.close();
+            }
+        }
+
         // set testing parameter
         m_testing = (arguments().indexOf(QStringLiteral("--test-mode")) != -1);
 
-- 
2.41.0