From d018b2e9c88f6669c68f3343dbbf53e6084e8ff7 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 18 Aug 2006 18:51:20 +1000 Subject: - (dtucker) [configure.ac openbsd-compat/bsd-closefrom.c] Resync with closefrom.c from sudo. --- openbsd-compat/bsd-closefrom.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'openbsd-compat/bsd-closefrom.c') diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c index e7a521e43..4b72920d6 100644 --- a/openbsd-compat/bsd-closefrom.c +++ b/openbsd-compat/bsd-closefrom.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004 Todd C. Miller + * Copyright (c) 2004-2005 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -52,12 +52,19 @@ #endif #ifndef lint -static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $"; +__unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $"; #endif /* lint */ /* * Close all file descriptors greater than or equal to lowfd. */ +#ifdef HAVE_FCNTL_CLOSEM +void +closefrom(int lowfd) +{ + (void) fcntl(lowfd, F_CLOSEM, 0); +} +#else void closefrom(int lowfd) { @@ -70,7 +77,7 @@ closefrom(int lowfd) /* Check for a /proc/$$/fd directory. */ len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid()); - if (len >= 0 && (u_int)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { + if (len > 0 && (size_t)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) { while ((dent = readdir(dirp)) != NULL) { fd = strtol(dent->d_name, &endp, 10); if (dent->d_name != endp && *endp == '\0' && @@ -79,10 +86,6 @@ closefrom(int lowfd) } (void) closedir(dirp); } else -#elif defined(USE_FCNTL_CLOSEM) - if (fcntl(lowfd, F_CLOSEM, 0) != -1) { - return; - } else #endif { /* @@ -102,6 +105,5 @@ closefrom(int lowfd) (void) close((int) fd); } } - +#endif /* !HAVE_FCNTL_CLOSEM */ #endif /* HAVE_CLOSEFROM */ - -- cgit v1.2.3