--- do_command-orig.c 2018-07-01 14:33:34.186759696 -0700 +++ do_command.c 2018-07-01 14:37:15.325880510 -0700 @@ -416,45 +416,55 @@ * we would block here. thus we must fork again. */ - if (*input_data && fork() == 0) { - register FILE *out = fdopen(stdin_pipe[WRITE_PIPE], "w"); - register int need_newline = FALSE; - register int escaped = FALSE; - register int ch; - - Debug(DPROC, ("[%d] child2 sending data to grandchild\n", getpid())) - - /* translation: - * \% -> % - * % -> \n - * \x -> \x for all x != % - */ - while ((ch = *input_data++) != '\0') { - if (escaped) { - if (ch != '%') - putc('\\', out); - } else { - if (ch == '%') - ch = '\n'; - } - - if (!(escaped = (ch == '\\'))) { - putc(ch, out); - need_newline = (ch != '\n'); + if (*input_data) { + switch (fork()) { + case -1: + log_it("CRON",getpid(),"error","can't fork to send input_data"); + break; + case 0: + register FILE *out = fdopen(stdin_pipe[WRITE_PIPE], "w"); + register int need_newline = FALSE; + register int escaped = FALSE; + register int ch; + + Debug(DPROC, ("[%d] child2 sending data to grandchild\n", getpid())) + + /* translation: + * \% -> % + * % -> \n + * \x -> \x for all x != % + */ + while ((ch = *input_data++) != '\0') { + if (escaped) { + if (ch != '%') + putc('\\', out); + } else { + if (ch == '%') + ch = '\n'; + } + + if (!(escaped = (ch == '\\'))) { + putc(ch, out); + need_newline = (ch != '\n'); + } } + if (escaped) + putc('\\', out); + if (need_newline) + putc('\n', out); + + /* close the pipe, causing an EOF condition. fclose causes + * stdin_pipe[WRITE_PIPE] to be closed, too. + */ + fclose(out); + + Debug(DPROC, ("[%d] child2 done sending to grandchild\n", getpid())) + exit(0); + break; + default: + children++; + break; } - if (escaped) - putc('\\', out); - if (need_newline) - putc('\n', out); - - /* close the pipe, causing an EOF condition. fclose causes - * stdin_pipe[WRITE_PIPE] to be closed, too. - */ - fclose(out); - - Debug(DPROC, ("[%d] child2 done sending to grandchild\n", getpid())) - exit(0); } /* close the pipe to the grandkiddie's stdin, since its wicked uncle @@ -462,8 +472,6 @@ */ close(stdin_pipe[WRITE_PIPE]); - children++; - /* * read output from the grandchild. it's stderr has been redirected to * it's stdout, which has been redirected to our pipe. if there is any