aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--doc/gdbm.texinfo49
-rw-r--r--export/export.c1
-rw-r--r--src/gdbm.h.in4
-rw-r--r--src/gdbm_load.c18
-rw-r--r--src/gdbmerrno.c2
-rw-r--r--src/gdbmload.c19
7 files changed, 94 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index edc4fc7..2164129 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2011-11-15 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Return a meaningful error code if failed to restore file's metadata.
+
+ * src/gdbm.h.in (GDBM_ERR_FILE_OWNER)
+ (GDBM_ERR_FILE_MODE): New error codes.
+ (_GDBM_MAX_ERRNO): Update.
+ * src/gdbmerrno.c (gdbm_errlist): Add new error codes.
+ * src/gdbmload.c (_set_gdbm_meta_info): Set gdbm_errno and
+ return 1 in case of errors.
+ (_gdbm_load_file): Propagate the return value from
+ _set_gdbm_meta_info.
+
+ * src/gdbm_load.c (main): Handle mild error conditions.
+ * export/export.c (usage): Print the GDBM version the program is
+ linked with.
+ * doc/gdbm.texinfo: Document changes.
+
2011-11-14 Sergey Poznyakoff <gray@gnu.org.ua>
* doc/gdbm.texinfo (Error codes): Document new flat format and
diff --git a/doc/gdbm.texinfo b/doc/gdbm.texinfo
index 4dcdd76..1e51322 100644
--- a/doc/gdbm.texinfo
+++ b/doc/gdbm.texinfo
@@ -727,8 +727,10 @@ set @code{gdbm_errno} to @samp{GDBM_NO_DBNAME} and return
The @var{flag} has the same meaning as the @var{flag} argument
to the @code{gdbm_store} function (@pxref{Store}).
-The function returns 0 upon successful completion or -1 on error. In
-the latter case, @code{gdbm_errno} will be set to one of the
+The function returns 0 upon successful completion or -1 on fatal
+errors and 1 on mild (non-fatal) errors.
+
+If a fatal error occurs, @code{gdbm_errno} will be set to one of the
following values:
@table @asis
@@ -753,10 +755,28 @@ length specification. Application developers are advised to treat
this error equally as @samp{GDBM_ILLEGAL_DATA}.
@end table
-If any error, excepting @var{GDBM_FILE_OPEN_ERROR}, occurs and the
-input file is in ASCII format, the number of line in which the error
-occurred will be stored in the location pointed to by the
-@var{errline} parameter, unless it is @samp{NULL}.
+Mild errors mean that the function was able to successfully load and
+restore the data, but was unable to change database file metadata
+afterwards. The table below lists possible values for @code{gdbm_errno}
+in this case. To get more detail, inspect the system @code{errno} variable.
+
+@table @asis
+@kwindex GDBM_ERR_FILE_OWNER
+@item GDBM_ERR_FILE_OWNER
+The function was unable to restore database file owner.
+
+@kwindex GDBM_ERR_FILE_MODE
+@item GDBM_ERR_FILE_MODE
+The function was unable to restore database file mode (permission bits).
+@end table
+
+If an error occurs while loading data from an input file in ASCII
+format, the number of line in which the error occurred will be stored
+in the location pointed to by the @var{errline} parameter, unless it
+is @samp{NULL}.
+
+If the line information is not available or applicable, @var{errline}
+will be set to @samp{0}.
@end deftypefn
@deftypefn {gdbm interface} int gdbm_dump_to_file (GDBM_FILE @var{dbf}, @
@@ -1676,6 +1696,23 @@ Output database name is not specified. This error code is set by
@code{gdbm_load} (@pxref{gdbm_load function,,gdbm_load}) if the first
argument points to @samp{NULL} and the input file does not specify the
database name.
+
+@kwindex GDBM_ERR_FILE_OWNER
+@item GDBM_ERR_FILE_OWNER
+This error code is set by @code{gdbm_load} if it is unable to restore
+database file owner. It is a mild error condition, meaning that the
+data have been restored successfully, only changing the target file
+owner failed. Inspect the system @code{errno} variable to get a more
+detailed diagnostics.
+
+@kwindex GDBM_ERR_FILE_MODE
+@item GDBM_ERR_FILE_MODE
+This error code is set by @code{gdbm_load} if it is unable to restore
+database file mode. It is a mild error condition, meaning that the data
+have been restored successfully, only changing the target file owner
+failed. Inspect the system @code{errno} variable to get a more
+detailed diagnostics.
+
@end table
@node Compatibility
diff --git a/export/export.c b/export/export.c
index 2ef4e6c..39e05d1 100644
--- a/export/export.c
+++ b/export/export.c
@@ -32,6 +32,7 @@ usage (char *s)
printf ("Usage: %s database outfile\n", s);
printf (" or: %s [-hv]\n", s);
printf ("Convert GDBM database into a flat dump format.\n");
+ printf ("Linked with %s\n", gdbm_version);
printf ("\n");
printf ("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
}
diff --git a/src/gdbm.h.in b/src/gdbm.h.in
index 81e9943..b81516d 100644
--- a/src/gdbm.h.in
+++ b/src/gdbm.h.in
@@ -159,9 +159,11 @@ extern int gdbm_load_from_file (GDBM_FILE *, FILE *, int replace,
# define GDBM_FILE_STAT_ERROR 24
# define GDBM_FILE_EOF 25
# define GDBM_NO_DBNAME 26
+# define GDBM_ERR_FILE_OWNER 27
+# define GDBM_ERR_FILE_MODE 28
# define _GDBM_MIN_ERRNO 0
-# define _GDBM_MAX_ERRNO GDBM_NO_DBNAME
+# define _GDBM_MAX_ERRNO GDBM_ERR_FILE_MODE
typedef int gdbm_error; /* For compatibilities sake. */
extern gdbm_error gdbm_errno;
extern const char * const gdbm_errlist[];
diff --git a/src/gdbm_load.c b/src/gdbm_load.c
index 4e14207..cdc7302 100644
--- a/src/gdbm_load.c
+++ b/src/gdbm_load.c
@@ -116,10 +116,20 @@ main (int argc, char **argv)
rc = gdbm_load_from_file (&dbf, fp, replace, &err_line);
if (rc)
{
- if (err_line)
- gdbm_perror ("%s:%lu", filename, err_line);
- else
- gdbm_perror ("cannot load from %s", filename);
+ switch (gdbm_errno)
+ {
+ case GDBM_ERR_FILE_OWNER:
+ case GDBM_ERR_FILE_MODE:
+ error (_("error restoring metadata for %s: %s (%s)"),
+ filename, gdbm_strerror (gdbm_errno), strerror (errno));
+ break;
+
+ default:
+ if (err_line)
+ gdbm_perror ("%s:%lu", filename, err_line);
+ else
+ gdbm_perror (_("cannot load from %s"), filename);
+ }
}
if (dbf)
diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c
index de1aab7..6829a3a 100644
--- a/src/gdbmerrno.c
+++ b/src/gdbmerrno.c
@@ -55,6 +55,8 @@ const char * const gdbm_errlist[_GDBM_MAX_ERRNO+1] = {
N_("Cannot stat file"), /* GDBM_FILE_STAT_ERROR */
N_("Unexpected end of file"), /* GDBM_FILE_EOF */
N_("Database name not given"), /* GDBM_NO_DBNAME */
+ N_("Failed to restore file owner"), /* GDBM_ERR_FILE_OWNER */
+ N_("Failed to restore file mode"), /* GDBM_ERR_FILE_MODE */
};
const char *
diff --git a/src/gdbmload.c b/src/gdbmload.c
index afd4866..1e9cb06 100644
--- a/src/gdbmload.c
+++ b/src/gdbmload.c
@@ -264,7 +264,7 @@ read_record (struct dump_file *file, char *param, int n, datum *dat)
rc = get_len (param, &len);
if (rc)
return rc;
- dat->dsize = len; // FIXME: data type mismatch
+ dat->dsize = len; /* FIXME: data type mismatch */
rc = get_data (file);
if (rc)
return rc;
@@ -294,7 +294,8 @@ _set_gdbm_meta_info (GDBM_FILE dbf, char *param)
int meta_flags = 0;
const char *p;
char *end;
-
+ int rc = 0;
+
p = getparm (param, "user");
if (p)
{
@@ -365,12 +366,18 @@ _set_gdbm_meta_info (GDBM_FILE dbf, char *param)
owner_gid = st.st_gid;
}
if (fchown (fd, owner_uid, owner_gid))
- /* FIXME: set error code */;
+ {
+ gdbm_errno = GDBM_ERR_FILE_OWNER;
+ rc = 1;
+ }
}
if ((meta_flags & META_MODE) && fchmod (fd, mode))
- /* FIXME: set error code */;
+ {
+ gdbm_errno = GDBM_ERR_FILE_OWNER;
+ rc = 1;
+ }
}
- return 0;
+ return rc;
}
int
@@ -432,7 +439,7 @@ _gdbm_load_file (struct dump_file *file, GDBM_FILE dbf, GDBM_FILE *ofp,
if (rc == 0)
{
- _set_gdbm_meta_info (dbf, file->header);
+ rc = _set_gdbm_meta_info (dbf, file->header);
*ofp = dbf;
}
else if (tmp)

Return to:

Send suggestions and report system problems to the System administrator.