]>
Commit | Line | Data |
---|---|---|
12788f63 MT |
1 | 2011-02-05 Ulrich Drepper <drepper@gmail.com> |
2 | ||
3 | * nscd/nscd-client.h: Define MAX_TIMEOUT_VALUE. | |
4 | (struct datahead): Reuse 32 bits of the alignment for a TTL field. | |
5 | * nscd/aicache.c (addhstaiX): Return timeout of added value. | |
6 | (readdhstai): Return value of addhstaiX call. | |
7 | * nscd/grpcache.c (cache_addgr): Return timeout of added value. | |
8 | (addgrbyX): Return value returned by cache_addgr. | |
9 | (readdgrbyname): Return value returned by addgrbyX. | |
10 | (readdgrbygid): Likewise. | |
11 | * nscd/pwdcache.c (cache_addpw): Return timeout of added value. | |
12 | (addpwbyX): Return value returned by cache_addpw. | |
13 | (readdpwbyname): Return value returned by addhstbyX. | |
14 | (readdpwbyuid): Likewise. | |
15 | * nscd/servicescache.c (cache_addserv): Return timeout of added value. | |
16 | (addservbyX): Return value returned by cache_addserv. | |
17 | (readdservbyname): Return value returned by addservbyX: | |
18 | (readdservbyport): Likewise. | |
19 | * nscd/hstcache.c (cache_addhst): Return timeout of added value. | |
20 | (addhstbyX): Return value returned by cache_addhst. | |
21 | (readdhstbyname): Return value returned by addhstbyX. | |
22 | (readdhstbyaddr): Likewise. | |
23 | (readdhstbynamev6): Likewise. | |
24 | (readdhstbyaddrv6): Likewise. | |
25 | * nscd/initgrcache.c (addinitgroupsX): Return timeout of added value. | |
26 | (readdinitgroups): Return value returned by addinitgroupsX. | |
27 | * nscd/cache.c (readdfcts): Change return value of functions to time_t. | |
28 | (prune_cache): Keep track of timeout value of re-added entries. | |
29 | * nscd/connections.c (nscd_run_prune): Use MAX_TIMEOUT_VALUE. | |
30 | * nscd/nscd.h: Adjust prototypes of readd* functions. | |
31 | ||
32 | Index: glibc-2.12-2-gc4ccff1/nscd/aicache.c | |
33 | =================================================================== | |
34 | --- glibc-2.12-2-gc4ccff1.orig/nscd/aicache.c | |
35 | +++ glibc-2.12-2-gc4ccff1/nscd/aicache.c | |
36 | @@ -58,7 +58,7 @@ static const ai_response_header notfound | |
37 | }; | |
38 | ||
39 | ||
40 | -static void | |
41 | +static time_t | |
42 | addhstaiX (struct database_dyn *db, int fd, request_header *req, | |
43 | void *key, uid_t uid, struct hashentry *const he, | |
44 | struct datahead *dh) | |
45 | @@ -119,6 +119,7 @@ addhstaiX (struct database_dyn *db, int | |
46 | ssize_t total = 0; | |
47 | char *key_copy = NULL; | |
48 | bool alloca_used = false; | |
49 | + time_t timeout = MAX_TIMEOUT_VALUE; | |
50 | ||
51 | while (!no_more) | |
52 | { | |
53 | @@ -388,8 +389,8 @@ addhstaiX (struct database_dyn *db, int | |
54 | dataset->head.usable = true; | |
55 | ||
56 | /* Compute the timeout time. */ | |
57 | - dataset->head.timeout = time (NULL) + (ttl == INT32_MAX | |
58 | - ? db->postimeout : ttl); | |
59 | + dataset->head.ttl = ttl == INT32_MAX ? db->postimeout : ttl; | |
60 | + timeout = dataset->head.timeout = time (NULL) + dataset->head.ttl; | |
61 | ||
62 | dataset->resp.version = NSCD_VERSION; | |
63 | dataset->resp.found = 1; | |
64 | @@ -421,6 +422,7 @@ addhstaiX (struct database_dyn *db, int | |
65 | timeout value. Note that the new record has been | |
66 | allocated on the stack and need not be freed. */ | |
67 | dh->timeout = dataset->head.timeout; | |
68 | + dh->ttl = dataset->head.ttl; | |
69 | ++dh->nreloads; | |
70 | } | |
71 | else | |
72 | @@ -496,6 +498,9 @@ next_nip: | |
73 | if (reload_count != UINT_MAX && dh->nreloads == reload_count) | |
74 | /* Do not reset the value if we never not reload the record. */ | |
75 | dh->nreloads = reload_count - 1; | |
76 | + | |
77 | + /* Reload with the same time-to-live value. */ | |
78 | + timeout = dh->timeout = time (NULL) + dh->ttl; | |
79 | } | |
80 | else | |
81 | { | |
82 | @@ -517,7 +522,8 @@ next_nip: | |
83 | dataset->head.usable = true; | |
84 | ||
85 | /* Compute the timeout time. */ | |
86 | - dataset->head.timeout = time (NULL) + db->negtimeout; | |
87 | + timeout = dataset->head.timeout = time (NULL) + db->negtimeout; | |
88 | + dataset->head.ttl = db->negtimeout; | |
89 | ||
90 | /* This is the reply. */ | |
91 | memcpy (&dataset->resp, ¬found, total); | |
92 | @@ -551,6 +557,8 @@ next_nip: | |
93 | if (dh != NULL) | |
94 | dh->usable = false; | |
95 | } | |
96 | + | |
97 | + return timeout; | |
98 | } | |
99 | ||
100 | ||
101 | @@ -562,7 +570,7 @@ addhstai (struct database_dyn *db, int f | |
102 | } | |
103 | ||
104 | ||
105 | -void | |
106 | +time_t | |
107 | readdhstai (struct database_dyn *db, struct hashentry *he, struct datahead *dh) | |
108 | { | |
109 | request_header req = | |
110 | @@ -571,5 +579,5 @@ readdhstai (struct database_dyn *db, str | |
111 | .key_len = he->len | |
112 | }; | |
113 | ||
114 | - addhstaiX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
115 | + return addhstaiX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
116 | } | |
117 | Index: glibc-2.12-2-gc4ccff1/nscd/cache.c | |
118 | =================================================================== | |
119 | --- glibc-2.12-2-gc4ccff1.orig/nscd/cache.c | |
120 | +++ glibc-2.12-2-gc4ccff1/nscd/cache.c | |
121 | @@ -45,9 +45,9 @@ extern void *xcalloc (size_t n, size_t s | |
122 | unsigned int reload_count = DEFAULT_RELOAD_LIMIT; | |
123 | ||
124 | ||
125 | -static void (*const readdfcts[LASTREQ]) (struct database_dyn *, | |
126 | - struct hashentry *, | |
127 | - struct datahead *) = | |
128 | +static time_t (*const readdfcts[LASTREQ]) (struct database_dyn *, | |
129 | + struct hashentry *, | |
130 | + struct datahead *) = | |
131 | { | |
132 | [GETPWBYNAME] = readdpwbyname, | |
133 | [GETPWBYUID] = readdpwbyuid, | |
134 | @@ -389,7 +389,8 @@ prune_cache (struct database_dyn *table, | |
135 | assert (runp->type < LASTREQ | |
136 | && readdfcts[runp->type] != NULL); | |
137 | ||
138 | - readdfcts[runp->type] (table, runp, dh); | |
139 | + time_t timeout = readdfcts[runp->type] (table, runp, dh); | |
140 | + next_timeout = MIN (next_timeout, timeout); | |
141 | ||
142 | /* If the entry has been replaced, we might need | |
143 | cleanup. */ | |
144 | Index: glibc-2.12-2-gc4ccff1/nscd/connections.c | |
145 | =================================================================== | |
146 | --- glibc-2.12-2-gc4ccff1.orig/nscd/connections.c | |
147 | +++ glibc-2.12-2-gc4ccff1/nscd/connections.c | |
148 | @@ -1533,10 +1533,7 @@ nscd_run_prune (void *p) | |
149 | pruning we want to know about it. Therefore set the | |
150 | timeout to the maximum. It will be descreased when adding | |
151 | new entries to the cache, if necessary. */ | |
152 | - if (sizeof (time_t) == sizeof (long int)) | |
153 | - dbs[my_number].wakeup_time = LONG_MAX; | |
154 | - else | |
155 | - dbs[my_number].wakeup_time = INT_MAX; | |
156 | + dbs[my_number].wakeup_time = MAX_TIMEOUT_VALUE; | |
157 | ||
158 | /* Unconditionally reset the flag. */ | |
159 | time_t prune_now = dbs[my_number].clear_cache ? LONG_MAX : now; | |
160 | Index: glibc-2.12-2-gc4ccff1/nscd/grpcache.c | |
161 | =================================================================== | |
162 | --- glibc-2.12-2-gc4ccff1.orig/nscd/grpcache.c | |
163 | +++ glibc-2.12-2-gc4ccff1/nscd/grpcache.c | |
164 | @@ -71,7 +71,7 @@ static const gr_response_header notfound | |
165 | }; | |
166 | ||
167 | ||
168 | -static void | |
169 | +static time_t | |
170 | cache_addgr (struct database_dyn *db, int fd, request_header *req, | |
171 | const void *key, struct group *grp, uid_t owner, | |
172 | struct hashentry *const he, struct datahead *dh, int errval) | |
173 | @@ -91,6 +91,7 @@ cache_addgr (struct database_dyn *db, in | |
174 | ||
175 | assert (offsetof (struct dataset, resp) == offsetof (struct datahead, data)); | |
176 | ||
177 | + time_t timeout = MAX_TIMEOUT_VALUE; | |
178 | if (grp == NULL) | |
179 | { | |
180 | if (he != NULL && errval == EAGAIN) | |
181 | @@ -102,6 +103,9 @@ cache_addgr (struct database_dyn *db, in | |
182 | /* Do not reset the value if we never not reload the record. */ | |
183 | dh->nreloads = reload_count - 1; | |
184 | ||
185 | + /* Reload with the same time-to-live value. */ | |
186 | + timeout = dh->timeout = t + db->postimeout; | |
187 | + | |
188 | written = total = 0; | |
189 | } | |
190 | else | |
191 | @@ -125,7 +129,7 @@ cache_addgr (struct database_dyn *db, in | |
192 | dataset->head.usable = true; | |
193 | ||
194 | /* Compute the timeout time. */ | |
195 | - dataset->head.timeout = t + db->negtimeout; | |
196 | + timeout = dataset->head.timeout = t + db->negtimeout; | |
197 | ||
198 | /* This is the reply. */ | |
199 | memcpy (&dataset->resp, ¬found, total); | |
200 | @@ -217,7 +221,7 @@ cache_addgr (struct database_dyn *db, in | |
201 | dataset->head.usable = true; | |
202 | ||
203 | /* Compute the timeout time. */ | |
204 | - dataset->head.timeout = t + db->postimeout; | |
205 | + timeout = dataset->head.timeout = t + db->postimeout; | |
206 | ||
207 | dataset->resp.version = NSCD_VERSION; | |
208 | dataset->resp.found = 1; | |
209 | @@ -379,6 +383,8 @@ cache_addgr (struct database_dyn *db, in | |
210 | dbg_log (_("short write in %s: %s"), __FUNCTION__, | |
211 | strerror_r (errno, buf, sizeof (buf))); | |
212 | } | |
213 | + | |
214 | + return timeout; | |
215 | } | |
216 | ||
217 | ||
218 | @@ -400,7 +406,7 @@ lookup (int type, union keytype key, str | |
219 | } | |
220 | ||
221 | ||
222 | -static void | |
223 | +static time_t | |
224 | addgrbyX (struct database_dyn *db, int fd, request_header *req, | |
225 | union keytype key, const char *keystr, uid_t uid, | |
226 | struct hashentry *he, struct datahead *dh) | |
227 | @@ -456,10 +462,12 @@ addgrbyX (struct database_dyn *db, int f | |
228 | buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen); | |
229 | } | |
230 | ||
231 | - cache_addgr (db, fd, req, keystr, grp, uid, he, dh, errval); | |
232 | + time_t timeout = cache_addgr (db, fd, req, keystr, grp, uid, he, dh, errval); | |
233 | ||
234 | if (use_malloc) | |
235 | free (buffer); | |
236 | + | |
237 | + return timeout; | |
238 | } | |
239 | ||
240 | ||
241 | @@ -473,7 +481,7 @@ addgrbyname (struct database_dyn *db, in | |
242 | } | |
243 | ||
244 | ||
245 | -void | |
246 | +time_t | |
247 | readdgrbyname (struct database_dyn *db, struct hashentry *he, | |
248 | struct datahead *dh) | |
249 | { | |
250 | @@ -484,7 +492,7 @@ readdgrbyname (struct database_dyn *db, | |
251 | }; | |
252 | union keytype u = { .v = db->data + he->key }; | |
253 | ||
254 | - addgrbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
255 | + return addgrbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
256 | } | |
257 | ||
258 | ||
259 | @@ -510,7 +518,7 @@ addgrbygid (struct database_dyn *db, int | |
260 | } | |
261 | ||
262 | ||
263 | -void | |
264 | +time_t | |
265 | readdgrbygid (struct database_dyn *db, struct hashentry *he, | |
266 | struct datahead *dh) | |
267 | { | |
268 | @@ -527,5 +535,5 @@ readdgrbygid (struct database_dyn *db, s | |
269 | }; | |
270 | union keytype u = { .g = gid }; | |
271 | ||
272 | - addgrbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
273 | + return addgrbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
274 | } | |
275 | Index: glibc-2.12-2-gc4ccff1/nscd/hstcache.c | |
276 | =================================================================== | |
277 | --- glibc-2.12-2-gc4ccff1.orig/nscd/hstcache.c | |
278 | +++ glibc-2.12-2-gc4ccff1/nscd/hstcache.c | |
279 | @@ -91,7 +91,7 @@ static const hst_response_header tryagai | |
280 | }; | |
281 | ||
282 | ||
283 | -static void | |
284 | +static time_t | |
285 | cache_addhst (struct database_dyn *db, int fd, request_header *req, | |
286 | const void *key, struct hostent *hst, uid_t owner, | |
287 | struct hashentry *const he, struct datahead *dh, int errval, | |
288 | @@ -111,6 +111,7 @@ cache_addhst (struct database_dyn *db, i | |
289 | ||
290 | assert (offsetof (struct dataset, resp) == offsetof (struct datahead, data)); | |
291 | ||
292 | + time_t timeout = MAX_TIMEOUT_VALUE; | |
293 | if (hst == NULL) | |
294 | { | |
295 | if (he != NULL && errval == EAGAIN) | |
296 | @@ -121,6 +122,9 @@ cache_addhst (struct database_dyn *db, i | |
297 | if (reload_count != UINT_MAX) | |
298 | /* Do not reset the value if we never not reload the record. */ | |
299 | dh->nreloads = reload_count - 1; | |
300 | + | |
301 | + /* Reload with the same time-to-live value. */ | |
302 | + timeout = dh->timeout = t + dh->ttl; | |
303 | } | |
304 | else | |
305 | { | |
306 | @@ -149,8 +153,8 @@ cache_addhst (struct database_dyn *db, i | |
307 | dataset->head.usable = true; | |
308 | ||
309 | /* Compute the timeout time. */ | |
310 | - dataset->head.timeout = t + (ttl == INT32_MAX | |
311 | - ? db->negtimeout : ttl); | |
312 | + dataset->head.ttl = ttl == INT32_MAX ? db->negtimeout : ttl; | |
313 | + timeout = dataset->head.timeout = t + dataset->head.ttl; | |
314 | ||
315 | /* This is the reply. */ | |
316 | memcpy (&dataset->resp, resp, total); | |
317 | @@ -214,7 +218,7 @@ cache_addhst (struct database_dyn *db, i | |
318 | ||
319 | if (h_addr_list_cnt == 0) | |
320 | /* Invalid entry. */ | |
321 | - return; | |
322 | + return MAX_TIMEOUT_VALUE; | |
323 | ||
324 | total += (sizeof (struct dataset) | |
325 | + h_name_len | |
326 | @@ -255,7 +259,8 @@ cache_addhst (struct database_dyn *db, i | |
327 | dataset->head.usable = true; | |
328 | ||
329 | /* Compute the timeout time. */ | |
330 | - dataset->head.timeout = t + (ttl == INT32_MAX ? db->postimeout : ttl); | |
331 | + dataset->head.ttl = ttl == INT32_MAX ? db->postimeout : ttl; | |
332 | + timeout = dataset->head.timeout = t + dataset->head.ttl; | |
333 | ||
334 | dataset->resp.version = NSCD_VERSION; | |
335 | dataset->resp.found = 1; | |
336 | @@ -312,6 +317,7 @@ cache_addhst (struct database_dyn *db, i | |
337 | timeout value. Note that the new record has been | |
338 | allocated on the stack and need not be freed. */ | |
339 | assert (h_addr_list_cnt == 1); | |
340 | + dh->ttl = dataset->head.ttl; | |
341 | dh->timeout = dataset->head.timeout; | |
342 | ++dh->nreloads; | |
343 | } | |
344 | @@ -433,6 +439,8 @@ cache_addhst (struct database_dyn *db, i | |
345 | dbg_log (_("short write in %s: %s"), __FUNCTION__, | |
346 | strerror_r (errno, buf, sizeof (buf))); | |
347 | } | |
348 | + | |
349 | + return timeout; | |
350 | } | |
351 | ||
352 | ||
353 | @@ -454,7 +462,7 @@ lookup (int type, void *key, struct host | |
354 | } | |
355 | ||
356 | ||
357 | -static void | |
358 | +static time_t | |
359 | addhstbyX (struct database_dyn *db, int fd, request_header *req, | |
360 | void *key, uid_t uid, struct hashentry *he, struct datahead *dh) | |
361 | { | |
362 | @@ -520,11 +528,13 @@ addhstbyX (struct database_dyn *db, int | |
363 | buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen); | |
364 | } | |
365 | ||
366 | - cache_addhst (db, fd, req, key, hst, uid, he, dh, | |
367 | - h_errno == TRY_AGAIN ? errval : 0, ttl); | |
368 | + time_t timeout = cache_addhst (db, fd, req, key, hst, uid, he, dh, | |
369 | + h_errno == TRY_AGAIN ? errval : 0, ttl); | |
370 | ||
371 | if (use_malloc) | |
372 | free (buffer); | |
373 | + | |
374 | + return timeout; | |
375 | } | |
376 | ||
377 | ||
378 | @@ -536,7 +546,7 @@ addhstbyname (struct database_dyn *db, i | |
379 | } | |
380 | ||
381 | ||
382 | -void | |
383 | +time_t | |
384 | readdhstbyname (struct database_dyn *db, struct hashentry *he, | |
385 | struct datahead *dh) | |
386 | { | |
387 | @@ -546,7 +556,7 @@ readdhstbyname (struct database_dyn *db, | |
388 | .key_len = he->len | |
389 | }; | |
390 | ||
391 | - addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
392 | + return addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
393 | } | |
394 | ||
395 | ||
396 | @@ -558,7 +568,7 @@ addhstbyaddr (struct database_dyn *db, i | |
397 | } | |
398 | ||
399 | ||
400 | -void | |
401 | +time_t | |
402 | readdhstbyaddr (struct database_dyn *db, struct hashentry *he, | |
403 | struct datahead *dh) | |
404 | { | |
405 | @@ -568,7 +578,7 @@ readdhstbyaddr (struct database_dyn *db, | |
406 | .key_len = he->len | |
407 | }; | |
408 | ||
409 | - addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
410 | + return addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
411 | } | |
412 | ||
413 | ||
414 | @@ -580,7 +590,7 @@ addhstbynamev6 (struct database_dyn *db, | |
415 | } | |
416 | ||
417 | ||
418 | -void | |
419 | +time_t | |
420 | readdhstbynamev6 (struct database_dyn *db, struct hashentry *he, | |
421 | struct datahead *dh) | |
422 | { | |
423 | @@ -590,7 +600,7 @@ readdhstbynamev6 (struct database_dyn *d | |
424 | .key_len = he->len | |
425 | }; | |
426 | ||
427 | - addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
428 | + return addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
429 | } | |
430 | ||
431 | ||
432 | @@ -602,7 +612,7 @@ addhstbyaddrv6 (struct database_dyn *db, | |
433 | } | |
434 | ||
435 | ||
436 | -void | |
437 | +time_t | |
438 | readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he, | |
439 | struct datahead *dh) | |
440 | { | |
441 | @@ -612,5 +622,5 @@ readdhstbyaddrv6 (struct database_dyn *d | |
442 | .key_len = he->len | |
443 | }; | |
444 | ||
445 | - addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
446 | + return addhstbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
447 | } | |
448 | Index: glibc-2.12-2-gc4ccff1/nscd/initgrcache.c | |
449 | =================================================================== | |
450 | --- glibc-2.12-2-gc4ccff1.orig/nscd/initgrcache.c | |
451 | +++ glibc-2.12-2-gc4ccff1/nscd/initgrcache.c | |
452 | @@ -52,7 +52,7 @@ static const initgr_response_header notf | |
453 | #include "../grp/compat-initgroups.c" | |
454 | ||
455 | ||
456 | -static void | |
457 | +static time_t | |
458 | addinitgroupsX (struct database_dyn *db, int fd, request_header *req, | |
459 | void *key, uid_t uid, struct hashentry *const he, | |
460 | struct datahead *dh) | |
461 | @@ -174,7 +174,9 @@ addinitgroupsX (struct database_dyn *db, | |
462 | ||
463 | ssize_t total; | |
464 | ssize_t written; | |
465 | + time_t timeout; | |
466 | out: | |
467 | + timeout = MAX_TIMEOUT_VALUE; | |
468 | if (!any_success) | |
469 | { | |
470 | /* Nothing found. Create a negative result record. */ | |
471 | @@ -188,6 +190,9 @@ addinitgroupsX (struct database_dyn *db, | |
472 | if (reload_count != UINT_MAX && dh->nreloads == reload_count) | |
473 | /* Do not reset the value if we never not reload the record. */ | |
474 | dh->nreloads = reload_count - 1; | |
475 | + | |
476 | + /* Reload with the same time-to-live value. */ | |
477 | + timeout = dh->timeout = time (NULL) + db->postimeout; | |
478 | } | |
479 | else | |
480 | { | |
481 | @@ -209,7 +214,7 @@ addinitgroupsX (struct database_dyn *db, | |
482 | dataset->head.usable = true; | |
483 | ||
484 | /* Compute the timeout time. */ | |
485 | - dataset->head.timeout = time (NULL) + db->negtimeout; | |
486 | + timeout = dataset->head.timeout = time (NULL) + db->negtimeout; | |
487 | ||
488 | /* This is the reply. */ | |
489 | memcpy (&dataset->resp, ¬found, total); | |
490 | @@ -273,7 +278,7 @@ addinitgroupsX (struct database_dyn *db, | |
491 | dataset->head.usable = true; | |
492 | ||
493 | /* Compute the timeout time. */ | |
494 | - dataset->head.timeout = time (NULL) + db->postimeout; | |
495 | + timeout = dataset->head.timeout = time (NULL) + db->postimeout; | |
496 | ||
497 | dataset->resp.version = NSCD_VERSION; | |
498 | dataset->resp.found = 1; | |
499 | @@ -401,6 +406,8 @@ addinitgroupsX (struct database_dyn *db, | |
500 | dbg_log (_("short write in %s: %s"), __FUNCTION__, | |
501 | strerror_r (errno, buf, sizeof (buf))); | |
502 | } | |
503 | + | |
504 | + return timeout; | |
505 | } | |
506 | ||
507 | ||
508 | @@ -412,7 +419,7 @@ addinitgroups (struct database_dyn *db, | |
509 | } | |
510 | ||
511 | ||
512 | -void | |
513 | +time_t | |
514 | readdinitgroups (struct database_dyn *db, struct hashentry *he, | |
515 | struct datahead *dh) | |
516 | { | |
517 | @@ -422,5 +429,5 @@ readdinitgroups (struct database_dyn *db | |
518 | .key_len = he->len | |
519 | }; | |
520 | ||
521 | - addinitgroupsX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
522 | + return addinitgroupsX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
523 | } | |
524 | Index: glibc-2.12-2-gc4ccff1/nscd/nscd-client.h | |
525 | =================================================================== | |
526 | --- glibc-2.12-2-gc4ccff1.orig/nscd/nscd-client.h | |
527 | +++ glibc-2.12-2-gc4ccff1/nscd/nscd-client.h | |
528 | @@ -179,6 +179,10 @@ typedef uint32_t ref_t; | |
529 | /* Timestamp type. */ | |
530 | typedef uint64_t nscd_time_t; | |
531 | ||
532 | +/* Maximum timestamp. */ | |
533 | +#define MAX_TIMEOUT_VALUE \ | |
534 | + (sizeof (time_t) == sizeof (long int) ? LONG_MAX : INT_MAX) | |
535 | + | |
536 | /* Alignment requirement of the beginning of the data region. */ | |
537 | #define ALIGN 16 | |
538 | ||
539 | @@ -192,7 +196,8 @@ struct datahead | |
540 | uint8_t notfound; /* Nonzero if data has not been found. */ | |
541 | uint8_t nreloads; /* Reloads without use. */ | |
542 | uint8_t usable; /* False if the entry must be ignored. */ | |
543 | - uint64_t :40; /* Alignment. */ | |
544 | + uint8_t unused; /* Unused. */ | |
545 | + uint32_t ttl; /* TTL value used. */ | |
546 | ||
547 | /* We need to have the following element aligned for the response | |
548 | header data types and their use in the 'struct dataset' types | |
549 | Index: glibc-2.12-2-gc4ccff1/nscd/nscd.h | |
550 | =================================================================== | |
551 | --- glibc-2.12-2-gc4ccff1.orig/nscd/nscd.h | |
552 | +++ glibc-2.12-2-gc4ccff1/nscd/nscd.h | |
553 | @@ -217,20 +217,20 @@ extern void addpwbyname (struct database | |
554 | void *key, uid_t uid); | |
555 | extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req, | |
556 | void *key, uid_t uid); | |
557 | -extern void readdpwbyname (struct database_dyn *db, struct hashentry *he, | |
558 | - struct datahead *dh); | |
559 | -extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he, | |
560 | - struct datahead *dh); | |
561 | +extern time_t readdpwbyname (struct database_dyn *db, struct hashentry *he, | |
562 | + struct datahead *dh); | |
563 | +extern time_t readdpwbyuid (struct database_dyn *db, struct hashentry *he, | |
564 | + struct datahead *dh); | |
565 | ||
566 | /* grpcache.c */ | |
567 | extern void addgrbyname (struct database_dyn *db, int fd, request_header *req, | |
568 | void *key, uid_t uid); | |
569 | extern void addgrbygid (struct database_dyn *db, int fd, request_header *req, | |
570 | void *key, uid_t uid); | |
571 | -extern void readdgrbyname (struct database_dyn *db, struct hashentry *he, | |
572 | - struct datahead *dh); | |
573 | -extern void readdgrbygid (struct database_dyn *db, struct hashentry *he, | |
574 | - struct datahead *dh); | |
575 | +extern time_t readdgrbyname (struct database_dyn *db, struct hashentry *he, | |
576 | + struct datahead *dh); | |
577 | +extern time_t readdgrbygid (struct database_dyn *db, struct hashentry *he, | |
578 | + struct datahead *dh); | |
579 | ||
580 | /* hstcache.c */ | |
581 | extern void addhstbyname (struct database_dyn *db, int fd, request_header *req, | |
582 | @@ -241,37 +241,37 @@ extern void addhstbynamev6 (struct datab | |
583 | request_header *req, void *key, uid_t uid); | |
584 | extern void addhstbyaddrv6 (struct database_dyn *db, int fd, | |
585 | request_header *req, void *key, uid_t uid); | |
586 | -extern void readdhstbyname (struct database_dyn *db, struct hashentry *he, | |
587 | - struct datahead *dh); | |
588 | -extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he, | |
589 | - struct datahead *dh); | |
590 | -extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he, | |
591 | +extern time_t readdhstbyname (struct database_dyn *db, struct hashentry *he, | |
592 | struct datahead *dh); | |
593 | -extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he, | |
594 | +extern time_t readdhstbyaddr (struct database_dyn *db, struct hashentry *he, | |
595 | struct datahead *dh); | |
596 | +extern time_t readdhstbynamev6 (struct database_dyn *db, struct hashentry *he, | |
597 | + struct datahead *dh); | |
598 | +extern time_t readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he, | |
599 | + struct datahead *dh); | |
600 | ||
601 | /* aicache.c */ | |
602 | extern void addhstai (struct database_dyn *db, int fd, request_header *req, | |
603 | void *key, uid_t uid); | |
604 | -extern void readdhstai (struct database_dyn *db, struct hashentry *he, | |
605 | - struct datahead *dh); | |
606 | +extern time_t readdhstai (struct database_dyn *db, struct hashentry *he, | |
607 | + struct datahead *dh); | |
608 | ||
609 | ||
610 | /* initgrcache.c */ | |
611 | extern void addinitgroups (struct database_dyn *db, int fd, | |
612 | request_header *req, void *key, uid_t uid); | |
613 | -extern void readdinitgroups (struct database_dyn *db, struct hashentry *he, | |
614 | - struct datahead *dh); | |
615 | +extern time_t readdinitgroups (struct database_dyn *db, struct hashentry *he, | |
616 | + struct datahead *dh); | |
617 | ||
618 | /* servicecache.c */ | |
619 | extern void addservbyname (struct database_dyn *db, int fd, | |
620 | request_header *req, void *key, uid_t uid); | |
621 | -extern void readdservbyname (struct database_dyn *db, struct hashentry *he, | |
622 | - struct datahead *dh); | |
623 | +extern time_t readdservbyname (struct database_dyn *db, struct hashentry *he, | |
624 | + struct datahead *dh); | |
625 | extern void addservbyport (struct database_dyn *db, int fd, | |
626 | request_header *req, void *key, uid_t uid); | |
627 | -extern void readdservbyport (struct database_dyn *db, struct hashentry *he, | |
628 | - struct datahead *dh); | |
629 | +extern time_t readdservbyport (struct database_dyn *db, struct hashentry *he, | |
630 | + struct datahead *dh); | |
631 | ||
632 | /* mem.c */ | |
633 | extern void *mempool_alloc (struct database_dyn *db, size_t len, | |
634 | Index: glibc-2.12-2-gc4ccff1/nscd/pwdcache.c | |
635 | =================================================================== | |
636 | --- glibc-2.12-2-gc4ccff1.orig/nscd/pwdcache.c | |
637 | +++ glibc-2.12-2-gc4ccff1/nscd/pwdcache.c | |
638 | @@ -77,7 +77,7 @@ static const pw_response_header notfound | |
639 | }; | |
640 | ||
641 | ||
642 | -static void | |
643 | +static time_t | |
644 | cache_addpw (struct database_dyn *db, int fd, request_header *req, | |
645 | const void *key, struct passwd *pwd, uid_t owner, | |
646 | struct hashentry *const he, struct datahead *dh, int errval) | |
647 | @@ -97,6 +97,7 @@ cache_addpw (struct database_dyn *db, in | |
648 | ||
649 | assert (offsetof (struct dataset, resp) == offsetof (struct datahead, data)); | |
650 | ||
651 | + time_t timeout = MAX_TIMEOUT_VALUE; | |
652 | if (pwd == NULL) | |
653 | { | |
654 | if (he != NULL && errval == EAGAIN) | |
655 | @@ -108,6 +109,9 @@ cache_addpw (struct database_dyn *db, in | |
656 | /* Do not reset the value if we never not reload the record. */ | |
657 | dh->nreloads = reload_count - 1; | |
658 | ||
659 | + /* Reload with the same time-to-live value. */ | |
660 | + timeout = dh->timeout = t + db->postimeout; | |
661 | + | |
662 | written = total = 0; | |
663 | } | |
664 | else | |
665 | @@ -132,7 +136,7 @@ cache_addpw (struct database_dyn *db, in | |
666 | dataset->head.usable = true; | |
667 | ||
668 | /* Compute the timeout time. */ | |
669 | - dataset->head.timeout = t + db->negtimeout; | |
670 | + timeout = dataset->head.timeout = t + db->negtimeout; | |
671 | ||
672 | /* This is the reply. */ | |
673 | memcpy (&dataset->resp, ¬found, total); | |
674 | @@ -212,7 +216,7 @@ cache_addpw (struct database_dyn *db, in | |
675 | dataset->head.usable = true; | |
676 | ||
677 | /* Compute the timeout time. */ | |
678 | - dataset->head.timeout = t + db->postimeout; | |
679 | + timeout = dataset->head.timeout = t + db->postimeout; | |
680 | ||
681 | dataset->resp.version = NSCD_VERSION; | |
682 | dataset->resp.found = 1; | |
683 | @@ -293,8 +297,8 @@ cache_addpw (struct database_dyn *db, in | |
684 | assert ((char *) dataset - (char *) db->head | |
685 | + total | |
686 | <= (sizeof (struct database_pers_head) | |
687 | - + db->head->module * sizeof (ref_t) | |
688 | - + db->head->data_size)); | |
689 | + + db->head->module * sizeof (ref_t) | |
690 | + + db->head->data_size)); | |
691 | written = sendfileall (fd, db->wr_fd, | |
692 | (char *) &dataset->resp | |
693 | - (char *) db->head, dataset->head.recsize ); | |
694 | @@ -374,6 +378,8 @@ cache_addpw (struct database_dyn *db, in | |
695 | dbg_log (_("short write in %s: %s"), __FUNCTION__, | |
696 | strerror_r (errno, buf, sizeof (buf))); | |
697 | } | |
698 | + | |
699 | + return timeout; | |
700 | } | |
701 | ||
702 | ||
703 | @@ -395,7 +401,7 @@ lookup (int type, union keytype key, str | |
704 | } | |
705 | ||
706 | ||
707 | -static void | |
708 | +static time_t | |
709 | addpwbyX (struct database_dyn *db, int fd, request_header *req, | |
710 | union keytype key, const char *keystr, uid_t c_uid, | |
711 | struct hashentry *he, struct datahead *dh) | |
712 | @@ -452,10 +458,13 @@ addpwbyX (struct database_dyn *db, int f | |
713 | } | |
714 | ||
715 | /* Add the entry to the cache. */ | |
716 | - cache_addpw (db, fd, req, keystr, pwd, c_uid, he, dh, errval); | |
717 | + time_t timeout = cache_addpw (db, fd, req, keystr, pwd, c_uid, he, dh, | |
718 | + errval); | |
719 | ||
720 | if (use_malloc) | |
721 | free (buffer); | |
722 | + | |
723 | + return timeout; | |
724 | } | |
725 | ||
726 | ||
727 | @@ -469,7 +478,7 @@ addpwbyname (struct database_dyn *db, in | |
728 | } | |
729 | ||
730 | ||
731 | -void | |
732 | +time_t | |
733 | readdpwbyname (struct database_dyn *db, struct hashentry *he, | |
734 | struct datahead *dh) | |
735 | { | |
736 | @@ -480,7 +489,7 @@ readdpwbyname (struct database_dyn *db, | |
737 | }; | |
738 | union keytype u = { .v = db->data + he->key }; | |
739 | ||
740 | - addpwbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
741 | + return addpwbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
742 | } | |
743 | ||
744 | ||
745 | @@ -506,7 +515,7 @@ addpwbyuid (struct database_dyn *db, int | |
746 | } | |
747 | ||
748 | ||
749 | -void | |
750 | +time_t | |
751 | readdpwbyuid (struct database_dyn *db, struct hashentry *he, | |
752 | struct datahead *dh) | |
753 | { | |
754 | @@ -523,5 +532,5 @@ readdpwbyuid (struct database_dyn *db, s | |
755 | }; | |
756 | union keytype u = { .u = uid }; | |
757 | ||
758 | - addpwbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
759 | + return addpwbyX (db, -1, &req, u, db->data + he->key, he->owner, he, dh); | |
760 | } | |
761 | Index: glibc-2.12-2-gc4ccff1/nscd/servicescache.c | |
762 | =================================================================== | |
763 | --- glibc-2.12-2-gc4ccff1.orig/nscd/servicescache.c | |
764 | +++ glibc-2.12-2-gc4ccff1/nscd/servicescache.c | |
765 | @@ -61,7 +61,7 @@ static const serv_response_header notfou | |
766 | }; | |
767 | ||
768 | ||
769 | -static void | |
770 | +static time_t | |
771 | cache_addserv (struct database_dyn *db, int fd, request_header *req, | |
772 | const void *key, struct servent *serv, uid_t owner, | |
773 | struct hashentry *const he, struct datahead *dh, int errval) | |
774 | @@ -81,6 +81,7 @@ cache_addserv (struct database_dyn *db, | |
775 | ||
776 | assert (offsetof (struct dataset, resp) == offsetof (struct datahead, data)); | |
777 | ||
778 | + time_t timeout = MAX_TIMEOUT_VALUE; | |
779 | if (serv == NULL) | |
780 | { | |
781 | if (he != NULL && errval == EAGAIN) | |
782 | @@ -92,6 +93,9 @@ cache_addserv (struct database_dyn *db, | |
783 | /* Do not reset the value if we never not reload the record. */ | |
784 | dh->nreloads = reload_count - 1; | |
785 | ||
786 | + /* Reload with the same time-to-live value. */ | |
787 | + timeout = dh->timeout = t + db->postimeout; | |
788 | + | |
789 | written = total = 0; | |
790 | } | |
791 | else | |
792 | @@ -115,7 +119,7 @@ cache_addserv (struct database_dyn *db, | |
793 | dataset->head.usable = true; | |
794 | ||
795 | /* Compute the timeout time. */ | |
796 | - dataset->head.timeout = t + db->negtimeout; | |
797 | + timeout = dataset->head.timeout = t + db->negtimeout; | |
798 | ||
799 | /* This is the reply. */ | |
800 | memcpy (&dataset->resp, ¬found, total); | |
801 | @@ -203,7 +207,7 @@ cache_addserv (struct database_dyn *db, | |
802 | dataset->head.usable = true; | |
803 | ||
804 | /* Compute the timeout time. */ | |
805 | - dataset->head.timeout = t + db->postimeout; | |
806 | + timeout = dataset->head.timeout = t + db->postimeout; | |
807 | ||
808 | dataset->resp.version = NSCD_VERSION; | |
809 | dataset->resp.found = 1; | |
810 | @@ -328,6 +332,8 @@ cache_addserv (struct database_dyn *db, | |
811 | dbg_log (_("short write in %s: %s"), __FUNCTION__, | |
812 | strerror_r (errno, buf, sizeof (buf))); | |
813 | } | |
814 | + | |
815 | + return timeout; | |
816 | } | |
817 | ||
818 | ||
819 | @@ -354,7 +360,7 @@ lookup (int type, char *key, struct serv | |
820 | } | |
821 | ||
822 | ||
823 | -static void | |
824 | +static time_t | |
825 | addservbyX (struct database_dyn *db, int fd, request_header *req, | |
826 | char *key, uid_t uid, struct hashentry *he, struct datahead *dh) | |
827 | { | |
828 | @@ -409,10 +415,12 @@ addservbyX (struct database_dyn *db, int | |
829 | buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen); | |
830 | } | |
831 | ||
832 | - cache_addserv (db, fd, req, key, serv, uid, he, dh, errval); | |
833 | + time_t timeout = cache_addserv (db, fd, req, key, serv, uid, he, dh, errval); | |
834 | ||
835 | if (use_malloc) | |
836 | free (buffer); | |
837 | + | |
838 | + return timeout; | |
839 | } | |
840 | ||
841 | ||
842 | @@ -424,7 +432,7 @@ addservbyname (struct database_dyn *db, | |
843 | } | |
844 | ||
845 | ||
846 | -void | |
847 | +time_t | |
848 | readdservbyname (struct database_dyn *db, struct hashentry *he, | |
849 | struct datahead *dh) | |
850 | { | |
851 | @@ -434,7 +442,7 @@ readdservbyname (struct database_dyn *db | |
852 | .key_len = he->len | |
853 | }; | |
854 | ||
855 | - addservbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
856 | + return addservbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
857 | } | |
858 | ||
859 | ||
860 | @@ -446,7 +454,7 @@ addservbyport (struct database_dyn *db, | |
861 | } | |
862 | ||
863 | ||
864 | -void | |
865 | +time_t | |
866 | readdservbyport (struct database_dyn *db, struct hashentry *he, | |
867 | struct datahead *dh) | |
868 | { | |
869 | @@ -456,5 +464,5 @@ readdservbyport (struct database_dyn *db | |
870 | .key_len = he->len | |
871 | }; | |
872 | ||
873 | - addservbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
874 | + return addservbyX (db, -1, &req, db->data + he->key, he->owner, he, dh); | |
875 | } |