Add support for the DisplayStopCommand entry #395

Merged
merged 2 commits into from Apr 10, 2015

Conversation

Projects
None yet
2 participants

tseliot commented Apr 2, 2015

The DisplayStopCommand entry allows executing a script right after stopping X.

This is relevant to the following feature request:
#393

Add support for the DisplayStopCommand entry
This entry allows executing a script right after stopping X
+ QString displayStopCommand = mainConfig.XDisplay.DisplayStopCommand.get();
+
+ // create display setup script process
+ QProcess *displayStopScript = new QProcess();
@tseliot

tseliot Apr 2, 2015

On 02-04-15 08:55:15, davidedmundson wrote:

In [1]src/daemon/XorgDisplayServer.cpp:

@@ -233,6 +233,23 @@ namespace SDDM {
// log message
qDebug() << "Display server stopped.";

  •    QString displayStopCommand = mainConfig.XDisplay.DisplayStopCommand.g
    
    et();
    +
  •    // create display setup script process
    
  •    QProcess *displayStopScript = new QProcess();
    

leaks.

Then we have two leaks, as XorgDisplayServer::setupDisplay() does the
same.

Alberto Milone

+
+ // start display setup script
+ qDebug() << "Running display stop script " << displayStopCommand;
+ displayStopScript->start(displayStopCommand);
@davidedmundson

davidedmundson Apr 2, 2015

Owner

should we block for it to finish?

@tseliot

tseliot Apr 2, 2015

On 02-04-15 08:56:57, davidedmundson wrote:

In [1]src/daemon/XorgDisplayServer.cpp:

  •    QString displayStopCommand = mainConfig.XDisplay.DisplayStopCommand.g
    
    et();
    +
  •    // create display setup script process
    
  •    QProcess *displayStopScript = new QProcess();
    
  •    // set process environment
    
  •    QProcessEnvironment env;
    
  •    env.insert("DISPLAY", m_display);
    
  •    env.insert("HOME", "/");
    
  •    env.insert("PATH", mainConfig.Users.DefaultPath.get());
    
  •    env.insert("SHELL", "/bin/sh");
    
  •    displayStopScript->setProcessEnvironment(env);
    
  •    // start display setup script
    
  •    qDebug() << "Running display stop script " << displayStopCommand;
    
  •    displayStopScript->start(displayStopCommand);
    

should we block for it to finish?

Yes, that would be a good idea. It's been a while since I last used Qt
and QProcess.

Alberto Milone

@tseliot

tseliot Apr 2, 2015

How about something like this?

From 067beb73065383dd557643e39d7fc859f713a418 Mon Sep 17 00:00:00 2001
From: Alberto Milone <alberto.milone@canonical.com>
Date: Thu, 2 Apr 2015 18:24:18 +0200
Subject: [PATCH 1/1] src/daemon/XorgDisplayServer.cpp: wait for
 DisplayStopCommand to finish

Also get rid of two memory leaks
---
 src/daemon/XorgDisplayServer.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/daemon/XorgDisplayServer.cpp b/src/daemon/XorgDisplayServer.cpp
index 4f75be9..8fbfc1f 100644
--- a/src/daemon/XorgDisplayServer.cpp
+++ b/src/daemon/XorgDisplayServer.cpp
@@ -250,6 +250,14 @@ namespace SDDM {
         qDebug() << "Running display stop script " << displayStopCommand;
         displayStopScript->start(displayStopCommand);

+        // wait for finished
+        if (!displayStopScript->waitForFinished(5000))
+            displayStopScript->kill();
+
+        // clean up the script process
+        displayStopScript->deleteLater();
+        displayStopScript = nullptr;
+
         // clean up
         process->deleteLater();
         process = nullptr;
@@ -279,6 +287,10 @@ namespace SDDM {
         // start display setup script
         qDebug() << "Running display setup script " << displayCommand;
         displayScript->start(displayCommand);
+
+        // clean up the script process
+        displayScript->deleteLater();
+        displayScript = nullptr;
     }

     void XorgDisplayServer::changeOwner(const QString &fileName) {
-- 
1.9.1
@davidedmundson

davidedmundson Apr 8, 2015

Owner

that won't work because then you're deleting the displayScript startup script potentially before it's finished.

in this case it kinda leaked for a reason... though a terrible one.

you'd need something like
connect(process, finished, process, deleteLater()));

or use QProcess::startDetatched which does it all internally.

Owner

davidedmundson commented Apr 2, 2015

Thanks for looking into this.

src/daemon/XorgDisplayServer.cpp: wait for DisplayStopCommand to finish
Also make sure to free the memory allocated for DisplayCommand

tseliot commented Apr 10, 2015

I got the code to work exactly the way I wanted in the last commit. I connected the signal as you suggested in order to free displayScript. Furthermore we now wait for displayStopScript to finish. As a result, I can easily switch between GPUs in Ubuntu now.

davidedmundson added a commit that referenced this pull request Apr 10, 2015

Merge pull request #395 from tseliot/master
Add support for the DisplayStopCommand entry

@davidedmundson davidedmundson merged commit a894e39 into sddm:master Apr 10, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

tseliot commented Apr 10, 2015

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment