+2005-08-23 Ulrich Drepper <drepper@redhat.com>
+
+ * nscd/nscd.c (main): Use error while process isn't running in the
+ background, not dbg_log.
+ * nscd/nscd_conf.c (nscd_parse_file): Likewise.
+ Mark messages with _(). Unify testing for database name.
+
+ * nscd/connection.c (DEFAULT_DATASIZE_PER_BUCKET): Move to nscd.h.
+ (dbs): Initialize max_db_size fields.
+ (nscd_init): When mapping the database, use max_db_size as the
+ mapping size even if it is bigger than the file size.
+ * nscd/mem.c (mempool_alloc): When resizing the file make sure the
+ limit in max_db_size is not exceeded. Don't use mremap, just
+ posix_fallocate is enough (according to Linus). Use posix_fallocate
+ correctly.
+ * nscd/nscd.conf: Add max-db-size parameters.
+ * nscd/nscd.h (struct database_dyn): Add max_db_size field.
+ Define DEFAULT_MAX_DB_SIZE and DEFAULT_DATASIZE_PER_BUCKET.
+ Temporarily define TEMP_FAILURE_RETRY_VAL here.
+ * nscd/nscd_conf.c (nscd_parse_file): Parse max-db-size parameter
+ and add sanity checks for it.
+
+ * nscd/aicache.c (addhstaiX): Use send with MSG_NOSIGNAL not write to
+ send reply.
+ * nscd/connection.c (writeall): Likewise.
+ (handle_request): Likewise.
+ * nscd/grpcache.c (cache_addgr): Likewise.
+ * nscd/hstcache.c (cache_addhst): Likewise.
+ * nscd/initgrcache.c (addinitgroupsX): Likewise.
+ * nscd/nscd.c (parse_opt): Likewise.
+ * nscd/nscd_stat.c (send_stats): Likewise.
+ (receive_print_stats): Likewise.
+ * nscd/pwdcache.c (cache_addpw): Likewise.
+
+ * sysdeps/unix/sysv/linux/Versions: Export inotify_* syscalls.
+
+2005-08-22 Jakub Jelinek <jakub@redhat.com>
+
+ * stdlib/bits/stdlib.h (mbstowcs): Divide __bos (__dst) by
+ sizeof (wchar_t) rather than multiplying __len by sizeof (wchar_t).
+ Pass __bos (__dst) / sizeof (wchar_t) to the *_chk routine.
+ * wcsmbs/bits/wchar2.h (mbsrtowcs, mbsnrtowcs): Likewise.
+ * debug/mbsnrtowcs_chk.c (__mbsnrtowcs_chk): Don't multiply
+ len by sizeof (wchar_t).
+ * debug/mbsrtowcs_chk.c (__mbsrtowcs_chk): Likewise.
+ * debug/mbstowcs_chk.c (__mbstowcs_chk): Likewise.
+ Fix type of SRC argument. Pass &SRC rather than SRC to
+ __mbsrtowcs.
+ * debug/wcstombs_chk.c (__wcstombs_chk): Pass &SRC rather than SRC
+ to __wcsrtombs.
+ * debug/tst-chk1.c: Include assert.h.
+ (do_test): Change enough array from VLA into a fixed size array.
+ Assert that MB_CUR_MAX is <= sizeof (enough). Use FAIL () macro
+ instead of print error details. Add several new tests.
+ Kill some unused variable warnings.
+
2005-08-21 Ulrich Drepper <drepper@redhat.com>
* resolv/res_send.c (Aerror): Fix printing IP address.
__mbsnrtowcs_chk (wchar_t *dst, __const char **src, size_t nmc, size_t len,
mbstate_t *ps, size_t dstlen)
{
- if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0))
+ if (__builtin_expect (dstlen < len, 0))
__chk_fail ();
return __mbsnrtowcs (dst, src, nmc, len, ps);
__mbsrtowcs_chk (wchar_t *dst, __const char **src, size_t len,
mbstate_t *ps, size_t dstlen)
{
- if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0))
+ if (__builtin_expect (dstlen < len, 0))
__chk_fail ();
return __mbsrtowcs (dst, src, len, ps);
size_t
-__mbstowcs_chk (wchar_t *dst, const char **src, size_t len, size_t dstlen)
+__mbstowcs_chk (wchar_t *dst, const char *src, size_t len, size_t dstlen)
{
- if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0))
+ if (__builtin_expect (dstlen < len, 0))
__chk_fail ();
mbstate_t state;
memset (&state, '\0', sizeof state);
/* Return how many we wrote (or maybe an error). */
- return __mbsrtowcs (dst, src, len, &state);
+ return __mbsrtowcs (dst, &src, len, &state);
}
/* Hack: make sure GCC doesn't know __chk_fail () will not return. */
#define __noreturn__
+#include <assert.h>
#include <fcntl.h>
#include <locale.h>
#include <paths.h>
#if PATH_MAX > 0
char largebuf[PATH_MAX];
char *realres = realpath (".", largebuf);
-#endif
-#if __USE_FORTIFY_LEVEL >= 1
+ if (realres != largebuf)
+ FAIL ();
+
+# if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
char realbuf[1];
realres = realpath (".", realbuf);
+ if (realres != realbuf)
+ FAIL ();
CHK_FAIL_END
+# endif
#endif
if (setlocale (LC_ALL, "de_DE.UTF-8") != NULL)
{
+ assert (MB_CUR_MAX <= 10);
+
/* First a simple test. */
- char enough[MB_CUR_MAX];
+ char enough[10];
if (wctomb (enough, L'A') != 1)
- {
- puts ("first wctomb test failed");
- ret = 1;
- }
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
/* We know the wchar_t encoding is ISO 10646. So pick a
CHK_FAIL_START
char smallbuf[2];
if (wctomb (smallbuf, L'\x100') != 2)
- {
- puts ("second wctomb test failed");
- ret = 1;
- }
+ FAIL ();
CHK_FAIL_END
#endif
mbstate_t s;
memset (&s, '\0', sizeof (s));
- if (wcrtomb (enough, L'A', &s) != 1)
- {
- puts ("first wcrtomb test failed");
- ret = 1;
- }
+ if (wcrtomb (enough, L'D', &s) != 1 || enough[0] != 'D')
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
/* We know the wchar_t encoding is ISO 10646. So pick a
CHK_FAIL_START
char smallbuf[2];
if (wcrtomb (smallbuf, L'\x100', &s) != 2)
- {
- puts ("second wcrtomb test failed");
- ret = 1;
- }
+ FAIL ();
CHK_FAIL_END
#endif
wchar_t wenough[10];
memset (&s, '\0', sizeof (s));
const char *cp = "A";
- if (mbsrtowcs (wenough, &cp, 10, &s) != 1)
- {
- puts ("first mbsrtowcs test failed");
- ret = 1;
- }
+ if (mbsrtowcs (wenough, &cp, 10, &s) != 1
+ || wcscmp (wenough, L"A") != 0)
+ FAIL ();
+
+ cp = "BC";
+ if (mbsrtowcs (wenough, &cp, l0 + 10, &s) != 2
+ || wcscmp (wenough, L"BC") != 0)
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
- /* We know the wchar_t encoding is ISO 10646. So pick a
- character which has a multibyte representation which does not
- fit. */
CHK_FAIL_START
wchar_t wsmallbuf[2];
cp = "ABC";
#endif
cp = "A";
- if (mbstowcs (wenough, cp, 10) != 1)
- {
- puts ("first mbstowcs test failed");
- ret = 1;
- }
+ if (mbstowcs (wenough, cp, 10) != 1
+ || wcscmp (wenough, L"A") != 0)
+ FAIL ();
+
+ cp = "DEF";
+ if (mbstowcs (wenough, cp, l0 + 10) != 3
+ || wcscmp (wenough, L"DEF") != 0)
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
- /* We know the wchar_t encoding is ISO 10646. So pick a
- character which has a multibyte representation which does not
- fit. */
CHK_FAIL_START
wchar_t wsmallbuf[2];
cp = "ABC";
#endif
memset (&s, '\0', sizeof (s));
- cp = "A";
- if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1)
- {
- puts ("first mbsnrtowcs test failed");
- ret = 1;
- }
+ cp = "ABC";
+ wcscpy (wenough, L"DEF");
+ if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1
+ || wcscmp (wenough, L"AEF") != 0)
+ FAIL ();
+
+ cp = "IJ";
+ if (mbsnrtowcs (wenough, &cp, 1, l0 + 10, &s) != 1
+ || wcscmp (wenough, L"IEF") != 0)
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
- /* We know the wchar_t encoding is ISO 10646. So pick a
- character which has a multibyte representation which does not
- fit. */
CHK_FAIL_START
wchar_t wsmallbuf[2];
cp = "ABC";
memset (&s, '\0', sizeof (s));
const wchar_t *wcp = L"A";
- if (wcsrtombs (enough, &wcp, 10, &s) != 1)
- {
- puts ("first wcsrtombs test failed");
- ret = 1;
- }
+ if (wcsrtombs (enough, &wcp, 10, &s) != 1
+ || strcmp (enough, "A") != 0)
+ FAIL ();
+
+ wcp = L"BC";
+ if (wcsrtombs (enough, &wcp, l0 + 10, &s) != 2
+ || strcmp (enough, "BC") != 0)
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
- /* We know the wchar_t encoding is ISO 10646. So pick a
- character which has a multibyte representation which does not
- fit. */
CHK_FAIL_START
char smallbuf[2];
wcp = L"ABC";
CHK_FAIL_END
#endif
- wcp = L"A";
- if (wcstombs (enough, wcp, 10) != 1)
- {
- puts ("first wcstombs test failed");
- ret = 1;
- }
+ memset (enough, 'Z', sizeof (enough));
+ wcp = L"EF";
+ if (wcstombs (enough, wcp, 10) != 2
+ || strcmp (enough, "EF") != 0)
+ FAIL ();
+
+ wcp = L"G";
+ if (wcstombs (enough, wcp, l0 + 10) != 1
+ || strcmp (enough, "G") != 0)
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
- /* We know the wchar_t encoding is ISO 10646. So pick a
- character which has a multibyte representation which does not
- fit. */
CHK_FAIL_START
char smallbuf[2];
wcp = L"ABC";
#endif
memset (&s, '\0', sizeof (s));
- wcp = L"A";
- if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1)
- {
- puts ("first wcsnrtombs test failed");
- ret = 1;
- }
+ wcp = L"AB";
+ if (wcsnrtombs (enough, &wcp, 1, 10, &s) != 1
+ || strcmp (enough, "A") != 0)
+ FAIL ();
+
+ wcp = L"BCD";
+ if (wcsnrtombs (enough, &wcp, 1, l0 + 10, &s) != 1
+ || strcmp (enough, "B") != 0)
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
- /* We know the wchar_t encoding is ISO 10646. So pick a
- character which has a multibyte representation which does not
- fit. */
CHK_FAIL_START
char smallbuf[2];
wcp = L"ABC";
{
char enough[1000];
if (ptsname_r (fd, enough, sizeof (enough)) != 0)
- {
- puts ("first ptsname_r failed");
- ret = 1;
- }
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
char smallbuf[2];
if (ptsname_r (fd, smallbuf, sizeof (smallbuf) + 1) == 0)
- {
- puts ("second ptsname_r somehow suceeded");
- ret = 1;
- }
+ FAIL ();
CHK_FAIL_END
#endif
close (fd);
}
+#if PATH_MAX > 0
confstr (_CS_GNU_LIBC_VERSION, largebuf, sizeof (largebuf));
-#if __USE_FORTIFY_LEVEL >= 1
+# if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
char smallbuf[1];
confstr (_CS_GNU_LIBC_VERSION, smallbuf, sizeof (largebuf));
CHK_FAIL_END
+# endif
#endif
gid_t grpslarge[5];
int ngr = getgroups (5, grpslarge);
+ asm volatile ("" : : "r" (ngr));
#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
char smallbuf[1];
ngr = getgroups (5, (gid_t *) smallbuf);
+ asm volatile ("" : : "r" (ngr));
CHK_FAIL_END
#endif
{
char enough[1000];
if (ttyname_r (fd, enough, sizeof (enough)) != 0)
- {
- puts ("first ttyname_r failed");
- ret = 1;
- }
+ FAIL ();
#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
char smallbuf[2];
if (ttyname_r (fd, smallbuf, sizeof (smallbuf) + 1) == 0)
- {
- puts ("second ttyname_r somehow suceeded");
- ret = 1;
- }
+ FAIL ();
CHK_FAIL_END
#endif
close (fd);
char domainnamelarge[1000];
int res = getdomainname (domainnamelarge, sizeof (domainnamelarge));
+ asm volatile ("" : : "r" (res));
#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
char smallbuf[1];
res = getdomainname (smallbuf, sizeof (domainnamelarge));
+ asm volatile ("" : : "r" (res));
CHK_FAIL_END
#endif
memset (&state, '\0', sizeof state);
/* Return how many we wrote (or maybe an error). */
- return __wcsrtombs (dst, src, len, &state);
+ return __wcsrtombs (dst, &src, len, &state);
}
glibc-base := HEAD
DIST_BRANCH := devel
COLLECTION := dist-fc4
-fedora-sync-date := 2005-08-22 07:27 UTC
-fedora-sync-tag := fedora-glibc-20050822T0727
+fedora-sync-date := 2005-08-24 07:05 UTC
+fedora-sync-tag := fedora-glibc-20050824T0705
+2005-08-23 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_routines.c (timer_helper_thread):
+ Use __sigfillset. Document that sigfillset does the right thing wrt
+ to SIGSETXID.
+
2005-08-08 Jakub Jelinek <jakub@redhat.com>
* tst-stackguard1.c (do_test): Likewise.
-/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
static void *
timer_helper_thread (void *arg)
{
- /* Wait for the SIGTIMER signal and none else. */
+ /* Wait for the SIGTIMER signal, allowing the setXid signal, and
+ none else. */
sigset_t ss;
sigemptyset (&ss);
- sigaddset (&ss, SIGTIMER);
+ __sigaddset (&ss, SIGTIMER);
/* Endless loop of waiting for signals. The loop is only ended when
the thread is canceled. */
(void) pthread_attr_init (&attr);
(void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
- /* Block all signals in the helper thread. To do this thoroughly we
- temporarily have to block all signals here. The helper can lose
- wakeups if SIGCANCEL is not blocked throughout, but sigfillset omits
- it. So, we add it back explicitly here. */
+ /* Block all signals in the helper thread but SIGSETXID. To do this
+ thoroughly we temporarily have to block all signals here. The
+ helper can lose wakeups if SIGCANCEL is not blocked throughout,
+ but sigfillset omits it SIGSETXID. So, we add SIGCANCEL back
+ explicitly here. */
sigset_t ss;
sigset_t oss;
sigfillset (&ss);
total = sizeof (notfound);
if (fd != -1)
- TEMP_FAILURE_RETRY (write (fd, ¬found, total));
+ TEMP_FAILURE_RETRY (send (fd, ¬found, total, MSG_NOSIGNAL));
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
/* If we cannot permanently store the result, so be it. */
#include "selinux.h"
-/* Number of bytes of data we initially reserve for each hash table bucket. */
-#define DEFAULT_DATASIZE_PER_BUCKET 1024
-
-
/* Wrapper functions with error checking for standard functions. */
extern void *xmalloc (size_t n);
extern void *xcalloc (size_t n, size_t s);
.check_file = 1,
.persistent = 0,
.shared = 0,
+ .max_db_size = DEFAULT_MAX_DB_SIZE,
.filename = "/etc/passwd",
.db_filename = _PATH_NSCD_PASSWD_DB,
.disabled_iov = &pwd_iov_disabled,
.check_file = 1,
.persistent = 0,
.shared = 0,
+ .max_db_size = DEFAULT_MAX_DB_SIZE,
.filename = "/etc/group",
.db_filename = _PATH_NSCD_GROUP_DB,
.disabled_iov = &grp_iov_disabled,
.check_file = 1,
.persistent = 0,
.shared = 0,
+ .max_db_size = DEFAULT_MAX_DB_SIZE,
.filename = "/etc/hosts",
.db_filename = _PATH_NSCD_HOSTS_DB,
.disabled_iov = &hst_iov_disabled,
ssize_t ret;
do
{
- ret = TEMP_FAILURE_RETRY (write (fd, buf, n));
+ ret = TEMP_FAILURE_RETRY (send (fd, buf, n, MSG_NOSIGNAL));
if (ret <= 0)
break;
buf = (const char *) buf + ret;
_("file size does not match"));
unlink (dbs[cnt].db_filename);
}
- else if ((mem = mmap (NULL, total, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, 0)) == MAP_FAILED)
+ /* Note we map with the maximum size allowed for the
+ database. This is likely much larger than the
+ actual file size. This is OK on most OSes since
+ extensions of the underlying file will
+ automatically translate more pages available for
+ memory access. */
+ else if ((mem = mmap (NULL, dbs[cnt].max_db_size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0))
+ == MAP_FAILED)
goto fail_db;
else if (!verify_persistent_db (mem, &head, cnt))
{
if ((TEMP_FAILURE_RETRY (write (fd, &head, sizeof (head)))
!= sizeof (head))
- || posix_fallocate (fd, 0, total) != 0
- || (mem = mmap (NULL, total, PROT_READ | PROT_WRITE,
+ || (TEMP_FAILURE_RETRY_VAL (posix_fallocate (fd, 0, total))
+ != 0)
+ || (mem = mmap (NULL, dbs[cnt].max_db_size,
+ PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0)) == MAP_FAILED)
{
write_fail:
if (!db->enabled)
{
/* No, sent the prepared record. */
- if (TEMP_FAILURE_RETRY (write (fd, db->disabled_iov->iov_base,
- db->disabled_iov->iov_len))
+ if (TEMP_FAILURE_RETRY (send (fd, db->disabled_iov->iov_base,
+ db->disabled_iov->iov_len,
+ MSG_NOSIGNAL))
!= (ssize_t) db->disabled_iov->iov_len
&& __builtin_expect (debug_level, 0) > 0)
{
case. */
total = sizeof (notfound);
- written = TEMP_FAILURE_RETRY (write (fd, ¬found, total));
+ written = TEMP_FAILURE_RETRY (send (fd, ¬found, total,
+ MSG_NOSIGNAL));
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
/* If we cannot permanently store the result, so be it. */
written = total = sizeof (notfound);
if (fd != -1)
- written = TEMP_FAILURE_RETRY (write (fd, ¬found, total));
+ written = TEMP_FAILURE_RETRY (send (fd, ¬found, total,
+ MSG_NOSIGNAL));
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
/* If we cannot permanently store the result, so be it. */
/* We have no data. This means we send the standard reply for this
case. */
if (fd != -1)
- written = TEMP_FAILURE_RETRY (write (fd, ¬found, total));
+ written = TEMP_FAILURE_RETRY (send (fd, ¬found, total,
+ MSG_NOSIGNAL));
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
/* If we cannot permanently store the result, so be it. */
if (! tried_resize)
{
/* Try to resize the database. Grow size of 1/8th. */
- size_t new_data_size = db->head->data_size + db->head->data_size / 8;
size_t oldtotal = (sizeof (struct database_pers_head)
+ db->head->module * sizeof (ref_t)
+ db->head->data_size);
+ size_t new_data_size = (db->head->data_size
+ + MAX (2 * len, db->head->data_size / 8));
size_t newtotal = (sizeof (struct database_pers_head)
+ db->head->module * sizeof (ref_t)
+ new_data_size);
+ if (newtotal > db->max_db_size)
+ {
+ new_data_size -= newtotal - db->max_db_size;
+ newtotal = db->max_db_size;
+ }
- if ((!db->mmap_used
- || posix_fallocate (db->wr_fd, oldtotal, newtotal) != 0)
- /* Try to resize the mapping. Note: no MREMAP_MAYMOVE. */
- && mremap (db->head, oldtotal, newtotal, 0) == 0)
+ if (db->mmap_used && newtotal > oldtotal
+ /* We only have to adjust the file size. The new pages
+ become magically available. */
+ && TEMP_FAILURE_RETRY_VAL (posix_fallocate (db->wr_fd, oldtotal,
+ newtotal
+ - oldtotal)) == 0)
{
db->head->data_size = new_data_size;
tried_resize = true;
/* Read the configuration file. */
if (nscd_parse_file (conffile, dbs) != 0)
- {
- /* We couldn't read the configuration file. We don't start the
- server. */
- dbg_log (_("cannot read configuration file; this is fatal"));
- exit (1);
- }
+ /* We couldn't read the configuration file. We don't start the
+ server. */
+ error (EXIT_FAILURE, 0,
+ _("failure while reading configuration file; this is fatal"));
/* Do we only get statistics? */
if (get_stats)
req.version = NSCD_VERSION;
req.type = SHUTDOWN;
req.key_len = 0;
- nbytes = TEMP_FAILURE_RETRY (write (sock, &req,
- sizeof (request_header)));
+ nbytes = TEMP_FAILURE_RETRY (send (sock, &req,
+ sizeof (request_header),
+ MSG_NOSIGNAL));
close (sock);
exit (nbytes != sizeof (request_header) ? EXIT_FAILURE : EXIT_SUCCESS);
}
# check-files <service> <yes|no>
# persistent <service> <yes|no>
# shared <service> <yes|no>
+# max-db-szie <service> <number bytes>
#
# Currently supported cache names (services): passwd, group, hosts
#
check-files passwd yes
persistent passwd yes
shared passwd yes
+ max-db-size passwd 33554432
enable-cache group yes
positive-time-to-live group 3600
check-files group yes
persistent group yes
shared group yes
+ max-db-size group 33554432
enable-cache hosts yes
positive-time-to-live hosts 3600
check-files hosts yes
persistent hosts yes
shared hosts yes
+ max-db-size hosts 33554432
int check_file;
int persistent;
int shared;
+ size_t max_db_size;
const char *filename;
const char *db_filename;
time_t file_mtime;
#define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
#define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
+/* Default value for the maximum size of the database files. */
+#define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
+
+/* Number of bytes of data we initially reserve for each hash table bucket. */
+#define DEFAULT_DATASIZE_PER_BUCKET 1024
+
/* Global variables. */
extern struct database_dyn dbs[lastdb];
/* nscd_setup_thread.c */
extern void setup_thread (struct database_dyn *db);
+
+/* Special version of TEMP_FAILURE_RETRY for functions returning error
+ values. */
+#define TEMP_FAILURE_RETRY_VAL(expression) \
+ (__extension__ \
+ ({ long int __result; \
+ do __result = (long int) (expression); \
+ while (__result == EINTR); \
+ __result; }))
+
#endif /* nscd.h */
-/* Copyright (c) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
#include <ctype.h>
#include <errno.h>
+#include <error.h>
#include <libintl.h>
#include <malloc.h>
#include <pwd.h>
[hstdb] = "hosts"
};
+
+static int
+find_db (const char *name)
+{
+ for (int cnt = 0; cnt < lastdb; ++cnt)
+ if (strcmp (name, dbnames[cnt]) == 0)
+ return cnt;
+
+ error (0, 0, _("database %s is not supported\n"), name);
+ return -1;
+}
+
int
nscd_parse_file (const char *fname, struct database_dyn dbs[lastdb])
{
char *line, *cp, *entry, *arg1, *arg2;
size_t len;
int cnt;
+ const unsigned int initial_error_message_count = error_message_count;
/* Open the configuration file. */
fp = fopen (fname, "r");
++arg1;
*cp = '\0';
if (strlen (entry) == 0)
- dbg_log (_("Parse error: %s"), line);
+ error (0, 0, _("Parse error: %s"), line);
while (isspace (*arg1) && *arg1 != '\0')
++arg1;
cp = arg1;
if (strcmp (entry, "positive-time-to-live") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- dbs[cnt].postimeout = atol (arg2);
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ dbs[idx].postimeout = atol (arg2);
}
else if (strcmp (entry, "negative-time-to-live") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- dbs[cnt].negtimeout = atol (arg2);
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ dbs[idx].negtimeout = atol (arg2);
}
else if (strcmp (entry, "suggested-size") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- dbs[cnt].suggested_module = atol (arg2);
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ dbs[idx].suggested_module = atol (arg2);
}
else if (strcmp (entry, "enable-cache") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- if (strcmp (arg2, "no") == 0)
- dbs[cnt].enabled = 0;
- else if (strcmp (arg2, "yes") == 0)
- dbs[cnt].enabled = 1;
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ {
+ if (strcmp (arg2, "no") == 0)
+ dbs[idx].enabled = 0;
+ else if (strcmp (arg2, "yes") == 0)
+ dbs[idx].enabled = 1;
+ }
}
else if (strcmp (entry, "check-files") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- if (strcmp (arg2, "no") == 0)
- dbs[cnt].check_file = 0;
- else if (strcmp (arg2, "yes") == 0)
- dbs[cnt].check_file = 1;
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ {
+ if (strcmp (arg2, "no") == 0)
+ dbs[idx].check_file = 0;
+ else if (strcmp (arg2, "yes") == 0)
+ dbs[idx].check_file = 1;
+ }
+ }
+ else if (strcmp (entry, "max-db-size") == 0)
+ {
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ dbs[idx].max_db_size = atol (arg2);
}
else if (strcmp (entry, "logfile") == 0)
set_logfile (arg1);
else if (strcmp (entry, "server-user") == 0)
{
if (!arg1)
- dbg_log (_("Must specify user name for server-user option"));
+ error (0, 0, _("Must specify user name for server-user option"));
else
server_user = xstrdup (arg1);
}
else if (strcmp (entry, "stat-user") == 0)
{
if (arg1 == NULL)
- dbg_log (_("Must specify user name for stat-user option"));
+ error (0, 0, _("Must specify user name for stat-user option"));
else
{
stat_user = xstrdup (arg1);
}
else if (strcmp (entry, "persistent") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- if (strcmp (arg2, "no") == 0)
- dbs[cnt].persistent = 0;
- else if (strcmp (arg2, "yes") == 0)
- dbs[cnt].persistent = 1;
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ {
+ if (strcmp (arg2, "no") == 0)
+ dbs[idx].persistent = 0;
+ else if (strcmp (arg2, "yes") == 0)
+ dbs[idx].persistent = 1;
+ }
}
else if (strcmp (entry, "shared") == 0)
{
- for (cnt = 0; cnt < lastdb; ++cnt)
- if (strcmp (arg1, dbnames[cnt]) == 0)
- {
- if (strcmp (arg2, "no") == 0)
- dbs[cnt].shared = 0;
- else if (strcmp (arg2, "yes") == 0)
- dbs[cnt].shared = 1;
- break;
- }
- if (cnt == lastdb)
- dbg_log ("database %s is not supported\n", arg1);
+ int idx = find_db (arg1);
+ if (idx >= 0)
+ {
+ if (strcmp (arg2, "no") == 0)
+ dbs[idx].shared = 0;
+ else if (strcmp (arg2, "yes") == 0)
+ dbs[idx].shared = 1;
+ }
}
else if (strcmp (entry, "reload-count") == 0)
{
else if (count >= 0)
reload_count = count;
else
- dbg_log (_("invalid value for 'reload-count': %u"), count);
+ error (0, 0, _("invalid value for 'reload-count': %u"), count);
}
}
else if (strcmp (entry, "paranoia") == 0)
if (arg1 != NULL)
restart_interval = atol (arg1);
else
- dbg_log (_("Must specify value for restart-interval option"));
+ error (0, 0, _("Must specify value for restart-interval option"));
}
else
- dbg_log (_("Unknown option: %s %s %s"), entry, arg1, arg2);
+ error (0, 0, _("Unknown option: %s %s %s"), entry, arg1, arg2);
}
while (!feof_unlocked (fp));
oldcwd = get_current_dir_name ();
if (oldcwd == NULL)
{
- dbg_log (_("\
+ error (0, 0, _("\
cannot get current working directory: %s; disabling paranoia mode"),
strerror (errno));
paranoia = 0;
if (max_nthreads < nthreads)
max_nthreads = nthreads;
+ for (cnt = 0; cnt < lastdb; ++cnt)
+ {
+ size_t datasize = (sizeof (struct database_pers_head)
+ + roundup (dbs[cnt].suggested_module
+ * sizeof (ref_t), ALIGN)
+ + (dbs[cnt].suggested_module
+ * DEFAULT_DATASIZE_PER_BUCKET));
+ if (datasize > dbs[cnt].max_db_size)
+ {
+ error (0, 0, _("maximum file size for %s database too small"),
+ dbnames[cnt]);
+ dbs[cnt].max_db_size = datasize;
+ }
+
+ }
+
/* Free the buffer. */
free (line);
/* Close configuration file. */
fclose (fp);
- return 0;
+ return error_message_count != initial_error_message_count;
}
if (selinux_enabled)
nscd_avc_cache_stats (&data.cstats);
- if (TEMP_FAILURE_RETRY (write (fd, &data, sizeof (data))) != sizeof (data))
+ if (TEMP_FAILURE_RETRY (send (fd, &data, sizeof (data), MSG_NOSIGNAL))
+ != sizeof (data))
{
char buf[256];
dbg_log (_("cannot write statistics: %s"),
req.version = NSCD_VERSION;
req.type = GETSTAT;
req.key_len = 0;
- nbytes = TEMP_FAILURE_RETRY (write (fd, &req, sizeof (request_header)));
+ nbytes = TEMP_FAILURE_RETRY (send (fd, &req, sizeof (request_header),
+ MSG_NOSIGNAL));
if (nbytes != sizeof (request_header))
{
int err = errno;
written = total = sizeof (notfound);
if (fd != -1)
- written = TEMP_FAILURE_RETRY (write (fd, ¬found, total));
+ written = TEMP_FAILURE_RETRY (send (fd, ¬found, total,
+ MSG_NOSIGNAL));
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
/* If we cannot permanently store the result, so be it. */
{
if (__bos (__dst) != (size_t) -1
&& (!__builtin_constant_p (__len)
- || __len * sizeof (wchar_t) > __bos (__dst)))
- return __mbstowcs_chk (__dst, __src, __len, __bos (__dst));
+ || __len > __bos (__dst) / sizeof (wchar_t)))
+ return __mbstowcs_chk (__dst, __src, __len,
+ __bos (__dst) / sizeof (wchar_t));
return __mbstowcs_alias (__dst, __src, __len);
}
GLIBC_2.3.4 {
sched_getaffinity; sched_setaffinity;
}
+ GLIBC_2.4 {
+ inotify_init; inotify_add_watch; inotify_rm_watch;
+ }
GLIBC_PRIVATE {
# functions used in other libraries
__syscall_rt_sigqueueinfo;
{
if (__bos (__dst) != (size_t) -1
&& (!__builtin_constant_p (__len)
- || __len * sizeof (wchar_t) > __bos (__dst)))
- return __mbsrtowcs_chk (__dst, __src, __len, __ps, __bos (__dst));
+ || __len > __bos (__dst) / sizeof (wchar_t)))
+ return __mbsrtowcs_chk (__dst, __src, __len, __ps,
+ __bos (__dst) / sizeof (wchar_t));
return __mbsrtowcs_alias (__dst, __src, __len, __ps);
}
{
if (__bos (__dst) != (size_t) -1
&& (!__builtin_constant_p (__len)
- || __len * sizeof (wchar_t) > __bos (__dst)))
- return __mbsnrtowcs_chk (__dst, __src, __nmc, __len, __ps, __bos (__dst));
+ || __len > __bos (__dst) / sizeof (wchar_t)))
+ return __mbsnrtowcs_chk (__dst, __src, __nmc, __len, __ps,
+ __bos (__dst) / sizeof (wchar_t));
return __mbsnrtowcs_alias (__dst, __src, __nmc, __len, __ps);
}