Commit dfc16041 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/tools: fix checking of child's return status in load-virtex

While checking return status first WIFEXITED has to be checked to know if child
returned normally.
waitpid's man page:
WEXITSTATUS(status) returns the exit status of the child. (...) This macro
should be employed only if WIFEXITED returned true.
WIFEXITED(status) returns true if the child terminated normally, that is, by
calling exit(3) or _exit(2), or by returning from main().
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent cb091c08
......@@ -318,9 +318,23 @@ int load_fpga_main(char *fname)
exit(0);
default: /* parent */
waitpid(pid, &status, 0);
if (!WEXITSTATUS(status))
return 0;
return -1;
/* check if exited normally and returned 0 */
if (WIFEXITED(status)) {
if (!WEXITSTATUS(status)) {
return 0; /* success */
} else {
/* process returned not 0 */
fprintf(stderr, "load-virtex: Error, child "
"process returned %d\n",
WEXITSTATUS(status));
return -1; /* fail */
}
} else {
/* Child process terminated abnormally */
fprintf(stderr, "load-virtex: Child process terminated"
" abnormally\n");
return -1; /* fail */
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment