From 501a039172d066d0b0ea9071c5d82467e89de9a6 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 12 Nov 2014 12:54:56 +0000 Subject: test-shell: Report write failures --- scripts/test-shell.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/test-shell.c b/scripts/test-shell.c index 2f8ecbd8..f4ac6bfa 100644 --- a/scripts/test-shell.c +++ b/scripts/test-shell.c @@ -10,6 +10,7 @@ #include #include #include +#include char *readlinka(char const *path){ size_t buflen = BUFSIZ; @@ -113,8 +114,8 @@ int copy_file_objects(FILE *source, FILE *target) { do { read = fread(buffer, 1, sizeof(buffer), source); fwrite(buffer, 1, read, target); - } while (!feof(source)); - return ferror(source) ? -1 : 0; + } while (!feof(source) && !feof(target)); + return (ferror(source) || ferror(target)) ? -1 : 0; } int run_commands(FILE *cmdstream){ @@ -145,8 +146,14 @@ int run_commands(FILE *cmdstream){ } else if (strstr(line, "create file ") == line) { char const *filename = line + sizeof("create file ") -1; FILE *outfile = fopen(filename, "w"); + if (outfile == NULL){ + ret = 1; + err(errno, "Opening %s for write failed", filename); + break; + } if (copy_file_objects(cmdstream, outfile) < 0) { ret = 1; + err(errno, "Writing to %s failed", filename); fclose(outfile); break; } -- cgit v1.2.1