/* This file is part of unscd, a complete nscd replacement.
- * Copyright (C) 2007 Denys Vlasenko. Licensed under the GPL version 2. */
+ * Copyright (C) 2007-2012 Denys Vlasenko. Licensed under the GPL version 2.
+ */
/* unscd is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* thanks to Sebastian Krahmer (krahmer AT suse.de)
* 0.46 fix a case when we forgot to remove a future entry on worker failure
* 0.47 fix nscd without -d to not bump debug level
+ * 0.48 fix for changes in __nss_disable_nscd API in glibc-2.15
+ * 0.49 minor tweaks to messages
*/
-#define PROGRAM_VERSION "0.47"
+#define PROGRAM_VERSION "0.49"
#define DEBUG_BUILD 1
#if DEBUG_BUILD
log(L_DEBUG, "version:%d type:%d(%s) key_len:%d '%s'",
ureq->version, ureq->type,
- ureq->type < ARRAY_SIZE(typestr) ? typestr[ureq->type] : "BAD",
+ ureq->type < ARRAY_SIZE(typestr) ? typestr[ureq->type] : "?",
ureq->key_len, req_str(ureq->type, ureq->reqbuf));
#endif
return 0; /* more to read */
}
if (cinfo[i].bytecnt > USER_HDR_SIZE + ureq->key_len) {
- log(L_INFO, "read overflow");
+ log(L_INFO, "read overflow: %u > %u",
+ (int)cinfo[i].bytecnt, (int)(USER_HDR_SIZE + ureq->key_len));
close_client(i);
return 0;
}
}
resp_sz = sz_and_found.version_or_size;
- if (resp_sz < sz || resp_sz > 0xfffffff) { /* 256 mb */
+ if (resp_sz < sz || resp_sz > 0x0fffffff) { /* 256 mb */
error("BUG: bad size from worker:%u", resp_sz);
goto err;
}
/* Create new block of cached info */
cached = xzalloc(ureq_sz_aligned + resp_sz);
- log(L_DEBUG2, "xzalloc(%u):%p", ureq_sz_aligned + resp_sz, cached);
+ log(L_DEBUG2, "xzalloc(%u):%p sz:%u resp_sz:%u found:%u",
+ ureq_sz_aligned + resp_sz, cached,
+ sz, resp_sz,
+ (int)sz_and_found.found
+ );
resp = (void*) (((char*) cached) + ureq_sz_aligned);
memcpy(cached, ureq, ureq_size(ureq));
memcpy(resp, &sz_and_found, sz);
resp = ureq_response(cinfo[i].resptr);
resp_sz = resp->version_or_size;
resp->version_or_size = NSCD_VERSION;
+ errno = 0;
r = safe_write(pfd[i].fd, ((char*) resp) + cinfo[i].respos, resp_sz - cinfo[i].respos);
resp->version_or_size = resp_sz;
if (r < 0 && errno == EAGAIN)
continue;
if (r <= 0) { /* client isn't there anymore */
- log(L_DEBUG, "client %d is gone (write returned %d)", i, r);
+ log(L_DEBUG, "client %d is gone (write returned:%d err:%s)",
+ i, r, errno ? strerror(errno) : "-");
write_out_is_done:
if (cinfo[i].cache_pp == NULL) {
log(L_DEBUG, "client %d: freeing fake cache entry %p", i, cinfo[i].resptr);
};
static const char *const help[] = {
- "Do not daemonize; log to stderr",
+ "Do not daemonize; log to stderr (-dd: more verbosity)",
"File to read configuration from",
"Invalidate cache",
"Shut the server down",
/* not static - don't inline me, compiler! */
+void readlink_self_exe(void);
void readlink_self_exe(void)
{
char buf[PATH_MAX + 1];
}
+/* Callback for glibc-2.15 */
+struct traced_file;
+static void do_nothing(size_t dbidx, struct traced_file *finfo)
+{
+ /* nscd from glibc-2.15 does something like this:
+ if (!dbs[dbidx].enabled || !dbs[dbidx].check_file)
+ return;
+ add_file_to_watch_list(finfo->fname);
+ */
+}
+
/* This internal glibc function is called to disable trying to contact nscd.
- * We _are_ nscd, so we need to do the lookups, and not recurse. */
-void __nss_disable_nscd(void);
+ * We _are_ nscd, so we need to do the lookups, and not recurse.
+ * Until 2.14, this function was taking no parameters.
+ * In 2.15, it takes a function pointer from hell.
+ */
+void __nss_disable_nscd(void (*hell)(size_t, struct traced_file*));
+
int main(int argc, char **argv)
{
const char *conffile;
/* make sure we don't get recursive calls */
- __nss_disable_nscd();
+ __nss_disable_nscd(do_nothing);
if (argv[0][0] == 'w') /* "worker_nscd" */
worker(argv[1]);
signal(SIGTSTP, SIG_IGN);
}
- log(L_ALL, "nscd v" PROGRAM_VERSION ", debug level 0x%x", debug & L_ALL);
+ log(L_ALL, "unscd v" PROGRAM_VERSION ", debug level 0x%x", debug & L_ALL);
log(L_DEBUG, "max %u requests in parallel", max_reqnum - 2);
log(L_DEBUG, "cache size %u x 8 entries", cache_size);