Reputation: 4191
The code below tries to insert a non-existent kernel module, and it fails - however it outputs "Success":
#include <iostream>
#include <boost/process/system.hpp>
int main()
{
std::error_code ec;
boost::process::system("modprobe abc", ec);
std::cout << ec.message() << std::endl;
}
Why is that?
Also, the Boost Process documentation claims, that the system
call without last argument here generates an exception - but it doesn't do that for me.
Should I use only a return value from this function, and forget about other ways to handle errors (std::error_code
, exceptions), described in the Boost documentation?
Upvotes: 1
Views: 942
Reputation: 392954
Launching and running the process were successful.
The module not being loaded is a perfectly acceptible outcome, and not at all "exceptional".
error_code
or exceptions come in when there are technical exceptions. Examples would be
/sbin/modprobe
isn't foundEtc.
Any other "failures" aren't failures for Boost Process. They might be for the program you're running. Look at the documentation of the program you're running to see how it will signal this (exit code, stderr, stdout).
So you decide what errors to handle but I suggest you handle both sets of errors.
Note: there's another hidden mode of termination where the program doesn't get a chance to compete because it received a signal (you, the kernel or another process killed it). It's up to you to decide whether you need to detect this kind of scenario and handle it separately.
Upvotes: 1