summaryrefslogtreecommitdiff
path: root/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-09-24 23:40:24 +0200
committerRicardo Wurmus <rekado@elephly.net>2021-09-24 23:40:24 +0200
commit85bf39702f0246ae3d601ac69f4b7828683a24d5 (patch)
tree3e9f4b202ee62c3f44f42fce151969f6b3d32765 /patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch
parent7f18ba0c2a97b50c9220b9388fca7170bfe38511 (diff)
patches: Update rstudio-server-multi-version patches.
The changes have been rebased on top of version 1.4.1717 and include a bug fix. Previous versions would fail to look up the user's active sessions (and thus fail to restore a previously set version of R) when rserver did not run as the same user account as the rsession process (e.g. root).
Diffstat (limited to 'patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch')
-rw-r--r--patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch38
1 files changed, 28 insertions, 10 deletions
diff --git a/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch b/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch
index 5105001..8b70bd0 100644
--- a/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch
+++ b/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch
@@ -1,4 +1,4 @@
1From 6172ab0908e8b80bd5838ed4336335d224b80941 Mon Sep 17 00:00:00 2001 1From 8202e0ae8276285afcdeee1fbec50a744a7171ff Mon Sep 17 00:00:00 2001
2From: Ricardo Wurmus <rekado@elephly.net> 2From: Ricardo Wurmus <rekado@elephly.net>
3Date: Fri, 18 Dec 2020 10:32:01 +0100 3Date: Fri, 18 Dec 2020 10:32:01 +0100
4Subject: [PATCH 2/7] sessionProcessConfig: Configure R version from active 4Subject: [PATCH 2/7] sessionProcessConfig: Configure R version from active
@@ -13,11 +13,11 @@ be used to launch the embedded R.
13Configure R environment using the R version that has been recorded in 13Configure R environment using the R version that has been recorded in
14the active session. 14the active session.
15--- 15---
16 src/cpp/server/ServerSessionManager.cpp | 26 ++++++++++++++++++++++++- 16 src/cpp/server/ServerSessionManager.cpp | 44 ++++++++++++++++++++++++-
17 1 file changed, 25 insertions(+), 1 deletion(-) 17 1 file changed, 43 insertions(+), 1 deletion(-)
18 18
19diff --git a/src/cpp/server/ServerSessionManager.cpp b/src/cpp/server/ServerSessionManager.cpp 19diff --git a/src/cpp/server/ServerSessionManager.cpp b/src/cpp/server/ServerSessionManager.cpp
20index 6e37578cab..86d212779a 100644 20index 22f138a6ad..01be702a83 100644
21--- a/src/cpp/server/ServerSessionManager.cpp 21--- a/src/cpp/server/ServerSessionManager.cpp
22+++ b/src/cpp/server/ServerSessionManager.cpp 22+++ b/src/cpp/server/ServerSessionManager.cpp
23@@ -2,6 +2,7 @@ 23@@ -2,6 +2,7 @@
@@ -43,20 +43,34 @@ index 6e37578cab..86d212779a 100644
43 #include <monitor/MonitorClient.hpp> 43 #include <monitor/MonitorClient.hpp>
44 #include <session/SessionConstants.hpp> 44 #include <session/SessionConstants.hpp>
45 45
46@@ -156,7 +161,26 @@ core::system::ProcessConfig sessionProcessConfig( 46@@ -156,7 +161,44 @@ core::system::ProcessConfig sessionProcessConfig(
47 std::copy(extraArgs.begin(), extraArgs.end(), std::back_inserter(args)); 47 std::copy(extraArgs.begin(), extraArgs.end(), std::back_inserter(args));
48 48
49 // append R environment variables 49 // append R environment variables
50- r_util::RVersion rVersion = r_environment::rVersion(); 50- r_util::RVersion rVersion = r_environment::rVersion();
51+ // Get the active session (e.g. after switching projects) and set R 51+ // Get the active session (e.g. after switching projects) and set R
52+ // variables according to the configured R version. 52+ // variables according to the configured R version.
53+ core::system::User user; 53+
54+ core::system::User::getUserFromIdentifier(context.username, user); 54+ // We cannot use core::system::userHomePath because it always
55+ FilePath userScratchPath_ = core::system::xdg::userDataDir(context.username); 55+ // returns the server user's home directory. This is /root when
56+ // rserver runs as root. Instead we want to get the home directory
57+ // of the *target* user for which rsession will be run. This is
58+ // why we launch a shell to determine the user's home directory.
59+ core::system::ProcessOptions poptions;
60+ core::system::ProcessResult presult;
61+ Error rError = core::system::runCommand(
62+ "/bin/sh -c 'echo -n ~" + context.username + "'",
63+ poptions,
64+ &presult);
65+ if (rError)
66+ LOG_ERROR(rError);
67+
68+ FilePath homeDir = FilePath(presult.stdOut);
69+ FilePath userScratchPath_ = core::system::xdg::userDataDir(context.username, homeDir);
56+ 70+
57+ r_util::ActiveSessions activeSessions(userScratchPath_); 71+ r_util::ActiveSessions activeSessions(userScratchPath_);
58+ std::vector<boost::shared_ptr<r_util::ActiveSession> > sessions = 72+ std::vector<boost::shared_ptr<r_util::ActiveSession> > sessions =
59+ activeSessions.list(user.getHomePath(), false); 73+ activeSessions.list(homeDir, false);
60+ 74+
61+ r_util::RVersion rVersion; 75+ r_util::RVersion rVersion;
62+ if (sessions.size() > 0) { 76+ if (sessions.size() > 0) {
@@ -65,6 +79,10 @@ index 6e37578cab..86d212779a 100644
65+ std::string errorMsg; 79+ std::string errorMsg;
66+ bool success = r_environment::detectRVersion(FilePath((*sessions.front()).rVersionHome()).completePath("bin/R"), 80+ bool success = r_environment::detectRVersion(FilePath((*sessions.front()).rVersionHome()).completePath("bin/R"),
67+ &rVersion, &errorMsg); 81+ &rVersion, &errorMsg);
82+
83+ if (!success) {
84+ rVersion = r_environment::rVersion();
85+ }
68+ } else { 86+ } else {
69+ rVersion = r_environment::rVersion(); 87+ rVersion = r_environment::rVersion();
70+ } 88+ }
@@ -72,5 +90,5 @@ index 6e37578cab..86d212779a 100644
72 environment.insert(environment.end(), rEnvVars.begin(), rEnvVars.end()); 90 environment.insert(environment.end(), rEnvVars.begin(), rEnvVars.end());
73 91
74-- 92--
752.31.1 932.33.0
76 94