* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.8 2003/11/29 19:51:40 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.9 2004/01/26 22:35:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
SLRU_CREATE_FAILED,
SLRU_SEEK_FAILED,
SLRU_READ_FAILED,
- SLRU_WRITE_FAILED
+ SLRU_WRITE_FAILED,
+ SLRU_CLOSE_FAILED
} SlruErrorCause;
static SlruErrorCause slru_errcause;
static int slru_errno;
return false;
}
- close(fd);
+ if (close(fd))
+ {
+ slru_errcause = SLRU_CLOSE_FAILED;
+ slru_errno = errno;
+ return false;
+ }
+
return true;
}
return false;
}
- close(fd);
+ if (close(fd))
+ {
+ slru_errcause = SLRU_CLOSE_FAILED;
+ slru_errno = errno;
+ return false;
+ }
+
return true;
}
errdetail("could not write to file \"%s\" at offset %u: %m",
path, offset)));
break;
+ case SLRU_CLOSE_FAILED:
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not access status of transaction %u", xid),
+ errdetail("could not close file \"%s\": %m",
+ path)));
+ break;
default:
/* can't get here, we trust */
elog(ERROR, "unrecognized SimpleLru error cause: %d",
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.132 2004/01/19 19:04:40 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.133 2004/01/26 22:35:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
if (openLogFile >= 0)
{
- if (close(openLogFile) != 0)
+ if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close log file %u, segment %u: %m",
if (openLogFile >= 0 &&
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
{
- if (close(openLogFile) != 0)
+ if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close log file %u, segment %u: %m",
(errcode_for_file_access(),
errmsg("could not fsync file \"%s\": %m", tmppath)));
- close(fd);
+ if (close(fd))
+ ereport(PANIC,
+ (errcode_for_file_access(),
+ errmsg("could not close file \"%s\": %m", tmppath)));
/*
* Now move the segment into place with its final name.
(errcode_for_file_access(),
errmsg("could not fsync control file: %m")));
- close(fd);
+ if (close(fd))
+ ereport(PANIC,
+ (errcode_for_file_access(),
+ errmsg("could not close control file: %m")));
}
static void
(errcode_for_file_access(),
errmsg("could not fsync control file: %m")));
- close(fd);
+ if (close(fd))
+ ereport(PANIC,
+ (errcode_for_file_access(),
+ errmsg("could not close control file: %m")));
}
/*
(errcode_for_file_access(),
errmsg("could not fsync bootstrap transaction log file: %m")));
- close(openLogFile);
+ if (close(openLogFile))
+ ereport(PANIC,
+ (errcode_for_file_access(),
+ errmsg("could not close bootstrap transaction log file: %m")));
+
openLogFile = -1;
memset(ControlFile, 0, sizeof(ControlFileData));
openLogId, openLogSeg)));
if (open_sync_bit != new_sync_bit)
{
- if (close(openLogFile) != 0)
+ if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close log file %u, segment %u: %m",
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.215 2004/01/18 02:15:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.216 2004/01/26 22:35:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
if (!pipe)
- FreeFile(copy_file);
+ {
+ /* we assume only the write case could fail here */
+ if (FreeFile(copy_file))
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": %m",
+ filename)));
+ }
else if (IsUnderPostmaster && !is_from)
SendCopyEnd(binary);
pfree(attribute_buf.data);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.132 2004/01/07 18:56:25 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.133 2004/01/26 22:35:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
heap_endscan(scan);
- fflush(fp);
- if (ferror(fp))
+ if (FreeFile(fp))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to temporary file \"%s\": %m", tempname)));
- FreeFile(fp);
+ errmsg("could not write to temporary file \"%s\": %m",
+ tempname)));
/*
* Rename the temp file to its final name, deleting the old pg_pwd. We
}
heap_endscan(scan);
- fflush(fp);
- if (ferror(fp))
+ if (FreeFile(fp))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to temporary file \"%s\": %m", tempname)));
- FreeFile(fp);
+ errmsg("could not write to temporary file \"%s\": %m",
+ tempname)));
/*
* Rename the temp file to its final name, deleting the old pg_pwd. We
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.358 2004/01/11 03:49:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.359 2004/01/26 22:35:32 tgl Exp $
*
* NOTES
*
fprintf(fp, " '%s'", argv[i]);
fputs("\n", fp);
- fflush(fp);
- if (ferror(fp))
+ if (fclose(fp))
{
elog(LOG, "could not write file \"%s\": %m", filename);
- fclose(fp);
return false;
}
- fclose(fp);
return true;
}
write_var(debug_flag,fp);
/* Release file */
- FreeFile(fp);
+ if (FreeFile(fp))
+ {
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": %m", filename)));
+ return false;
+ }
+
return true;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.105 2003/12/20 17:31:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.106 2004/01/26 22:35:32 tgl Exp $
*
* NOTES:
*
/* close the file */
if (close(vfdP->fd))
- elog(LOG, "failed to close \"%s\": %m",
+ elog(ERROR, "failed to close \"%s\": %m",
vfdP->fileName);
--nfile;
/* close the file */
if (close(vfdP->fd))
- elog(LOG, "failed to close \"%s\": %m",
+ elog(ERROR, "failed to close \"%s\": %m",
vfdP->fileName);
--nfile;
return NULL;
}
-void
+/*
+ * Close a file returned by AllocateFile.
+ *
+ * Note we do not check fclose's return value --- it is up to the caller
+ * to handle close errors.
+ */
+int
FreeFile(FILE *file)
{
int i;
if (i < 0)
elog(WARNING, "file passed to FreeFile was not obtained from AllocateFile");
- fclose(file);
+ return fclose(file);
}
/*
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.29 2004/01/11 03:49:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.30 2004/01/26 22:35:32 tgl Exp $
*
*
* NOTES:
/* Clean up */
LWLockRelease(FreeSpaceLock);
- FreeFile(fp);
+ if (FreeFile(fp))
+ {
+ elog(LOG, "could not write \"%s\": %m", cachefilename);
+ /* Remove busted cache file */
+ unlink(cachefilename);
+ }
return;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.194 2003/12/28 21:57:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.195 2004/01/26 22:35:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
MemoryContextSwitchTo(oldcxt);
}
- FreeFile(fp);
+ if (FreeFile(fp))
+ elog(FATAL, "could not write init file");
/*
* Now we have to check whether the data we've so painstakingly
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.119 2004/01/08 06:01:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.120 2004/01/26 22:35:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
(errcode_for_file_access(),
errmsg("could not write lock file \"%s\": %m", filename)));
}
- close(fd);
+ if (close(fd))
+ {
+ int save_errno = errno;
+
+ unlink(filename);
+ errno = save_errno;
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not write lock file \"%s\": %m", filename)));
+ }
/*
* Arrange for automatic removal of lockfile at proc_exit.
close(fd);
return;
}
- close(fd);
+ if (close(fd))
+ {
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": %m",
+ directoryLockFile)));
+ }
}
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.180 2004/01/24 20:00:45 wieck Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.181 2004/01/26 22:35:32 tgl Exp $
*
*--------------------------------------------------------------------
*/
}
}
- FreeFile(fp);
+ if (FreeFile(fp))
+ {
+ free(new_filename);
+ free(filename);
+ ereport(elevel,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
+ return;
+ }
+
/* Put new file in place, this could delay on Win32 */
rename(new_filename, filename);
free(new_filename);
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.18 2003/12/23 21:50:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.19 2004/01/26 22:35:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
sprintf(path, "%s/%s/PG_VERSION", pg_data, extrapath);
}
version_file = fopen(path, PG_BINARY_W);
+ if (version_file == NULL)
+ exit_nicely();
fprintf(version_file, "%s\n", short_version);
- fclose(version_file);
+ if (fclose(version_file))
+ exit_nicely();
}
/*
path = xmalloc(strlen(pg_data) + 17);
sprintf(path, "%s/postgresql.conf", pg_data);
conf_file = fopen(path, PG_BINARY_W);
- fclose(conf_file);
+ if (conf_file == NULL || fclose(conf_file))
+ exit_nicely();
}
/*
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.111 2004/01/25 03:07:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.112 2004/01/26 22:35:32 tgl Exp $
*/
#include "postgres_fe.h"
#include "command.h"
remove(fname);
error = true;
}
- else
- fclose(stream);
+ else if (fclose(stream) != 0)
+ {
+ psql_error("%s: %s\n", fname, strerror(errno));
+ remove(fname);
+ error = true;
+ }
}
}
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.39 2004/01/25 03:07:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.40 2004/01/26 22:35:32 tgl Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
PQclear(result);
if (options->file != NULL)
- fclose(copystream);
+ {
+ if (fclose(copystream) != 0)
+ {
+ psql_error("%s: %s\n", options->file, strerror(errno));
+ success = false;
+ }
+ }
free_copy_options(options);
return success;
}
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/fd.h,v 1.41 2003/12/20 17:31:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/fd.h,v 1.42 2004/01/26 22:35:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Operations that allow use of regular stdio --- USE WITH CAUTION */
extern FILE *AllocateFile(char *name, char *mode);
-extern void FreeFile(FILE *);
+extern int FreeFile(FILE *);
/* If you've really really gotta have a plain kernel FD, use this */
extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.46 2004/01/07 18:56:29 neilc Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.47 2004/01/26 22:35:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
/*
- * read in from the Unix file and write to the inversion file
+ * read in from the inversion file and write to the Unix file
*/
while ((nbytes = lo_read(conn, lobj, buf, LO_BUFSIZE)) > 0)
{
}
(void) lo_close(conn, lobj);
- (void) close(fd);
+
+ if (close(fd))
+ {
+ printfPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("error while writing to file \"%s\"\n"),
+ filename);
+ return -1;
+ }
return 1;
}