improved stdin management in cron

This commit is contained in:
Roberto De Ioris
2012-12-07 12:40:29 +01:00
parent 813074b010
commit 504151b695
2 changed files with 24 additions and 0 deletions
+23
View File
@@ -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;
}
+1
View File
@@ -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