configuration can now be taken from the cluster nodes automagically

This commit is contained in:
roberto@fiorenzo
2010-11-24 18:55:15 +01:00
parent f420bf3266
commit df0b3f7eb5
4 changed files with 38 additions and 5 deletions
+5 -1
View File
@@ -651,7 +651,6 @@ int uwsgi_hooked_parse_dict_dgram(int fd, char *buffer, size_t len, uint8_t modi
uint16_t keysize = 0, valsize = 0;
char *key;
ptrbuf = buffer;
rlen = read(fd, buffer, len);
@@ -660,6 +659,8 @@ int uwsgi_hooked_parse_dict_dgram(int fd, char *buffer, size_t len, uint8_t modi
return -1;
}
uwsgi_log("RLEN: %d\n", rlen);
// check for valid dict 4(header) 2(non-zero key)+1 2(value)
if (rlen < (4+2+1+2)) {
uwsgi_log("invalid uwsgi dictionary\n");
@@ -673,6 +674,8 @@ int uwsgi_hooked_parse_dict_dgram(int fd, char *buffer, size_t len, uint8_t modi
return -1;
}
ptrbuf = buffer + 4;
if (uh->pktsize > len) {
uwsgi_log("* WARNING * the uwsgi dictionary received is too big, data will be truncated\n");
bufferend = ptrbuf + len;
@@ -682,6 +685,7 @@ int uwsgi_hooked_parse_dict_dgram(int fd, char *buffer, size_t len, uint8_t modi
}
uwsgi_log("%p %p %d\n", ptrbuf, bufferend, bufferend-ptrbuf);
while (ptrbuf < bufferend) {
if (ptrbuf + 2 >= bufferend) return -1;
memcpy(&keysize, ptrbuf, 2);
+20
View File
@@ -765,6 +765,26 @@ char *uwsgi_concat3(char *one, char *two, char *three) {
}
char *uwsgi_concat2n(char *one, int s1, char *two, int s2) {
char *buf;
size_t len = s1 + s2 + 1;
buf = malloc(len);
if (buf == NULL) {
uwsgi_error("malloc()");
exit(1);
}
buf[len-1] = 0;
memcpy( buf, one, s1);
memcpy( buf + s1, two, s2);
return buf;
}
char *uwsgi_concat3n(char *one, int s1, char *two, int s2, char *three, int s3) {
char *buf;
+12 -4
View File
@@ -583,6 +583,7 @@ int main(int argc, char *argv[], char *envp[])
uwsgi_log("unable to send multicast message to %s\n", uwsgi.cluster);
continue;
}
waitfd:
rlen = uwsgi_waitfd(uwsgi.cluster_fd, 10);
if (rlen < 0) {
break;
@@ -590,13 +591,19 @@ int main(int argc, char *argv[], char *envp[])
else if (rlen > 0) {
// receive the packet
char clusterbuf[4096];
uwsgi_hooked_parse_dict_dgram(uwsgi.cluster_fd, clusterbuf, 4096, 99, 1, manage_string_opt);
break;
if (!uwsgi_hooked_parse_dict_dgram(uwsgi.cluster_fd, clusterbuf, 4096, 99, 1, manage_string_opt)) {
goto options_parsed;
}
else {
goto waitfd;
}
}
}
}
}
options_parsed:
//call after_opt hooks
if (uwsgi.binary_path == argv[0]) {
@@ -2166,9 +2173,10 @@ void manage_string_opt(char *key, int keylen, char *val, int vallen) {
struct option *lopt, *aopt;
// never free this value
char *key2 = uwsgi_concat2(key, "");
char *val2 = uwsgi_concat2(val, "");
char *key2 = uwsgi_concat2n(key, keylen, "", 0);
char *val2 = uwsgi_concat2n(val, vallen, "", 0);
uwsgi_log("%s = %s\n", key2, val2);
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name) break;
+1
View File
@@ -1112,6 +1112,7 @@ inline int uwsgi_startswith(char *, char *, int);
char *uwsgi_concat(int,...);
char *uwsgi_concatn(int,...);
char *uwsgi_concat2(char *, char *);
char *uwsgi_concat2n(char *, int, char *, int);
char *uwsgi_concat3(char *, char *, char *);
char *uwsgi_concat3n(char *, int, char *, int, char *, int);
char *uwsgi_concat4(char *, char *, char *, char *);