commit 129c9029861ee47c090c14de35b827f44c6b8884
parent 82e97eddc249c1b6a1fd595fac25cdd636d9a7c0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 29 Feb 2024 14:21:53 +0100
Fix return of executed commands
The output stream of the command could be closed several times, causing
an error. In addition, the error code of the executed command was not
the one reported out of the program. Indeed, we returned the pclose
output code that is not the command error code, but the state out of the
wait function. To find the expected error code, we need to retrieve it
via the WEXITSTATUS macro.
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/sadist_probe_boundary.c b/src/sadist_probe_boundary.c
@@ -31,6 +31,7 @@
#include <float.h>
#include <getopt.h>
#include <string.h> /* strerror */
+#include <wait.h> /* WIFEXITED, WEXITSTATUS */
/* Axis Aligned Bounding Box */
struct aabb {
@@ -340,6 +341,7 @@ run1(const struct sadist_trilinear_profile* profile)
double SE = 0;
int n = 0;
int err = 0;
+ int status = 0;
printf(COMMAND1"\n");
@@ -357,8 +359,10 @@ run1(const struct sadist_trilinear_profile* profile)
}
/* Check command exit status */
- if((err = pclose(output))) goto error;
- output = NULL;
+ if((status=pclose(output), output=NULL, status)) {
+ if(WIFEXITED(status)) err = WEXITSTATUS(status);
+ goto error;
+ }
ref = sadist_trilinear_profile(profile, P);
printf("T = %g ~ %g +/- %g\n", ref, E, SE);
@@ -383,6 +387,7 @@ runN(const struct sadist_trilinear_profile* profile, const size_t nprobes)
FILE* output = NULL;
size_t i = 0;
int err = 0;
+ int status = 0;
ASSERT(profile && nprobes);
if(!(probes = mem_calloc(nprobes, sizeof(double)*3))) {
@@ -427,7 +432,10 @@ runN(const struct sadist_trilinear_profile* profile, const size_t nprobes)
}
/* Check command exit status */
- if((err = pclose(output))) goto error;
+ if((status=pclose(output)), output = NULL, status) {
+ if(WIFEXITED(status)) err = WEXITSTATUS(status);
+ goto error;
+ }
output = NULL;
/* Validate the calculations */