summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-26 07:43:34 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-07-26 07:43:34 (GMT)
commit7fb0d1cbbf7842f2632b7dca0451d6f3918dd7ab (patch) (side-by-side diff)
tree899bdcd5c62eb632de6fb3c660a192c1929446c9 /src
parent465e893bfa0cdfb8f260500599fc3af458047a76 (diff)
downloadgdbm-7fb0d1cbbf7842f2632b7dca0451d6f3918dd7ab.tar.gz
gdbm-7fb0d1cbbf7842f2632b7dca0451d6f3918dd7ab.tar.bz2
Fix remaining uses of gdbm_set_errno function.
Use the GDBM_SET_ERRNO and GDBM_SET_ERRNO2 macros to make sure the error gets reported in debug output. * src/fullio.c (_gdbm_full_read) (_gdbm_full_write): Return -1 and set gdbm_errno on error. * src/bucket.c: Use GDBM_SET_ERRNO(2?) or GDBM_DEBUG where necessary. * src/falloc.c: Likewise. * src/findkey.c: Likewise. * src/gdbmdefs.h: Likewise. * src/gdbmopen.c: Likewise. * src/gdbmstore.c: Likewise. * src/mmap.c: Likewise. * src/recover.c: Likewise. * src/update.c: Likewise.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/bucket.c18
-rw-r--r--src/falloc.c5
-rw-r--r--src/findkey.c5
-rw-r--r--src/fullio.c23
-rw-r--r--src/gdbmdefs.h2
-rw-r--r--src/gdbmopen.c48
-rw-r--r--src/gdbmstore.c9
-rw-r--r--src/mmap.c6
-rw-r--r--src/recover.c20
-rw-r--r--src/update.c13
10 files changed, 79 insertions, 70 deletions
diff --git a/src/bucket.c b/src/bucket.c
index 912a7b4..9f423f4 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -111,8 +111,11 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
_gdbm_full_read (dbf, dbf->bucket, dbf->header->bucket_size));
if (rc)
{
- _gdbm_fatal (dbf, gdbm_strerror (rc));
- GDBM_SET_ERRNO (dbf, rc, TRUE);
+ GDBM_DEBUG (GDBM_DEBUG_ERR,
+ "%s: error reading bucket: %s",
+ dbf->name, gdbm_db_strerror (dbf));
+ dbf->need_recovery = TRUE;
+ _gdbm_fatal (dbf, gdbm_db_strerror (dbf));
return -1;
}
}
@@ -150,10 +153,11 @@ _gdbm_read_bucket_at (GDBM_FILE dbf, off_t off, hash_bucket *bucket,
GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
return -1;
}
- rc = _gdbm_full_read (dbf, bucket, size);
- if (rc)
+ if (_gdbm_full_read (dbf, bucket, size))
{
- GDBM_SET_ERRNO (dbf, rc, TRUE);
+ GDBM_DEBUG (GDBM_DEBUG_ERR,
+ "%s: error reading bucket: %s",
+ dbf->name, gdbm_db_strerror (dbf));
return -1;
}
return 0;
@@ -394,7 +398,9 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry)
_gdbm_full_write (dbf, ca_entry->ca_bucket, dbf->header->bucket_size));
if (rc)
{
- GDBM_SET_ERRNO (dbf, rc, TRUE);
+ GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
+ "%s: error writing bucket: %s",
+ dbf->name, gdbm_db_strerror (dbf));
_gdbm_fatal (dbf, gdbm_strerror (rc));
return -1;
}
diff --git a/src/falloc.c b/src/falloc.c
index c5ffdc3..516a197 100644
--- a/src/falloc.c
+++ b/src/falloc.c
@@ -202,7 +202,6 @@ pop_avail_block (GDBM_FILE dbf)
_gdbm_full_read (dbf, new_blk, new_el.av_size));
if (rc)
{
- GDBM_SET_ERRNO (dbf, rc, TRUE);
_gdbm_fatal (dbf, gdbm_strerror (rc));
return -1;
}
@@ -321,7 +320,9 @@ push_avail_block (GDBM_FILE dbf)
_gdbm_full_write (dbf, temp, av_size));
if (rc)
{
- GDBM_SET_ERRNO (dbf, rc, TRUE);
+ GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
+ "%s: error writing avail data: %s",
+ dbf->name, gdbm_db_strerror (dbf));
_gdbm_fatal (dbf, gdbm_strerror (rc));
return -1;
}
diff --git a/src/findkey.c b/src/findkey.c
index 135856b..b2e0e8c 100644
--- a/src/findkey.c
+++ b/src/findkey.c
@@ -79,7 +79,10 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc)
_gdbm_full_read (dbf, data_ca->dptr, key_size+data_size));
if (rc)
{
- GDBM_SET_ERRNO2 (dbf, rc, TRUE, GDBM_DEBUG_LOOKUP);
+ GDBM_DEBUG (GDBM_DEBUG_ERR|GDBM_DEBUG_LOOKUP|GDBM_DEBUG_READ,
+ "%s: error reading entry: %s",
+ dbf->name, gdbm_db_strerror (dbf));
+ dbf->need_recovery = TRUE;
_gdbm_fatal (dbf, gdbm_strerror (rc));
return NULL;
}
diff --git a/src/fullio.c b/src/fullio.c
index adfff2c..0b65187 100644
--- a/src/fullio.c
+++ b/src/fullio.c
@@ -18,9 +18,9 @@
#include "gdbmdefs.h"
/* Read exactly SIZE bytes of data into BUFFER. Return value is 0 on
- success, GDBM_FILE_EOF, if not enough data is available, and
- GDBM_FILE_READ_ERROR, if a read error occurs. In the latter case
- errno keeps actual system error code. */
+ success, and -1 on error. In the latter case, gdbm_errno is set to
+ GDBM_FILE_EOF, if not enough data is available, and to
+ GDBM_FILE_READ_ERROR, if a read error occurs. */
int
_gdbm_full_read (GDBM_FILE dbf, void *buffer, size_t size)
{
@@ -32,10 +32,14 @@ _gdbm_full_read (GDBM_FILE dbf, void *buffer, size_t size)
{
if (errno == EINTR)
continue;
- return GDBM_FILE_READ_ERROR;
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_READ_ERROR, FALSE);
+ return -1;
}
if (rdbytes == 0)
- return GDBM_FILE_EOF;
+ {
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_EOF, FALSE);
+ return -1;
+ }
ptr += rdbytes;
size -= rdbytes;
}
@@ -43,8 +47,7 @@ _gdbm_full_read (GDBM_FILE dbf, void *buffer, size_t size)
}
/* Write exactly SIZE bytes of data from BUFFER tp DBF. Return 0 on
- success, and GDBM_FILE_READ_ERROR on error. In the latter case errno
- will keep actual system error code. */
+ success, and -1 (setting gdbm_errno to GDBM_FILE_READ_ERROR) on error. */
int
_gdbm_full_write (GDBM_FILE dbf, void *buffer, size_t size)
{
@@ -56,12 +59,14 @@ _gdbm_full_write (GDBM_FILE dbf, void *buffer, size_t size)
{
if (errno == EINTR)
continue;
- return GDBM_FILE_WRITE_ERROR;
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_WRITE_ERROR, TRUE);
+ return -1;
}
if (wrbytes == 0)
{
errno = ENOSPC;
- return GDBM_FILE_WRITE_ERROR;
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_WRITE_ERROR, TRUE);
+ return -1;
}
ptr += wrbytes;
size -= wrbytes;
diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h
index e1c143d..286f3fc 100644
--- a/src/gdbmdefs.h
+++ b/src/gdbmdefs.h
@@ -245,7 +245,7 @@ struct gdbm_file_info
{ \
if (dbf->need_recovery) \
{ \
- gdbm_set_errno (dbf, GDBM_NEED_RECOVERY, TRUE); \
+ GDBM_SET_ERRNO (dbf, GDBM_NEED_RECOVERY, TRUE); \
return onerr; \
} \
} \
diff --git a/src/gdbmopen.c b/src/gdbmopen.c
index 101d497..e444bc1 100644
--- a/src/gdbmopen.c
+++ b/src/gdbmopen.c
@@ -57,7 +57,6 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
struct stat file_stat; /* Space for the stat information. */
off_t file_pos; /* Used with seeks. */
int index; /* Used as a loop index. */
- int rc; /* temporary error code */
/* Initialize the gdbm_errno variable. */
gdbm_set_errno (NULL, GDBM_NO_ERROR, FALSE);
@@ -270,35 +269,38 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
/* Write initial configuration to the file. */
/* Block 0 is the file header and active avail block. */
- rc = _gdbm_full_write (dbf, dbf->header, dbf->header->block_size);
- if (rc)
+ if (_gdbm_full_write (dbf, dbf->header, dbf->header->block_size))
{
+ GDBM_DEBUG (GDBM_DEBUG_OPEN|GDBM_DEBUG_ERR,
+ "%s: error writing header: %s",
+ dbf->name, gdbm_db_strerror (dbf));
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_set_errno (NULL, rc, FALSE);
return NULL;
}
/* Block 1 is the initial bucket directory. */
- rc = _gdbm_full_write (dbf, dbf->dir, dbf->header->dir_size);
- if (rc)
+ if (_gdbm_full_write (dbf, dbf->dir, dbf->header->dir_size))
{
+ GDBM_DEBUG (GDBM_DEBUG_OPEN|GDBM_DEBUG_ERR,
+ "%s: error writing directory: %s",
+ dbf->name, gdbm_db_strerror (dbf));
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_set_errno (NULL, rc, FALSE);
return NULL;
}
/* Block 2 is the only bucket. */
- rc = _gdbm_full_write (dbf, dbf->bucket, dbf->header->bucket_size);
- if (rc)
+ if (_gdbm_full_write (dbf, dbf->bucket, dbf->header->bucket_size))
{
+ GDBM_DEBUG (GDBM_DEBUG_OPEN|GDBM_DEBUG_ERR,
+ "%s: error writing bucket: %s",
+ dbf->name, gdbm_db_strerror (dbf));
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_set_errno (NULL, rc, FALSE);
return NULL;
}
@@ -315,16 +317,14 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
gdbm_file_header partial_header; /* For the first part of it. */
/* Read the partial file header. */
- rc = _gdbm_full_read (dbf, &partial_header, sizeof (gdbm_file_header));
- if (rc)
+ if (_gdbm_full_read (dbf, &partial_header, sizeof (gdbm_file_header)))
{
GDBM_DEBUG (GDBM_DEBUG_ERR|GDBM_DEBUG_OPEN,
"%s: error reading partial header: %s",
- dbf->name, strerror (errno));
+ dbf->name, gdbm_db_strerror (dbf));
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_set_errno (NULL, rc, FALSE);
return NULL;
}
@@ -332,10 +332,6 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
if (partial_header.header_magic != GDBM_MAGIC
&& partial_header.header_magic != GDBM_OMAGIC)
{
- GDBM_DEBUG (GDBM_DEBUG_ERR|GDBM_DEBUG_OPEN,
- "%s: unexpected magic: %#4x",
- dbf->name, partial_header.header_magic);
-
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
gdbm_close (dbf);
@@ -370,17 +366,15 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
return NULL;
}
memcpy (dbf->header, &partial_header, sizeof (gdbm_file_header));
- rc = _gdbm_full_read (dbf, &dbf->header->avail.av_table[1],
- dbf->header->block_size - sizeof (gdbm_file_header));
- if (rc)
+ if (_gdbm_full_read (dbf, &dbf->header->avail.av_table[1],
+ dbf->header->block_size - sizeof (gdbm_file_header)))
{
GDBM_DEBUG (GDBM_DEBUG_ERR|GDBM_DEBUG_OPEN,
- "%s: error reading av_table",
- dbf->name);
+ "%s: error reading av_table: %s",
+ dbf->name, gdbm_db_strerror (dbf));
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_set_errno (NULL, rc, FALSE);
return NULL;
}
@@ -406,16 +400,14 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
return NULL;
}
- rc = _gdbm_full_read (dbf, dbf->dir, dbf->header->dir_size);
- if (rc)
+ if (_gdbm_full_read (dbf, dbf->dir, dbf->header->dir_size))
{
GDBM_DEBUG (GDBM_DEBUG_ERR|GDBM_DEBUG_OPEN,
"%s: error reading dir: %s",
- dbf->name, strerror (errno));
+ dbf->name, gdbm_db_strerror (dbf));
if (!(flags & GDBM_CLOERROR))
dbf->desc = -1;
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_set_errno (NULL, rc, FALSE);
return NULL;
}
diff --git a/src/gdbmstore.c b/src/gdbmstore.c
index 4cd7ad1..404687c 100644
--- a/src/gdbmstore.c
+++ b/src/gdbmstore.c
@@ -165,8 +165,8 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
if (rc)
{
GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
- "%s: writing key: %s", dbf->name, strerror (errno));
- gdbm_set_errno (dbf, rc, TRUE);
+ "%s: error writing key: %s",
+ dbf->name, gdbm_db_strerror (dbf));
_gdbm_fatal (dbf, gdbm_strerror (rc));
return -1;
}
@@ -177,9 +177,8 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
if (rc)
{
GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
- "%s: writing content: %s",
- dbf->name, strerror (errno));
- gdbm_set_errno (dbf, rc, TRUE);
+ "%s: error writing content: %s",
+ dbf->name, gdbm_db_strerror (dbf));
_gdbm_fatal (dbf, gdbm_strerror (rc));
return -1;
}
diff --git a/src/mmap.c b/src/mmap.c
index d5fe5c0..7ec5fe3 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -99,7 +99,7 @@ _gdbm_internal_remap (GDBM_FILE dbf, size_t size)
if (p == MAP_FAILED)
{
dbf->mapped_region = NULL;
- gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, FALSE);
+ GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, FALSE);
return -1;
}
@@ -135,7 +135,7 @@ _gdbm_mapped_remap (GDBM_FILE dbf, off_t size, int flag)
if (_gdbm_file_size (dbf, &file_size))
{
SAVE_ERRNO (_gdbm_mapped_unmap (dbf));
- gdbm_set_errno (dbf, GDBM_FILE_STAT_ERROR, FALSE);
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_STAT_ERROR, FALSE);
return -1;
}
@@ -330,7 +330,7 @@ _gdbm_mapped_lseek (GDBM_FILE dbf, off_t offset, int whence)
off_t file_size;
if (_gdbm_file_size (dbf, &file_size))
{
- gdbm_set_errno (dbf, GDBM_FILE_STAT_ERROR, FALSE);
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_STAT_ERROR, FALSE);
return -1;
}
needle = file_size - offset;
diff --git a/src/recover.c b/src/recover.c
index 69644f9..ecf47c5 100644
--- a/src/recover.c
+++ b/src/recover.c
@@ -26,17 +26,17 @@ gdbm_copy_meta (GDBM_FILE dst, GDBM_FILE src)
if (fstat (src->desc, &st))
{
- gdbm_set_errno (src, GDBM_FILE_STAT_ERROR, src->need_recovery);
+ GDBM_SET_ERRNO (src, GDBM_FILE_STAT_ERROR, src->need_recovery);
return -1;
}
if (fchown (dst->desc, st.st_uid, st.st_gid))
{
- gdbm_set_errno (dst, GDBM_ERR_FILE_OWNER, dst->need_recovery);
+ GDBM_SET_ERRNO (dst, GDBM_ERR_FILE_OWNER, dst->need_recovery);
return -1;
}
if (fchmod (dst->desc, st.st_mode & 0777))
{
- gdbm_set_errno (dst, GDBM_ERR_FILE_MODE, dst->need_recovery);
+ GDBM_SET_ERRNO (dst, GDBM_ERR_FILE_MODE, dst->need_recovery);
return -1;
}
return 0;
@@ -117,13 +117,13 @@ _gdbm_finish_transfer (GDBM_FILE dbf, GDBM_FILE new_dbf,
if (!bkname)
{
SAVE_ERRNO (gdbm_close (new_dbf));
- gdbm_set_errno (NULL, GDBM_BACKUP_FAILED, FALSE);
+ GDBM_SET_ERRNO (NULL, GDBM_BACKUP_FAILED, FALSE);
return -1;
}
if (rename (dbf->name, bkname) != 0)
{
SAVE_ERRNO (gdbm_close (new_dbf); free (bkname));
- gdbm_set_errno (NULL, GDBM_BACKUP_FAILED, FALSE);
+ GDBM_SET_ERRNO (NULL, GDBM_BACKUP_FAILED, FALSE);
return -1;
}
rcvr->backup_name = bkname;
@@ -133,7 +133,7 @@ _gdbm_finish_transfer (GDBM_FILE dbf, GDBM_FILE new_dbf,
if (rename (new_dbf->name, dbf->name) != 0)
{
- gdbm_set_errno (NULL, GDBM_REORGANIZE_FAILED, FALSE);
+ GDBM_SET_ERRNO (NULL, GDBM_REORGANIZE_FAILED, FALSE);
gdbm_close (new_dbf);
return -1;
}
@@ -342,7 +342,7 @@ gdbm_recover (GDBM_FILE dbf, gdbm_recovery *rcvr, int flags)
/* Readers can not reorganize! */
if (dbf->read_write == GDBM_READER)
{
- gdbm_set_errno (dbf, GDBM_READER_CANT_REORGANIZE, dbf->need_recovery);
+ GDBM_SET_ERRNO (dbf, GDBM_READER_CANT_REORGANIZE, dbf->need_recovery);
return -1;
}
@@ -365,7 +365,7 @@ gdbm_recover (GDBM_FILE dbf, gdbm_recovery *rcvr, int flags)
new_name = malloc (len + sizeof (TMPSUF));
if (!new_name)
{
- gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, FALSE);
+ GDBM_SET_ERRNO (NULL, GDBM_MALLOC_ERROR, FALSE);
return -1;
}
strcat (strcpy (new_name, dbf->name), TMPSUF);
@@ -373,7 +373,7 @@ gdbm_recover (GDBM_FILE dbf, gdbm_recovery *rcvr, int flags)
fd = mkstemp (new_name);
if (fd == -1)
{
- gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, FALSE);
+ GDBM_SET_ERRNO (NULL, GDBM_FILE_OPEN_ERROR, FALSE);
free (new_name);
return -1;
}
@@ -387,7 +387,7 @@ gdbm_recover (GDBM_FILE dbf, gdbm_recovery *rcvr, int flags)
if (new_dbf == NULL)
{
- gdbm_set_errno (NULL, GDBM_REORGANIZE_FAILED, FALSE);
+ GDBM_SET_ERRNO (NULL, GDBM_REORGANIZE_FAILED, FALSE);
return -1;
}
diff --git a/src/update.c b/src/update.c
index 90a6524..eb9f33b 100644
--- a/src/update.c
+++ b/src/update.c
@@ -34,7 +34,7 @@ write_header (GDBM_FILE dbf)
__lseek (dbf, 0L, SEEK_SET));
if (file_pos != 0)
{
- gdbm_set_errno (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
+ GDBM_SET_ERRNO2 (dbf, GDBM_FILE_SEEK_ERROR, TRUE, GDBM_DEBUG_STORE);
_gdbm_fatal (dbf, _("lseek error"));
return -1;
}
@@ -44,8 +44,9 @@ write_header (GDBM_FILE dbf)
if (rc)
{
- gdbm_set_errno (dbf, rc, TRUE);
- gdbm_set_errno (dbf, rc, TRUE);
+ GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
+ "%s: error writing header: %s",
+ dbf->name, gdbm_db_strerror (dbf));
return -1;
}
@@ -99,7 +100,7 @@ _gdbm_end_update (GDBM_FILE dbf)
__lseek (dbf, dbf->header->dir, SEEK_SET));
if (file_pos != dbf->header->dir)
{
- gdbm_set_errno (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
+ GDBM_SET_ERRNO2 (dbf, GDBM_FILE_SEEK_ERROR, TRUE, GDBM_DEBUG_STORE);
_gdbm_fatal (dbf, _("lseek error"));
return -1;
}
@@ -108,7 +109,9 @@ _gdbm_end_update (GDBM_FILE dbf)
_gdbm_full_write (dbf, dbf->dir, dbf->header->dir_size));
if (rc)
{
- gdbm_set_errno (dbf, rc, TRUE);
+ GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
+ "%s: error writing directory: %s",
+ dbf->name, gdbm_db_strerror (dbf));
_gdbm_fatal (dbf, gdbm_strerror (rc));
return -1;
}

Return to:

Send suggestions and report system problems to the System administrator.