[quota/f14] Report quotacheck failures by return code

Petr Pisar ppisar at fedoraproject.org
Fri Jul 15 08:56:47 UTC 2011


commit 0ff8fa792a4bb45e6aef3e1490f56e388d400bb4
Author: Petr Písař <ppisar at redhat.com>
Date:   Fri Jul 15 08:48:31 2011 +0200

    Report quotacheck failures by return code

 ...Report-quotacheck-failures-by-return-code.patch |  203 ++++++++++++++++++++
 quota.spec                                         |    8 +-
 2 files changed, 210 insertions(+), 1 deletions(-)
---
diff --git a/quota-3.17-Report-quotacheck-failures-by-return-code.patch b/quota-3.17-Report-quotacheck-failures-by-return-code.patch
new file mode 100644
index 0000000..77f5e65
--- /dev/null
+++ b/quota-3.17-Report-quotacheck-failures-by-return-code.patch
@@ -0,0 +1,203 @@
+From 5e9f100fdea9fad526a2dfa5e5b7dca162ac5416 Mon Sep 17 00:00:00 2001
+From: Petr Pisar <ppisar at redhat.com>
+Date: Fri, 1 Jul 2011 10:13:54 +0200
+Subject: [PATCH 1/2] Report quotacheck failures by return code
+
+Signed-off-by: Jan Kara <jack at suse.cz>
+
+Petr Pisar: Back-ported to 3.17
+---
+ quotacheck.c |   57 ++++++++++++++++++++++++++++++++++++---------------------
+ 1 files changed, 36 insertions(+), 21 deletions(-)
+
+diff --git a/quotacheck.c b/quotacheck.c
+index 3c56eee..26fb035 100644
+--- a/quotacheck.c
++++ b/quotacheck.c
+@@ -850,8 +850,9 @@ static int dump_to_file(struct mntent *mnt, int type)
+ 	return 0;
+ }
+ 
+-/* Substract space used by old quota file from usage */
+-static void sub_quota_file(struct mntent *mnt, int qtype, int ftype)
++/* Substract space used by old quota file from usage.
++ * Return non-zero in case of failure, zero otherwise. */
++static int sub_quota_file(struct mntent *mnt, int qtype, int ftype)
+ {
+ 	char *filename;
+ 	struct stat st;
+@@ -862,13 +863,13 @@ static void sub_quota_file(struct mntent *mnt, int qtype, int ftype)
+ 	debug(FL_DEBUG, _("Substracting space used by old %s quota file.\n"), type2name(ftype));
+ 	if (get_qf_name(mnt, ftype, 1 << cfmt, 0, &filename) < 0) {
+ 		debug(FL_VERBOSE, _("Old %s file not found. Usage will not be substracted.\n"), type2name(ftype));
+-		return;
++		return 0;
+ 	}
+ 
+ 	if (stat(filename, &st) < 0) {
+ 		debug(FL_VERBOSE, _("Cannot stat old %s quota file: %s\n"), type2name(ftype), strerror(errno));
+ 		free(filename);
+-		return;
++		return 0;
+ 	}
+ 	qspace = getqsize(filename, &st);
+ 	free(filename);
+@@ -879,18 +880,21 @@ static void sub_quota_file(struct mntent *mnt, int qtype, int ftype)
+ 		id = st.st_gid;
+ 	if ((d = lookup_dquot(id, qtype)) == NODQUOT) {
+ 		errstr(_("Quota structure for %s owning quota file not present! Something is really wrong...\n"), type2name(qtype));
+-		return;
++		return -1;
+ 	}
+ 	d->dq_dqb.dqb_curinodes--;
+ 	d->dq_dqb.dqb_curspace -= qspace;
+ 	debug(FL_DEBUG, _("Substracted %lu bytes.\n"), (unsigned long)qspace);
++    return 0;
+ }
+ 
+-/* Buffer quotafile, run filesystem scan, dump quotafiles */
+-static void check_dir(struct mntent *mnt)
++/* Buffer quotafile, run filesystem scan, dump quotafiles.
++ * Return non-zero value in case of failure, zero otherwise. */
++static int check_dir(struct mntent *mnt)
+ {
+ 	struct stat st;
+ 	int remounted = 0;
++	int failed = 0;
+ 
+ 	if (lstat(mnt->mnt_dir, &st) < 0)
+ 		die(2, _("Cannot stat mountpoint %s: %s\n"), mnt->mnt_dir, strerror(errno));
+@@ -905,7 +909,7 @@ static void check_dir(struct mntent *mnt)
+ 		if (process_file(mnt, GRPQUOTA) < 0)
+ 			gcheck = 0;
+ 	if (!ucheck && !gcheck)	/* Nothing to check? */
+-		return;
++		return 0;
+ 	if (!(flags & FL_NOREMOUNT)) {
+ 		/* Now we try to remount fs read-only to prevent races when scanning filesystem */
+ 		if (mount
+@@ -915,12 +919,14 @@ static void check_dir(struct mntent *mnt)
+ 				printf(_("Cannot remount filesystem mounted on %s read-only. Counted values might not be right.\n"), mnt->mnt_dir);
+ 				if (!ask_yn(_("Should I continue"), 0)) {
+ 					printf(_("As you wish... Canceling check of this file.\n"));
++					failed = -1;
+ 					goto out;
+ 				}
+ 			}
+ 			else {
+ 				errstr(_("Cannot remount filesystem mounted on %s read-only so counted values might not be right.\n\
+ Please stop all programs writing to filesystem or use -m flag to force checking.\n"), mnt->mnt_dir);
++				failed = -1;
+ 				goto out;
+ 			}
+ 		}
+@@ -931,7 +937,7 @@ Please stop all programs writing to filesystem or use -m flag to force checking.
+ 	debug(FL_VERBOSE, _("Scanning %s [%s] "), mnt->mnt_fsname, mnt->mnt_dir);
+ #if defined(EXT2_DIRECT)
+ 	if (!strcmp(mnt->mnt_type, MNTTYPE_EXT2) || !strcmp(mnt->mnt_type, MNTTYPE_EXT3)) {
+-		if (ext2_direct_scan(mnt->mnt_fsname) < 0)
++		if ((failed = ext2_direct_scan(mnt->mnt_fsname)) < 0)
+ 			goto out;
+ 	}
+ 	else {
+@@ -940,19 +946,19 @@ Please stop all programs writing to filesystem or use -m flag to force checking.
+ #endif
+ 		if (flags & FL_VERYVERBOSE)
+ 			putchar('\n');
+-		if (scan_dir(mnt->mnt_dir) < 0)
++		if ((failed = scan_dir(mnt->mnt_dir)) < 0)
+ 			goto out;
+ 	}
+ 	dirs_done++;
+ 	if (flags & FL_VERBOSE || flags & FL_VERYVERBOSE)
+ 		fputs(_("done\n"), stdout);
+ 	if (ucheck) {
+-		sub_quota_file(mnt, USRQUOTA, USRQUOTA);
+-		sub_quota_file(mnt, USRQUOTA, GRPQUOTA);
++		failed |= sub_quota_file(mnt, USRQUOTA, USRQUOTA);
++		failed |= sub_quota_file(mnt, USRQUOTA, GRPQUOTA);
+ 	}
+ 	if (gcheck) {
+-		sub_quota_file(mnt, GRPQUOTA, USRQUOTA);
+-		sub_quota_file(mnt, GRPQUOTA, GRPQUOTA);
++		failed |= sub_quota_file(mnt, GRPQUOTA, USRQUOTA);
++		failed |= sub_quota_file(mnt, GRPQUOTA, GRPQUOTA);
+ 	}
+ 	debug(FL_DEBUG | FL_VERBOSE, _("Checked %d directories and %d files\n"), dirs_done,
+ 	      files_done);
+@@ -962,11 +968,12 @@ Please stop all programs writing to filesystem or use -m flag to force checking.
+ 		debug(FL_DEBUG, _("Filesystem remounted RW.\n"));
+ 	}
+ 	if (ucheck)
+-		dump_to_file(mnt, USRQUOTA);
++		failed |= dump_to_file(mnt, USRQUOTA);
+ 	if (gcheck)
+-		dump_to_file(mnt, GRPQUOTA);
++		failed |= dump_to_file(mnt, GRPQUOTA);
+ out:
+ 	remove_list();
++	return failed;
+ }
+ 
+ /* Detect quota format from filename of present files */
+@@ -1037,11 +1044,13 @@ jquota_err:
+ 	return -1;
+ }
+ 
+-static void check_all(void)
++/* Return 0 in case of success, non-zero otherwise. */
++static int check_all(void)
+ {
+ 	struct mntent *mnt;
+ 	int checked = 0;
+ 	static int warned;
++	int failed = 0;
+ 
+ 	if (init_mounts_scan((flags & FL_ALL) ? 0 : 1, &mntpoint, 0) < 0)
+ 		die(2, _("Cannot initialize mountpoint scan.\n"));
+@@ -1070,6 +1079,7 @@ static void check_all(void)
+ 			if ((cfmt = detect_filename_format(mnt, ucheck ? USRQUOTA : GRPQUOTA)) == -1) {
+ 				errstr(_("Cannot guess format from filename on %s. Please specify format on commandline.\n"),
+ 					mnt->mnt_fsname);
++				failed = -1;
+ 				continue;
+ 			}
+ 			debug(FL_DEBUG, _("Detected quota format %s\n"), fmt2name(cfmt));
+@@ -1106,25 +1116,30 @@ static void check_all(void)
+ 		}
+ 
+ 		checked++;
+-		check_dir(mnt);
++		failed |= check_dir(mnt);
+ 	}
+ 	end_mounts_scan();
+-	if (!checked && (!(flags & FL_ALL) || flags & (FL_VERBOSE | FL_DEBUG)))
++	if (!checked && (!(flags & FL_ALL) || flags & (FL_VERBOSE | FL_DEBUG))) {
+ 		errstr(_("Cannot find filesystem to check or filesystem not mounted with quota option.\n"));
++		failed = -1;
++    }
++    return failed;
+ }
+ 
+ int main(int argc, char **argv)
+ {
++	int failed;
++
+ 	gettexton();
+ 	progname = basename(argv[0]);
+ 
+ 	parse_options(argc, argv);
+ 	init_kernel_interface();
+ 
+-	check_all();
++	failed = check_all();
+ #ifdef DEBUG_MALLOC
+ 	errstr(_("Allocated %d bytes memory\nFree'd %d bytes\nLost %d bytes\n"),
+ 		malloc_mem, free_mem, malloc_mem - free_mem);
+ #endif
+-	return 0;
++	return (failed ? EXIT_FAILURE : EXIT_SUCCESS);
+ }
+-- 
+1.7.6
+
diff --git a/quota.spec b/quota.spec
index 6476782..7998f70 100644
--- a/quota.spec
+++ b/quota.spec
@@ -5,7 +5,7 @@ Name: quota
 Summary: System administration tools for monitoring users' disk usage
 Epoch: 1
 Version: 3.17
