summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2015-01-05 15:50:24 +0100
committerJan Kara <jack@suse.cz>2015-01-05 15:50:24 +0100
commit885a0205b2639e38fdde52754b8075fba8559a71 (patch)
treee5bfe1e23f751070bb8c73485487f6a6e584943f
parent13d47cc8fde955bbf1bffa6f98c0b75f52269e75 (diff)
edquota: Unify code for editing grace times and quota limits
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--edquota.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/edquota.c b/edquota.c
index 872e642..266e67c 100644
--- a/edquota.c
+++ b/edquota.c
@@ -290,42 +290,24 @@ int main(int argc, char **argv)
ret = -1;
}
}
- else if (flags & FL_EDIT_TIMES) {
- for (; argc > 0; argc--, argv++) {
- id = name2id(*argv, quotatype, !!(flags & FL_NUMNAMES), NULL);
- curprivs = getprivs(id, handles, 0);
- if (!curprivs)
- die(1, _("Cannot get quota information for user %s.\n"), *argv);
- if (writeindividualtimes(curprivs, tmpfd, *argv, quotatype) < 0) {
- errstr(_("Cannot write individual grace times to file.\n"));
- ret = -1;
- continue;
- }
- if (editprivs(tmpfil) < 0) {
- errstr(_("Error while editing individual grace times.\n"));
- ret = -1;
- continue;
- }
- if (readindividualtimes(curprivs, tmpfd) < 0) {
- errstr(_("Cannot read individual grace times from file.\n"));
- ret = -1;
- continue;
- }
- if (putprivs(curprivs, COMMIT_TIMES) == -1)
- ret = -1;
- freeprivs(curprivs);
- }
- }
else {
for (; argc > 0; argc--, argv++) {
id = name2id(*argv, quotatype, !!(flags & FL_NUMNAMES), NULL);
curprivs = getprivs(id, handles, 0);
if (!curprivs)
die(1, _("Cannot get quota information for user %s.\n"), *argv);
- if (writeprivs(curprivs, tmpfd, *argv, quotatype) < 0) {
- errstr(_("Cannot write quotas to file.\n"));
- ret = -1;
- continue;
+ if (flags & FL_EDIT_TIMES) {
+ if (writeindividualtimes(curprivs, tmpfd, *argv, quotatype) < 0) {
+ errstr(_("Cannot write individual grace times to file.\n"));
+ ret = -1;
+ continue;
+ }
+ } else {
+ if (writeprivs(curprivs, tmpfd, *argv, quotatype) < 0) {
+ errstr(_("Cannot write quotas to file.\n"));
+ ret = -1;
+ continue;
+ }
}
if (editprivs(tmpfil) < 0) {
errstr(_("Error while editing quotas.\n"));
@@ -339,10 +321,18 @@ int main(int argc, char **argv)
*/
if ((tmpfd = open(tmpfil, O_RDWR)) < 0)
die(1, _("Cannot reopen!"));
- if (readprivs(curprivs, tmpfd) < 0) {
- errstr(_("Cannot read quotas from file.\n"));
- ret = -1;
- continue;
+ if (flags & FL_EDIT_TIMES) {
+ if (readindividualtimes(curprivs, tmpfd) < 0) {
+ errstr(_("Cannot read individual grace times from file.\n"));
+ ret = -1;
+ continue;
+ }
+ } else {
+ if (readprivs(curprivs, tmpfd) < 0) {
+ errstr(_("Cannot read quotas from file.\n"));
+ ret = -1;
+ continue;
+ }
}
if (putprivs(curprivs, COMMIT_LIMITS) == -1)
ret = -1;