Project

General

Profile

lighttpd-mod_rrdtool-emptyfile.patch

proposed patch - glen, 2008-10-07 10:34

View differences:

lighttpd-1.4.20/src/mod_rrdtool.c 2008-10-07 13:27:54.472090759 +0300
200 200
					"not a regular file:", s->path_rrd);
201 201
			return HANDLER_ERROR;
202 202
		}
203
	} else {
204
		int r ;
205
		/* create a new one */
203
	}
206 204

  
207
		buffer_copy_string_len(p->cmd, CONST_STR_LEN("create "));
208
		buffer_append_string_buffer(p->cmd, s->path_rrd);
209
		buffer_append_string_len(p->cmd, CONST_STR_LEN(
210
			" --step 60 "
211
			"DS:InOctets:ABSOLUTE:600:U:U "
212
			"DS:OutOctets:ABSOLUTE:600:U:U "
213
			"DS:Requests:ABSOLUTE:600:U:U "
214
			"RRA:AVERAGE:0.5:1:600 "
215
			"RRA:AVERAGE:0.5:6:700 "
216
			"RRA:AVERAGE:0.5:24:775 "
217
			"RRA:AVERAGE:0.5:288:797 "
218
			"RRA:MAX:0.5:1:600 "
219
			"RRA:MAX:0.5:6:700 "
220
			"RRA:MAX:0.5:24:775 "
221
			"RRA:MAX:0.5:288:797 "
222
			"RRA:MIN:0.5:1:600 "
223
			"RRA:MIN:0.5:6:700 "
224
			"RRA:MIN:0.5:24:775 "
225
			"RRA:MIN:0.5:288:797\n"));
205
	/* still create DB if it's empty file */
206
	if (st.st_size > 0) {
207
		return HANDLER_GO_ON;
208
	}
226 209

  
227
		if (-1 == (r = write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
228
			log_error_write(srv, __FILE__, __LINE__, "ss",
229
				"rrdtool-write: failed", strerror(errno));
210
	int r;
211
	/* create a new one */
212
	buffer_copy_string_len(p->cmd, CONST_STR_LEN("create "));
213
	buffer_append_string_buffer(p->cmd, s->path_rrd);
214
	buffer_append_string_len(p->cmd, CONST_STR_LEN(
215
		" --step 60 "
216
		"DS:InOctets:ABSOLUTE:600:U:U "
217
		"DS:OutOctets:ABSOLUTE:600:U:U "
218
		"DS:Requests:ABSOLUTE:600:U:U "
219
		"RRA:AVERAGE:0.5:1:600 "
220
		"RRA:AVERAGE:0.5:6:700 "
221
		"RRA:AVERAGE:0.5:24:775 "
222
		"RRA:AVERAGE:0.5:288:797 "
223
		"RRA:MAX:0.5:1:600 "
224
		"RRA:MAX:0.5:6:700 "
225
		"RRA:MAX:0.5:24:775 "
226
		"RRA:MAX:0.5:288:797 "
227
		"RRA:MIN:0.5:1:600 "
228
		"RRA:MIN:0.5:6:700 "
229
		"RRA:MIN:0.5:24:775 "
230
		"RRA:MIN:0.5:288:797\n"));
231

  
232
	if (-1 == (r = write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
233
		log_error_write(srv, __FILE__, __LINE__, "ss",
234
			"rrdtool-write: failed", strerror(errno));
230 235

  
231
			return HANDLER_ERROR;
232
		}
236
		return HANDLER_ERROR;
237
	}
233 238

  
234
		buffer_prepare_copy(p->resp, 4096);
235
		if (-1 == (r = read(p->read_fd, p->resp->ptr, p->resp->size))) {
236
			log_error_write(srv, __FILE__, __LINE__, "ss",
237
				"rrdtool-read: failed", strerror(errno));
239
	buffer_prepare_copy(p->resp, 4096);
240
	if (-1 == (r = read(p->read_fd, p->resp->ptr, p->resp->size))) {
241
		log_error_write(srv, __FILE__, __LINE__, "ss",
242
			"rrdtool-read: failed", strerror(errno));
238 243

  
239
			return HANDLER_ERROR;
240
		}
244
		return HANDLER_ERROR;
245
	}
241 246

  
242
		p->resp->used = r;
247
	p->resp->used = r;
243 248

  
244
		if (p->resp->ptr[0] != 'O' ||
245
		    p->resp->ptr[1] != 'K') {
246
			log_error_write(srv, __FILE__, __LINE__, "sbb",
247
				"rrdtool-response:", p->cmd, p->resp);
249
	if (p->resp->ptr[0] != 'O' ||
250
		p->resp->ptr[1] != 'K') {
251
		log_error_write(srv, __FILE__, __LINE__, "sbb",
252
			"rrdtool-response:", p->cmd, p->resp);
248 253

  
249
			return HANDLER_ERROR;
250
		}
254
		return HANDLER_ERROR;
251 255
	}
252 256

  
253 257
	return HANDLER_GO_ON;