Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin - KNF



details:   https://anonhg.NetBSD.org/src/rev/c66a30061cc9
branches:  trunk
changeset: 762972:c66a30061cc9
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 06 22:33:55 2011 +0000

description:
- KNF
- merge code
- fix error printing
- don't use static buffers

diffstat:

 usr.sbin/edquota/Makefile    |    6 +-
 usr.sbin/edquota/edquota.c   |  474 ++++++++++++++++++------------------------
 usr.sbin/repquota/Makefile   |    5 +-
 usr.sbin/repquota/repquota.c |  281 +++++++++---------------
 4 files changed, 315 insertions(+), 451 deletions(-)

diffs (truncated from 1474 to 300 lines):

diff -r 6b5fffb39daf -r c66a30061cc9 usr.sbin/edquota/Makefile
--- a/usr.sbin/edquota/Makefile Sun Mar 06 22:15:29 2011 +0000
+++ b/usr.sbin/edquota/Makefile Sun Mar 06 22:33:55 2011 +0000
@@ -1,7 +1,9 @@
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
-#      $NetBSD: Makefile,v 1.6 2011/03/06 17:08:42 bouyer Exp $
+#      $NetBSD: Makefile,v 1.7 2011/03/06 22:34:57 christos Exp $
 
 .include <bsd.own.mk>
+
+WARNS ?= 4
 PROG=  edquota
 SRCS=  edquota.c
 MAN=   edquota.8
@@ -11,7 +13,7 @@
 LDADD= -lprop
 
 .PATH: ${NETBSDSRCDIR}/usr.bin/quota
-SRCS+= getvfsquota.c printquota.c
+SRCS+= getvfsquota.c printquota.c quotautil.c
 .PATH: ${NETBSDSRCDIR}/sys/ufs/ufs 
 SRCS+= quota2_prop.c quota1_subr.c
 
