MCPcopy Index your code
hub / github.com/NetHack/NetHack / execplinehandler

Function execplinehandler

src/pline.c:640–686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638static boolean use_pline_handler = TRUE;
639
640staticfn void
641execplinehandler(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 */
689void

Callers 2

vplineFunction · 0.85
vraw_printfFunction · 0.85

Calls 4

getuidFunction · 0.85
fprintfFunction · 0.85
nh_terminateFunction · 0.70
plineFunction · 0.70

Tested by

no test coverage detected