Fix exit status on failure.

This commit is contained in:
Matt Kraai 2000-12-06 15:55:23 +00:00
parent ab147f608d
commit 92ed8a3519
8 changed files with 42 additions and 36 deletions

View File

@ -36,7 +36,7 @@ static int df(char *device, const char *mountPoint)
long blocks_percent_used; long blocks_percent_used;
if (statfs(mountPoint, &s) != 0) { if (statfs(mountPoint, &s) != 0) {
perror(mountPoint); perrorMsg("%s", mountPoint);
return FALSE; return FALSE;
} }
@ -63,12 +63,13 @@ static int df(char *device, const char *mountPoint)
extern int df_main(int argc, char **argv) extern int df_main(int argc, char **argv)
{ {
int status = EXIT_SUCCESS;
printf("%-20s %-14s %s %s %s %s\n", "Filesystem", printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on"); "1k-blocks", "Used", "Available", "Use%", "Mounted on");
if (argc > 1) { if (argc > 1) {
struct mntent *mountEntry; struct mntent *mountEntry;
int status;
if (**(argv + 1) == '-') { if (**(argv + 1) == '-') {
usage(df_usage); usage(df_usage);
@ -76,32 +77,30 @@ extern int df_main(int argc, char **argv)
while (argc > 1) { while (argc > 1) {
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) { if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
errorMsg("%s: can't find mount point.\n", argv[1]); errorMsg("%s: can't find mount point.\n", argv[1]);
exit(FALSE); status = EXIT_FAILURE;
} } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir); status = EXIT_FAILURE;
if (status != TRUE)
return EXIT_FAILURE;
argc--; argc--;
argv++; argv++;
} }
return EXIT_SUCCESS;
} else { } else {
FILE *mountTable; FILE *mountTable;
struct mntent *mountEntry; struct mntent *mountEntry;
mountTable = setmntent(mtab_file, "r"); mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) { if (mountTable == 0) {
perror(mtab_file); perrorMsg("%s", mtab_file);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
while ((mountEntry = getmntent(mountTable))) { while ((mountEntry = getmntent(mountTable))) {
df(mountEntry->mnt_fsname, mountEntry->mnt_dir); if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
status = EXIT_FAILURE;
} }
endmntent(mountTable); endmntent(mountTable);
} }
return EXIT_FAILURE; return status;
} }
/* /*

View File

@ -125,6 +125,7 @@ static long du(char *filename)
int du_main(int argc, char **argv) int du_main(int argc, char **argv)
{ {
int status = EXIT_SUCCESS;
int i; int i;
int c; int c;
@ -147,12 +148,14 @@ int du_main(int argc, char **argv)
/* go through remaining args (if any) */ /* go through remaining args (if any) */
if (optind >= argc) { if (optind >= argc) {
du("."); if (du(".") == 0)
status = EXIT_FAILURE;
} else { } else {
long sum; long sum;
for (i=optind; i < argc; i++) { for (i=optind; i < argc; i++) {
sum = du(argv[i]); if (du(argv[i]) == 0)
status = EXIT_FAILURE;
if (sum && isDirectory(argv[i], FALSE, NULL)) { if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]); print_normal(sum, argv[i]);
} }
@ -160,10 +163,10 @@ int du_main(int argc, char **argv)
} }
} }
return EXIT_SUCCESS; return status;
} }
/* $Id: du.c,v 1.26 2000/12/01 02:55:13 kraai Exp $ */ /* $Id: du.c,v 1.27 2000/12/06 15:55:23 kraai Exp $ */
/* /*
Local Variables: Local Variables:
c-file-style: "linux" c-file-style: "linux"

21
df.c
View File

@ -36,7 +36,7 @@ static int df(char *device, const char *mountPoint)
long blocks_percent_used; long blocks_percent_used;
if (statfs(mountPoint, &s) != 0) { if (statfs(mountPoint, &s) != 0) {
perror(mountPoint); perrorMsg("%s", mountPoint);
return FALSE; return FALSE;
} }
@ -63,12 +63,13 @@ static int df(char *device, const char *mountPoint)
extern int df_main(int argc, char **argv) extern int df_main(int argc, char **argv)
{ {
int status = EXIT_SUCCESS;
printf("%-20s %-14s %s %s %s %s\n", "Filesystem", printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on"); "1k-blocks", "Used", "Available", "Use%", "Mounted on");
if (argc > 1) { if (argc > 1) {
struct mntent *mountEntry; struct mntent *mountEntry;
int status;
if (**(argv + 1) == '-') { if (**(argv + 1) == '-') {
usage(df_usage); usage(df_usage);
@ -76,32 +77,30 @@ extern int df_main(int argc, char **argv)
while (argc > 1) { while (argc > 1) {
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) { if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
errorMsg("%s: can't find mount point.\n", argv[1]); errorMsg("%s: can't find mount point.\n", argv[1]);
exit(FALSE); status = EXIT_FAILURE;
} } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir); status = EXIT_FAILURE;
if (status != TRUE)
return EXIT_FAILURE;
argc--; argc--;
argv++; argv++;
} }
return EXIT_SUCCESS;
} else { } else {
FILE *mountTable; FILE *mountTable;
struct mntent *mountEntry; struct mntent *mountEntry;
mountTable = setmntent(mtab_file, "r"); mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) { if (mountTable == 0) {
perror(mtab_file); perrorMsg("%s", mtab_file);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
while ((mountEntry = getmntent(mountTable))) { while ((mountEntry = getmntent(mountTable))) {
df(mountEntry->mnt_fsname, mountEntry->mnt_dir); if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
status = EXIT_FAILURE;
} }
endmntent(mountTable); endmntent(mountTable);
} }
return EXIT_FAILURE; return status;
} }
/* /*

11
du.c
View File

@ -125,6 +125,7 @@ static long du(char *filename)
int du_main(int argc, char **argv) int du_main(int argc, char **argv)
{ {
int status = EXIT_SUCCESS;
int i; int i;
int c; int c;
@ -147,12 +148,14 @@ int du_main(int argc, char **argv)
/* go through remaining args (if any) */ /* go through remaining args (if any) */
if (optind >= argc) { if (optind >= argc) {
du("."); if (du(".") == 0)
status = EXIT_FAILURE;
} else { } else {
long sum; long sum;
for (i=optind; i < argc; i++) { for (i=optind; i < argc; i++) {
sum = du(argv[i]); if (du(argv[i]) == 0)
status = EXIT_FAILURE;
if (sum && isDirectory(argv[i], FALSE, NULL)) { if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]); print_normal(sum, argv[i]);
} }
@ -160,10 +163,10 @@ int du_main(int argc, char **argv)
} }
} }
return EXIT_SUCCESS; return status;
} }
/* $Id: du.c,v 1.26 2000/12/01 02:55:13 kraai Exp $ */ /* $Id: du.c,v 1.27 2000/12/06 15:55:23 kraai Exp $ */
/* /*
Local Variables: Local Variables:
c-file-style: "linux" c-file-style: "linux"

View File

@ -493,8 +493,9 @@ singlemount:
} }
} }
#endif #endif
rc = mount_one(device, directory, filesystemType, flags, if (!mount_one(device, directory, filesystemType, flags,
string_flags, useMtab, fakeIt, extra_opts, TRUE); string_flags, useMtab, fakeIt, extra_opts, TRUE))
rc = EXIT_FAILURE;
if (all == FALSE) if (all == FALSE)
break; break;

View File

@ -278,7 +278,7 @@ extern int umount_main(int argc, char **argv)
else else
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (do_umount(*argv, useMtab) == 0) if (do_umount(*argv, useMtab) == TRUE)
return EXIT_SUCCESS; return EXIT_SUCCESS;
perror("umount"); perror("umount");
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -493,8 +493,9 @@ singlemount:
} }
} }
#endif #endif
rc = mount_one(device, directory, filesystemType, flags, if (!mount_one(device, directory, filesystemType, flags,
string_flags, useMtab, fakeIt, extra_opts, TRUE); string_flags, useMtab, fakeIt, extra_opts, TRUE))
rc = EXIT_FAILURE;
if (all == FALSE) if (all == FALSE)
break; break;

View File

@ -278,7 +278,7 @@ extern int umount_main(int argc, char **argv)
else else
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (do_umount(*argv, useMtab) == 0) if (do_umount(*argv, useMtab) == TRUE)
return EXIT_SUCCESS; return EXIT_SUCCESS;
perror("umount"); perror("umount");
return EXIT_FAILURE; return EXIT_FAILURE;