Try to convert string options to shorts for numeric options in config file; allows to use env-vars for numeric options. (#1159, thx andrewb)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2321 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.21
Stefan Bühler 2008-10-01 13:24:19 +00:00
parent c426767ea2
commit 65f4e4a8db
2 changed files with 18 additions and 0 deletions

1
NEWS
View File

@ -11,6 +11,7 @@ NEWS
* Now really fix mod auth ldap (#1066)
* Fix leaving zombie process with include_shell (#1777)
* Removed debian/, openwrt/ and cygwin/; they weren't kept up-to-date, and we decided to remove dist. specific stuff
* Try to convert string options to shorts for numeric options in config file; allows to use env-vars for numeric options. (#1159, thx andrewb)
- 1.4.20 - 2008-09-30

View File

@ -1,4 +1,5 @@
#include <string.h>
#include <stdlib.h>
#include "base.h"
#include "buffer.h"
@ -90,6 +91,22 @@ int config_insert_values_internal(server *srv, array *ca, const config_values_t
case TYPE_STRING: {
data_string *ds = (data_string *)du;
/* If the value came from an environment variable, then it is a
* data_string, although it may contain a number in ASCII
* decimal format. We try to interpret the string as a decimal
* short before giving up, in order to support setting numeric
* values with environment variables (eg, port number).
*/
if (ds->value->ptr && *ds->value->ptr) {
char *e;
long l = strtol(ds->value->ptr, &e, 10);
if (e != ds->value->ptr && !*e && l >=0 && l <= 65535) {
*((unsigned short *)(cv[i].destination)) = l;
break;
}
}
log_error_write(srv, __FILE__, __LINE__, "ssb", "got a string but expected a short:", cv[i].key, ds->value);
return -1;