Should CommandExt::exec be safe?

Currently CommandExt::exec is safe although successful exec does not release resources by either calling destructors or terminating program (so kernel can release resources by its own).

Therefore my suggestion is to make exec unsafe, as this function requires, similar to many other unsafe functions, programmer's attention to prevent similar class of bugs. Is there any reason to keep exec safe, or was there another discussion on this topic that I couldn’t find?

Not running destructors or calling process::exit is perfectly safe though, thus CommandExt::exec doesn't violate memory-safety or by itself can cause other unsound behavior (well, uh ... except for bugs of course).

5 Likes

It is quite safe, standard library uses O_CLOEXEC for files and pipes. After exploring it seems to be not as much risky, as it was looking for me earlier.

Even if it didn't, leaking file descriptors would not be unsafe. In general leaks (be it of memory or other resources) is not unsound. std::mem::forget is safe after all.

2 Likes