int web_eat(int max) { char buf[512]; int n; while (max > 0) { if ((n = web_read(buf, (max < sizeof(buf)) ? max : sizeof(buf))) <= 0) return 0; max -= n; } return 1; }
void wi_bwmrestore(char *url, int len, char *boundary) { char *buf; const char *error; int ok; int n; char tmp[64]; check_id(url); tmp[0] = 0; buf = NULL; error = "Error reading file"; ok = 0; if (!skip_header(&len)) { goto ERROR; } if ((len < 64) || (len > 10240)) { goto ERROR; } if ((buf = malloc(len)) == NULL) { error = "Not enough memory"; goto ERROR; } n = web_read(buf, len); len -= n; sprintf(tmp, "%s.new", hfn); if (f_write(tmp, buf, n, 0, 0600) != n) { unlink(tmp); error = "Error writing temporary file"; goto ERROR; } f_write("/var/tmp/rstats-load", NULL, 0, 0, 0600); killall("rstats", SIGHUP); sleep(1); error = NULL; rboot = 1; // used as "ok" ERROR: free(buf); web_eat(len); if (error != NULL) resmsg_set(error); }