These reflect either file descriptors which aren't tested
for failure, or closures of fd's which may have failed.
In setup_tdb(), test for failure of mkstemp and return
without trying to open the file (again).
In reserve_stdio_fds, rather than closing the "extra"
fd == 3 due to the way the loop is written, just
don't go that far by using while (fd <= 2).
In logsave, it forks and retries forever if open fails,
but at least make coverity happy by explicitly not
trying to close a negative file descriptor.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
uuid_unparse(ctx->fs->super->s_uuid, uuid);
sprintf(db->tdb_fn, "%s/%s-dirinfo-XXXXXX", tdb_dir, uuid);
fd = mkstemp(db->tdb_fn);
+ if (fd < 0) {
+ db->tdb = NULL;
+ return;
+ }
db->tdb = tdb_open(db->tdb_fn, 0, TDB_CLEAR_IF_FIRST,
O_RDWR | O_CREAT | O_TRUNC, 0600);
close(fd);
#define PATH_SET "PATH=/sbin"
+/*
+ * Make sure 0,1,2 file descriptors are open, so that we don't open
+ * the filesystem using the same file descriptor as stdout or stderr.
+ */
static void reserve_stdio_fds(void)
{
- int fd;
+ int fd = 0;
- while (1) {
+ while (fd <= 2) {
fd = open("/dev/null", O_RDWR);
- if (fd > 2)
- break;
if (fd < 0) {
fprintf(stderr, _("ERROR: Couldn't open "
"/dev/null (%s)\n"),
break;
}
}
- close(fd);
}
#ifdef HAVE_SIGNAL_H
write_all(outfd, outbuf, outbufsize);
free(outbuf);
}
- close(outfd);
+ if (outfd >= 0)
+ close(outfd);
exit(rc);
}