From 037a25f6ca4874f3561f9ebf878058efd23c48f2 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 22 Aug 2016 14:04:01 +0200 Subject: [PATCH] crash-pipe: Always return -errno on error Change-Id: I330b5366a5350cd9e8e54f4a04b7fa53f9122eca --- src/crash-pipe/crash-pipe.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/crash-pipe/crash-pipe.c b/src/crash-pipe/crash-pipe.c index d0177fa..8a3f99f 100644 --- a/src/crash-pipe/crash-pipe.c +++ b/src/crash-pipe/crash-pipe.c @@ -179,11 +179,12 @@ static int save_core(const char *core_path) int fd; static char buf[4096]; int readb, remaining; + int ret = 0; fd = open(core_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { syslog(LOG_ERR, "crash-pipe: Unable to save core file to %s: %m\n", core_path); - return -1; + return -errno; } while ((readb = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { @@ -192,6 +193,7 @@ static int save_core(const char *core_path) for (n = 0, remaining = readb ; remaining > 0; remaining -= n) { n = write(fd, buf, remaining); if (n == -1) { + ret = -errno; syslog(LOG_ERR, "crash-pipe: Error while saving core file %s: %m. Removing core.\n", core_path); (void)unlink(core_path); // XXX check errors here too goto out; @@ -202,7 +204,7 @@ static int save_core(const char *core_path) out: close(fd); - return 0; + return ret; } -- 2.7.4