diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 4155bec683..e8c50454af 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -297,7 +297,7 @@ handleit(struct cmd_syndesc *as, void *arock) #ifndef AFS_NT40_ENV if (geteuid() != 0) { fprintf(stderr, "%s: Must be run as root; sorry\n", progname); - exit(1); + return 1; } #endif @@ -371,7 +371,7 @@ handleit(struct cmd_syndesc *as, void *arock) fprintf(stderr, "%s: %s is not an AFS partition name on this server.\n", progname, partName); - exit(1); + return 1; } } @@ -390,7 +390,7 @@ handleit(struct cmd_syndesc *as, void *arock) fprintf(stderr, "%s: Current partition is not a vice partition.\n", progname); - exit(1); + return 1; } } snprintf(name1, sizeof name1, VFORMAT, @@ -432,7 +432,7 @@ FindCurrentPartition(void) fprintf(stderr, "%s: Failed to get current working directory: ", progname); perror("pwd"); - exit(1); + return NULL; } p = strchr(&partName[1], OS_DIRSEPC); if (p) { @@ -444,7 +444,7 @@ FindCurrentPartition(void) *p = tmp; fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname, partName); - exit(1); + return NULL; } return dp; } @@ -487,7 +487,7 @@ HandlePart(struct DiskPartition64 *partP) if ((dirp = opendir(p)) == NULL) { fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname, p); - exit(1); + return; } while ((dp = readdir(dirp))) { p = (char *)strrchr(dp->d_name, '.'); @@ -772,15 +772,15 @@ NT_date(FILETIME * ft) } #endif -static void +static int GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, char **atime) { #ifdef AFS_NT40_ENV BY_HANDLE_FILE_INFORMATION fi; if (!GetFileInformationByHandle(fd, &fi)) { - fprintf(stderr, "%s: GetFileInformationByHandle failed, exiting\n", + fprintf(stderr, "%s: GetFileInformationByHandle failed\n", progname); - exit(1); + return -1; } *size = (int)fi.nFileSizeLow; *ctime = "N/A"; @@ -790,13 +790,14 @@ GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, char **atime) struct afs_stat_st status; if (afs_fstat(fd, &status) == -1) { fprintf(stderr, "%s: fstat failed %d\n", progname, errno); - exit(1); + return -1; } *size = (int)status.st_size; *ctime = date(status.st_ctime); *mtime = date(status.st_mtime); *atime = date(status.st_atime); #endif + return 0; } /** @@ -885,12 +886,12 @@ HandleVnodes(Volume * vp, VnodeClass class) (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE); char buf[SIZEOF_LARGEDISKVNODE]; struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf; - StreamHandle_t *file; + StreamHandle_t *file = NULL; int vnodeIndex, nVnodes; afs_foff_t offset = 0; Inode ino; IHandle_t *ih = vp->vnodeIndex[class].handle; - FdHandle_t *fdP; + FdHandle_t *fdP = NULL; int size; char *ctime, *atime, *mtime; @@ -907,7 +908,7 @@ HandleVnodes(Volume * vp, VnodeClass class) if (SaveInodes) { printf("Saving all volume files to current directory ...\n"); if (ShowSizes) { - PrintingVolumeSizes = 0; /* print heading again */ + PrintingVolumeSizes = 0; /* print heading again */ } } } @@ -915,16 +916,18 @@ HandleVnodes(Volume * vp, VnodeClass class) fdP = IH_OPEN(ih); if (fdP == NULL) { fprintf(stderr, "%s: open failed: ", progname); - exit(1); + goto error; } file = FDH_FDOPEN(fdP, "r"); if (!file) { fprintf(stderr, "%s: fdopen failed\n", progname); - exit(1); + goto error; } - GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime); + if (GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime) != 0) { + goto error; + } if (InodeTimes) { printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime, mtime, atime); @@ -958,8 +961,14 @@ HandleVnodes(Volume * vp, VnodeClass class) bitNumberToVnodeNumber(vnodeIndex, class), ino, vp); } } - STREAM_CLOSE(file); - FDH_CLOSE(fdP); + + error: + if (file) { + STREAM_CLOSE(file); + } + if (fdP) { + FDH_CLOSE(fdP); + } } void