Add proper error reports in write_random_seed, via the new 'nonfatal'

error reporting function.

[originally from svn r9933]
This commit is contained in:
Simon Tatham 2013-07-19 17:44:33 +00:00
Родитель acf38797eb
Коммит 2854ae1f33
1 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -672,18 +672,45 @@ void write_random_seed(void *data, int len)
*/
fd = open(fname, O_CREAT | O_WRONLY, 0600);
if (fd < 0) {
if (errno != ENOENT) {
char *msg = dupprintf("Unable to write random seed: open(\"%s\") "
"returned '%s'", fname, strerror(errno));
nonfatal(msg);
sfree(msg);
return;
}
char *dir;
dir = make_filename(INDEX_DIR, NULL);
mkdir(dir, 0700);
if (mkdir(dir, 0700) < 0) {
char *msg = dupprintf("Unable to write random seed: mkdir(\"%s\") "
"returned '%s'", dir, strerror(errno));
nonfatal(msg);
sfree(msg);
sfree(dir);
return;
}
sfree(dir);
fd = open(fname, O_CREAT | O_WRONLY, 0600);
if (errno != ENOENT) {
char *msg = dupprintf("Unable to write random seed: open(\"%s\") "
"returned '%s'", fname, strerror(errno));
nonfatal(msg);
sfree(msg);
return;
}
}
while (len > 0) {
int ret = write(fd, data, len);
if (ret <= 0) break;
if (ret < 0) {
char *msg = dupprintf("Unable to write random seed: write "
"returned '%s'", strerror(errno));
nonfatal(msg);
sfree(msg);
break;
}
len -= ret;
data = (char *)data + len;
}