Project

General

Profile

max_procs.patch

Max processes limit patch -- nmav - Anonymous, 2008-01-22 08:37

View differences:

mod_cgi.c (working copy)
53 53

  
54 54
typedef struct {
55 55
	array *cgi;
56
	short int max_procs;
56 57
} plugin_config;
57 58

  
58 59
typedef struct {
......
65 66
	plugin_config **config_storage;
66 67

  
67 68
	plugin_config conf;
69
	
70
	unsigned short running_procs;
68 71
} plugin_data;
69 72

  
70 73
typedef struct {
......
148 151

  
149 152
	config_values_t cv[] = {
150 153
		{ "cgi.assign",                  NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
154
		{ "cgi.max_processes",                  NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
151 155
		{ NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET}
152 156
	};
153 157

  
......
161 165
		s = calloc(1, sizeof(plugin_config));
162 166
		assert(s);
163 167

  
168
		s->max_procs = 10;
164 169
		s->cgi    = array_init();
165 170

  
166 171
		cv[0].destination = s->cgi;
172
		cv[1].destination = &s->max_procs;
167 173

  
168 174
		p->config_storage[i] = s;
169 175

  
......
175 181
	return HANDLER_GO_ON;
176 182
}
177 183

  
184
static int cgi_running_procs(server *srv, plugin_data *p) {
185
	UNUSED(srv);
186
	return p->running_procs;
187
}
178 188

  
189
static int cgi_running_procs_del(server *srv, plugin_data *p) {
190
	UNUSED(srv);
191
	return --p->running_procs;
192
}
193

  
194

  
195
static int cgi_running_procs_add(server *srv, plugin_data *p) {
196
	UNUSED(srv);
197
	return ++p->running_procs;
198
}
199

  
179 200
static int cgi_pid_add(server *srv, plugin_data *p, pid_t pid) {
180 201
	int m = -1;
181 202
	size_t i;
......
542 563
				con->mode = DIRECT;
543 564
			}
544 565

  
566
			cgi_running_procs_del(srv, p);
545 567
			if (WIFEXITED(status)) {
546 568
#if 0
547 569
				log_error_write(srv, __FILE__, __LINE__, "sd", "(debug) cgi exited fine, pid:", pid);
......
558 580

  
559 581

  
560 582
		kill(pid, SIGTERM);
583
		cgi_running_procs_del(srv, p);
561 584

  
562 585
		/* cgi-script is still alive, queue the PID for removal */
563 586
		cgi_pid_add(srv, p, pid);
......
694 717
	int to_cgi_fds[2];
695 718
	int from_cgi_fds[2];
696 719
	struct stat st;
720
	int procs;
721
	plugin_config* config = p->config_storage[0];
697 722

  
723
	procs = cgi_running_procs(srv, p);
724
	if (procs+1 > config->max_procs) {
725
		/* we will not run something over max procs */
726
		log_error_write(srv, __FILE__, __LINE__, "ss", "Max proccesses reached:", strerror(errno));
727
		return -1;
728
	}
729

  
730
#if 0 /* debug */
731
	log_error_write(srv, __FILE__, procs, "ss", "procs:", strerror(errno));
732
	log_error_write(srv, __FILE__, config->max_procs, "ss", "Max procs:", strerror(errno));
733
#endif
734

  
698 735
#ifndef __WIN32
699

  
700 736
	if (cgi_handler->used > 1) {
701 737
		/* stat the exec file */
702 738
		if (-1 == (stat(cgi_handler->ptr, &st))) {
......
977 1013
	default: {
978 1014
		handler_ctx *hctx;
979 1015
		/* father */
1016
		cgi_running_procs_add(srv, p);
980 1017

  
981 1018
		close(from_cgi_fds[1]);
982 1019
		close(to_cgi_fds[0]);