Fix some low-hanging fruit in the warnings department; ANSIfy functions,
sort out some const issues.
This commit is contained in:
parent
2720780e6c
commit
a62032343e
@ -38,43 +38,44 @@
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1980, 1990, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Disk quota reporting program.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpcsvc/rquota.h>
|
||||
|
||||
#include <ufs/ufs/quota.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <fstab.h>
|
||||
#include <grp.h>
|
||||
#include <netdb.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpcsvc/rquota.h>
|
||||
|
||||
char *qfname = QUOTAFILENAME;
|
||||
char *qfextension[] = INITQFNAMES;
|
||||
const char *qfname = QUOTAFILENAME;
|
||||
const char *qfextension[] = INITQFNAMES;
|
||||
|
||||
struct quotause {
|
||||
struct quotause *next;
|
||||
@ -84,34 +85,31 @@ struct quotause {
|
||||
};
|
||||
#define FOUND 0x01
|
||||
|
||||
static char *timeprt(time_t seconds);
|
||||
static const char *timeprt(time_t seconds);
|
||||
static struct quotause *getprivs(long id, int quotatype);
|
||||
static void usage ();
|
||||
static void usage(void);
|
||||
static void showuid(u_long uid);
|
||||
static void showgid(u_long gid);
|
||||
static int alldigits(char *s);
|
||||
static void showusrname(char *name);
|
||||
static void showgrpname(char *name);
|
||||
static void showquotas(int type, u_long id, char *name);
|
||||
static void heading(int type, u_long id, char *name, char *tag);
|
||||
static char *timeprt(time_t seconds);
|
||||
static void showquotas(int type, u_long id, const char *name);
|
||||
static void heading(int type, u_long id, const char *name, const char *tag);
|
||||
static struct quotause *getprivs(long id, int quotatype);
|
||||
static int ufshasquota(struct fstab *fs, int type, char **qfnamep);
|
||||
static int getufsquota(struct statfs *fst, struct fstab *fs,
|
||||
struct quotause *qup, long id, int quotatype);
|
||||
static int getnfsquota(struct statfs *fst, struct fstab *fs,
|
||||
struct quotause *qup, long id, int quotatype);
|
||||
static int getufsquota(struct fstab *fs, struct quotause *qup, long id,
|
||||
int quotatype);
|
||||
static int getnfsquota(struct statfs *fst, struct quotause *qup, long id,
|
||||
int quotatype);
|
||||
static int callaurpc(char *host, int prognum, int versnum, int procnum,
|
||||
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
|
||||
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
|
||||
static int alldigits(char *s);
|
||||
|
||||
int qflag;
|
||||
int vflag;
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ngroups;
|
||||
gid_t mygid, gidset[NGROUPS];
|
||||
@ -178,7 +176,7 @@ main(argc, argv)
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
|
||||
fprintf(stderr, "%s\n%s\n%s\n",
|
||||
@ -192,12 +190,11 @@ usage()
|
||||
* Print out quotas for a specified user identifier.
|
||||
*/
|
||||
static void
|
||||
showuid(uid)
|
||||
u_long uid;
|
||||
showuid(u_long uid)
|
||||
{
|
||||
struct passwd *pwd = getpwuid(uid);
|
||||
u_long myuid;
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
if (pwd == NULL)
|
||||
name = "(no account)";
|
||||
@ -215,8 +212,7 @@ showuid(uid)
|
||||
* Print out quotas for a specifed user name.
|
||||
*/
|
||||
static void
|
||||
showusrname(name)
|
||||
char *name;
|
||||
showusrname(char *name)
|
||||
{
|
||||
struct passwd *pwd = getpwnam(name);
|
||||
u_long myuid;
|
||||
@ -237,14 +233,13 @@ showusrname(name)
|
||||
* Print out quotas for a specified group identifier.
|
||||
*/
|
||||
static void
|
||||
showgid(gid)
|
||||
u_long gid;
|
||||
showgid(u_long gid)
|
||||
{
|
||||
struct group *grp = getgrgid(gid);
|
||||
int ngroups;
|
||||
gid_t mygid, gidset[NGROUPS];
|
||||
register int i;
|
||||
char *name;
|
||||
int i;
|
||||
const char *name;
|
||||
|
||||
if (grp == NULL)
|
||||
name = "(no entry)";
|
||||
@ -272,13 +267,12 @@ showgid(gid)
|
||||
* Print out quotas for a specifed group name.
|
||||
*/
|
||||
static void
|
||||
showgrpname(name)
|
||||
char *name;
|
||||
showgrpname(char *name)
|
||||
{
|
||||
struct group *grp = getgrnam(name);
|
||||
int ngroups;
|
||||
gid_t mygid, gidset[NGROUPS];
|
||||
register int i;
|
||||
int i;
|
||||
|
||||
if (grp == NULL) {
|
||||
warnx("%s: unknown group", name);
|
||||
@ -304,14 +298,12 @@ showgrpname(name)
|
||||
}
|
||||
|
||||
static void
|
||||
showquotas(type, id, name)
|
||||
int type;
|
||||
u_long id;
|
||||
char *name;
|
||||
showquotas(int type, u_long id, const char *name)
|
||||
{
|
||||
register struct quotause *qup;
|
||||
struct quotause *qup;
|
||||
struct quotause *quplist;
|
||||
char *msgi, *msgb, *nam;
|
||||
const char *msgi, *msgb;
|
||||
const char *nam;
|
||||
int lines = 0;
|
||||
static time_t now;
|
||||
|
||||
@ -330,21 +322,23 @@ showquotas(type, id, name)
|
||||
qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit)
|
||||
msgi = "File limit reached on";
|
||||
else if (qup->dqblk.dqb_isoftlimit &&
|
||||
qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit)
|
||||
qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
|
||||
if (qup->dqblk.dqb_itime > now)
|
||||
msgi = "In file grace period on";
|
||||
else
|
||||
msgi = "Over file quota on";
|
||||
}
|
||||
msgb = (char *)0;
|
||||
if (qup->dqblk.dqb_bhardlimit &&
|
||||
qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit)
|
||||
msgb = "Block limit reached on";
|
||||
else if (qup->dqblk.dqb_bsoftlimit &&
|
||||
qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit)
|
||||
qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
|
||||
if (qup->dqblk.dqb_btime > now)
|
||||
msgb = "In block grace period on";
|
||||
else
|
||||
msgb = "Over block quota on";
|
||||
}
|
||||
if (qflag) {
|
||||
if ((msgi != (char *)0 || msgb != (char *)0) &&
|
||||
lines++ == 0)
|
||||
@ -392,10 +386,7 @@ showquotas(type, id, name)
|
||||
}
|
||||
|
||||
static void
|
||||
heading(type, id, name, tag)
|
||||
int type;
|
||||
u_long id;
|
||||
char *name, *tag;
|
||||
heading(int type, u_long id, const char *name, const char *tag)
|
||||
{
|
||||
|
||||
printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type],
|
||||
@ -418,9 +409,8 @@ heading(type, id, name, tag)
|
||||
/*
|
||||
* Calculate the grace period and return a printable string for it.
|
||||
*/
|
||||
static char *
|
||||
timeprt(seconds)
|
||||
time_t seconds;
|
||||
static const char *
|
||||
timeprt(time_t seconds)
|
||||
{
|
||||
time_t hours, minutes;
|
||||
static char buf[20];
|
||||
@ -449,12 +439,10 @@ timeprt(seconds)
|
||||
* Collect the requested quota information.
|
||||
*/
|
||||
static struct quotause *
|
||||
getprivs(id, quotatype)
|
||||
register long id;
|
||||
int quotatype;
|
||||
getprivs(long id, int quotatype)
|
||||
{
|
||||
register struct quotause *qup, *quptail;
|
||||
register struct fstab *fs;
|
||||
struct quotause *qup, *quptail;
|
||||
struct fstab *fs;
|
||||
struct quotause *quphead;
|
||||
struct statfs *fst;
|
||||
int nfst, i;
|
||||
@ -472,7 +460,7 @@ getprivs(id, quotatype)
|
||||
errx(2, "out of memory");
|
||||
}
|
||||
if (strcmp(fst[i].f_fstypename, "nfs") == 0) {
|
||||
if (getnfsquota(&fst[i], NULL, qup, id, quotatype)
|
||||
if (getnfsquota(&fst[i], qup, id, quotatype)
|
||||
== 0)
|
||||
continue;
|
||||
} else if (strcmp(fst[i].f_fstypename, "ufs") == 0) {
|
||||
@ -486,7 +474,7 @@ getprivs(id, quotatype)
|
||||
*/
|
||||
if ((fs = getfsspec(fst[i].f_mntfromname)) == NULL)
|
||||
continue;
|
||||
if (getufsquota(&fst[i], fs, qup, id, quotatype) == 0)
|
||||
if (getufsquota(fs, qup, id, quotatype) == 0)
|
||||
continue;
|
||||
} else
|
||||
continue;
|
||||
@ -509,10 +497,7 @@ getprivs(id, quotatype)
|
||||
* Check to see if a particular quota is to be enabled.
|
||||
*/
|
||||
static int
|
||||
ufshasquota(fs, type, qfnamep)
|
||||
register struct fstab *fs;
|
||||
int type;
|
||||
char **qfnamep;
|
||||
ufshasquota(struct fstab *fs, int type, char **qfnamep)
|
||||
{
|
||||
static char initname, usrname[100], grpname[100];
|
||||
static char buf[BUFSIZ];
|
||||
@ -544,12 +529,7 @@ ufshasquota(fs, type, qfnamep)
|
||||
}
|
||||
|
||||
static int
|
||||
getufsquota(fst, fs, qup, id, quotatype)
|
||||
struct statfs *fst;
|
||||
struct fstab *fs;
|
||||
struct quotause *qup;
|
||||
long id;
|
||||
int quotatype;
|
||||
getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype)
|
||||
{
|
||||
char *qfpathname;
|
||||
int fd, qcmd;
|
||||
@ -585,12 +565,7 @@ getufsquota(fst, fs, qup, id, quotatype)
|
||||
}
|
||||
|
||||
static int
|
||||
getnfsquota(fst, fs, qup, id, quotatype)
|
||||
struct statfs *fst;
|
||||
struct fstab *fs;
|
||||
struct quotause *qup;
|
||||
long id;
|
||||
int quotatype;
|
||||
getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype)
|
||||
{
|
||||
struct getquota_args gq_args;
|
||||
struct getquota_rslt gq_rslt;
|
||||
@ -673,11 +648,8 @@ getnfsquota(fst, fs, qup, id, quotatype)
|
||||
}
|
||||
|
||||
static int
|
||||
callaurpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
|
||||
char *host;
|
||||
xdrproc_t inproc, outproc;
|
||||
char *in, *out;
|
||||
int prognum, versnum, procnum;
|
||||
callaurpc(char *host, int prognum, int versnum, int procnum,
|
||||
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out)
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
enum clnt_stat clnt_stat;
|
||||
@ -685,19 +657,19 @@ callaurpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
|
||||
struct timeval timeout, tottimeout;
|
||||
|
||||
CLIENT *client = NULL;
|
||||
int socket = RPC_ANYSOCK;
|
||||
int sock = RPC_ANYSOCK;
|
||||
|
||||
if ((hp = gethostbyname(host)) == NULL)
|
||||
return ((int) RPC_UNKNOWNHOST);
|
||||
timeout.tv_usec = 0;
|
||||
timeout.tv_sec = 6;
|
||||
bcopy(hp->h_addr, &server_addr.sin_addr,
|
||||
MIN(hp->h_length,sizeof(server_addr.sin_addr)));
|
||||
MIN(hp->h_length,(int)sizeof(server_addr.sin_addr)));
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = 0;
|
||||
|
||||
if ((client = clntudp_create(&server_addr, prognum,
|
||||
versnum, timeout, &socket)) == NULL)
|
||||
versnum, timeout, &sock)) == NULL)
|
||||
return ((int) rpc_createerr.cf_stat);
|
||||
|
||||
client->cl_auth = authunix_create_default();
|
||||
@ -710,10 +682,9 @@ callaurpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
|
||||
}
|
||||
|
||||
static int
|
||||
alldigits(s)
|
||||
register char *s;
|
||||
alldigits(char *s)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = *s++;
|
||||
do {
|
||||
|
Loading…
Reference in New Issue
Block a user