xfs
[Top] [All Lists]

[PATCH 4/6] xfs_quota: Return non zero exit status in error conditions.

To: linux-xfs@xxxxxxxxxxx
Subject: [PATCH 4/6] xfs_quota: Return non zero exit status in error conditions.
From: Arkadiusz Miskiewicz <arekm@xxxxxxxx>
Date: Mon, 15 Dec 2008 20:29:44 +0100
Cc: Arkadiusz Miskiewicz <arekm@xxxxxxxx>
In-reply-to: <1229369386-66312-3-git-send-email-arekm@xxxxxxxx>
References: <1229369386-66312-1-git-send-email-arekm@xxxxxxxx> <1229369386-66312-2-git-send-email-arekm@xxxxxxxx> <1229369386-66312-3-git-send-email-arekm@xxxxxxxx>
Patch by Arkadiusz Miśkiewicz <arekm@xxxxxxxx>.
---
 xfsprogs/quota/edit.c    |   45 ++++++++++++++++++++++++++++++---------------
 xfsprogs/quota/free.c    |    5 +++++
 xfsprogs/quota/project.c |   29 ++++++++++++++++++++++-------
 xfsprogs/quota/quota.c   |    4 ++++
 xfsprogs/quota/report.c  |    1 +
 xfsprogs/quota/state.c   |    4 ++++
 xfsprogs/quota/util.c    |    2 ++
 7 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/xfsprogs/quota/edit.c b/xfsprogs/quota/edit.c
index a60d37e..15c72c4 100644
--- a/xfsprogs/quota/edit.c
+++ b/xfsprogs/quota/edit.c
@@ -140,9 +140,11 @@ set_limits(
        d.d_rtb_hardlimit = *rtbhard;
        d.d_rtb_softlimit = *rtbsoft;
 
-       if (xfsquotactl(XFS_SETQLIM, dev, type, id, (void *)&d) < 0)
+       if (xfsquotactl(XFS_SETQLIM, dev, type, id, (void *)&d) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot set limits: %s\n"),
                                progname, strerror(errno));
+       }
 }
 
 static void
@@ -159,10 +161,11 @@ set_user_limits(
 {
        uid_t           uid = uid_from_string(name);
 
-       if (uid == -1)
+       if (uid == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: invalid user name: %s\n"),
                                progname, name);
-       else
+       } else
                set_limits(uid, type, mask, fs_path->fs_name,
                                bsoft, bhard, isoft, ihard, rtbsoft, rtbhard);
 }
@@ -181,10 +184,11 @@ set_group_limits(
 {
        gid_t           gid = gid_from_string(name);
 
-       if (gid == -1)
+       if (gid == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: invalid group name: %s\n"),
                                progname, name);
-       else
+       } else
                set_limits(gid, type, mask, fs_path->fs_name,
                                bsoft, bhard, isoft, ihard, rtbsoft, rtbhard);
 }
@@ -203,10 +207,11 @@ set_project_limits(
 {
        prid_t          prid = prid_from_string(name);
 
-       if (prid == -1)
+       if (prid == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: invalid project name: %s\n"),
                                progname, name);
-       else
+       } else
                set_limits(prid, type, mask, fs_path->fs_name,
                                bsoft, bhard, isoft, ihard, rtbsoft, rtbhard);
 }
@@ -315,12 +320,14 @@ limit_f(
                else if (extractb(s, "rtbhard=", 7, bsize, ssize, &rtbhard))
                        mask |= FS_DQ_RTBHARD;
                else {
+                       exitcode = 1;
                        fprintf(stderr, _("%s: unrecognised argument %s\n"),
                                progname, s);
                        return 0;
                }
        }
        if (!mask) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot find any valid arguments\n"),
                        progname);
                return 0;
