summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorManuel Schneider2014-09-02 19:14:52 +0200
committerManuel Schneider2014-09-02 19:14:52 +0200
commitaf9d6791c82a9e848df66efa5fa569d2313812c9 (patch)
tree4a9d1cb85b09479da2a9777f5765d46e210a8b46 /src/dialog.cpp
parentRevert "detached pvsclient start" (diff)
downloadvmchooser2-af9d6791c82a9e848df66efa5fa569d2313812c9.tar.gz
vmchooser2-af9d6791c82a9e848df66efa5fa569d2313812c9.tar.xz
vmchooser2-af9d6791c82a9e848df66efa5fa569d2313812c9.zip
Use plain c to fork and detach vm session start script.
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index ae157ba..2806d7c 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -15,6 +15,7 @@
#include "globals.h"
#include "vsession.h"
#include "choosersettings.h"
+#include <unistd.h>
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
@@ -79,44 +80,57 @@ void Dialog::changeEvent(QEvent *e) {
}
}
-void Dialog::on_treeView_activated(QModelIndex index) {
- // this method gets called when a Session has been activated
-
- SessionTreeItem* item =
- static_cast<SessionTreeItem*>(index.internalPointer());
-
- const Session* s(item->session());
- if (!s) {
- // no valid session has been selected, do nothing
- return;
- }
-
- if (s->run()) {
- // Run session start script
- if (QFile::exists(sessionStartScript)) {
- // Use the current environment variables and add the necessary
- // information for the startUpScipt. In this case it is intended to tell
- // the startupscript if the PVS should be started. Further in the future
- // the session id will be passed this way.
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- if (ui->PVS_checkbox->isChecked()) {
- env.insert("PVS_SESSIONID", "xxxx");
- }
- QProcess scriptProcess;
- scriptProcess.setProcessEnvironment(env);
- scriptProcess.start(sessionStartScript, QIODevice::ReadOnly);
- scriptProcess.waitForFinished();
- scriptProcess.close();
+void Dialog::on_treeView_activated(QModelIndex index)
+{
+ // this method gets called when a Session has been activated
+
+ SessionTreeItem* item =
+ static_cast<SessionTreeItem*>(index.internalPointer());
+
+ const Session* s(item->session());
+ if (!s) {
+ // no valid session has been selected, do nothing
+ return;
+ }
+
+ if (s->run())
+ {
+ // Run session start script
+ if (QFile::exists(sessionStartScript))
+ {
+ // Use the current environment variables and add the necessary
+ // information for the startUpScipt.
+ char pvs_ac[128];
+ sprintf(pvs_ac, "PVS_AUTO_CONNECT=%s", ui->PVS_checkbox->isChecked()?"TRUE":"FALSE");
+ putenv(pvs_ac);
+
+ // fork this process
+ pid_t pid = fork();
+ if (pid < 0)
+ exit(EXIT_FAILURE);
+
+ // Branch for the clone
+ if (pid == 0){
+ // At this point we are executing as the child process
+ // Create a new SID for the child process (detach)
+ pid_t sid = setsid();
+ if (sid < 0)
+ exit(EXIT_FAILURE);
+
+ // Replace this clone with the process we'd like to start
+ // execv seems to copy this environment.
+ char const * const args[] = {VMCHOOSER_SESSION_START_SCRIPT, NULL};
+ execv(VMCHOOSER_SESSION_START_SCRIPT, (char**)args);
}
-
- ChooserSettings::setSetting("last-session", (s->shortDescription()));
- ChooserSettings::setSetting("last-tab", QString::number(activeTab_));
- setVisible(false);
- } else {
- QMessageBox::warning(
- this, trUtf8("vmchooser"),
- trUtf8("Vmchooser failed to run the selected session!"));
}
+ ChooserSettings::setSetting("last-session", (s->shortDescription()));
+ ChooserSettings::setSetting("last-tab", QString::number(activeTab_));
+ setVisible(false);
+ } else {
+ QMessageBox::warning(
+ this, trUtf8("vmchooser"),
+ trUtf8("Vmchooser failed to run the selected session!"));
+ }
}
void Dialog::addItems(const QList<Session*>& entries, int tab) {