Explorar o código

src: improve error messages and add extra checks when opening files

Nathalie Furmento %!s(int64=4) %!d(string=hai) anos
pai
achega
a007e79576
Modificáronse 2 ficheiros con 41 adicións e 11 borrados
  1. 1 1
      src/common/utils.c
  2. 40 10
      src/debug/traces/starpu_fxt.c

+ 1 - 1
src/common/utils.c

@@ -112,7 +112,7 @@ int _starpu_mkpath(const char *s, mode_t mode)
 	{
 		if (!S_ISDIR(sb.st_mode))
 		{
-			_STARPU_MSG("Error: %s is not a directory:\n", path);
+			_STARPU_MSG("Error: %s already exists and is not a directory:\n", path);
 			STARPU_ABORT();
 		}
 		/* It already exists and is a directory.  */

+ 40 - 10
src/debug/traces/starpu_fxt.c

@@ -3432,8 +3432,7 @@ void _starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *op
 	fd_in = open(filename_in, O_RDONLY);
 	if (fd_in < 0)
 	{
-	        perror("open failed :");
-	        exit(-1);
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", filename_in, strerror(errno));
 	}
 
 	static fxt_t fut;
@@ -4275,6 +4274,8 @@ void _starpu_fxt_distrib_file_init(struct starpu_fxt_options *options)
 	if (options->distrib_time_path)
 	{
 		distrib_time = fopen(options->distrib_time_path, "w+");
+		if (distrib_time == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->distrib_time_path, strerror(errno));
 	}
 	else
 	{
@@ -4299,7 +4300,11 @@ static
 void _starpu_fxt_activity_file_init(struct starpu_fxt_options *options)
 {
 	if (options->activity_path)
+	{
 		activity_file = fopen(options->activity_path, "w+");
+		if (activity_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->activity_path, strerror(errno));
+	}
 	else
 		activity_file = NULL;
 }
@@ -4308,7 +4313,11 @@ static
 void _starpu_fxt_sched_tasks_file_init(struct starpu_fxt_options *options)
 {
 	if (options->sched_tasks_path)
+	{
 		sched_tasks_file = fopen(options->sched_tasks_path, "w+");
+		if (sched_tasks_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->sched_tasks_path, strerror(errno));
+	}
 	else
 		sched_tasks_file = NULL;
 }
@@ -4319,6 +4328,9 @@ void _starpu_fxt_anim_file_init(struct starpu_fxt_options *options)
 	if (options->anim_path)
 	{
 		anim_file = fopen(options->anim_path, "w+");
+		if (anim_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->anim_path, strerror(errno));
+
 		_starpu_fxt_component_print_header(anim_file);
 	}
 	else
@@ -4329,7 +4341,11 @@ static
 void _starpu_fxt_tasks_file_init(struct starpu_fxt_options *options)
 {
 	if (options->tasks_path)
+	{
 		tasks_file = fopen(options->tasks_path, "w+");
+		if (tasks_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->tasks_path, strerror(errno));
+	}
 	else
 		tasks_file = NULL;
 }
@@ -4338,7 +4354,11 @@ static
 void _starpu_fxt_data_file_init(struct starpu_fxt_options *options)
 {
 	if (options->data_path)
+	{
 		data_file = fopen(options->data_path, "w+");
+		if (data_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->data_path, strerror(errno));
+	}
 	else
 		data_file = NULL;
 }
@@ -4347,7 +4367,11 @@ static
 void _starpu_fxt_comms_file_init(struct starpu_fxt_options *options)
 {
 	if (options->comms_path)
+	{
 		comms_file = fopen(options->comms_path, "w+");
+		if (comms_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->comms_path, strerror(errno));
+	}
 	else
 		comms_file = NULL;
 }
@@ -4358,6 +4382,8 @@ void _starpu_fxt_number_events_file_init(struct starpu_fxt_options *options)
 	if (options->number_events_path)
 	{
 		number_events_file = fopen(options->number_events_path, "w+");
+		if (number_events_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->number_events_path, strerror(errno));
 
 		/* FUT_SETUP_CODE is the event with the maximal value */
 		number_events = calloc(FUT_SETUP_CODE+1, sizeof(uint64_t));
@@ -4371,7 +4397,11 @@ void _starpu_fxt_papi_file_init(struct starpu_fxt_options *options)
 {
 #ifdef STARPU_PAPI
 	if (options->papi_path)
+	{
 		papi_file = fopen(options->papi_path, "w+");
+		if (papi_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->papi_path, strerror(errno));
+	}
 	else
 		papi_file = NULL;
 #endif
@@ -4395,7 +4425,11 @@ static
 void _starpu_fxt_trace_file_init(struct starpu_fxt_options *options)
 {
 	if (options->states_path)
+	{
 		trace_file = fopen(options->states_path, "w+");
+		if (trace_file == NULL)
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", options->states_path, strerror(errno));
+	}
 	else
 		trace_file = NULL;
 
@@ -4545,8 +4579,7 @@ uint64_t _starpu_fxt_find_start_time(char *filename_in)
 	fd_in = open(filename_in, O_RDONLY);
 	if (fd_in < 0)
 	{
-	        perror("open failed :");
-	        exit(-1);
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", filename_in, strerror(errno));
 	}
 
 	static fxt_t fut;
@@ -4765,8 +4798,7 @@ static void write_task(struct parse_task pt)
 		kernel->file = fopen(codelet_name, "w+");
 		if(!kernel->file)
 		{
-			perror("open failed :");
-			exit(-1);
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", codelet_name, strerror(errno));
 		}
 		HASH_ADD_STR(kernels, name, kernel);
 		fprintf(codelet_list, "%s\n", codelet_name);
@@ -4781,8 +4813,7 @@ void starpu_fxt_write_data_trace(char *filename_in)
 	fd_in = open(filename_in, O_RDONLY);
 	if (fd_in < 0)
 	{
-	        perror("open failed :");
-	        exit(-1);
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", filename_in, strerror(errno));
 	}
 
 	static fxt_t fut;
@@ -4796,8 +4827,7 @@ void starpu_fxt_write_data_trace(char *filename_in)
 	codelet_list = fopen("codelet_list", "w+");
 	if(!codelet_list)
 	{
-		perror("open failed :");
-		exit(-1);
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", "codelet_list", strerror(errno));
 	}
 
 	fxt_blockev_t block;