-Release: 16%{?dist}
+Release: 17%{?dist}
 License: BSD and GPLv2+
 URL: http://sourceforge.net/projects/linuxquota/
 Group: System Environment/Base
@@ -33,6 +33,8 @@ Patch10: quota-3.17-add-gfs2-support.patch
 Patch11: quota-3.17-use-proc-mounts-for-mountpoint-scanning.patch
 # Submitted to upstream (SF#3300978), bug #703567
 Patch12: quota-4.00_pre1-Make-dirname-static.patch
+# In upstream 4.00_pre2 (SF#3347047), bug #717982
+Patch13: quota-3.17-Report-quotacheck-failures-by-return-code.patch
 
 %description
 The quota package contains system administration tools for monitoring
@@ -68,6 +70,7 @@ on remote machines.
 %patch10 -p1 -b .gfs2
 %patch11 -p1 -b .use_proc_mounts
 %patch12 -p1 -b .static_dirname
+%patch13 -p1 -b .report_quotacheck_failures
 
 #fix typos/mistakes in localized documentation
 for pofile in $(find ./po/*.p*)
@@ -137,6 +140,9 @@ rm -rf %{buildroot}
 %attr(0644,root,root) %{_mandir}/man3/*
 
 %changelog
+* Fri Jul 15 2011 Petr Pisar <ppisar at redhat.com> - 1:3.17-17
+- Report quotacheck failures by return code (bug #717982)
+
 * Thu May 12 2011 Petr Pisar <ppisar at redhat.com> - 1:3.17-16
 - Make dirname static to work with nss_db (bug #703567)
 


More information about the scm-commits mailing list