@@ -428,6 +435,7 @@ restore_f(
 
        if (fname) {
                if ((fp = fopen(fname, "r")) == NULL) {
+                       exitcode = 1;
                        fprintf(stderr, _("%s: fopen on %s failed: %s\n"),
                                progname, fname, strerror(errno));
                        return 0;
@@ -458,9 +466,11 @@ set_timer(
        d.d_btimer = value;
        d.d_rtbtimer = value;
 
-       if (xfsquotactl(XFS_SETQLIM, dev, type, 0, (void *)&d) < 0)
+       if (xfsquotactl(XFS_SETQLIM, dev, type, 0, (void *)&d) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot set timer: %s\n"),
                                progname, strerror(errno));
+       }
 }
 
 static int
@@ -530,9 +540,11 @@ set_warnings(
        d.d_bwarns = value;
        d.d_rtbwarns = value;
 
-       if (xfsquotactl(XFS_SETQLIM, dev, type, id, (void *)&d) < 0)
+       if (xfsquotactl(XFS_SETQLIM, dev, type, id, (void *)&d) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot set warnings: %s\n"),
                                progname, strerror(errno));
+       }
 }
 
 static void
@@ -544,10 +556,11 @@ set_user_warnings(
 {
        uid_t           uid = uid_from_string(name);
 
-       if (uid == -1)
+       if (uid == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: invalid user name: %s\n"),
                                progname, name);
-       else
+       } else
                set_warnings(uid, type, mask, fs_path->fs_name, value);
 }
 
@@ -560,10 +573,11 @@ set_group_warnings(
 {
        gid_t           gid = gid_from_string(name);
 
-       if (gid == -1)
+       if (gid == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: invalid group name: %s\n"),
                                progname, name);
-       else
+       } else
                set_warnings(gid, type, mask, fs_path->fs_name, value);
 }
 
@@ -576,10 +590,11 @@ set_project_warnings(
 {
        prid_t          prid = prid_from_string(name);
 
-       if (prid == -1)
+       if (prid == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: invalid project name: %s\n"),
                                progname, name);
-       else
+       } else
                set_warnings(prid, type, mask, fs_path->fs_name, value);
 }
 
diff --git a/xfsprogs/quota/free.c b/xfsprogs/quota/free.c
index 28b944b..1f10ded 100644
--- a/xfsprogs/quota/free.c
+++ b/xfsprogs/quota/free.c
@@ -61,6 +61,7 @@ mount_free_space_data(
        int                     fd;
 
        if ((fd = open(mount->fs_dir, O_RDONLY)) < 0) {
+               exitcode = 1;
                fprintf(stderr, "%s: cannot open %s: %s\n",
                        progname, mount->fs_dir, strerror(errno));
                return 0;
@@ -128,17 +129,20 @@ projects_free_space_data(
                return 0;
 
        if ((fd = open(path->fs_dir, O_RDONLY)) < 0) {
+               exitcode = 1;
                fprintf(stderr, "%s: cannot open %s: %s\n",
                        progname, path->fs_dir, strerror(errno));
                return 0;
        }
 
        if ((xfsctl(path->fs_dir, fd, XFS_IOC_FSGETXATTR, &fsx)) < 0) {
+               exitcode = 1;
                perror("XFS_IOC_FSGETXATTR");
                close(fd);
                return 0;
        }
        if (!(fsx.fsx_xflags & XFS_XFLAG_PROJINHERIT)) {
+               exitcode = 1;
                fprintf(stderr, _("%s: project quota flag not set on %s\n"),
                        progname, path->fs_dir);
                close(fd);
@@ -146,6 +150,7 @@ projects_free_space_data(
        }
 
        if (path->fs_prid != fsx.fsx_projid) {
+               exitcode = 1;
                fprintf(stderr,
                        _("%s: project ID %u (%s) doesn't match ID %u (%s)\n"),
                        progname, path->fs_prid, projects_file,
diff --git a/xfsprogs/quota/project.c b/xfsprogs/quota/project.c
index e2e61c3..7eac8e4 100644
--- a/xfsprogs/quota/project.c
+++ b/xfsprogs/quota/project.c
@@ -91,6 +91,7 @@ check_project(
        int                     fd;
 
        if (flag == FTW_NS ){
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
                return 0;
        }
@@ -99,13 +100,15 @@ check_project(
                return 0;
        }
 
-       if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1)
+       if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
-       else if ((xfsctl(path, fd, XFS_IOC_FSGETXATTR, &fsx)) < 0)
+       } else if ((xfsctl(path, fd, XFS_IOC_FSGETXATTR, &fsx)) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, path, strerror(errno));
-       else {
+       } else {
                if (fsx.fsx_projid != prid)
                        printf(_("%s - project identifier is not set"
                                 " (inode=%u, tree=%u)\n"),
@@ -130,6 +133,7 @@ clear_project(
        int                     fd;
 
        if (flag == FTW_NS ){
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
                return 0;
        }
@@ -139,10 +143,12 @@ clear_project(
        }
 
        if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
                return 0;
        } else if (xfsctl(path, fd, XFS_IOC_FSGETXATTR, &fsx) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, path, strerror(errno));
                close(fd);
@@ -151,9 +157,11 @@ clear_project(
 
        fsx.fsx_projid = 0;
        fsx.fsx_xflags &= ~XFS_XFLAG_PROJINHERIT;
-       if (xfsctl(path, fd, XFS_IOC_FSSETXATTR, &fsx) < 0)
+       if (xfsctl(path, fd, XFS_IOC_FSSETXATTR, &fsx) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
                        progname, path, strerror(errno));
+       }
        close(fd);
        return 0;
 }
@@ -169,6 +177,7 @@ setup_project(
        int                     fd;
 
        if (flag == FTW_NS ){
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
                return 0;
        }
@@ -178,10 +187,12 @@ setup_project(
        }
 
        if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
                return 0;
        } else if (xfsctl(path, fd, XFS_IOC_FSGETXATTR, &fsx) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, path, strerror(errno));
                close(fd);
@@ -190,9 +201,11 @@ setup_project(
 
        fsx.fsx_projid = prid;
        fsx.fsx_xflags |= XFS_XFLAG_PROJINHERIT;
-       if (xfsctl(path, fd, XFS_IOC_FSSETXATTR, &fsx) < 0)
+       if (xfsctl(path, fd, XFS_IOC_FSSETXATTR, &fsx) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
                        progname, path, strerror(errno));
+       }
        close(fd);
        return 0;
 }
@@ -272,6 +285,7 @@ project_f(
 
        setprfiles();
        if (access(projects_file, F_OK) != 0) {
+               exitcode = 1;
                fprintf(stderr, _("projects file \"%s\" doesn't exist\n"),
                        projects_file);
                return 0;
@@ -279,10 +293,11 @@ project_f(
 
         while (argc > optind) {
                prid = prid_from_string(argv[optind]);
-               if (prid == -1)
+               if (prid == -1) {
+                       exitcode = 1;
                        fprintf(stderr, _("%s - no such project in %s\n"),
                                argv[optind], projects_file);
-               else
+               } else
                        project(argv[optind], type);
                optind++;
        }
diff --git a/xfsprogs/quota/quota.c b/xfsprogs/quota/quota.c
index b3b65eb..4a1f39f 100644
--- a/xfsprogs/quota/quota.c
+++ b/xfsprogs/quota/quota.c
@@ -231,6 +231,7 @@ quota_user_type(
                        id = u->pw_uid;
                        name = u->pw_name;
                } else {
+                       exitcode = 1;
                        fprintf(stderr, _("%s: cannot find user %s\n"),
                                progname, name);
                        return;
@@ -280,6 +281,7 @@ quota_group_type(
                                gid = g->gr_gid;
                                name = g->gr_name;
                        } else {
+                               exitcode = 1;
                                fprintf(stderr, _("%s: cannot find group %s\n"),
                                        progname, name);
                                return;
@@ -336,6 +338,7 @@ quota_proj_type(
        prid_t          id;
 
        if (!name) {
+               exitcode = 1;
                fprintf(stderr, _("%s: must specify a project name/ID\n"),
                        progname);
                return;
@@ -348,6 +351,7 @@ quota_proj_type(
                id = p->pr_prid;
                name = p->pr_name;
        } else {
+               exitcode = 1;
                fprintf(stderr, _("%s: cannot find project %s\n"),
                        progname, name);
                return;
diff --git a/xfsprogs/quota/report.c b/xfsprogs/quota/report.c
index 332c3cc..7902dbd 100644
--- a/xfsprogs/quota/report.c
+++ b/xfsprogs/quota/report.c
@@ -115,6 +115,7 @@ dump_limits_any_type(
        uint            id;
 
        if ((mount = fs_table_lookup(dir, FS_MOUNT_POINT)) == NULL) {
+               exitcode = 1;
                fprintf(stderr, "%s: cannot find mount point %s\n",
                        progname, dir);
                return;
diff --git a/xfsprogs/quota/state.c b/xfsprogs/quota/state.c
index dd1eeec..aa03340 100644
--- a/xfsprogs/quota/state.c
+++ b/xfsprogs/quota/state.c
@@ -253,6 +253,7 @@ enable_enforcement(
 
        mount = fs_table_lookup(dir, FS_MOUNT_POINT);
        if (!mount) {
+               exitcode = 1;
                fprintf(stderr, "%s: unknown mount point %s\n", progname, dir);
                return;
        }
@@ -274,6 +275,7 @@ disable_enforcement(
 
        mount = fs_table_lookup(dir, FS_MOUNT_POINT);
        if (!mount) {
+               exitcode = 1;
                fprintf(stderr, "%s: unknown mount point %s\n", progname, dir);
                return;
        }
@@ -295,6 +297,7 @@ quotaoff(
 
        mount = fs_table_lookup(dir, FS_MOUNT_POINT);
        if (!mount) {
+               exitcode = 1;
                fprintf(stderr, "%s: unknown mount point %s\n", progname, dir);
                return;
        }
@@ -327,6 +330,7 @@ remove_extents(
 
        mount = fs_table_lookup(dir, FS_MOUNT_POINT);
        if (!mount) {
+               exitcode = 1;
                fprintf(stderr, "%s: unknown mount point %s\n", progname, dir);
                return;
        }
diff --git a/xfsprogs/quota/util.c b/xfsprogs/quota/util.c
index 274bfe6..18ccae2 100644
--- a/xfsprogs/quota/util.c
+++ b/xfsprogs/quota/util.c
@@ -413,11 +413,13 @@ fopen_write_secure(
                return stdout;
 
        if ((fd = open(fname, O_CREAT|O_WRONLY|O_EXCL, 0600)) < 0) {
+               exitcode = 1;
                fprintf(stderr, _("%s: open on %s failed: %s\n"),
                        progname, fname, strerror(errno));
                return NULL;
        }
        if ((fp = fdopen(fd, "w")) == NULL) {
+               exitcode = 1;
                fprintf(stderr, _("%s: fdopen on %s failed: %s\n"),
                        progname, fname, strerror(errno));
                close(fd);
-- 
1.6.0.5

<Prev in Thread] Current Thread [Next in Thread>