瀏覽代碼

catch unsafe use of non-reentrant getenv

Samuel Thibault 10 年之前
父節點
當前提交
1b2f436a98

+ 5 - 0
Makefile.am

@@ -115,6 +115,11 @@ if STARPU_DEVEL
 		echo "Please do not use ssize_t, it is not available on Windows, use starpu_ssize_t instead"; \
 		false ; \
 	fi
+	@if grep -re '\<getenv\>' $$( find $(srcdir)/src $(srcdir)/mpi/src $(srcdir)/include -name \*.[ch] -a \! -name starpu_util.h -a \! -name utils.c) ; \
+	then \
+		echo "Please do not use getenv, use starpu_getenv instead, which catches unsafe uses"; \
+		false ; \
+	fi
 endif
 
 if BUILD_STARPU_TOP

+ 7 - 2
include/starpu_util.h

@@ -229,11 +229,16 @@ extern "C"
 {
 #endif
 
+extern int _starpu_silent;
+
+char *starpu_getenv(const char *str);
+
+
 static __starpu_inline int starpu_get_env_number(const char *str)
 {
 	char *strval;
 
-	strval = getenv(str);
+	strval = starpu_getenv(str);
 	if (strval)
 	{
 		/* the env variable was actually set */
@@ -269,7 +274,7 @@ static __starpu_inline float starpu_get_env_float_default(const char *str, float
 {
 	char *strval;
 
-	strval = getenv(str);
+	strval = starpu_getenv(str);
 	if (strval)
 	{
 		/* the env variable was actually set */

+ 1 - 0
mpi/src/starpu_mpi.c

@@ -1539,6 +1539,7 @@ int _starpu_mpi_initialize(int *argc, char ***argv, int initialize_mpi, MPI_Comm
 	detached_requests = _starpu_mpi_req_list_new();
 
 	STARPU_PTHREAD_MUTEX_INIT(&mutex_posted_requests, NULL);
+	_starpu_mpi_comm = starpu_getenv("STARPU_MPI_COMM") != NULL;
 
 #ifdef STARPU_MPI_ACTIVITY
 	hookid = starpu_progression_hook_register(_starpu_mpi_progression_hook_func, NULL);

+ 1 - 1
mpi/src/starpu_mpi_cache.c

@@ -74,7 +74,7 @@ void _starpu_mpi_cache_init(MPI_Comm comm)
 
 	if (_starpu_cache_enabled == 0)
 	{
-		if (!getenv("STARPU_SILENT")) fprintf(stderr,"Warning: StarPU MPI Communication cache is disabled\n");
+		if (!_starpu_silent) fprintf(stderr,"Warning: StarPU MPI Communication cache is disabled\n");
 		return;
 	}
 

+ 1 - 1
mpi/src/starpu_mpi_cache_stats.c

@@ -33,7 +33,7 @@ void _starpu_mpi_cache_stats_init(MPI_Comm comm)
 	}
 	if (stats_enabled == 0) return;
 
-	if (!getenv("STARPU_SILENT")) fprintf(stderr,"Warning: StarPU is executed with STARPU_MPI_CACHE_STATS=1, which slows down a bit\n");
+	if (!_starpu_silent) fprintf(stderr,"Warning: StarPU is executed with STARPU_MPI_CACHE_STATS=1, which slows down a bit\n");
 
 	starpu_mpi_comm_size(comm, &world_size);
 	_STARPU_MPI_DEBUG(1, "allocating for %d nodes\n", world_size);

+ 1 - 0
mpi/src/starpu_mpi_private.c

@@ -21,6 +21,7 @@ int _starpu_debug_rank=-1;
 int _starpu_debug_level_min=0;
 int _starpu_debug_level_max=0;
 int _starpu_mpi_tag = 42;
+int _starpu_mpi_comm;
 
 void _starpu_mpi_set_debug_level_min(int level)
 {

+ 6 - 5
mpi/src/starpu_mpi_private.h

@@ -31,6 +31,7 @@ extern "C" {
 
 extern int _starpu_debug_rank;
 char *_starpu_mpi_get_mpi_code(int code);
+extern int _starpu_mpi_comm;
 
 #ifdef STARPU_VERBOSE
 extern int _starpu_debug_level_min;
@@ -72,7 +73,7 @@ int _starpu_debug_rank;
 #  define _STARPU_MPI_COMM_DEBUG(count, datatype, node, tag, utag, comm, way) \
 	do \
 	{ \
-	     	if (getenv("STARPU_MPI_COMM"))	\
+	     	if (_starpu_mpi_commgetenv("STARPU_MPI_COMM"))	\
 	     	{ \
      			int __size; \
 			if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
@@ -86,7 +87,7 @@ int _starpu_debug_rank;
 #  define _STARPU_MPI_DEBUG(level, fmt, ...) \
 	do \
 	{								\
-		if (!getenv("STARPU_SILENT") && _starpu_debug_level_min <= level && level <= _starpu_debug_level_max)	\
+		if (!_starpu_silent && _starpu_debug_level_min <= level && level <= _starpu_debug_level_max)	\
 		{							\
 			if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
 			fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] " fmt , (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__ , __LINE__,## __VA_ARGS__); \
@@ -100,7 +101,7 @@ int _starpu_debug_rank;
 #  define _STARPU_MPI_DEBUG(level, fmt, ...)		do { } while(0)
 #endif
 
-#define _STARPU_MPI_DISP(fmt, ...) do { if (!getenv("STARPU_SILENT")) { \
+#define _STARPU_MPI_DISP(fmt, ...) do { if (!_starpu_silent) { \
 	       				     if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank); \
                                              fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] " fmt , (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__ , __LINE__ ,## __VA_ARGS__); \
                                              fflush(stderr); }} while(0);
@@ -109,11 +110,11 @@ int _starpu_debug_rank;
                                              fflush(stderr); } while(0);
 
 #ifdef STARPU_VERBOSE0
-#  define _STARPU_MPI_LOG_IN()             do { if (!getenv("STARPU_SILENT")) { \
+#  define _STARPU_MPI_LOG_IN()             do { if (!_starpu_silent) { \
                                                if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank);                        \
                                                fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] -->\n", (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__ , __LINE__); \
                                                fflush(stderr); }} while(0)
-#  define _STARPU_MPI_LOG_OUT()            do { if (!getenv("STARPU_SILENT")) { \
+#  define _STARPU_MPI_LOG_OUT()            do { if (!_starpu_silent) { \
                                                if (_starpu_debug_rank == -1) starpu_mpi_comm_rank(MPI_COMM_WORLD, &_starpu_debug_rank);                        \
                                                fprintf(stderr, "%*s[%d][starpu_mpi][%s:%d] <--\n", (_starpu_debug_rank+1)*4, "", _starpu_debug_rank, __starpu_func__, __LINE__ ); \
                                                fflush(stderr); }} while(0)

+ 1 - 1
mpi/src/starpu_mpi_stats.c

@@ -34,7 +34,7 @@ void _starpu_mpi_comm_amounts_init(MPI_Comm comm)
 
 	if (stats_enabled == 0) return;
 
-	if (!getenv("STARPU_SILENT")) fprintf(stderr,"Warning: StarPU is executed with STARPU_COMM_STATS=1, which slows down a bit\n");
+	if (!_starpu_silent) fprintf(stderr,"Warning: StarPU is executed with STARPU_COMM_STATS=1, which slows down a bit\n");
 
 	starpu_mpi_comm_size(comm, &world_size);
 	_STARPU_MPI_DEBUG(1, "allocating for %d nodes\n", world_size);

+ 2 - 2
src/common/fxt.c

@@ -78,7 +78,7 @@ static void _starpu_profile_set_tracefile(void *last, ...)
 	va_list vl;
 	char *user;
 
-	char *fxt_prefix = getenv("STARPU_FXT_PREFIX");
+	char *fxt_prefix = starpu_getenv("STARPU_FXT_PREFIX");
 	if (!fxt_prefix)
 	     fxt_prefix = "/tmp/";
 
@@ -86,7 +86,7 @@ static void _starpu_profile_set_tracefile(void *last, ...)
 	vsprintf(_STARPU_PROF_FILE_USER, fxt_prefix, vl);
 	va_end(vl);
 
-	user = getenv("USER");
+	user = starpu_getenv("USER");
 	if (!user)
 		user = "";
 

+ 18 - 5
src/common/utils.c

@@ -18,6 +18,7 @@
 #include <starpu.h>
 #include <common/config.h>
 #include <common/utils.h>
+#include <core/workers.h>
 #include <errno.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -227,13 +228,13 @@ int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex)
 
 char *_starpu_get_home_path(void)
 {
-	char *path = getenv("XDG_CACHE_HOME");
+	char *path = starpu_getenv("XDG_CACHE_HOME");
 	if (!path)
-		path = getenv("STARPU_HOME");
+		path = starpu_getenv("STARPU_HOME");
 	if (!path)
-		path = getenv("HOME");
+		path = starpu_getenv("HOME");
 	if (!path)
-		path = getenv("USERPROFILE");
+		path = starpu_getenv("USERPROFILE");
 	if (!path)
 	{
 		static int warn;
@@ -249,7 +250,7 @@ char *_starpu_get_home_path(void)
 
 void _starpu_gethostname(char *hostname, size_t size)
 {
-	char *forced_hostname = getenv("STARPU_HOSTNAME");
+	char *forced_hostname = starpu_getenv("STARPU_HOSTNAME");
 	if (forced_hostname && forced_hostname[0])
 	{
 		snprintf(hostname, size-1, "%s", forced_hostname);
@@ -281,3 +282,15 @@ void _starpu_sleep(struct timespec ts)
 #endif
 }
 
+char *starpu_getenv(const char *str)
+{
+	struct _starpu_worker * worker;
+
+	worker = _starpu_get_local_worker_key();
+
+#if defined(STARPU_DEVEL) || defined(STARPU_DEBUG)
+	if (worker && worker->worker_is_initialized)
+		_STARPU_DISP( "getenv should not be called from running workers, only for main() or worker initialization, since it is not reentrant\n");
+#endif
+	return getenv(str);
+}

+ 0 - 2
src/common/utils.h

@@ -147,8 +147,6 @@ int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
 
 void _starpu_sleep(struct timespec ts);
 
-extern int _starpu_silent;
-
 void _starpu_util_init(void);
 
 #endif // __COMMON_UTILS_H__

+ 1 - 1
src/core/debug.c

@@ -38,7 +38,7 @@ void _starpu_open_debug_logfile(void)
 	/* what is  the name of the file ? default = "starpu.log" */
 	char *logfile_name;
 
-	logfile_name = getenv("STARPU_LOGFILENAME");
+	logfile_name = starpu_getenv("STARPU_LOGFILENAME");
 	if (!logfile_name)
 	{
 		logfile_name = "starpu.log";

+ 2 - 2
src/core/disk.c

@@ -351,11 +351,11 @@ void _starpu_swap_init(void)
 	struct starpu_disk_ops *ops;
 	int dd;
 
-	path = getenv("STARPU_DISK_SWAP");
+	path = starpu_getenv("STARPU_DISK_SWAP");
 	if (!path)
 		return;
 
-	backend = getenv("STARPU_DISK_SWAP_BACKEND");
+	backend = starpu_getenv("STARPU_DISK_SWAP_BACKEND");
 	if (!backend)
 	{
 		_starpu_mkpath(path, S_IRWXU);

+ 1 - 1
src/core/perfmodel/perfmodel.c

@@ -446,7 +446,7 @@ void _starpu_set_perf_model_dirs()
 #else
 	snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s/.starpu/sampling/", _starpu_get_home_path());
 #endif
-	char *path = getenv("STARPU_PERF_MODEL_DIR");
+	char *path = starpu_getenv("STARPU_PERF_MODEL_DIR");
 	if (path)
 	{
 		snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s/", path);

+ 3 - 1
src/core/sched_ctx.c

@@ -32,6 +32,7 @@ static double flops[STARPU_NMAX_SCHED_CTXS][STARPU_NMAXWORKERS];
 static size_t data_size[STARPU_NMAX_SCHED_CTXS][STARPU_NMAXWORKERS];
 static double hyp_actual_start_sample[STARPU_NMAX_SCHED_CTXS];
 static double window_size;
+static int nobind;
 
 static unsigned _starpu_get_first_free_sched_ctx(struct _starpu_machine_config *config);
 static void _starpu_sched_ctx_add_workers_to_master(unsigned sched_ctx_id, int *workerids, int nworkers, int new_master);
@@ -1166,6 +1167,7 @@ void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config)
 {
 	STARPU_PTHREAD_KEY_CREATE(&sched_ctx_key, NULL);
 	window_size = starpu_get_env_float_default("STARPU_WINDOW_TIME_SIZE", 0.0);
+	nobind = starpu_get_env_number("STARPU_WORKERS_NOBIND");
 
 	unsigned i;
 	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
@@ -1885,7 +1887,7 @@ void starpu_sched_ctx_bind_current_thread_to_cpuid(unsigned cpuid STARPU_ATTRIBU
 
 	/* FIXME: why not factorize with _starpu_bind_thread_on_cpu? */
 
-	if (starpu_get_env_number("STARPU_WORKERS_NOBIND") > 0)
+	if (nobind > 0)
 		return;
 
 #ifdef STARPU_HAVE_HWLOC

+ 3 - 3
src/core/sched_policy.c

@@ -128,7 +128,7 @@ static struct starpu_sched_policy *find_sched_policy_from_name(const char *polic
 
 static void display_sched_help_message(void)
 {
-	const char *sched_env = getenv("STARPU_SCHED");
+	const char *sched_env = starpu_getenv("STARPU_SCHED");
 	if (sched_env && (strcmp(sched_env, "help") == 0))
 	{
 		/* display the description of all predefined policies */
@@ -158,7 +158,7 @@ struct starpu_sched_policy *_starpu_select_sched_policy(struct _starpu_machine_c
 
 	/* Otherwise, we look if the application specified the name of a policy to load */
 	const char *sched_pol_name;
-	sched_pol_name = getenv("STARPU_SCHED");
+	sched_pol_name = starpu_getenv("STARPU_SCHED");
 	if (sched_pol_name == NULL && user_conf && user_conf->sched_policy_name)
 		sched_pol_name = user_conf->sched_policy_name;
 
@@ -994,7 +994,7 @@ void _starpu_print_idle_time()
 		all_idle += idle[i];
 
 	FILE *f;
-	const char *sched_env = getenv("STARPU_IDLE_FILE");
+	const char *sched_env = starpu_getenv("STARPU_IDLE_FILE");
 	if(!sched_env)
 		sched_env = "starpu_idle_microsec.log";
 	f = fopen(sched_env, "a");

+ 1 - 1
src/core/simgrid.h

@@ -35,7 +35,7 @@ struct _starpu_pthread_args
 #define MAX_TSD 16
 
 #define STARPU_MPI_AS_PREFIX "StarPU-MPI"
-#define _starpu_simgrid_running_smpi() (getenv("SMPI_GLOBAL_SIZE") != NULL)
+#define _starpu_simgrid_running_smpi() (starpu_getenv("SMPI_GLOBAL_SIZE") != NULL)
 
 void _starpu_simgrid_init(void);
 void _starpu_simgrid_wait_tasks(int workerid);

+ 2 - 2
src/core/task.c

@@ -1181,7 +1181,7 @@ static void *watchdog_func(void *arg)
 void _starpu_watchdog_init(void)
 {
 	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
-	char *timeout_env = getenv("STARPU_WATCHDOG_TIMEOUT");
+	char *timeout_env = starpu_getenv("STARPU_WATCHDOG_TIMEOUT");
 
 	STARPU_PTHREAD_MUTEX_INIT(&config->submitted_mutex, NULL);
 
@@ -1193,7 +1193,7 @@ void _starpu_watchdog_init(void)
 
 void _starpu_watchdog_shutdown(void)
 {
-	char *timeout_env = getenv("STARPU_WATCHDOG_TIMEOUT");
+	char *timeout_env = starpu_getenv("STARPU_WATCHDOG_TIMEOUT");
 
 	if (!timeout_env)
 		return;

+ 8 - 5
src/core/topology.c

@@ -47,6 +47,7 @@
 #endif
 
 static unsigned topology_is_initialized = 0;
+static int nobind;
 
 #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
 
@@ -90,7 +91,7 @@ _starpu_initialize_workers_deviceid (int *explicit_workers_gpuid,
 	 * cores. */
 
 	/* what do we use, explicit value, env. variable, or round-robin ? */
-	if ((strval = getenv(varname)))
+	if ((strval = starpu_getenv(varname)))
 	{
 		/* STARPU_WORKERS_CUDAID certainly contains less entries than
 		 * STARPU_NMAXWORKERS, so we reuse its entries in a round
@@ -372,8 +373,8 @@ _starpu_init_mic_node (struct _starpu_machine_config *config, int mic_idx,
 	/* Let's get the helper program to run on the MIC device */
 	int mic_file_found =
 	    _starpu_src_common_locate_file (mic_sink_program_path,
-					    getenv("STARPU_MIC_SINK_PROGRAM_NAME"),
-					    getenv("STARPU_MIC_SINK_PROGRAM_PATH"),
+					    starpu_getenv("STARPU_MIC_SINK_PROGRAM_NAME"),
+					    starpu_getenv("STARPU_MIC_SINK_PROGRAM_PATH"),
 					    user_conf->mic_sink_program_path,
 					    (argv ? (*argv)[0] : NULL),
 					    suffixes);
@@ -426,6 +427,8 @@ _starpu_init_topology (struct _starpu_machine_config *config)
 	if (topology_is_initialized)
 		return;
 
+	nobind = starpu_get_env_number("STARPU_WORKERS_NOBIND");
+
 	topology->nhwcpus = 0;
 	topology->nhwpus = 0;
 
@@ -511,7 +514,7 @@ _starpu_initialize_workers_bindid (struct _starpu_machine_config *config)
 	 * cores. */
 
 	/* what do we use, explicit value, env. variable, or round-robin ? */
-	if ((strval = getenv("STARPU_WORKERS_CPUID")))
+	if ((strval = starpu_getenv("STARPU_WORKERS_CPUID")))
 	{
 		/* STARPU_WORKERS_CPUID certainly contains less entries than
 		 * STARPU_NMAXWORKERS, so we reuse its entries in a round
@@ -1176,7 +1179,7 @@ _starpu_bind_thread_on_cpu (
 #ifdef STARPU_SIMGRID
 	return;
 #else
-	if (starpu_get_env_number("STARPU_WORKERS_NOBIND") > 0)
+	if (nobind > 0)
 		return;
 	if (cpuid < 0)
 		return;

+ 5 - 5
src/core/workers.c

@@ -917,7 +917,7 @@ int starpu_conf_init(struct starpu_conf *conf)
 
 	memset(conf, 0, sizeof(*conf));
 	conf->magic = 42;
-	conf->sched_policy_name = getenv("STARPU_SCHED");
+	conf->sched_policy_name = starpu_getenv("STARPU_SCHED");
 	conf->sched_policy = NULL;
 	conf->global_sched_ctx_min_priority = starpu_get_env_number("STARPU_MIN_PRIO");
 	conf->global_sched_ctx_max_priority = starpu_get_env_number("STARPU_MAX_PRIO");
@@ -935,7 +935,7 @@ int starpu_conf_init(struct starpu_conf *conf)
 	conf->nscc = starpu_get_env_number("STARPU_NSCC");
 	conf->calibrate = starpu_get_env_number("STARPU_CALIBRATE");
 	conf->bus_calibrate = starpu_get_env_number("STARPU_BUS_CALIBRATE");
-	conf->mic_sink_program_path = getenv("STARPU_MIC_PROGRAM_PATH");
+	conf->mic_sink_program_path = starpu_getenv("STARPU_MIC_PROGRAM_PATH");
 
 	if (conf->calibrate == -1)
 	     conf->calibrate = 0;
@@ -1002,7 +1002,7 @@ static void _starpu_conf_set_value_against_environment(char *name, int *value)
 
 void _starpu_conf_check_environment(struct starpu_conf *conf)
 {
-	char *sched = getenv("STARPU_SCHED");
+	char *sched = starpu_getenv("STARPU_SCHED");
 	if (sched)
 	{
 		conf->sched_policy_name = sched;
@@ -1090,7 +1090,7 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 
 	/* If StarPU was configured to use MP sinks, we have to control the
 	 * kind on node we are running on : host or sink ? */
-	if (getenv("STARPU_SINK"))
+	if (starpu_getenv("STARPU_SINK"))
 		is_a_sink = 1;
 #else
 	(void)argc;
@@ -1107,7 +1107,7 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 	_starpu_simgrid_init();
 	/* Warn when the lots of stacks malloc()-ated by simgrid for transfer
 	 * processes will take a long time to get initialized */
-	if (getenv("MALLOC_PERTURB_"))
+	if (starpu_getenv("MALLOC_PERTURB_"))
 		_STARPU_DISP("Warning: MALLOC_PERTURB_ is set, this makes simgrid runs very slow\n");
 #else
 #ifdef __GNUC__

+ 1 - 0
src/drivers/cpu/driver_cpu.c

@@ -317,6 +317,7 @@ int _starpu_cpu_driver_deinit(struct _starpu_worker *cpu_worker)
 	 * coherency is not maintained anymore at that point ! */
 	_starpu_free_all_automatically_allocated_buffers(memnode);
 
+	cpu_worker->worker_is_initialized = 0;
 	_STARPU_TRACE_WORKER_DEINIT_END(_STARPU_FUT_CPU_KEY);
 
 	return 0;

+ 1 - 0
src/drivers/cuda/driver_cuda.c

@@ -859,6 +859,7 @@ int _starpu_cuda_driver_deinit(struct _starpu_worker_set *worker_set)
 		deinit_worker_context(workerid);
 	}
 
+	worker_set->workers[0].worker_is_initialized = 0;
 	_STARPU_TRACE_WORKER_DEINIT_END(_STARPU_FUT_CUDA_KEY);
 
 	return 0;

+ 1 - 0
src/drivers/mic/driver_mic_source.c

@@ -550,6 +550,7 @@ void *_starpu_mic_src_worker(void *arg)
 
 	_STARPU_TRACE_WORKER_DEINIT_START;
 
+	worker->worker_is_initialized = 0;
 	_STARPU_TRACE_WORKER_DEINIT_END(_STARPU_FUT_CUDA_KEY);
 
 	return NULL;

+ 2 - 2
src/drivers/mp_common/mp_common.c

@@ -74,8 +74,8 @@ _starpu_mp_common_node_create(enum _starpu_mp_node_kind node_kind,
 
 	case STARPU_MIC_SINK:
 	{
-		node->devid = atoi(getenv("_STARPU_MIC_DEVID"));
-		node->nb_mp_sinks = atoi(getenv("_STARPU_MIC_NB"));
+		node->devid = atoi(starpu_getenv("_STARPU_MIC_DEVID"));
+		node->nb_mp_sinks = atoi(starpu_getenv("_STARPU_MIC_NB"));
 
 		node->init = _starpu_mic_sink_init;
 		node->launch_workers = _starpu_mic_sink_launch_workers;

+ 1 - 1
src/drivers/mp_common/sink_common.c

@@ -38,7 +38,7 @@ static enum _starpu_mp_node_kind _starpu_sink_common_get_kind(void)
 {
 	/* Environment varible STARPU_SINK must be defined when running on sink
 	 * side : let's use it to get the kind of node we're running on */
-	char *node_kind = getenv("STARPU_SINK");
+	char *node_kind = starpu_getenv("STARPU_SINK");
 	STARPU_ASSERT(node_kind);
 
 	if (!strcmp(node_kind, "STARPU_MIC"))

+ 2 - 1
src/drivers/opencl/driver_opencl.c

@@ -571,7 +571,7 @@ void _starpu_opencl_init(void)
 		}
 
                 // Get location of OpenCl kernel source files
-                _starpu_opencl_program_dir = getenv("STARPU_OPENCL_PROGRAM_DIR");
+                _starpu_opencl_program_dir = starpu_getenv("STARPU_OPENCL_PROGRAM_DIR");
 
 		if (nb_devices > STARPU_MAXOPENCLDEVS)
 		{
@@ -794,6 +794,7 @@ int _starpu_opencl_driver_deinit(struct _starpu_worker *worker)
 	unsigned devid   = worker->devid;
         _starpu_opencl_deinit_context(devid);
 
+	worker->worker_is_initialized = 0;
 	_STARPU_TRACE_WORKER_DEINIT_END(_STARPU_FUT_OPENCL_KEY);
 
 	return 0;

+ 1 - 0
src/drivers/scc/driver_scc_source.c

@@ -316,6 +316,7 @@ void *_starpu_scc_src_worker(void *arg)
 
 	_starpu_scc_src_deinit_context(args->subworkerid);
 
+	worker->worker_is_initialized = 0;
 	_STARPU_TRACE_WORKER_DEINIT_END(_STARPU_FUT_SCC_KEY);
 
 	return NULL;

+ 1 - 1
src/profiling/profiling.c

@@ -119,7 +119,7 @@ void _starpu_profiling_init(void)
 
 	_starpu_profiling_reset_counters();
 
-	if ((env = getenv("STARPU_PROFILING")) && atoi(env))
+	if ((env = starpu_getenv("STARPU_PROFILING")) && atoi(env))
 	{
 		ANNOTATE_HAPPENS_AFTER(&_starpu_profiling);
 		_starpu_profiling = STARPU_PROFILING_ENABLE;

+ 3 - 3
src/profiling/profiling_helpers.c

@@ -23,7 +23,7 @@ void starpu_profiling_bus_helper_display_summary(void)
 	const char *stats;
 	int long long sum_transferred = 0;
 
-	if (!((stats = getenv("STARPU_BUS_STATS")) && atoi(stats))) return;
+	if (!((stats = starpu_getenv("STARPU_BUS_STATS")) && atoi(stats))) return;
 
 	fprintf(stderr, "\nData transfer statistics:\n");
 	fprintf(stderr,   "*************************\n");
@@ -61,7 +61,7 @@ void starpu_profiling_worker_helper_display_summary(void)
 	int workerid;
 	int worker_cnt = starpu_worker_get_count();
 
-	if (!((stats = getenv("STARPU_WORKER_STATS")) && atoi(stats))) return;
+	if (!((stats = starpu_getenv("STARPU_WORKER_STATS")) && atoi(stats))) return;
 
 	fprintf(stderr, "\nWorker statistics:\n");
 	fprintf(stderr,   "******************\n");
@@ -99,7 +99,7 @@ void starpu_profiling_worker_helper_display_summary(void)
 
 	if (profiling)
 	{
-		const char *strval_idle_power = getenv("STARPU_IDLE_POWER");
+		const char *strval_idle_power = starpu_getenv("STARPU_IDLE_POWER");
 		if (strval_idle_power)
 		{
 			double idle_power = atof(strval_idle_power); /* Watt */

+ 9 - 9
src/util/openmp_runtime_support_environment.c

@@ -104,7 +104,7 @@ static int stringsn_cmp(const char *strings[], const char *str, size_t n)
 /* TODO: move to utils */
 static void read_boolean_var(const char *var, int *dest)
 {
-	const char *env = getenv(var);
+	const char *env = starpu_getenv(var);
 	if (env)
 	{
 		char *str = strdup(env);
@@ -128,7 +128,7 @@ static void read_boolean_var(const char *var, int *dest)
 /* TODO: move to utils */
 static void read_int_var(const char *var, int *dest)
 {
-	const char *env = getenv(var);
+	const char *env = starpu_getenv(var);
 	if (env)
 	{
 		char *str = strdup(env);
@@ -151,7 +151,7 @@ static void read_int_var(const char *var, int *dest)
 
 static void read_size_var(const char *var, int *dest)
 {
-	const char *env = getenv(var);
+	const char *env = starpu_getenv(var);
 	if (env)
 	{
 		char *str = strdup(env);
@@ -192,7 +192,7 @@ static void read_size_var(const char *var, int *dest)
 
 static void read_sched_var(const char *var, int *dest, unsigned long long *dest_chunk)
 {
-	const char *env = getenv(var);
+	const char *env = starpu_getenv(var);
 	if (env)
 	{
 		char *str = strdup(env);
@@ -232,7 +232,7 @@ static void read_sched_var(const char *var, int *dest, unsigned long long *dest_
 
 static void read_wait_policy_var(const char *var, int *dest)
 {
-	const char *env = getenv(var);
+	const char *env = starpu_getenv(var);
 	if (env)
 	{
 		char *str = strdup(env);
@@ -255,7 +255,7 @@ static void read_wait_policy_var(const char *var, int *dest)
 
 static void read_display_env_var(const char *var, int *dest)
 {
-	const char *env = getenv(var);
+	const char *env = starpu_getenv(var);
 	if (env)
 	{
 		char *str = strdup(env);
@@ -693,7 +693,7 @@ static void read_omp_environment(void)
 			/* TODO: check what should be used as default value */
 			bind_list[level] = starpu_omp_proc_bind_undefined;
 		}
-		const char *env = getenv("OMP_PROC_BIND");
+		const char *env = starpu_getenv("OMP_PROC_BIND");
 		if (env)
 		{
 			convert_bind_string(env, bind_list, max_levels);
@@ -712,7 +712,7 @@ static void read_omp_environment(void)
 			/* TODO: check what should be used as default value */
 			num_threads_list[level] = 0;
 		}
-		const char *env = getenv("OMP_NUM_THREADS");
+		const char *env = starpu_getenv("OMP_NUM_THREADS");
 		if (env)
 		{
 			convert_num_threads_string(env, num_threads_list, max_levels);
@@ -724,7 +724,7 @@ static void read_omp_environment(void)
 	{
 		memset(&_initial_icv_values.places, 0, sizeof(_initial_icv_values.places));
 		_initial_icv_values.places.abstract_name = starpu_omp_place_undefined;
-		const char *env = getenv("OMP_PLACES");
+		const char *env = starpu_getenv("OMP_PLACES");
 		if (env)
 		{
 			convert_places_string(env, &_initial_icv_values.places);