MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / exec_preprocessor

Function exec_preprocessor

cfg_pp.c:631–814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

629}
630
631static int exec_preprocessor(FILE *flat_cfg, const char *preproc_cmdline,
632 str *out)
633{
634 int parent_w[2], parent_r[2], cfgsz = 0, cfgbufsz = 0;
635 char chunk[1024], *cfgbuf = NULL;
636 ssize_t written, bytes;
637 size_t bytes2write;
638 char *p, *tok, *cmd, **argv = NULL, *pp_binary = NULL;
639 int argv_len = 0, flags, have_input = 0, done_writing = 0;
640
641 if (strlen(preproc_cmdline) == 0) {
642 LM_ERR("preprocessor command (-p) is an empty string!\n");
643 goto out_err;
644 }
645
646 if (pipe(parent_w) != 0 || pipe(parent_r) != 0) {
647 LM_ERR("failed to create pipe: %d (%s)\n", errno, strerror(errno));
648 goto out_err;
649 }
650
651 /* fork a data-hungry preprocessor beast! (a.k.a. some tiny sed) */
652 if (fork() == 0) {
653 close(parent_w[1]);
654 if (dup2(parent_w[0], STDIN_FILENO) < 0) {
655 LM_ERR("dup2 failed with: %d (%s)\n", errno, strerror(errno));
656 exit(-1);
657 }
658 close(parent_w[0]);
659
660 close(parent_r[0]);
661 if (dup2(parent_r[1], STDOUT_FILENO) < 0) {
662 LM_ERR("dup2 failed with: %d (%s)\n", errno, strerror(errno));
663 exit(-1);
664 }
665 close(parent_w[1]);
666
667 for (cmd = strdup(preproc_cmdline); ; cmd = NULL) {
668 tok = strtok(cmd, " \t\r\n");
669 if (!tok)
670 break;
671
672 if (!pp_binary)
673 pp_binary = tok;
674
675 argv = realloc(argv, (argv_len + 1) * sizeof *argv);
676 argv[argv_len++] = tok;
677 }
678
679 argv = realloc(argv, (argv_len + 1) * sizeof *argv);
680 argv[argv_len++] = NULL;
681
682 if (pp_binary) {
683 execvp(pp_binary, argv);
684 LM_ERR("failed to exec preprocessor '%s': %d (%s)\n",
685 preproc_cmdline, errno, strerror(errno));
686 } else
687 LM_ERR("no binary to run: '%s'\n", preproc_cmdline);
688

Callers 1

parse_opensips_cfgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected