Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

How do I Exit a Process if a Child Fails?

$
0
0

The program I'm working with requires a secondary executable to run (for asset compression). For error handling reasons, I need the return value of the child process. According to the system man page,

If all system calls succeed, then the return value is the termination status of the child shell used to execute [the] command. (The termination status of a shell is the termination status of the last command it executes.)

According to this, my system call's return state should be the called process's return value. But it doesn't seem to be. Instead, when the Generator returns EXIT_FAILURE, the program receives an EXIT_SUCCESS, or 0. Am I misunderstanding something?

My code is below.

// Checks to see if the generator still exists using access().bool asset_generator_availability = CheckAssetGenerator();if (!asset_generator_availability) LogMessage("Assets already generated.");else{    LogWarning("Assets still uncompressed and unformatted. Running the Generator.");    u8 generator_state = system("./AssetGenerator && rm AssetGenerator");    // Here is the problem line.    if (generator_state == EXIT_FAILURE) exit(EXIT_FAILURE);}

Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>