diff options
Diffstat (limited to 'usr/src/lib')
18 files changed, 193 insertions, 342 deletions
diff --git a/usr/src/lib/fm/libfmd_log/common/fmd_log.c b/usr/src/lib/fm/libfmd_log/common/fmd_log.c index d47bc241ed..c052587099 100644 --- a/usr/src/lib/fm/libfmd_log/common/fmd_log.c +++ b/usr/src/lib/fm/libfmd_log/common/fmd_log.c @@ -38,11 +38,7 @@ #include <fcntl.h> #include <errno.h> #include <libgen.h> - -#define _POSIX_PTHREAD_SEMANTICS #include <dirent.h> -#undef _POSIX_PTHREAD_SEMANTICS - #include <fmd_log_impl.h> #include <fmd_log.h> @@ -273,7 +269,7 @@ fmd_log_load_xrdir(fmd_log_t *lp) { fmd_log_t *xlp; char dirbuf[PATH_MAX], path[PATH_MAX], *dirpath; - struct dirent *dp, *ep; + struct dirent *dp; DIR *dirp; lp->log_flags |= FMD_LF_XREFS; @@ -283,10 +279,7 @@ fmd_log_load_xrdir(fmd_log_t *lp) if ((dirp = opendir(dirpath)) == NULL) return; /* failed to open directory; just skip it */ - ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); - bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); - - while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { + while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] == '.') continue; /* skip "." and ".." and hidden files */ diff --git a/usr/src/lib/libdevinfo/devinfo_devlink.c b/usr/src/lib/libdevinfo/devinfo_devlink.c index f020e8f8a4..5417b88bc3 100644 --- a/usr/src/lib/libdevinfo/devinfo_devlink.c +++ b/usr/src/lib/libdevinfo/devinfo_devlink.c @@ -2405,7 +2405,7 @@ do_recurse( struct stat sbuf; char cur[PATH_MAX], *cp; int i, rv = DI_WALK_CONTINUE; - struct dirent *entp, *result; + struct dirent *entp; if ((rel = rel_path(hdp, dir)) == NULL) @@ -2427,23 +2427,12 @@ do_recurse( if ((dp = opendir(dir)) == NULL) return (DI_WALK_CONTINUE); - entp = malloc(sizeof (struct dirent) + PATH_MAX + 1); - if (entp == NULL) { - SET_DB_ERR(hdp); - (void) closedir(dp); - *retp = -1; - return (DI_WALK_TERMINATE); - } - (void) snprintf(cur, sizeof (cur), "%s/", dir); len = strlen(cur); cp = cur + len; len = sizeof (cur) - len; - while (readdir_r(dp, entp, &result) == 0) { - - if (result == NULL) - break; + while ((entp = readdir(dp)) != NULL) { if (strcmp(entp->d_name, ".") == 0 || strcmp(entp->d_name, "..") == 0) { @@ -2486,7 +2475,6 @@ next_entry: break; } - free(entp); (void) closedir(dp); return (rv); diff --git a/usr/src/lib/libdevinfo/devinfo_devperm.c b/usr/src/lib/libdevinfo/devinfo_devperm.c index ef5ca55c48..b89544510a 100644 --- a/usr/src/lib/libdevinfo/devinfo_devperm.c +++ b/usr/src/lib/libdevinfo/devinfo_devperm.c @@ -26,7 +26,7 @@ #pragma ident "%Z%%M% %I% %E% SMI" -#define _POSIX_PTHREAD_SEMANTICS /* for readdir_r */ +#define _POSIX_PTHREAD_SEMANTICS /* for getgrnam_r */ #ifdef lint #define _REENTRANT /* for strtok_r */ #endif @@ -39,7 +39,6 @@ #include <errno.h> #include <grp.h> #include <pwd.h> -#include <alloca.h> #include <nss_dbdefs.h> #include <stdarg.h> #include <syslog.h> @@ -375,7 +374,7 @@ dir_dev_acc(char *path, char *left_to_do, uid_t uid, gid_t gid, mode_t mode, struct stat stat_buf; int err = 0; DIR *dirp; - struct dirent *direntp, *result; + struct dirent *direntp; /* path must be a valid name */ if (stat(path, &stat_buf) == -1) { @@ -433,11 +432,7 @@ dir_dev_acc(char *path, char *left_to_do, uid_t uid, gid_t gid, mode_t mode, } } - direntp = alloca(sizeof (struct dirent) + MAXPATHLEN); - while (readdir_r(dirp, direntp, &result) == 0) { - if (result == NULL) - break; - + while ((direntp = readdir(dirp)) != NULL) { name = direntp->d_name; if ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) diff --git a/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c b/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c index e7120da2a9..195c42f56d 100644 --- a/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c +++ b/usr/src/lib/libdhcpsvc/modules/binfiles/dhcp_network.c @@ -20,8 +20,8 @@ * CDDL HEADER END */ /* - * Copyright (c) 2000 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -1104,8 +1104,7 @@ int list_dn(const char *location, char ***listppp, uint_t *countp) { char ipaddr[INET_ADDRSTRLEN]; - uint64_t direntbuf[(MAXPATHLEN + sizeof (struct dirent)) / 8]; - struct dirent *result, *dirent = (struct dirent *)&direntbuf; + struct dirent *result; DIR *dirp; unsigned int i, count = 0; char *re, **new_listpp, **listpp = NULL; @@ -1137,14 +1136,7 @@ list_dn(const char *location, char ***listppp, uint_t *countp) if (re == NULL) return (DSVC_NO_MEMORY); - for (;;) { - /* - * readdir_r() is very broken; see 4329196 -- in the - * meantime, workaround as best we can. - */ - error = readdir_r(dirp, dirent, &result); - if (error != 0 || result == NULL) - break; + while ((result = readdir(dirp)) != NULL) { if (regex(re, result->d_name, conver, ipaddr) != NULL) { if (atoi(conver) != DSVC_CONVER) diff --git a/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c b/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c index e62c30f43a..898d2bf01b 100644 --- a/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c +++ b/usr/src/lib/libdhcpsvc/modules/files/dhcp_network.c @@ -20,8 +20,8 @@ * CDDL HEADER END */ /* - * Copyright (c) 2000 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -630,8 +630,7 @@ int list_dn(const char *location, char ***listppp, uint_t *countp) { char ipaddr[INET_ADDRSTRLEN]; - uint64_t direntbuf[(MAXPATHLEN + sizeof (struct dirent)) / 8]; - struct dirent *result, *dirent = (struct dirent *)&direntbuf; + struct dirent *result; DIR *dirp; unsigned int i, count = 0; char *re, **new_listpp, **listpp = NULL; @@ -663,15 +662,7 @@ list_dn(const char *location, char ***listppp, uint_t *countp) if (re == NULL) return (DSVC_NO_MEMORY); - for (;;) { - /* - * readdir_r() is very broken; see 4329196 -- in the - * meantime, workaround as best we can. - */ - error = readdir_r(dirp, dirent, &result); - if (error != 0 || result == NULL) - break; - + while ((result = readdir(dirp)) != NULL) { if (regex(re, result->d_name, conver, ipaddr) != NULL) { if (atoi(conver) != DSVC_CONVER) continue; diff --git a/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c b/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c index 1270fbb364..9442c3df6c 100644 --- a/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c +++ b/usr/src/lib/libdhcpsvc/modules/files0/dhcp_network.c @@ -20,8 +20,8 @@ * CDDL HEADER END */ /* - * Copyright (c) 2000-2001 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -533,8 +533,7 @@ int list_dn(const char *location, char ***listppp, uint_t *countp) { char ipaddr[INET_ADDRSTRLEN]; - uint64_t direntbuf[(MAXPATHLEN + sizeof (struct dirent)) / 8]; - struct dirent *result, *dirent = (struct dirent *)&direntbuf; + struct dirent *result; DIR *dirp; unsigned int i, count = 0; char *re, **new_listpp, **listpp = NULL; @@ -563,15 +562,7 @@ list_dn(const char *location, char ***listppp, uint_t *countp) if (re == NULL) return (DSVC_NO_MEMORY); - for (;;) { - /* - * readdir_r() is very broken; see 4329196 -- in the - * meantime, workaround as best we can. - */ - error = readdir_r(dirp, dirent, &result); - if (error != 0 || result == NULL) - break; - + while ((result = readdir(dirp)) != NULL) { if (regex(re, result->d_name, ipaddr) != NULL) { new_listpp = realloc(listpp, (sizeof (char **)) * (count + 1)); diff --git a/usr/src/lib/libdiskmgt/common/drive.c b/usr/src/lib/libdiskmgt/common/drive.c index aed1db3b59..b3f32c70d6 100644 --- a/usr/src/lib/libdiskmgt/common/drive.c +++ b/usr/src/lib/libdiskmgt/common/drive.c @@ -658,21 +658,18 @@ drive_open_disk(disk_t *diskp, char *opath, int len) return (-1); } - if (buf.st_mode & S_IFCHR) { + if (S_ISCHR(buf.st_mode)) { /* opened, is device, so done */ if (opath != NULL) { (void) strlcpy(opath, rmmedia_devpath, len); } return (fd); - } else if (buf.st_mode & S_IFDIR) { + } else if (S_ISDIR(buf.st_mode)) { /* disk w/ slices so handle the directory */ DIR *dirp; struct dirent *dentp; int dfd; -#ifdef _LP64 - struct dirent *result; -#endif /* each device file in the dir represents a slice */ @@ -681,17 +678,7 @@ drive_open_disk(disk_t *diskp, char *opath, int len) return (-1); } - if ((dentp = (struct dirent *)malloc(sizeof (struct dirent) + - PATH_MAX + 1)) == NULL) { - /* out of memory */ - (void) close(fd); - return (-1); - } -#ifdef _LP64 - while (readdir_r(dirp, dentp, &result) != NULL) { -#else - while (readdir_r(dirp, dentp) != NULL) { -#endif + while ((dentp = readdir(dirp)) != NULL) { char slice_path[MAXPATHLEN]; if (libdiskmgt_str_eq(".", dentp->d_name) || @@ -706,10 +693,9 @@ drive_open_disk(disk_t *diskp, char *opath, int len) continue; } - if (fstat(dfd, &buf) == 0 && (buf.st_mode & S_IFCHR)) { + if (fstat(dfd, &buf) == 0 && S_ISCHR(buf.st_mode)) { /* opened, is device, so done */ - free(dentp); - (void) close(fd); + (void) closedir(dirp); if (opath != NULL) { (void) strlcpy(opath, slice_path, len); } @@ -721,11 +707,12 @@ drive_open_disk(disk_t *diskp, char *opath, int len) } /* did not find a device under the rmmedia_path */ - free(dentp); - (void) close(fd); + (void) closedir(dirp); + return (-1); } /* didn't find a device under volume management control */ + (void) close(fd); return (-1); } diff --git a/usr/src/lib/libdiskmgt/common/inuse_fs.c b/usr/src/lib/libdiskmgt/common/inuse_fs.c index c2e751dcb2..1dafdc05e5 100644 --- a/usr/src/lib/libdiskmgt/common/inuse_fs.c +++ b/usr/src/lib/libdiskmgt/common/inuse_fs.c @@ -210,7 +210,7 @@ load_heuristics() (void) snprintf(path, sizeof (path), "/usr/lib/fs/%s", dp->d_name); - if (stat(path, &buf) != 0 || !(buf.st_mode & S_IFDIR)) { + if (stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) { continue; } @@ -226,7 +226,7 @@ load_heuristics() "/usr/lib/fs/%s/fstyp", dp->d_name); if (stat(progpath, &buf) == 0 && - buf.st_mode & S_IFREG) { + S_ISREG(buf.st_mode)) { struct heuristic *hp; diff --git a/usr/src/lib/libdiskmgt/common/partition.c b/usr/src/lib/libdiskmgt/common/partition.c index 32141fc8ac..49fa757330 100644 --- a/usr/src/lib/libdiskmgt/common/partition.c +++ b/usr/src/lib/libdiskmgt/common/partition.c @@ -626,21 +626,18 @@ open_disk(disk_t *diskp, char *opath, int len) return (-1); } - if (buf.st_mode & S_IFCHR) { + if (S_ISCHR(buf.st_mode)) { /* opened, is device, so done */ if (opath != NULL) { (void) strlcpy(opath, rmmedia_devpath, len); } return (fd); - } else if (buf.st_mode & S_IFDIR) { + } else if (S_ISDIR(buf.st_mode)) { /* disk w/ slices so handle the directory */ DIR *dirp; struct dirent *dentp; int dfd; -#ifdef _LP64 - struct dirent *result; -#endif /* each device file in the dir represents a slice */ @@ -649,17 +646,7 @@ open_disk(disk_t *diskp, char *opath, int len) return (-1); } - if ((dentp = (struct dirent *)malloc(sizeof (struct dirent) + - PATH_MAX + 1)) == NULL) { - /* out of memory */ - (void) close(fd); - return (-1); - } -#ifdef _LP64 - while (readdir_r(dirp, dentp, &result) != NULL) { -#else - while (readdir_r(dirp, dentp) != NULL) { -#endif + while ((dentp = readdir(dirp)) != NULL) { char slice_path[MAXPATHLEN]; if (libdiskmgt_str_eq(".", dentp->d_name) || @@ -674,10 +661,9 @@ open_disk(disk_t *diskp, char *opath, int len) continue; } - if (fstat(dfd, &buf) == 0 && (buf.st_mode & S_IFCHR)) { + if (fstat(dfd, &buf) == 0 && S_ISCHR(buf.st_mode)) { /* opened, is device, so done */ - free(dentp); - (void) close(fd); + (void) closedir(dirp); if (opath != NULL) { (void) strlcpy(opath, slice_path, len); } @@ -689,11 +675,12 @@ open_disk(disk_t *diskp, char *opath, int len) } /* did not find a device under the rmmedia_path */ - free(dentp); - (void) close(fd); + (void) closedir(dirp); + return (-1); } /* didn't find a device under volume management control */ + (void) close(fd); return (-1); } diff --git a/usr/src/lib/libdiskmgt/common/slice.c b/usr/src/lib/libdiskmgt/common/slice.c index c88c0a31c9..33997e1b0c 100644 --- a/usr/src/lib/libdiskmgt/common/slice.c +++ b/usr/src/lib/libdiskmgt/common/slice.c @@ -766,10 +766,10 @@ get_removable_assocs(descriptor_t *desc, char *volm_path, int *errp) /* get the media name from the descriptor */ if (desc->type == DM_MEDIA) { - media_name = desc->name; + media_name = desc->name; } else { - /* must be a DM_PARTITION */ - media_name = desc->secondary_name; + /* must be a DM_PARTITION */ + media_name = desc->secondary_name; } /* @@ -781,113 +781,104 @@ get_removable_assocs(descriptor_t *desc, char *volm_path, int *errp) if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) < 0 || fstat(fd, &buf) != 0) { - *errp = ENODEV; - return (NULL); + *errp = ENODEV; + return (NULL); } cnt = num_removable_slices(fd, &buf, volm_path); /* allocate the array for the descriptors */ - slices = (descriptor_t **)calloc(cnt + 1, sizeof (descriptor_t *)); + slices = calloc(cnt + 1, sizeof (descriptor_t *)); if (slices == NULL) { - *errp = ENOMEM; - return (NULL); + *errp = ENOMEM; + return (NULL); } slice_rdsk2dsk(volm_path, devpath, sizeof (devpath)); pos = 0; *errp = 0; - if (buf.st_mode & S_IFCHR) { - struct dk_minfo minfo; - - /* Make sure media has readable label */ - if (media_read_info(fd, &minfo)) { - int status; - int data_format = FMT_UNKNOWN; - struct vtoc vtoc; - struct dk_gpt *efip; - - if ((status = read_vtoc(fd, &vtoc)) >= 0) { - data_format = FMT_VTOC; - } else if (status == VT_ENOTSUP && - efi_alloc_and_read(fd, &efip) >= 0) { - data_format = FMT_EFI; - } + if (S_ISCHR(buf.st_mode)) { + struct dk_minfo minfo; - if (data_format != FMT_UNKNOWN) { - /* has a readable label */ - slices[pos++] = cache_get_desc(DM_SLICE, desc->p.disk, - devpath, media_name, errp); - } - } + /* Make sure media has readable label */ + if (media_read_info(fd, &minfo)) { + int status; + int data_format = FMT_UNKNOWN; + struct vtoc vtoc; + struct dk_gpt *efip; + + if ((status = read_vtoc(fd, &vtoc)) >= 0) { + data_format = FMT_VTOC; + } else if (status == VT_ENOTSUP && + efi_alloc_and_read(fd, &efip) >= 0) { + data_format = FMT_EFI; + } - } else if (buf.st_mode & S_IFDIR) { - DIR *dirp; -#ifdef _LP64 - struct dirent *result; -#endif + if (data_format != FMT_UNKNOWN) { + /* has a readable label */ + slices[pos++] = + cache_get_desc(DM_SLICE, desc->p.disk, + devpath, media_name, errp); + } + } + (void) close(fd); + } else if (S_ISDIR(buf.st_mode)) { + DIR *dirp; + struct dirent *dentp; - /* rewind, num_removable_slices already traversed */ - (void) lseek(fd, 0, SEEK_SET); + /* rewind, num_removable_slices already traversed */ + (void) lseek(fd, 0, SEEK_SET); - if ((dirp = fdopendir(fd)) != NULL) { - struct dirent *dentp; + if ((dirp = fdopendir(fd)) == NULL) { + *errp = errno; + (void) close(fd); + return (NULL); + } - dentp = (struct dirent *)malloc(sizeof (struct dirent) + - PATH_MAX + 1); - if (dentp != NULL) { -#ifdef _LP64 - while (readdir_r(dirp, dentp, &result) != NULL) { -#else - while (readdir_r(dirp, dentp) != NULL) { -#endif + while ((dentp = readdir(dirp)) != NULL) { int dfd; int is_dev = 0; char slice_path[MAXPATHLEN]; if (libdiskmgt_str_eq(".", dentp->d_name) || libdiskmgt_str_eq("..", dentp->d_name)) { - continue; + continue; } (void) snprintf(slice_path, sizeof (slice_path), "%s/%s", devpath, dentp->d_name); if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) { - struct stat buf; + struct stat buf; - if (fstat(dfd, &buf) == 0 && - buf.st_mode & S_IFCHR) { - is_dev = 1; - } - (void) close(dfd); + if (fstat(dfd, &buf) == 0 && + S_ISCHR(buf.st_mode)) { + is_dev = 1; + } + (void) close(dfd); } if (!is_dev) { - continue; + continue; } slices[pos++] = cache_get_desc(DM_SLICE, desc->p.disk, slice_path, media_name, errp); if (*errp != 0) { - break; + break; } - - } - free(dentp); } - /* don't call closedir since it closes the fd */ - } + (void) closedir(dirp); + } else { + (void) close(fd); } - (void) close(fd); - slices[pos] = NULL; if (*errp != 0) { - cache_free_descriptors(slices); - return (NULL); + cache_free_descriptors(slices); + return (NULL); } return (slices); @@ -1023,7 +1014,7 @@ make_removable_descriptors(disk_t *dp) struct stat buf; if (fstat(fd, &buf) == 0) { - if (buf.st_mode & S_IFCHR) { + if (S_ISCHR(buf.st_mode)) { int status; int data_format = FMT_UNKNOWN; struct dk_minfo minfo; @@ -1054,7 +1045,7 @@ make_removable_descriptors(disk_t *dp) /* The media name is the volm_path in this case. */ cache_load_desc(DM_SLICE, dp, devpath, volm_path, &error); - } else if (buf.st_mode & S_IFDIR) { + } else if (S_ISDIR(buf.st_mode)) { /* each device file in the dir represents a slice */ error = make_volm_dir_descriptors(dp, fd, volm_path); } @@ -1076,56 +1067,48 @@ make_volm_dir_descriptors(disk_t *dp, int dirfd, char *volm_path) int error; DIR *dirp; struct dirent *dentp; -#ifdef _LP64 - struct dirent *result; -#endif char devpath[MAXPATHLEN]; + dirfd = dup(dirfd); + if (dirfd < 0) + return (0); if ((dirp = fdopendir(dirfd)) == NULL) { - return (0); + (void) close(dirfd); + return (0); } slice_rdsk2dsk(volm_path, devpath, sizeof (devpath)); error = 0; - dentp = (struct dirent *)malloc(sizeof (struct dirent) + - PATH_MAX + 1); - if (dentp != NULL) { -#ifdef _LP64 - while (readdir_r(dirp, dentp, &result) != NULL) { -#else - while (readdir_r(dirp, dentp) != NULL) { -#endif + while ((dentp = readdir(dirp)) != NULL) { int fd; char slice_path[MAXPATHLEN]; if (libdiskmgt_str_eq(".", dentp->d_name) || libdiskmgt_str_eq("..", dentp->d_name)) { - continue; + continue; } (void) snprintf(slice_path, sizeof (slice_path), "%s/%s", devpath, dentp->d_name); if ((fd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) { - struct stat buf; + struct stat buf; - if (fstat(fd, &buf) == 0 && buf.st_mode & S_IFCHR) { /* The media name is the volm_path in this case. */ - cache_load_desc(DM_SLICE, dp, slice_path, volm_path, - &error); - if (error != 0) { - (void) close(fd); - break; + if (fstat(fd, &buf) == 0 && S_ISCHR(buf.st_mode)) { + cache_load_desc(DM_SLICE, dp, slice_path, + volm_path, &error); + if (error != 0) { + (void) close(fd); + break; + } } - } - (void) close(fd); + (void) close(fd); } - } - free(dentp); } - /* don't call closedir since it closes the fd */ + (void) closedir(dirp); return (error); } @@ -1255,82 +1238,75 @@ match_removable_name(disk_t *diskp, char *name, int *errp) *errp = 0; + if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) == -1 || + fstat(fd, &buf) != 0) { + return (0); + } + found = 0; - if ((fd = open(volm_path, O_RDONLY|O_NDELAY)) >= 0 && - fstat(fd, &buf) == 0) { - if (buf.st_mode & S_IFCHR) { + if (S_ISCHR(buf.st_mode)) { char devpath[MAXPATHLEN]; slice_rdsk2dsk(volm_path, devpath, sizeof (devpath)); if (libdiskmgt_str_eq(name, devpath)) { - found = 1; + found = 1; } - - } else if (buf.st_mode & S_IFDIR) { + (void) close(fd); + return (found); + } else if (S_ISDIR(buf.st_mode)) { /* each device file in the dir represents a slice */ DIR *dirp; + struct dirent *dentp; + char devpath[MAXPATHLEN]; - if ((dirp = fdopendir(fd)) != NULL) { - struct dirent *dentp; -#ifdef _LP64 - struct dirent *result; -#endif - char devpath[MAXPATHLEN]; + if ((dirp = fdopendir(fd)) == NULL) { + (void) close(fd); + return (0); + } - slice_rdsk2dsk(volm_path, devpath, sizeof (devpath)); + slice_rdsk2dsk(volm_path, devpath, sizeof (devpath)); - dentp = (struct dirent *)malloc(sizeof (struct dirent) + - PATH_MAX + 1); - if (dentp != NULL) { -#ifdef _LP64 - while (readdir_r(dirp, dentp, &result) != NULL) { -#else - while (readdir_r(dirp, dentp) != NULL) { -#endif - char slice_path[MAXPATHLEN]; + while ((dentp = readdir(dirp)) != NULL) { + char slice_path[MAXPATHLEN]; - if (libdiskmgt_str_eq(".", dentp->d_name) || - libdiskmgt_str_eq("..", dentp->d_name)) { + if (libdiskmgt_str_eq(".", dentp->d_name) || + libdiskmgt_str_eq("..", dentp->d_name)) { continue; - } + } - (void) snprintf(slice_path, sizeof (slice_path), - "%s/%s", devpath, dentp->d_name); + (void) snprintf(slice_path, sizeof (slice_path), + "%s/%s", devpath, dentp->d_name); - if (libdiskmgt_str_eq(name, slice_path)) { + if (libdiskmgt_str_eq(name, slice_path)) { /* found name, check device */ int dfd; int is_dev = 0; - if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) - >= 0) { - struct stat buf; + dfd = open(slice_path, O_RDONLY|O_NDELAY); + if (dfd >= 0) { + struct stat buf; - if (fstat(dfd, &buf) == 0 && - buf.st_mode & S_IFCHR) { - is_dev = 1; - } - (void) close(dfd); + if (fstat(dfd, &buf) == 0 && + S_ISCHR(buf.st_mode)) { + is_dev = 1; + } + (void) close(dfd); } /* we found the name */ found = 1; if (!is_dev) { - *errp = ENODEV; + *errp = ENODEV; } break; - } } - free(dentp); - } - /* don't call closedir since it closes the fd */ } - } /* end of dir handling */ - - (void) close(fd); + (void) closedir(dirp); + } else { + (void) close(fd); } return (found); @@ -1341,56 +1317,50 @@ num_removable_slices(int fd, struct stat *bufp, char *volm_path) { int cnt = 0; - if (bufp->st_mode & S_IFCHR) { - cnt = 1; - - } else if (bufp->st_mode & S_IFDIR) { - /* each device file in the dir represents a slice */ - DIR *dirp; + if (S_ISCHR(bufp->st_mode)) + return (1); - if ((dirp = fdopendir(fd)) != NULL) { + if (S_ISDIR(bufp->st_mode)) { + /* each device file in the dir represents a slice */ + DIR *dirp; struct dirent *dentp; -#ifdef _LP64 - struct dirent *result; -#endif char devpath[MAXPATHLEN]; + fd = dup(fd); + + if (fd < 0) + return (0); + + if ((dirp = fdopendir(fd)) == NULL) { + (void) close(fd); + return (0); + } + slice_rdsk2dsk(volm_path, devpath, sizeof (devpath)); - dentp = (struct dirent *)malloc(sizeof (struct dirent) + - PATH_MAX + 1); - if (dentp != NULL) { -#ifdef _LP64 - while (readdir_r(dirp, dentp, &result) != NULL) { -#else - while (readdir_r(dirp, dentp) != NULL) { -#endif + while ((dentp = readdir(dirp)) != NULL) { int dfd; char slice_path[MAXPATHLEN]; if (libdiskmgt_str_eq(".", dentp->d_name) || libdiskmgt_str_eq("..", dentp->d_name)) { - continue; + continue; } (void) snprintf(slice_path, sizeof (slice_path), "%s/%s", devpath, dentp->d_name); if ((dfd = open(slice_path, O_RDONLY|O_NDELAY)) >= 0) { - struct stat buf; + struct stat buf; - if (fstat(dfd, &buf) == 0 && - buf.st_mode & S_IFCHR) { - cnt++; - } - (void) close(dfd); + if (fstat(dfd, &buf) == 0 && + S_ISCHR(buf.st_mode)) { + cnt++; + } + (void) close(dfd); } - } - free(dentp); } - /* don't call closedir since it closes the fd */ - } - } /* end of dir handling */ - + (void) closedir(dirp); + } return (cnt); } diff --git a/usr/src/lib/libdtrace/common/dt_cc.c b/usr/src/lib/libdtrace/common/dt_cc.c index 508bbc7389..bd7204101a 100644 --- a/usr/src/lib/libdtrace/common/dt_cc.c +++ b/usr/src/lib/libdtrace/common/dt_cc.c @@ -95,13 +95,8 @@ #include <errno.h> #include <ucontext.h> #include <limits.h> -#include <alloca.h> #include <ctype.h> - -#define _POSIX_PTHREAD_SEMANTICS #include <dirent.h> -#undef _POSIX_PTHREAD_SEMANTICS - #include <dt_module.h> #include <dt_program.h> #include <dt_provider.h> @@ -1646,7 +1641,7 @@ err: static int dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path) { - struct dirent *dp, *ep; + struct dirent *dp; const char *p; DIR *dirp; @@ -1659,10 +1654,7 @@ dt_load_libs_dir(dtrace_hdl_t *dtp, const char *path) return (0); } - ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); - bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); - - while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { + while ((dp = readdir(dirp)) != NULL) { if ((p = strrchr(dp->d_name, '.')) == NULL || strcmp(p, ".d")) continue; /* skip any filename not ending in .d */ diff --git a/usr/src/lib/libdtrace/common/dt_module.c b/usr/src/lib/libdtrace/common/dt_module.c index bd219579c9..46ad7c6529 100644 --- a/usr/src/lib/libdtrace/common/dt_module.c +++ b/usr/src/lib/libdtrace/common/dt_module.c @@ -42,11 +42,7 @@ #include <limits.h> #include <assert.h> #include <errno.h> -#include <alloca.h> - -#define _POSIX_PTHREAD_SEMANTICS #include <dirent.h> -#undef _POSIX_PTHREAD_SEMANTICS #include <dt_strtab.h> #include <dt_module.h> @@ -903,12 +899,9 @@ dtrace_update(dtrace_hdl_t *dtp) */ if (!(dtp->dt_oflags & DTRACE_O_NOSYS) && (dirp = opendir(OBJFS_ROOT)) != NULL) { - struct dirent *dp, *ep; - - ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); - bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); + struct dirent *dp; - while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { + while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] != '.') dt_module_update(dtp, dp->d_name); } diff --git a/usr/src/lib/libresolv2/common/bsd/writev.c b/usr/src/lib/libresolv2/common/bsd/writev.c index e3a97a0c39..6e348810ec 100644 --- a/usr/src/lib/libresolv2/common/bsd/writev.c +++ b/usr/src/lib/libresolv2/common/bsd/writev.c @@ -1,5 +1,5 @@ /* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,7 +36,7 @@ __writev(int fd, struct iovec *iov, int iovlen) /* * Allow for atomic writes to network. */ - if (statbuf.st_mode & S_IFSOCK) { + if (S_ISSOCK(statbuf.st_mode)) { struct msghdr mesg; memset(&mesg, 0, sizeof(mesg)); diff --git a/usr/src/lib/libresolv2/common/isc/logging.c b/usr/src/lib/libresolv2/common/isc/logging.c index 13fc49259d..48ce0859c9 100644 --- a/usr/src/lib/libresolv2/common/isc/logging.c +++ b/usr/src/lib/libresolv2/common/isc/logging.c @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -121,7 +121,7 @@ log_open_stream(log_channel chan) { } regular = 1; } else - regular = (sb.st_mode & S_IFREG); + regular = S_ISREG(sb.st_mode); if (chan->out.file.versions) { if (!regular) { diff --git a/usr/src/lib/libsmedia/library/common/l_misc.c b/usr/src/lib/libsmedia/library/common/l_misc.c index dc6ba063fd..f917e20cea 100644 --- a/usr/src/lib/libsmedia/library/common/l_misc.c +++ b/usr/src/lib/libsmedia/library/common/l_misc.c @@ -470,7 +470,7 @@ get_handle_from_fd(int32_t fd) clnt_destroy(handle->sm_clnt); return (NULL); } - if ((stat.st_mode & S_IFDOOR) != S_IFDOOR) { + if (!S_ISDOOR(stat.st_mode)) { DPRINTF( "Descriptor returned by door_call is not of type DOOR\n"); (void) dlclose(handle->sm_lib_handle); diff --git a/usr/src/lib/libsysevent/libsysevent.c b/usr/src/lib/libsysevent/libsysevent.c index 6dff4538df..3dd246babb 100644 --- a/usr/src/lib/libsysevent/libsysevent.c +++ b/usr/src/lib/libsysevent/libsysevent.c @@ -1756,7 +1756,7 @@ sysevent_open_channel_common(const char *channel_path) errno = EACCES; return (NULL); } else if (chan_stat.st_uid != getuid() || - !(chan_stat.st_mode & S_IFDIR)) { + !S_ISDIR(chan_stat.st_mode)) { dprint("sysevent_open_channel: Invalid " "permissions for channel %s\n: %d:%d:%d", channel_path, (int)chan_stat.st_uid, (int)chan_stat.st_gid, diff --git a/usr/src/lib/lvm/libmeta/common/meta_name.c b/usr/src/lib/lvm/libmeta/common/meta_name.c index 7becd6af2f..793d21648a 100644 --- a/usr/src/lib/lvm/libmeta/common/meta_name.c +++ b/usr/src/lib/lvm/libmeta/common/meta_name.c @@ -95,13 +95,13 @@ rawname( "line containing device %s\n"), uname); exit(1); } - if ((sbuf1.st_mode & S_IFBLK) == 0) { + if (!S_ISBLK(sbuf1.st_mode)) { (void) printf(dgettext(TEXT_DOMAIN, "/etc/vfstab device to mount is not a " "block device for device %s\n"), uname); exit(1); } - if ((sbuf2.st_mode & S_IFCHR) == 0) { + if (!S_ISCHR(sbuf2.st_mode)) { (void) printf(dgettext(TEXT_DOMAIN, "/etc/vfstab device to fsck is not a " "raw device for device %s\n"), p); diff --git a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c index b39e11244b..d67efb6b3d 100644 --- a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c +++ b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystoreUtil.c @@ -835,27 +835,13 @@ cleanup: static CK_RV get_all_objs_in_dir(DIR *dirp, ks_obj_handle_t *ks_handle, - ks_obj_t **result_obj_list, boolean_t lock_held, char *dir_name) + ks_obj_t **result_obj_list, boolean_t lock_held) { - struct dirent *dp = NULL, *result = NULL; + struct dirent *dp; ks_obj_t *obj; CK_RV rv; - long path_limit; - - if ((path_limit = pathconf(dir_name, _PC_NAME_MAX)) == -1) { - path_limit = PATH_MAX; - } - - dp = malloc(path_limit + 1 + sizeof (struct dirent)); - if (dp == NULL) { - return (CKR_HOST_MEMORY); - } - - while (readdir_r(dirp, dp, &result) == 0) { - if (result == NULL) { - break; - } + while ((dp = readdir(dirp)) != NULL) { if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..") == 0)) { @@ -865,7 +851,6 @@ get_all_objs_in_dir(DIR *dirp, ks_obj_handle_t *ks_handle, (void) strcpy((char *)ks_handle->name, dp->d_name); rv = soft_keystore_get_single_obj(ks_handle, &obj, lock_held); if (rv != CKR_OK) { - free(dp); return (rv); } if (obj != NULL) { @@ -877,7 +862,6 @@ get_all_objs_in_dir(DIR *dirp, ks_obj_handle_t *ks_handle, } } } - free(dp); return (CKR_OK); } @@ -1497,7 +1481,7 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held) soft_object_t *new_crypt_key = NULL, *new_hmac_key = NULL; char filebuf[BUFSIZ]; DIR *pri_dirp; - struct dirent *pri_ent = NULL, *result = NULL; + struct dirent *pri_ent; char pri_obj_path[MAXPATHLEN], ks_desc_file[MAXPATHLEN], tmp_ks_desc_name[MAXPATHLEN]; typedef struct priobjs { @@ -1741,16 +1725,7 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held) } } - pri_ent = malloc(pathconf(pri_obj_path, _PC_NAME_MAX) + 1 - + sizeof (struct dirent)); - if (pri_ent == NULL) { - goto cleanup2; - } - - while (readdir_r(pri_dirp, pri_ent, &result) == 0) { - if (result == NULL) { - break; - } + while ((pri_ent = readdir(pri_dirp)) != NULL) { if ((strcmp(pri_ent->d_name, ".") == 0) || (strcmp(pri_ent->d_name, "..") == 0) || @@ -1761,7 +1736,6 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held) obj = malloc(sizeof (priobjs_t)); if (obj == NULL) { - free(pri_ent); goto cleanup2; } (void) snprintf(obj->orig_name, MAXPATHLEN, @@ -1771,7 +1745,6 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held) (pri_ent->d_name) + strlen(OBJ_PREFIX)); if (reencrypt_obj(new_crypt_key, new_hmac_key, obj->orig_name, obj->tmp_name) != 0) { - free(pri_ent); free(obj); goto cleanup2; } @@ -1785,7 +1758,6 @@ soft_keystore_setpin(uchar_t *oldpin, uchar_t *newpin, boolean_t lock_held) pri_objs = obj; } } - free(pri_ent); /* rename all the private objects */ tmp = pri_objs; @@ -2007,7 +1979,7 @@ soft_keystore_get_objs(ks_search_type_t search_type, return (CKR_FUNCTION_FAILED); } rv = get_all_objs_in_dir(dirp, &ks_handle, result_obj_list, - lock_held, pub_obj_path); + lock_held); if (rv != CKR_OK) { (void) closedir(dirp); goto cleanup; @@ -2036,7 +2008,7 @@ soft_keystore_get_objs(ks_search_type_t search_type, return (CKR_OK); } rv = get_all_objs_in_dir(dirp, &ks_handle, result_obj_list, - lock_held, pri_obj_path); + lock_held); if (rv != CKR_OK) { (void) closedir(dirp); goto cleanup; |
