| 638 | static boolean use_pline_handler = TRUE; |
| 639 | |
| 640 | staticfn void |
| 641 | execplinehandler(const char *line) |
| 642 | { |
| 643 | #if defined(UNIX) && (defined(POSIX_TYPES) || defined(__GNUC__)) |
| 644 | int f; |
| 645 | #endif |
| 646 | const char *args[3]; |
| 647 | |
| 648 | if (!use_pline_handler || !sysopt.msghandler) |
| 649 | return; |
| 650 | |
| 651 | #if defined(UNIX) && (defined(POSIX_TYPES) || defined(__GNUC__)) |
| 652 | f = fork(); |
| 653 | if (f == 0) { /* child */ |
| 654 | args[0] = sysopt.msghandler; |
| 655 | args[1] = line; |
| 656 | args[2] = NULL; |
| 657 | (void) setgid(getgid()); |
| 658 | (void) setuid(getuid()); |
| 659 | (void) execv(args[0], (char *const *) args); |
| 660 | perror((char *) 0); |
| 661 | (void) fprintf(stderr, "Exec to message handler %s failed.\n", sysopt.msghandler); |
| 662 | nh_terminate(EXIT_FAILURE); |
| 663 | } else if (f > 0) { |
| 664 | int status; |
| 665 | |
| 666 | waitpid(f, &status, 0); |
| 667 | } else if (f == -1) { |
| 668 | perror((char *) 0); |
| 669 | use_pline_handler = FALSE; |
| 670 | pline("%s", "Fork to message handler failed."); |
| 671 | } |
| 672 | #elif defined(WIN32) |
| 673 | { |
| 674 | intptr_t ret; |
| 675 | args[0] = sysopt.msghandler; |
| 676 | args[1] = line; |
| 677 | args[2] = NULL; |
| 678 | ret = _spawnv(_P_NOWAIT, sysopt.msghandler, args); |
| 679 | nhUse(ret); /* -Wunused-but-set-variable */ |
| 680 | } |
| 681 | #else |
| 682 | use_pline_handler = FALSE; |
| 683 | nhUse(args); |
| 684 | nhUse(line); |
| 685 | #endif |
| 686 | } |
| 687 | |
| 688 | /* nhassert_failed is called when an nhassert's condition is false */ |
| 689 | void |
no test coverage detected