From 48c02e71e5bf548180c0191645bb77dec01a5559 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 12 Jan 2022 12:47:01 +0100 Subject: 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". --- src/gui_backend_slurm.c | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) (limited to 'src') 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