diff options
author | Thomas White <taw@physics.org> | 2022-01-12 12:47:01 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-01-12 12:47:01 +0100 |
commit | 48c02e71e5bf548180c0191645bb77dec01a5559 (patch) | |
tree | cb110d079e0864c35bc512b70f47692f1f76104a | |
parent | 5f4d0976a893aad5aca17daed96cb743f48bdd21 (diff) |
SLURM: Copy environment from parent process
Unfortunately, several environments rely on "magic" environment
variables to make things work. These need to be propagated.
The path to the GUI will no longer be added to the PATH. This was
intended to help when the indexing executables (mosflm, dirax etc) were
found alongside the CrystFEL executables. However, it's highly likely
that the path to the CrystFEL executables will be in PATH anyway.
This way, running the SLURM jobs in the same environment as the GUI
itself, also seems more compliant with the "principle of least
surprise".
-rw-r--r-- | src/gui_backend_slurm.c | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c index 0d3d0284..e3286e5c 100644 --- a/src/gui_backend_slurm.c +++ b/src/gui_backend_slurm.c @@ -251,44 +251,25 @@ static void cancel_task(void *job_priv) static char **create_env(int *psize, char *path_add) { char **env; - const char *base_path = "PATH=/bin:/usr/bin"; - char *crystfel_path; - size_t path_len; + gchar **env_list; + int i, n_env; - env = malloc(10*sizeof(char *)); - if ( env == NULL ) return NULL; - - crystfel_path = get_crystfel_path_str(); - - path_len = 4 + strlen(base_path); + env_list = g_get_environ(); + n_env = 0; + while ( env_list[n_env] == NULL ) n_env++; - if ( path_add != NULL ) { - path_len += strlen(path_add); - } - - if ( crystfel_path != NULL ) { - path_len += strlen(crystfel_path); - } - - env[0] = malloc(path_len); - if ( env[0] == NULL ) { - free(env); - return NULL; - } + /* Can't mix g_malloc/g_free with normal malloc/free, so we + * must do a deep copy */ + env = malloc(n_env*sizeof(char *)); + if ( env == NULL ) return NULL; - strcpy(env[0], base_path); - if ( crystfel_path != NULL ) { - strcat(env[0], ":"); - strcat(env[0], crystfel_path); - g_free(crystfel_path); - } - if ( path_add != NULL ) { - strcat(env[0], ":"); - strcat(env[0], path_add); + for ( i=0; i<n_env; i++ ) { + env[i] = strdup(env_list[i]); } - *psize = 1; + g_strfreev(env_list); + *psize = n_env; return env; } |