crash-pipe: Always return -errno on error 39/84839/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Mon, 22 Aug 2016 12:04:01 +0000 (14:04 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Mon, 22 Aug 2016 12:10:39 +0000 (14:10 +0200)
Change-Id: I330b5366a5350cd9e8e54f4a04b7fa53f9122eca

src/crash-pipe/crash-pipe.c

index d0177fa..8a3f99f 100644 (file)
@@ -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;
 }