[education/rkward] rkward: Add experimental '--quirkmode' option

Thomas Friedrichsmeier null at kde.org
Wed Aug 3 14:34:42 BST 2022


Git commit 0ddf1acf027924af329ac5ff1376e6c21f078604 by Thomas Friedrichsmeier.
Committed on 03/08/2022 at 13:34.
Pushed by tfry into branch 'master'.

Add experimental '--quirkmode' option

M  +2    -0    rkward/main.cpp
M  +15   -4    rkward/rbackend/rkfrontendtransmitter.cpp
M  +1    -0    rkward/rbackend/rkfrontendtransmitter.h

https://invent.kde.org/education/rkward/commit/0ddf1acf027924af329ac5ff1376e6c21f078604

diff --git a/rkward/main.cpp b/rkward/main.cpp
index c7c5e56a..92a0613f 100644
--- a/rkward/main.cpp
+++ b/rkward/main.cpp
@@ -295,6 +295,7 @@ int main (int argc, char *argv[]) {
 	parser.addOption (QCommandLineOption ("reuse", i18n ("Reuse a running RKWard instance (if available). If a running instance is reused, only the file arguments will be interpreted, all other options will be ignored.")));
 	parser.addOption (QCommandLineOption ("autoreuse", i18n ("Behaves like --reuse, if any file arguments are also given, starts a new instance, otherwise. Intended for use in the .desktop file.")));
 	parser.addOption (QCommandLineOption ("nowarn-external", i18n ("When used in conjunction with rkward://runplugin/-URLs specified on the command line, suppresses the warning about application-external (untrusted) links.")));
+	parser.addOption(QCommandLineOption("quirkmode", i18n("Disable some startup validation code. Experimental option, not intended for regular use.")));
 	parser.addPositionalArgument ("files", i18n ("File or files to open, typically a workspace, or an R script file. When loading several things, you should specify the workspace, first."), "[Files...]");
 
 	aboutData.setupCommandLine (&parser);
@@ -327,6 +328,7 @@ int main (int argc, char *argv[]) {
 	}
 	RKSettingsModuleGeneral::setStartupOption("evaluate", parser.value("evaluate"));
 	RKSettingsModuleGeneral::setStartupOption("backend-debugger", parser.value("backend-debugger"));
+	RKSettingsModuleGeneral::setStartupOption("quirkmode", parser.isSet("quirkmode"));
 
 	// MacOS may need some path adjustments, first
 #ifdef Q_OS_MACOS
diff --git a/rkward/rbackend/rkfrontendtransmitter.cpp b/rkward/rbackend/rkfrontendtransmitter.cpp
index 4492dfbe..f091088a 100644
--- a/rkward/rbackend/rkfrontendtransmitter.cpp
+++ b/rkward/rbackend/rkfrontendtransmitter.cpp
@@ -45,6 +45,7 @@ RKFrontendTransmitter::RKFrontendTransmitter () : RKAbstractTransmitter () {
 	RK_TRACE (RBACKEND);
 
 	rkd_transmitter = new RKGraphicsDeviceFrontendTransmitter ();
+	quirkmode = false;
 	start ();
 }
 
@@ -66,12 +67,15 @@ QString localeDir () {
 void RKFrontendTransmitter::run () {
 	RK_TRACE (RBACKEND);
 
+	quirkmode = RKSettingsModuleGeneral::startupOption("quirkmode").toBool();
+
 	// start server
 	server = new QLocalServer (this);
 	// we add a bit of randomness to the servername, as in general the servername must be unique
 	// there could be conflicts with concurrent or with previous crashed rkward sessions.
 	if (!server->listen ("rkward" + KRandom::randomString (8))) handleTransmissionError ("Failure to start frontend server: " + server->errorString ());
 	connect (server, &QLocalServer::newConnection, this, &RKFrontendTransmitter::connectAndEnterLoop, Qt::QueuedConnection);
+	if (quirkmode) server->setSocketOptions(QLocalServer::UserAccessOption);
 	// start backend
 	backend = new QProcess (this);
 	connect (backend, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &RKFrontendTransmitter::backendExit);
@@ -130,7 +134,7 @@ void RKFrontendTransmitter::run () {
 	RK_DEBUG(RBACKEND, DL_INFO, "Setting working directory to %s", qPrintable (r_home));
 	backend->setWorkingDirectory (r_home);
 #endif
-//#if defined(Q_OS_WIN)
+#if defined(Q_OS_WIN)
 	// On some windows systems, the _first_ invocation of the backend seems to fail as somehow process output from the backend (the token) never arrives.
 	// What appears to function as a workaround is start a dummy process, before that.
 	QProcess dummy;
@@ -139,14 +143,17 @@ void RKFrontendTransmitter::run () {
 	dummy.start(RKSessionVars::RBinary(), dummyargs, QIODevice::ReadOnly);
 	dummy.waitForFinished();
 	dummy.readAllStandardOutput();
-//#endif
+#endif
 	RK_DEBUG(RBACKEND, DL_DEBUG, "Starting backend. Timestamp %d", QDateTime::currentMSecsSinceEpoch(), token.length());
 	backend->start(RKSessionVars::RBinary(), args, QIODevice::ReadOnly);
 
 	if (!backend->waitForStarted()) {
 		handleTransmissionError(i18n("The backend executable could not be started. Error message was: %1", backend->errorString()));
 	} else {
-		token = waitReadLine(backend, 5000).trimmed();
+		if (!quirkmode) {
+			token = waitReadLine(backend, 5000).trimmed();
+		}
+		RK_DEBUG(RBACKEND, DL_DEBUG, "Now closing stdio channels");
 		backend->closeReadChannel(QProcess::StandardError);
 		backend->closeReadChannel(QProcess::StandardOutput);
 	}
@@ -191,7 +198,11 @@ void RKFrontendTransmitter::connectAndEnterLoop () {
 
 	// handshake
 	QString token_c = waitReadLine(con, 1000).trimmed();
-	if (token_c != token) handleTransmissionError (i18n ("Error during handshake with backend process. Expected token '%1', received token '%2'", token, token_c));
+	if (quirkmode) {
+		token = token_c;
+	} else {
+		if (token_c != token) handleTransmissionError (i18n ("Error during handshake with backend process. Expected token '%1', received token '%2'", token, token_c));
+	}
 	QString version_c = waitReadLine(con, 1000).trimmed();
 	if (version_c != RKWARD_VERSION) handleTransmissionError (i18n ("Version mismatch during handshake with backend process. Frontend is version '%1' while backend is '%2'.\nPlease fix your installation.", QString (RKWARD_VERSION), version_c));
 
diff --git a/rkward/rbackend/rkfrontendtransmitter.h b/rkward/rbackend/rkfrontendtransmitter.h
index 32281d83..630460e9 100644
--- a/rkward/rbackend/rkfrontendtransmitter.h
+++ b/rkward/rbackend/rkfrontendtransmitter.h
@@ -38,6 +38,7 @@ private slots:
 private:
 	void handleTransmissionError (const QString &message) override;
 
+	bool quirkmode;
 	QProcess* backend;
 	QLocalServer* server;
 	RKGraphicsDeviceFrontendTransmitter* rkd_transmitter;


More information about the rkward-tracker mailing list