From 872384d61b9cc393b06c3399afc3097a538d81bf Mon Sep 17 00:00:00 2001 From: jkar8572 Date: Tue, 13 Nov 2007 11:02:09 +0000 Subject: Added -c, --continue-batch option to setquota (8) (Jan Kara) --- Changelog | 2 +- setquota.8 | 5 ++++- setquota.c | 32 ++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index 5ad2e2b..3cea0d8 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,5 @@ Changes in quota-tools from 3.15 to 3.16 -* let setquota batch mode accept comments and blank lines (Jacky Bruno, Jan Kara) +* let setquota batch mode accept comments and blank lines, add -c option (Jacky Bruno, Jan Kara) * print more verbose list of compile options when --version specified (Jan Kara) * quotaon(8) should work only on local filesystems (Ladislav Michnovic) * made possible to use quota rpc in mixed NFSv3 and NFSv4 environments (Jan Kara) diff --git a/setquota.8 b/setquota.8 index 4593d9f..c8b6614 100644 --- a/setquota.8 +++ b/setquota.8 @@ -156,7 +156,10 @@ to set the quota for the named user or group. .B -b, --batch Read information to set from stdin (input format is .I name block-softlimit block-hardlimit inode-softlimit inode-hardlimit -). +). Empty lines and lines starting with # are ignored. +.TP +.B -c, --continue-batch +If parsing of an input line in batch mode fails, continue with processing the next line. .TP .B -t, --edit-period Set grace times for users/groups. Times diff --git a/setquota.c b/setquota.c index da0fbf5..73d9b6c 100644 --- a/setquota.c +++ b/setquota.c @@ -32,6 +32,7 @@ #define FL_BATCH 128 #define FL_NUMNAMES 256 #define FL_NO_MIXED_PATHS 512 +#define FL_CONTINUE_BATCH 1024 int flags, fmt = -1; char **mnt; @@ -52,7 +53,7 @@ static void usage(void) setquota [-u|-g] %1$s[-F quotaformat] \n\ \t -a|...\n\ setquota [-u|-g] %1$s[-F quotaformat] <-p protouser|protogroup> -a|...\n\ - setquota [-u|-g] %1$s[-F quotaformat] -b -a|...\n\ + setquota [-u|-g] %1$s[-F quotaformat] -b [-c] -a|...\n\ setquota [-u|-g] [-F quotaformat] -t -a|...\n\ setquota [-u|-g] [-F quotaformat] -T -a|...\n\n\ -u, --user set limits for user\n\ @@ -62,7 +63,8 @@ static void usage(void) composed only of digits\n\ -F, --format=formatname operate on specific quota format\n\ -p, --prototype=protoname copy limits from user/group\n\ --b, --batch read limits from standard input\n"), ropt); +-b, --batch read limits from standard input\n\ +-c, --continue-batch continue in input processing in case of an error\n"), ropt); #if defined(RPC_SETQUOTA) fputs(_("-r, --remote set remote quota (via RPC)\n\ -m, --no-mixed-pathnames trim leading slashes from NFSv4 mountpoints\n"), stderr); @@ -105,9 +107,9 @@ static void parse_options(int argcnt, char **argstr) char *protoname = NULL; #ifdef RPC_SETQUOTA - char *opts = "gp:urmVF:taTb"; + char *opts = "gp:urmVF:taTbc"; #else - char *opts = "gp:uVF:taTb"; + char *opts = "gp:uVF:taTbc"; #endif struct option long_opts[] = { { "user", 0, NULL, 'u' }, @@ -122,6 +124,7 @@ static void parse_options(int argcnt, char **argstr) { "edit-period", 0, NULL, 't' }, { "edit-times", 0, NULL, 'T' }, { "batch", 0, NULL, 'b' }, + { "continue", 0, NULL, 'c' }, { "format", 1, NULL, 'F' }, { "version", 0, NULL, 'V' }, { "help", 0, NULL, 'h' }, @@ -161,6 +164,9 @@ static void parse_options(int argcnt, char **argstr) case 'b': flags |= FL_BATCH; break; + case 'c': + flags |= FL_CONTINUE_BATCH; + break; case 'T': flags |= FL_INDIVIDUAL_GRACE; break; @@ -312,11 +318,21 @@ static int read_entry(qid_t *id, qsize_t *isoftlimit, qsize_t *ihardlimit, qsize if (*chptr == '\n') continue; ret = sscanf(chptr, "%s %lu %lu %lu %lu", name, &bs, &bh, &is, &ih); - if (ret != 5) - die(1, _("Cannot parse input line %d.\n"), line); + if (ret != 5) { + errstr(_("Cannot parse input line %d.\n"), line); + if (!(flags & FL_CONTINUE_BATCH)) + die(1, _("Exitting.\n")); + errstr(_("Skipping line.\n")); + continue; + } *id = name2id(name, flag2type(flags), !!(flags & FL_NUMNAMES), &ret); - if (ret) - die(1, _("Unable to resolve name '%s' on line %d.\n"), name, line); + if (ret) { + errstr(_("Unable to resolve name '%s' on line %d.\n"), name, line); + if (!(flags & FL_CONTINUE_BATCH)) + die(1, _("Exitting.\n")); + errstr(_("Skipping line.\n")); + continue; + } break; } *isoftlimit = is; -- cgit v1.2.3