I am trying to track down a very strange glitch. What is strange is the workaround that someone has discovered and which I cannot explain.
A workaround is a small program that I will call a "runner":
#include <stdio.h> #include <unistd.h> #include <string.h> #include <errno.h> int main(int argc, char *argv[]) { if (argc == 1) { fprintf(stderr, "Usage: %s prog [args ...]\n", argv[0]); return 1; } execvp(argv[1], argv + 1); fprintf(stderr, "execv failed: %s\n", strerror(errno)); // If exec returns because the program is not found or we // don't have the appropriate permission return 255; }
As you can see, this entire program uses execvp to replace itself with another program.
A program crashes when it is directly called from the command line:
/path/to/prog args
but works fine when it is indirectly called through my runner pad:
/path/to/runner /path/to/prog args
Throughout life, I can understand how the presence of additional exec can change the behavior of an executable program (since you can see that the program does not change the environment).
Some background to the accident. The crash itself occurs during C ++ execution. In particular, when a program performs a throw , the erroneous version incorrectly thinks that there is no corresponding catch (although there is one) and calls terminate . When I call the program through the runner, the exception gets right.
My question is any idea, why does additional exec change the behavior of the exec'ed program?
c ++ linux exec crash
R Samuel Klatchko
source share