- int fds[2];
- socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
- sock_fd = fds[0];
-
- pid = fork();
- if(pid==0)
- {
- string fd_str = lexical_cast(fds[1]);
- setenv("LD_PRELOAD", (libdir/"glwrap.so").str().c_str(), true);
- setenv("GLWRAP_FD", fd_str.c_str(), true);
- close(fds[0]);
- std::vector<char *> argv(args.size()+1);
- for(unsigned i=0; i<args.size(); ++i)
- argv[i] = strdup(args[i].c_str());
- argv[args.size()] = 0;
- execvp(argv[0], &argv[0]);
- ::exit(127);
- }
- else if(pid>0)
- {
- close(fds[1]);
- }
- else
- {
- throw SystemError("Could not launch process", errno);
- }