Mercurial > dropbear
changeset 106:e13f8a712a1c
Fix if the first write fails
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 24 Aug 2004 07:22:36 +0000 |
parents | 68b84c20ca1e |
children | d3eb1fa8484e |
files | cli-kex.c |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/cli-kex.c Tue Aug 24 05:05:48 2004 +0000 +++ b/cli-kex.c Tue Aug 24 07:22:36 2004 +0000 @@ -164,13 +164,16 @@ snprintf(filename, len+18, "%s/.ssh/known_hosts", pw->pw_dir); hostsfile = fopen(filename, "a+"); - fseek(hostsfile, 0, SEEK_SET); - /* We mightn't have been able to open it if it was read-only */ - if (hostsfile == NULL && (errno == EACCES || errno == EROFS)) { - TRACE(("trying readonly: %s", strerror(errno))); - readonly = 1; - hostsfile = fopen(filename, "r"); + if (hostsfile != NULL) { + fseek(hostsfile, 0, SEEK_SET); + } else { + /* We mightn't have been able to open it if it was read-only */ + if (errno == EACCES || errno == EROFS) { + TRACE(("trying readonly: %s", strerror(errno))); + readonly = 1; + hostsfile = fopen(filename, "r"); + } } if (hostsfile == NULL) {