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) {
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;
out:
close(fd);
- return 0;
+ return ret;
}