diff --git a/libexec/ld.elf_so/paths.c b/libexec/ld.elf_so/paths.c index f2a474f0d9b4..4074d19b064c 100644 --- a/libexec/ld.elf_so/paths.c +++ b/libexec/ld.elf_so/paths.c @@ -1,4 +1,4 @@ -/* $NetBSD: paths.c,v 1.37 2007/10/05 22:21:07 ad Exp $ */ +/* $NetBSD: paths.c,v 1.38 2008/06/03 18:36:59 ad Exp $ */ /* * Copyright 1996 Matt Thomas @@ -30,7 +30,7 @@ #include #ifndef lint -__RCSID("$NetBSD: paths.c,v 1.37 2007/10/05 22:21:07 ad Exp $"); +__RCSID("$NetBSD: paths.c,v 1.38 2008/06/03 18:36:59 ad Exp $"); #endif /* not lint */ #include @@ -337,10 +337,11 @@ _rtld_process_hints(const char *execname, Search_Path **path_p, Library_Xform **lib_p, const char *fname) { int fd; - char *buf; + char *buf, small[128]; const char *b, *ep, *ptr; struct stat st; size_t sz; + ssize_t rsz; Search_Path **head_p = path_p; if ((fd = open(fname, O_RDONLY)) == -1) { @@ -356,12 +357,23 @@ _rtld_process_hints(const char *execname, Search_Path **path_p, sz = (size_t) st.st_size; - buf = mmap(0, sz, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0); - if (buf == MAP_FAILED) { - xwarn("mmap: %s", fname); + /* Try to avoid mmap/stat on the file. */ + buf = small; + buf[0] = '\0'; + rsz = read(fd, buf, sz); + if (rsz == -1) { + xwarn("read: %s", fname); (void)close(fd); return; } + if (rsz >= sizeof(small)) { + buf = mmap(0, sz, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0); + if (buf == MAP_FAILED) { + xwarn("mmap: %s", fname); + (void)close(fd); + return; + } + } (void)close(fd); while ((*path_p) != NULL) @@ -392,7 +404,8 @@ _rtld_process_hints(const char *execname, Search_Path **path_p, (void)getstr(&b, ep, "\n"); } - (void)munmap(buf, sz); + if (buf != small) + (void)munmap(buf, sz); } /* Basic name -> sysctl MIB translation */