diff options
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.patch | 94 |
1 files changed, 0 insertions, 94 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 deleted file mode 100644 index 2b19cb0..0000000 --- a/patches/rstudio-server-multi-version/0002-sessionProcessConfig-Configure-R-version-from-active.patch +++ /dev/null | |||
| @@ -1,94 +0,0 @@ | |||
| 1 | From 242819ba38ed77e28629737dff9bfd5410ec1fdc Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Ricardo Wurmus <rekado@elephly.net> | ||
| 3 | Date: Fri, 18 Dec 2020 10:32:01 +0100 | ||
| 4 | Subject: [PATCH 2/7] sessionProcessConfig: Configure R version from active | ||
| 5 | session. | ||
| 6 | |||
| 7 | When switching projects the R version is recorded in the active | ||
| 8 | session. Before launching a new rsession process R environment | ||
| 9 | variables need to be set to select the variant of libR.so that should | ||
| 10 | be used to launch the embedded R. | ||
| 11 | |||
| 12 | * src/cpp/server/ServerSessionManager.cpp (sessionProcessConfig): | ||
| 13 | Configure R environment using the R version that has been recorded in | ||
| 14 | the active session. | ||
| 15 | --- | ||
| 16 | .../server/session/ServerSessionManager.cpp | 44 ++++++++++++++++++- | ||
| 17 | 1 file changed, 43 insertions(+), 1 deletion(-) | ||
| 18 | |||
| 19 | diff --git a/src/cpp/server/session/ServerSessionManager.cpp b/src/cpp/server/session/ServerSessionManager.cpp | ||
| 20 | index d4da986378..28d3248606 100644 | ||
| 21 | --- a/src/cpp/server/session/ServerSessionManager.cpp | ||
| 22 | +++ b/src/cpp/server/session/ServerSessionManager.cpp | ||
| 23 | @@ -2,6 +2,7 @@ | ||
| 24 | * ServerSessionManager.cpp | ||
| 25 | * | ||
| 26 | * Copyright (C) 2022 by Posit Software, PBC | ||
| 27 | + * Copyright (C) 2020-2025 Ricardo Wurmus | ||
| 28 | * | ||
| 29 | * Unless you have received this program directly from Posit Software pursuant | ||
| 30 | * to the terms of a commercial license agreement with Posit Software, then | ||
| 31 | @@ -22,10 +23,14 @@ | ||
| 32 | #include <shared_core/SafeConvert.hpp> | ||
| 33 | #include <core/SocketRpc.hpp> | ||
| 34 | #include <core/system/Process.hpp> | ||
| 35 | +#include <shared_core/system/User.hpp> | ||
| 36 | #include <core/system/PosixUser.hpp> | ||
| 37 | #include <core/system/Environment.hpp> | ||
| 38 | #include <core/json/JsonRpc.hpp> | ||
| 39 | |||
| 40 | +#include <core/r_util/RActiveSessions.hpp> | ||
| 41 | +#include <core/r_util/RUserData.hpp> | ||
| 42 | + | ||
| 43 | #include <monitor/MonitorClient.hpp> | ||
| 44 | #include <session/SessionConstants.hpp> | ||
| 45 | |||
| 46 | @@ -160,7 +165,44 @@ core::system::ProcessConfig sessionProcessConfig( | ||
| 47 | std::copy(extraArgs.begin(), extraArgs.end(), std::back_inserter(args)); | ||
| 48 | |||
| 49 | // append R environment variables | ||
| 50 | - r_util::RVersion rVersion = r_environment::rVersion(); | ||
| 51 | + // Get the active session (e.g. after switching projects) and set R | ||
| 52 | + // variables according to the configured R version. | ||
| 53 | + | ||
| 54 | + // We cannot use core::system::userHomePath because it always | ||
| 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); | ||
| 70 | + | ||
| 71 | + r_util::ActiveSessions activeSessions(userScratchPath_); | ||
| 72 | + std::vector<boost::shared_ptr<r_util::ActiveSession> > sessions = | ||
| 73 | + activeSessions.list(homeDir, false); | ||
| 74 | + | ||
| 75 | + r_util::RVersion rVersion; | ||
| 76 | + if (sessions.size() > 0) { | ||
| 77 | + // Get the R version from the active user session. This will | ||
| 78 | + // have been set earlier when the user switched to a project. | ||
| 79 | + std::string errorMsg; | ||
| 80 | + bool success = r_environment::detectRVersion(FilePath((*sessions.front()).rVersionHome()).completePath("bin/R"), | ||
| 81 | + &rVersion, &errorMsg); | ||
| 82 | + | ||
| 83 | + if (!success) { | ||
| 84 | + rVersion = r_environment::rVersion(); | ||
| 85 | + } | ||
| 86 | + } else { | ||
| 87 | + rVersion = r_environment::rVersion(); | ||
| 88 | + } | ||
| 89 | core::system::Options rEnvVars = rVersion.environment(); | ||
| 90 | environment.insert(environment.end(), rEnvVars.begin(), rEnvVars.end()); | ||
| 91 | |||
| 92 | -- | ||
| 93 | 2.49.0 | ||
| 94 | |||
