close stdin in vassals

This commit is contained in:
roberto@precise64
2012-02-29 14:57:44 +01:00
parent 3c6de0e84d
commit 57bade7eae
+23 -1
View File
@@ -379,8 +379,22 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size, ui
}
vassal_argv[counter] = NULL;
// disable stdin
int stdin_fd = open("/dev/null", O_RDONLY);
if (stdin_fd < 0) {
uwsgi_error_open("/dev/null");
exit(1);
}
if (stdin_fd != 0) {
if (dup2(stdin_fd, 0)) {
uwsgi_error("dup2()");
exit(1);
}
close(stdin_fd);
}
// close all of the unneded fd
for(i=3;i<sysconf(_SC_OPEN_MAX);i++) {
for(i=3;i<(int)uwsgi.max_fd;i++) {
if (i != n_ui->pipe[1]) {
close(i);
}
@@ -435,6 +449,7 @@ void emperor_loop() {
int nevents;
int interesting_fd;
char notification_message[64];
struct rlimit rl;
uwsgi.emperor_stats_fd = -1;
@@ -446,6 +461,13 @@ void emperor_loop() {
memset(&ui_base, 0, sizeof(struct uwsgi_instance));
if (getrlimit(RLIMIT_NOFILE, &rl)) {
uwsgi_error("getrlimit()");
exit(1);
}
uwsgi.max_fd = rl.rlim_cur;
emperor_queue = event_queue_init();