From b4adf61bc70edc1f4c1d14bf5981be1246e105c5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 19 Jul 2013 17:44:38 +0000 Subject: [PATCH] Report errors in store_host_key too. [originally from svn r9934] --- unix/uxstore.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/unix/uxstore.c b/unix/uxstore.c index 785e1e3b..913b736a 100644 --- a/unix/uxstore.c +++ b/unix/uxstore.c @@ -596,18 +596,28 @@ void store_host_key(const char *hostname, int port, */ tmpfilename = make_filename(INDEX_HOSTKEYS_TMP, NULL); wfp = fopen(tmpfilename, "w"); - if (!wfp) { + if (!wfp && errno == ENOENT) { char *dir; dir = make_filename(INDEX_DIR, NULL); - mkdir(dir, 0700); + if (mkdir(dir, 0700) < 0) { + char *msg = dupprintf("Unable to store host key: mkdir(\"%s\") " + "returned '%s'", dir, strerror(errno)); + nonfatal(msg); + sfree(dir); + sfree(tmpfilename); + return; + } sfree(dir); wfp = fopen(tmpfilename, "w"); } if (!wfp) { - sfree(tmpfilename); - return; + char *msg = dupprintf("Unable to store host key: open(\"%s\") " + "returned '%s'", tmpfilename, strerror(errno)); + nonfatal(msg); + sfree(tmpfilename); + return; } filename = make_filename(INDEX_HOSTKEYS, NULL); rfp = fopen(filename, "r");