summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/apr/apr-util/0001-Fix-error-handling-in-gdbm.patch
blob: 6f27876a7f0e8e518b01852be89fc265dd4b9ca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
From 6b638fa9afbeb54dfa19378e391465a5284ce1ad Mon Sep 17 00:00:00 2001
From: Changqing Li <changqing.li@windriver.com>
Date: Wed, 12 Sep 2018 17:16:36 +0800
Subject: [PATCH] Fix error handling in gdbm

Only check for gdbm_errno if the return value of the called gdbm_*
function says so. This fixes apr-util with gdbm 1.14, which does not
seem to always reset gdbm_errno.

Also make the gdbm driver return error codes starting with
APR_OS_START_USEERR instead of always returning APR_EGENERAL. This is
what the berkleydb driver already does.

Also ensure that dsize is 0 if dptr == NULL.

Upstream-Status: Backport [https://svn.apache.org/viewvc?view=revision&amp;revision=1825311]

Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 dbm/apr_dbm_gdbm.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/dbm/apr_dbm_gdbm.c b/dbm/apr_dbm_gdbm.c
index 749447a..1c86327 100644
--- a/dbm/apr_dbm_gdbm.c
+++ b/dbm/apr_dbm_gdbm.c
@@ -36,13 +36,25 @@
 static apr_status_t g2s(int gerr)
 {
     if (gerr == -1) {
-        /* ### need to fix this */
-        return APR_EGENERAL;
+        if (gdbm_errno == GDBM_NO_ERROR)
+           return APR_SUCCESS;
+        return APR_OS_START_USEERR + gdbm_errno;
     }
 
     return APR_SUCCESS;
 }
 
+static apr_status_t gdat2s(datum d)
+{
+    if (d.dptr == NULL) {
+        if (gdbm_errno == GDBM_NO_ERROR || gdbm_errno == GDBM_ITEM_NOT_FOUND)
+           return APR_SUCCESS;
+        return APR_OS_START_USEERR + gdbm_errno;
+   }
+
+    return APR_SUCCESS;
+}
+
 static apr_status_t datum_cleanup(void *dptr)
 {
     if (dptr)
@@ -53,22 +65,15 @@ static apr_status_t datum_cleanup(void *dptr)
 
 static apr_status_t set_error(apr_dbm_t *dbm, apr_status_t dbm_said)
 {
-    apr_status_t rv = APR_SUCCESS;
 
-    /* ### ignore whatever the DBM said (dbm_said); ask it explicitly */
+    dbm->errcode = dbm_said;  
 
-    if ((dbm->errcode = gdbm_errno) == GDBM_NO_ERROR) {
+    if (dbm_said == APR_SUCCESS)
         dbm->errmsg = NULL;
-    }
-    else {
-        dbm->errmsg = gdbm_strerror(gdbm_errno);
-        rv = APR_EGENERAL;        /* ### need something better */
-    }
-
-    /* captured it. clear it now. */
-    gdbm_errno = GDBM_NO_ERROR;
+    else
+        dbm->errmsg = gdbm_strerror(dbm_said - APR_OS_START_USEERR);
 
-    return rv;
+    return dbm_said;
 }
 
 /* --------------------------------------------------------------------------
@@ -107,7 +112,7 @@ static apr_status_t vt_gdbm_open(apr_dbm_t **pdb, const char *pathname,
                      NULL);
 
     if (file == NULL)
-        return APR_EGENERAL;      /* ### need a better error */
+        return APR_OS_START_USEERR + gdbm_errno;   /* ### need a better error */
 
     /* we have an open database... return it */
     *pdb = apr_pcalloc(pool, sizeof(**pdb));
@@ -141,10 +146,12 @@ static apr_status_t vt_gdbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
     if (pvalue->dptr)
         apr_pool_cleanup_register(dbm->pool, pvalue->dptr, datum_cleanup,
                                   apr_pool_cleanup_null);
+    else
+       pvalue->dsize = 0;
 
     /* store the error info into DBM, and return a status code. Also, note
        that *pvalue should have been cleared on error. */
-    return set_error(dbm, APR_SUCCESS);
+    return set_error(dbm, gdat2s(rd));
 }
 
 static apr_status_t vt_gdbm_store(apr_dbm_t *dbm, apr_datum_t key,
@@ -201,9 +208,11 @@ static apr_status_t vt_gdbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey)
     if (pkey->dptr)
         apr_pool_cleanup_register(dbm->pool, pkey->dptr, datum_cleanup,
                                   apr_pool_cleanup_null);
+    else
+        pkey->dsize = 0;
 
     /* store any error info into DBM, and return a status code. */
-    return set_error(dbm, APR_SUCCESS);
+    return set_error(dbm, gdat2s(rd));
 }
 
 static apr_status_t vt_gdbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
@@ -221,9 +230,11 @@ static apr_status_t vt_gdbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
     if (pkey->dptr)
         apr_pool_cleanup_register(dbm->pool, pkey->dptr, datum_cleanup,
                                   apr_pool_cleanup_null);
+    else
+       pkey->dsize = 0;
 
     /* store any error info into DBM, and return a status code. */
-    return set_error(dbm, APR_SUCCESS);
+    return set_error(dbm, gdat2s(rd));
 }
 
 static void vt_gdbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
-- 
2.7.4