| 308 | } |
| 309 | |
| 310 | bool FullCommandList::runGeneratedFile(const char *file, ShellState &state, |
| 311 | ArgumentValueList &args) const { |
| 312 | |
| 313 | auto pid = fork(); |
| 314 | if(!pid) { |
| 315 | unsigned long file0 = (file ? 1 : 0); |
| 316 | unsigned long count = args.getIndexedCount(); |
| 317 | char **argv = static_cast<char **>( |
| 318 | malloc((file0 + count + 1) * sizeof(*argv))); |
| 319 | unsigned long argc = 0; |
| 320 | if(file0) argv[argc++] = const_cast<char *>(file); |
| 321 | for(unsigned long i = 0; i < count; i ++) { |
| 322 | argv[argc++] = strdup(args.getIndexed(i).getString().c_str()); |
| 323 | } |
| 324 | argv[argc] = nullptr; |
| 325 | #if 0 |
| 326 | for(unsigned long i = 0; argv[i]; i ++) { |
| 327 | std::cout << "\"" << argv[i] << "\","; |
| 328 | } |
| 329 | std::cout << std::endl; |
| 330 | #endif |
| 331 | execvp(argv[0], argv); |
| 332 | std::exit(1); |
| 333 | } |
| 334 | else { |
| 335 | int status = 0; |
| 336 | waitpid(pid, &status, 0); |
| 337 | |
| 338 | bool normal = (WIFEXITED(status) && WEXITSTATUS(status) == 0); |
| 339 | return normal; |
| 340 | } |
| 341 | } |
nothing calls this directly
no test coverage detected