diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-08-27 13:34:37 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-08-27 13:34:37 -0400 |
commit | b5ede97977d81e429a0389bf821312ec05d3faca (patch) | |
tree | f544d14d4ad41bdba7a5602447ff5d15910166b6 | |
parent | ea8ec855c3c6870d29c55afe3787afb2c05026a1 (diff) | |
download | stasis-b5ede97977d81e429a0389bf821312ec05d3faca.tar.gz |
Revert "Try a different approach using declare -f"
This reverts commit ea8ec855c3c6870d29c55afe3787afb2c05026a1.
-rw-r--r-- | include/conda.h | 1 | ||||
-rw-r--r-- | src/conda.c | 43 | ||||
-rw-r--r-- | src/delivery.c | 4 |
3 files changed, 22 insertions, 26 deletions
diff --git a/include/conda.h b/include/conda.h index 5e8b8d9..c546672 100644 --- a/include/conda.h +++ b/include/conda.h @@ -192,5 +192,4 @@ int conda_index(const char *path); */ int pip_index_provides(const char *index_url, const char *name, const char *version); -char *conda_runtime_dump(const char *root); #endif //STASIS_CONDA_H diff --git a/src/conda.c b/src/conda.c index 07a39c2..ff55f14 100644 --- a/src/conda.c +++ b/src/conda.c @@ -178,33 +178,20 @@ int conda_exec(const char *args) { return system(command); } -char *conda_runtime_dump(const char *root) { - const char *init_script_conda = "/etc/profile.d/conda.sh"; - const char *init_script_mamba = "/etc/profile.d/mamba.sh"; - int state = 0; - char cmd[BUFSIZ] = {0}; - sprintf(cmd, "source %s%s; source %s%s; env; declare -f", root, init_script_conda, root, init_script_mamba); - - char *output = shell_output(cmd, &state); - if (state) { - guard_free(output); - return NULL; - } - return output; -} - int conda_activate(const char *root, const char *env_name) { int fd = -1; FILE *fp = NULL; + const char *init_script_conda = "/etc/profile.d/conda.sh"; + const char *init_script_mamba = "/etc/profile.d/mamba.sh"; + char path_conda[PATH_MAX] = {0}; + char path_mamba[PATH_MAX] = {0}; char logfile[PATH_MAX] = {0}; struct Process proc; memset(&proc, 0, sizeof(proc)); - char *full_runtime = conda_runtime_dump(root); - if (!full_runtime) { - SYSERROR("%s", "Failed to read variables and functions from the runtime environment"); - return -1; - } + // Where to find conda's init scripts + sprintf(path_conda, "%s%s", root, init_script_conda); + sprintf(path_mamba, "%s%s", root, init_script_mamba); // Set the path to our stdout log // Emulate mktemp()'s behavior. Give us a unique file name, but don't use @@ -220,10 +207,22 @@ int conda_activate(const char *root, const char *env_name) { // Configure our process for output to a log file strcpy(proc.f_stdout, logfile); + // Verify conda's init scripts are available + if (access(path_conda, F_OK) < 0) { + perror(path_conda); + remove(logfile); + return -1; + } + + if (access(path_mamba, F_OK) < 0) { + perror(path_mamba); + remove(logfile); + return -1; + } + // Fully activate conda and record its effect on the runtime environment char command[PATH_MAX * 3]; - snprintf(command, sizeof(command) - 1, "%s\nconda activate %s &>/dev/null\nenv -0\n", full_runtime, env_name); - guard_free(full_runtime); + snprintf(command, sizeof(command) - 1, "source %s; source %s; conda activate %s &>/dev/null; env -0", path_conda, path_mamba, env_name); int retval = shell(&proc, command); if (retval) { // it didn't work; drop out for cleanup diff --git a/src/delivery.c b/src/delivery.c index 2d2273c..6dcfb4b 100644 --- a/src/delivery.c +++ b/src/delivery.c @@ -1789,9 +1789,7 @@ void delivery_tests_run(struct Delivery *ctx) { puts(cmd); char runner_cmd[PATH_MAX] = {0}; - char *full_runtime = conda_runtime_dump(ctx->storage.conda_install_prefix); - sprintf(runner_cmd, "%s\nset -x\n%s", full_runtime, cmd); - guard_free(full_runtime); + sprintf(runner_cmd, "set -x\n%s", cmd); status = shell(&proc, runner_cmd); if (status) { msg(STASIS_MSG_ERROR, "Script failure: %s\n%s\n\nExit code: %d\n", ctx->tests[i].name, ctx->tests[i].script, status); |