From owner-p4-projects@FreeBSD.ORG Wed Feb 3 10:12:24 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6B3E31065672; Wed, 3 Feb 2010 10:12:24 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2EAAE106566B for ; Wed, 3 Feb 2010 10:12:24 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 1A34C8FC08 for ; Wed, 3 Feb 2010 10:12:24 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o13ACNtT030536 for ; Wed, 3 Feb 2010 10:12:23 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o13ACNb3030534 for perforce@freebsd.org; Wed, 3 Feb 2010 10:12:23 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 3 Feb 2010 10:12:23 GMT Message-Id: <201002031012.o13ACNb3030534@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 174213 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2010 10:12:24 -0000 http://p4web.freebsd.org/chv.cgi?CH=174213 Change 174213 by rwatson@rwatson_vimage_client on 2010/02/03 10:11:53 Improve style alignment of capability-related code with existing rtld style (which isn't style(9)). Affected files ... .. //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#36 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/libexec/rtld-elf/rtld.c#36 (text+ko) ==== @@ -251,7 +251,6 @@ (func_ptr_type) &ld_insandbox, #endif (func_ptr_type) &ld_libdirs, - NULL }; @@ -833,19 +832,19 @@ static void * find_capstart(const Obj_Entry *obj) { - const char *capstart_str = "_capstart"; - const Elf_Sym *def; - const Obj_Entry *defobj; - unsigned long hash; + const char *capstart_str = "_capstart"; + const Elf_Sym *def; + const Obj_Entry *defobj; + unsigned long hash; - hash = elf_hash(capstart_str); - def = symlook_default(capstart_str, hash, obj, &defobj, NULL, - SYMLOOK_IN_PLT); - if (def == NULL) - return (NULL); - if (ELF_ST_TYPE(def->st_info) != STT_FUNC) - return (NULL); - return (make_function_pointer(def, defobj)); + hash = elf_hash(capstart_str); + def = symlook_default(capstart_str, hash, obj, &defobj, NULL, + SYMLOOK_IN_PLT); + if (def == NULL) + return (NULL); + if (ELF_ST_TYPE(def->st_info) != STT_FUNC) + return (NULL); + return (make_function_pointer(def, defobj)); } #endif @@ -1233,23 +1232,24 @@ #ifdef IN_RTLD_CAP /* - * Find the library with the given name, and return an open file descriptor to it. + * Find the library with the given name, and return an open file descriptor + * to it. */ static int -find_library_fd(const char *name) { +find_library_fd(const char *name) +{ + int fd, i; if (ld_library_dirs == NULL) - init_libdirs(); - - for (int i = 0; (i < ld_library_dirlen) && (ld_library_dirs[i] != -1); i++) { - - int fd = openat(ld_library_dirs[i], name, O_RDONLY); + init_libdirs(); + for (i = 0; (i < ld_library_dirlen) && (ld_library_dirs[i] != -1); i++) { + fd = openat(ld_library_dirs[i], name, O_RDONLY); if (fd >= 0) - return fd; + return (fd); } - return (-1); } + #else /* * Find the library with the given name, and return its full pathname. @@ -1663,24 +1663,22 @@ _rtld_error("Unable to find \"%s\" in LD_LIBRARY_DIRS", path); } #else - if (fd == -1) { - path = find_library(name, refobj); - if (path == NULL) + path = find_library(name, refobj); + if (path == NULL) return NULL; - /* - * If we didn't find a match by pathname, open the file and check - * again by device and inode. This avoids false mismatches caused - * by multiple links or ".." in pathnames. - * - * To avoid a race, we open the file and use fstat() rather than - * using stat(). - */ - if ((fd = open(path, O_RDONLY)) == -1) { + /* + * If we didn't find a match by pathname, open the file and check + * again by device and inode. This avoids false mismatches caused + * by multiple links or ".." in pathnames. + * + * To avoid a race, we open the file and use fstat() rather than + * using stat(). + */ + if ((fd = open(path, O_RDONLY)) == -1) { _rtld_error("Cannot open \"%s\"", path); free(path); return NULL; - } } #endif if (fstat(fd, &sb) == -1) { @@ -2113,40 +2111,42 @@ * Add a file descriptor to ld_library_dirs. */ static void -add_libdir_fd(int fd) { +add_libdir_fd(int fd) +{ + int i; - if (ld_library_dirs == NULL) { - /* Initialize the FD list. */ + if (ld_library_dirs == NULL) { + /* Initialize the FD list. */ + ld_library_dirlen = INITIAL_FDLEN; + ld_library_dirs = xmalloc(ld_library_dirlen * sizeof(int)); + memset(ld_library_dirs, 0xff, ld_library_dirlen * sizeof(int)); + } - ld_library_dirlen = INITIAL_FDLEN; - ld_library_dirs = xmalloc(ld_library_dirlen * sizeof(int)); - memset(ld_library_dirs, 0xff, ld_library_dirlen * sizeof(int)); - } + /* Find the next available FD slot. */ + for (i = 0; (i < ld_library_dirlen) && (ld_library_dirs[i] != -1); i++) + ; - /* Find the next available FD slot. */ - int i; - for (i = 0; (i < ld_library_dirlen) && (ld_library_dirs[i] != -1); i++) ; + if (i == ld_library_dirlen) { + /* We need more space. */ + int old_size = ld_library_dirlen + sizeof(int); - if (i == ld_library_dirlen) { - /* We need more space. */ - int old_size = ld_library_dirlen + sizeof(int); + ld_library_dirlen *= 2; + ld_library_dirs = realloc(ld_library_dirs, 2 * old_size); + memset(ld_library_dirs + old_size, 0xff, old_size); - ld_library_dirlen *= 2; - ld_library_dirs = realloc(ld_library_dirs, 2 * old_size); - memset(ld_library_dirs + old_size, 0xff, old_size); - - if (ld_library_dirs == NULL) - err(-1, "realloc() failed"); - } - - ld_library_dirs[i] = fd; + if (ld_library_dirs == NULL) + err(-1, "realloc() failed"); + } + ld_library_dirs[i] = fd; } /* - * Add file descriptors for a path list (e.g. '/lib:/usr/lib') to ld_library_dirs. + * Add file descriptors for a path list (e.g. '/lib:/usr/lib') to + * ld_library_dirs. */ static void -add_libdir_paths(const char *path) { +add_libdir_paths(const char *path) +{ if (path == NULL) return; @@ -2158,24 +2158,22 @@ strncpy(pathcopy, path, pathlen + 1); for (dirname = strtok_r(pathcopy, ":", &tokcontext); dirname; - dirname = strtok_r(NULL, ":", &tokcontext)) { - + dirname = strtok_r(NULL, ":", &tokcontext)) { + struct try_library_args arg; int fd; - struct try_library_args arg; arg.name = ""; arg.namelen = 0; arg.buffer = xmalloc(PATH_MAX); arg.buflen = PATH_MAX; - if (try_library_path(dirname, strnlen(dirname, PATH_MAX), &arg)) + if (try_library_path(dirname, strnlen(dirname, PATH_MAX), &arg)) { fd = open(dirname, O_RDONLY); - - else { + } else { /* 'dirname' is not a directory path; perhaps it's a descriptor? */ fd = (int) strtol(dirname, NULL, 0); if ((fd == 0) && (errno == 0)) - continue; + continue; } if (fd >= 0) @@ -2189,17 +2187,16 @@ * Build the list of library file descriptors. */ static void -init_libdirs(void) { +init_libdirs(void) +{ #ifdef IN_RTLD_CAP + char *envvar = getenv(LD_ "LIBRARY_DIRS"); - char *envvar = getenv(LD_ "LIBRARY_DIRS"); if (envvar == NULL) err(-1, "No %s set in capability mode", LD_ "LIBRARY_DIRS"); add_libdir_paths(envvar); - #else /* !IN_RTLD_CAP */ - /* Look for directories a la find_library (TODO: refactor!). */ add_libdir_paths(ld_library_path); add_libdir_paths(gethints()); @@ -2212,34 +2209,34 @@ ld_library_dirs[0] = -1; } } + /* * Return an array of file descriptors for the library search paths. + * + * XXX: synchronization of ld_library_dirs? */ int -ld_libdirs(int *fds, int *fdcount) { +ld_libdirs(int *fds, int *fdcount) +{ + int i = 0; - if (fdcount == NULL) - return (-1); - - else if (fds == NULL) { - *fdcount = -1; - return (-1); - } - - if (ld_library_dirs == NULL) - init_libdirs(); - - int i = 0; - for (i = 0; (i < ld_library_dirlen) && (ld_library_dirs[i] != -1); i++) ; - - if (*fdcount < i) { - *fdcount = i; - return (-1); - } - + if (fdcount == NULL) + return (-1); + else if (fds == NULL) { + *fdcount = -1; + return (-1); + } + if (ld_library_dirs == NULL) + init_libdirs(); + for (i = 0; (i < ld_library_dirlen) && (ld_library_dirs[i] != -1); i++) + ; + if (*fdcount < i) { *fdcount = i; - memcpy(fds, ld_library_dirs, i * sizeof(int)); - return 0; + return (-1); + } + *fdcount = i; + memcpy(fds, ld_library_dirs, i * sizeof(int)); + return (0); } int