diff --git a/core/utils.c b/core/utils.c index 32daa211..8b525ec8 100644 --- a/core/utils.c +++ b/core/utils.c @@ -3299,6 +3299,21 @@ pid_t uwsgi_run_command(char *command, int *stdin_fd, int stdout_fd) { if (stdin_fd) { close(stdin_fd[1]); } + else { + if (!uwsgi_valid_fd(0)) { + int in_fd = open("/dev/null", O_RDONLY); + if (in_fd < 0) { + uwsgi_error_open("/dev/null"); + } + else { + if (in_fd != 0) { + if (dup2(in_fd, 0)) { + uwsgi_error("dup2()"); + } + } + } + } + } if (stdout_fd > -1 && stdout_fd != 1) { if (dup2(stdout_fd, 1) < 0) { @@ -4849,3 +4864,11 @@ char *uwsgi_strip(char *src) { return dst; } + +int uwsgi_valid_fd(int fd) { + int ret = fcntl(fd, F_GETFL); + if (ret == 0) { + return 1; + } + return 0; +} diff --git a/uwsgi.h b/uwsgi.h index 465f9ed7..04e279c5 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -3580,6 +3580,7 @@ void uwsgi_legion_atexit(void); #endif struct uwsgi_option *uwsgi_opt_get(char *); +int uwsgi_valid_fd(int); void uwsgi_check_emperor(void); #ifdef UWSGI_AS_SHARED_LIBRARY