diff -r 6b5fffb39daf -r c66a30061cc9 usr.sbin/edquota/edquota.c
--- a/usr.sbin/edquota/edquota.c        Sun Mar 06 22:15:29 2011 +0000
+++ b/usr.sbin/edquota/edquota.c        Sun Mar 06 22:33:55 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: edquota.c,v 1.30 2011/03/06 17:08:42 bouyer Exp $ */
+/*      $NetBSD: edquota.c,v 1.31 2011/03/06 22:34:57 christos Exp $ */
 /*
  * Copyright (c) 1980, 1990, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "from: @(#)edquota.c    8.3 (Berkeley) 4/27/95";
 #else
-__RCSID("$NetBSD: edquota.c,v 1.30 2011/03/06 17:08:42 bouyer Exp $");
+__RCSID("$NetBSD: edquota.c,v 1.31 2011/03/06 22:34:57 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -73,14 +73,14 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <printquota.h>
-#include <getvfsquota.h>
+#include "printquota.h"
+#include "getvfsquota.h"
+#include "quotautil.h"
 
 #include "pathnames.h"
 
-const char *qfname = QUOTAFILENAME;
-const char *quotagroup = QUOTAGROUP;
-char tmpfil[] = _PATH_TMP;
+static const char *quotagroup = QUOTAGROUP;
+static char tmpfil[] = _PATH_TMP;
 
 struct quotause {
        struct  quotause *next;
@@ -95,34 +95,27 @@
 
 #define MAX_TMPSTR     (100+MAXPATHLEN)
 
-int    main(int, char **);
-void   usage(void);
-int    getentry(const char *, int);
-struct quotause * getprivs(long, int, const char *, int);
-struct quotause * getprivs2(long, int, const char *, int);
-struct quotause * getprivs1(long, int, const char *);
-void   putprivs(long, int, struct quotause *);
-void   putprivs2(long, int, struct quotause *);
-void   putprivs1(long, int, struct quotause *);
-int    editit(char *);
-int    writeprivs(struct quotause *, int, char *, int);
-int    readprivs(struct quotause *, int);
-int    writetimes(struct quotause *, int, int);
-int    readtimes(struct quotause *, int);
-void   freeq(struct quotause *);
-void   freeprivs(struct quotause *);
-int    alldigits(const char *);
-int    hasquota(struct fstab *, int, char **);
+static void    usage(void) __attribute__((__noreturn__));
+static int     getentry(const char *, int);
+static struct quotause * getprivs(long, int, const char *, int);
+static struct quotause * getprivs2(long, int, const char *, int);
+static struct quotause * getprivs1(long, int, const char *);
+static void    putprivs(uint32_t, int, struct quotause *);
+static void    putprivs2(uint32_t, int, struct quotause *);
+static void    putprivs1(uint32_t, int, struct quotause *);
+static int     editit(const char *);
+static int     writeprivs(struct quotause *, int, const char *, int);
+static int     readprivs(struct quotause *, int);
+static void    freeq(struct quotause *);
+static void    freeprivs(struct quotause *);
 static void clearpriv(int, char **, const char *, int);
 
-int Hflag = 0;
-int Dflag = 0;
-int dflag = 0;
+static int Hflag = 0;
+static int Dflag = 0;
+static int dflag = 0;
 
 int
-main(argc, argv)
-       int argc;
-       char **argv;
+main(int argc, char *argv[])
 {
        struct quotause *qup, *protoprivs, *curprivs;
        long id, protoid;
@@ -187,7 +180,7 @@
                if (soft || hard || grace || dflag || cflag)
                        usage();
                if ((protoid = getentry(protoname, quotatype)) == -1)
-                       exit(1);
+                       return 1;
                protoprivs = getprivs(protoid, quotatype, fs, 0);
                for (qup = protoprivs; qup; qup = qup->next) {
                        qup->q2e.q2e_val[QL_BLOCK].q2v_time = 0;
@@ -198,7 +191,7 @@
                                continue;
                        putprivs(id, quotatype, protoprivs);
                }
-               exit(0);
+               return 0;
        }
        if (soft || hard || grace) {
                struct quotause *lqup;
@@ -241,61 +234,65 @@
                if (dflag) {
                        curprivs = getprivs(0, quotatype, fs, 1);
                        for (lqup = curprivs; lqup; lqup = lqup->next) {
+                               struct quota2_val *q = lqup->q2e.q2e_val;
                                if (soft) {
-                                       lqup->q2e.q2e_val[QL_BLOCK].q2v_softlimit = softb;
-                                       lqup->q2e.q2e_val[QL_FILE].q2v_softlimit = softi;
+                                       q[QL_BLOCK].q2v_softlimit = softb;
+                                       q[QL_FILE].q2v_softlimit = softi;
                                }
                                if (hard) {
-                                       lqup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit = hardb;
-                                       lqup->q2e.q2e_val[QL_FILE].q2v_hardlimit = hardi;
+                                       q[QL_BLOCK].q2v_hardlimit = hardb;
+                                       q[QL_FILE].q2v_hardlimit = hardi;
                                }
                                if (grace) {
-                                       lqup->q2e.q2e_val[QL_BLOCK].q2v_grace = graceb;
-                                       lqup->q2e.q2e_val[QL_FILE].q2v_grace = gracei;
+                                       q[QL_BLOCK].q2v_grace = graceb;
+                                       q[QL_FILE].q2v_grace = gracei;
                                }
                        }
                        putprivs(0, quotatype, curprivs);
                        freeprivs(curprivs);
-                       exit(0);
+                       return 0;
                }
                for ( ; argc > 0; argc--, argv++) {
                        if ((id = getentry(*argv, quotatype)) == -1)
                                continue;
                        curprivs = getprivs(id, quotatype, fs, 0);
                        for (lqup = curprivs; lqup; lqup = lqup->next) {
+                               struct quota2_val *q = lqup->q2e.q2e_val;
                                if (soft) {
                                        if (softb &&
-                                           lqup->q2e.q2e_val[QL_BLOCK].q2v_cur >= softb &&
-                                           (lqup->q2e.q2e_val[QL_BLOCK].q2v_softlimit == 0 ||
-                                           lqup->q2e.q2e_val[QL_BLOCK].q2v_cur < lqup->q2e.q2e_val[QL_BLOCK].q2v_softlimit))
-                                               lqup->q2e.q2e_val[QL_BLOCK].q2v_time = 0;
+                                           q[QL_BLOCK].q2v_cur >= softb &&
+                                           (q[QL_BLOCK].q2v_softlimit == 0 ||
+                                           q[QL_BLOCK].q2v_cur <
+                                           q[QL_BLOCK].q2v_softlimit))
+                                               q[QL_BLOCK].q2v_time = 0;
                                        if (softi &&
-                                           lqup->q2e.q2e_val[QL_FILE].q2v_cur >= softb &&
-                                           (lqup->q2e.q2e_val[QL_FILE].q2v_softlimit == 0 ||
-                                           lqup->q2e.q2e_val[QL_FILE].q2v_cur < lqup->q2e.q2e_val[QL_FILE].q2v_softlimit))
-                                               lqup->q2e.q2e_val[QL_FILE].q2v_time = 0;
-                                       lqup->q2e.q2e_val[QL_BLOCK].q2v_softlimit = softb;
-                                       lqup->q2e.q2e_val[QL_FILE].q2v_softlimit = softi;
+                                           q[QL_FILE].q2v_cur >= softb &&
+                                           (q[QL_FILE].q2v_softlimit == 0 ||
+                                           q[QL_FILE].q2v_cur <
+                                           q[QL_FILE].q2v_softlimit))
+                                               q[QL_FILE].q2v_time = 0;
+                                       q[QL_BLOCK].q2v_softlimit = softb;
+                                       q[QL_FILE].q2v_softlimit = softi;
                                }
                                if (hard) {
-                                       lqup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit = hardb;
-                                       lqup->q2e.q2e_val[QL_FILE].q2v_hardlimit = hardi;
+                                       q[QL_BLOCK].q2v_hardlimit = hardb;
+                                       q[QL_FILE].q2v_hardlimit = hardi;
                                }
                                if (grace) {
-                                       lqup->q2e.q2e_val[QL_BLOCK].q2v_grace = graceb;
-                                       lqup->q2e.q2e_val[QL_FILE].q2v_grace = gracei;
+                                       q[QL_BLOCK].q2v_grace = graceb;
+                                       q[QL_FILE].q2v_grace = gracei;
                                }
                        }
                        putprivs(id, quotatype, curprivs);
                        freeprivs(curprivs);
                }
-               exit(0);
+               return 0;
        }
        if (cflag) {
                if (dflag)
                        usage();
                clearpriv(argc, argv, fs, quotatype);
-               exit(0);
+               return 0;
        }
        tmpfd = mkstemp(tmpfil);
        fchown(tmpfd, getuid(), getgid());
@@ -318,21 +315,25 @@
        }
        close(tmpfd);
        unlink(tmpfil);
-       exit(0);
+       return 0;
 }
 
-void
-usage()
+static void
+usage(void)
 {
+       const char *p = getprogname();
        fprintf(stderr,
-           "usage:\n"
-           "  edquota [-D] [-H] [-u] [-p username] [-f filesystem] -d | username ...\n"
-           "  edquota [-D] [-H] -g [-p groupname] [-f filesystem] -d | groupname ...\n"
-           "  edquota [-D] [-u] [-f filesystem] [-s b#/i#] [-h b#/i#] [-t t#/t#] \\\n\t-d | username ...\n"
-           "  edquota [-D] -g [-f filesystem] [-s b#/i#] [-h b#/i#] [-t t#/t#] \\\n\t-d | groupname ...\n"
-           "  edquota [-D] [-H] [-u] -c [-f filesystem] username ...\n"
-           "  edquota [-D] [-H] -g -c [-f filesystem] groupname ...\n"
-           );
+           "Usage: %s [-D] [-H] [-u] [-p <username>] [-f <filesystem>] "
+               "-d | <username> ...\n"
+           "\t%s [-D] [-H] -g [-p <groupname>] [-f <filesystem>] "
+               "-d | <groupname> ...\n"
+           "\t%s [-D] [-u] [-f <filesystem>] [-s b#/i#] [-h b#/i#] [-t t#/t#] "
+               "-d | <username> ...\n"
+           "\t%s [-D] -g [-f <filesystem>] [-s b#/i#] [-h b#/i#] [-t t#/t#] "
+               "-d | <groupname> ...\n"
+           "\t%s [-D] [-H] [-u] -c [-f <filesystem>] username ...\n"
+           "\t%s [-D] [-H] -g -c [-f <filesystem>] groupname ...\n",
+           p, p, p, p, p, p);
        exit(1);
 }
 
@@ -341,25 +342,23 @@
  * an identifier. This routine must agree with the kernel routine
  * getinoquota as to the interpretation of quota types.
  */
-int
-getentry(name, quotatype)
-       const char *name;
-       int quotatype;
+static int
+getentry(const char *name, int quotatype)
 {
        struct passwd *pw;
        struct group *gr;
 
        if (alldigits(name))
-               return (atoi(name));
+               return atoi(name);
        switch(quotatype) {
        case USRQUOTA:
                if ((pw = getpwnam(name)) != NULL)
-                       return (pw->pw_uid);
+                       return pw->pw_uid;
                warnx("%s: no such user", name);
                break;
        case GRPQUOTA:
                if ((gr = getgrnam(name)) != NULL)
-                       return (gr->gr_gid);
+                       return gr->gr_gid;
                warnx("%s: no such group", name);
                break;
        default:
@@ -367,13 +366,13 @@
                break;
        }
        sleep(1);
-       return (-1);
+       return -1;
 }
 
 /*
  * Collect the requested quota information.
  */
-struct quotause *



Home | Main Index | Thread Index | Old Index