add proper error handling for in-place restarts (Thanks Markus)

fixes #806
This commit is contained in:
Michael Stapelberg 2012-09-21 16:47:43 +02:00
parent 514265b529
commit 8c8fce82e5
2 changed files with 15 additions and 4 deletions

View File

@ -52,7 +52,7 @@ static bool mkdirp(const char *path) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
return false;
}
char *copy = strdup(path);
char *copy = sstrdup(path);
/* strip trailing slashes, if any */
while (copy[strlen(copy)-1] == '/')
copy[strlen(copy)-1] = '\0';

View File

@ -350,11 +350,22 @@ void tree_append_json(const char *filename) {
/* TODO: percent of other windows are not correctly fixed at the moment */
FILE *f;
if ((f = fopen(filename, "r")) == NULL) {
LOG("Cannot open file\n");
LOG("Cannot open file \"%s\"\n", filename);
return;
}
struct stat stbuf;
if (fstat(fileno(f), &stbuf) != 0) {
LOG("Cannot fstat() the file\n");
fclose(f);
return;
}
char *buf = smalloc(stbuf.st_size);
int n = fread(buf, 1, stbuf.st_size, f);
if (n != stbuf.st_size) {
LOG("File \"%s\" could not be read entirely, not loading.\n", filename);
fclose(f);
return;
}
char *buf = malloc(65535); /* TODO */
int n = fread(buf, 1, 65535, f);
LOG("read %d bytes\n", n);
yajl_gen g;
yajl_handle hand;