summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog1
-rw-r--r--setquota.c27
2 files changed, 21 insertions, 7 deletions
diff --git a/Changelog b/Changelog
index b6f344c..5ad2e2b 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +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)
* 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.c b/setquota.c
index 78c8317..da0fbf5 100644
--- a/setquota.c
+++ b/setquota.c
@@ -11,6 +11,7 @@
#include <string.h>
#include <getopt.h>
#include <time.h>
+#include <ctype.h>
#if defined(RPC)
#include "rquota.h"
@@ -284,28 +285,40 @@ static int setlimits(struct quota_handle **handles)
return ret;
}
-#define MAXLINELEN (MAXNUMLEN*4+MAXNAMELEN+16)
+#define MAXLINELEN 65536
/* Read & parse one batch entry */
static int read_entry(qid_t *id, qsize_t *isoftlimit, qsize_t *ihardlimit, qsize_t *bsoftlimit, qsize_t *bhardlimit)
{
static int line = 0;
char name[MAXNAMELEN+1];
+ char linebuf[MAXLINELEN], *chptr;
unsigned long is, ih, bs, bh;
int ret;
- do {
+ while (1) {
line++;
- ret = scanf("%s %lu %lu %lu %lu", name, &bs, &bh, &is, &ih);
- if (ret == -1)
+ if (!fgets(linebuf, sizeof(linebuf), stdin))
return -1;
+ if (linebuf[strlen(linebuf)-1] != '\n')
+ die(1, _("Line %d too long.\n"), line);
+ /* Comment? */
+ if (linebuf[0] == '#')
+ continue;
+ /* Blank line? */
+ chptr = linebuf;
+ while (isblank(*chptr))
+ chptr++;
+ 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);
- ret = 0;
*id = name2id(name, flag2type(flags), !!(flags & FL_NUMNAMES), &ret);
if (ret)
- errstr(_("Unable to get name '%s'.\n"), name);
- } while (ret);
+ die(1, _("Unable to resolve name '%s' on line %d.\n"), name, line);
+ break;
+ }
*isoftlimit = is;
*ihardlimit = ih;
*bsoftlimit = bs;