Skip to contentSkip to conversation

Misc. cleanup and portability patches for quota-tools

PATCH In review Theodore Ts'o 2 participants 7 messages Mar 30, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Misc. cleanup and portability patches for quota-tools

Hi Jan,

Here are some patches that provide some additional compatibility for quota-tools package.

No, this isn't quite enough to allow quota-tools to build for Android/Bionic. These changes are sufficient to allow things to build, but there are still a few missing functions, most notably a syscall wrapper for quotactl(2), that are missing and which I'll add to a compatibility library in xfstests-bld, and/or get upstream into the Bionic libc at some point, if I can.

I think these changes are generally useful, though. For example, with glibc on x86, if you try to do a build after configuring with --enable-rpc=no, the result is a huge number of build failures. This patch series will fix things so we can compile without rpc support.

Theodore Ts'o (5):
Update the gitignore file to ignore additional generated files Allow building on systems that do not have rpc header files Use NGROUPS_MAX instead of NGROUPS
Provide fallback definitions for MNTTYPE_NFS and MNTTYPE_NOAUTO Support systems which do not have nl_langinfo()

 .gitignore   |  3 +++
 Makefile.am  | 38 ++++++++++++++++++++++----------------
 configure.ac |  1 +
 mntopt.h     |  8 ++++++++
 quota.c      |  5 +++--
 quotaops.c   |  7 +++++--
 setquota.c   |  2 ++
 warnquota.c  |  4 ++++
 8 files changed, 48 insertions(+), 20 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/5 Update the gitignore file to ignore additional generated files

Ignore the files generated by libtool, gettext, and rpcgen

---
 .gitignore | 3 +++
 1 file changed, 3 insertions(+)
.gitignore +3 -0
index 961387a..de81510 100644
@@ -9,6 +9,7 @@ missing
 *~
 *.swp
 *.bak
+.*.d
 config.h
 config.h.in
 config.log
@@ -31,6 +32,8 @@ rquota.h
 rquota_clnt.c
 convertquota
 edquota
+po/*.mo
+rquota_xdr.c
 quot
 quota
 quotacheck
Signature · 1 line
2.5.0
#2 lore raw

PATCH 2/5 Allow building on systems that do not have rpc header files

In reply to Theodore Ts'o

Android's bionic C library doesn't have Sun RPC support.

---
 Makefile.am | 38 ++++++++++++++++++++++----------------
 quotaops.c  |  2 ++
 setquota.c  |  2 ++
 3 files changed, 26 insertions(+), 16 deletions(-)
Makefile.am +22 -16
index 77f8400..6018fe8 100644
@@ -1,8 +1,6 @@
 ACLOCAL_AMFLAGS = -I m4
 AM_LDFLAGS = -pie
 
-BUILT_SOURCES = rquota.h rquota.c rquota_clnt.c
-
 doc_DATA = \
 	README.mailserver \
 	README.ldap-support \
@@ -12,11 +10,6 @@ doc_DATA = \
 	doc/quotas.preformated \
 	doc/quotas-1.eps
 
-rpcsvcdir = $(includedir)/rpcsvc
-rpcsvc_DATA = \
-	rquota.h \
-	rquota.x
-
 sysconf_DATA = \
 	warnquota.conf \
 	quotatab \
@@ -35,15 +28,12 @@ man_MANS = \
 	quota.1 \
 	quot.8 \
 	repquota.8 \
-	rpc.rquotad.8 \
 	rquota.3 \
 	setquota.8 \
 	warnquota.conf.5 \
 	warnquota.8 \
 	xqmstats.8
 
-CLEANFILES = rquota.c rquota.h rquota_clnt.c
-
 SUBDIRS = po
 
 EXTRA_DIST = \
@@ -55,9 +45,15 @@ EXTRA_DIST = \
 	Changelog \
 	ldap-scripts
 
-noinst_LIBRARIES = \
-	libquota.a \
-	librpcclient.a
+noinst_LIBRARIES = libquota.a
+
+if WITH_RPC
+rpcsvcdir = $(includedir)/rpcsvc
+rpcsvc_DATA = \
+	rquota.h \
+	rquota.x
+
+noinst_LIBRARIES += librpcclient.a
 
 librpcclient_a_SOURCES = \
 	rquota.c \
@@ -67,8 +63,10 @@ librpcclient_a_SOURCES = \
 	rquota_clnt.c
 librpcclient_a_CFLAGS = -Wno-unused
 
-if WITH_RPC
 RPCLIBS = librpcclient.a
+BUILT_SOURCES = rquota.h rquota.c rquota_clnt.c
+CLEANFILES = rquota.c rquota.h rquota_clnt.c
+man_MANS += rpc.rquotad.8
 endif
 
 libquota_a_SOURCES = \
@@ -116,12 +114,16 @@ sbin_PROGRAMS = \
 	xqmstats \
 	edquota \
 	setquota \
-	convertquota \
-	rpc.rquotad
+	convertquota
 if WITH_NETLINK
 sbin_PROGRAMS += \
 	quota_nld
 endif
+if WITH_RPC
+sbin_PROGRAMS += \
+	rpc.rquotad
+endif
+
 
 quotaon_SOURCES = \
 	quotaon.c \
@@ -214,6 +216,7 @@ convertquota_LDADD = \
 	libquota.a \
 	$(RPCLIBS)
 
+if WITH_RPC
 rpc_rquotad_SOURCES = \
 	rquota_server.c \
 	rquota_svc.c \
@@ -222,6 +225,7 @@ rpc_rquotad_LDADD = \
 	libquota.a \
 	$(WRAP_LIBS) \
 	$(RPCLIBS)
+endif
 
 quota_nld_SOURCES = quota_nld.c
 quota_nld_CFLAGS = \
@@ -233,6 +237,7 @@ quota_nld_LDADD = \
 	$(DBUS_LIBS) \
 	$(LIBNL3_LIBS)
 
+if WITH_RPC
 # ------------------
 # Rpcgen conversions
 # ------------------
@@ -247,6 +252,7 @@ quota_nld_LDADD = \
 rquota_clnt.c: rquota.x
 	@rm -f $@
 	@$(RPCGEN) -l -o $@ $<
+endif
 
 # --------
 # Quotaoff
quotaops.c +2 -0
index 47ef9a7..136aec3 100644
@@ -34,7 +34,9 @@
 
 #include "config.h"
 
+#if defined(RPC)
 #include <rpc/rpc.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/file.h>
setquota.c +2 -0
index 37f577f..d50aadb 100644
@@ -7,7 +7,9 @@
 
 #include "config.h"
 
+#if defined(RPC)
 #include <rpc/rpc.h>
+#endif
 #include <sys/types.h>
 #include <errno.h>
 #include <stdio.h>
Signature · 1 line
2.5.0
#3 lore raw

PATCH 3/5 Use NGROUPS_MAX instead of NGROUPS

In reply to Theodore Ts'o

NGRROUPS_MAX is what is defined by SuSv3; NGROUPS is not guaranteed by any standard, but is just an ancient BSD'ism. Since Android's bionic libc has the former but not the latter, let's use NGROUPS_MAX instead.

---
 quota.c    | 5 +++--
 quotaops.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
quota.c +3 -2
index d3ab800..da66a46 100644
@@ -48,6 +48,7 @@
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 #ifdef RPC
 #include <rpc/rpc.h>
 #include "rquota.h"
@@ -298,7 +299,7 @@ static int showquotas(int type, qid_t id, int mntcnt, char **mnt)
 int main(int argc, char **argv)
 {
 	int ngroups;
-	gid_t gidset[NGROUPS], *gidsetp;
+	gid_t gidset[NGROUPS_MAX], *gidsetp;
 	int i, ret, type = 0;
 	struct option long_opts[] = {
 		{ "help", 0, NULL, 'h' },
@@ -411,7 +412,7 @@ int main(int argc, char **argv)
 			ret |= showquotas(USRQUOTA, getuid(), argc, argv);
 		if (flags & FL_GROUP) {
 			ngroups = sysconf(_SC_NGROUPS_MAX);
-			if (ngroups > NGROUPS) {
+			if (ngroups > NGROUPS_MAX) {
 				gidsetp = malloc(ngroups * sizeof(gid_t));
 				if (!gidsetp)
 					die(1, _("Gid set allocation (%d): %s\n"), ngroups, strerror(errno));
quotaops.c +3 -2
index 136aec3..590dc1b 100644
@@ -51,6 +51,7 @@
 #include <unistd.h>
 #include <time.h>
 #include <ctype.h>
+#include <limits.h>
 
 #if defined(RPC)
 #include "rquota.h"
@@ -97,7 +98,7 @@ struct dquot *getprivs(qid_t id, struct quota_handle **handles, int quiet)
 #if defined(BSD_BEHAVIOUR)
 	int j, ngroups;
 	uid_t euid;
-	gid_t gidset[NGROUPS], *gidsetp;
+	gid_t gidset[NGROUPS_MAX], *gidsetp;
 #endif
 
 	for (i = 0; handles[i]; i++) {
@@ -115,7 +116,7 @@ struct dquot *getprivs(qid_t id, struct quota_handle **handles, int quiet)
 				if (geteuid() == 0)
 					break;
 				ngroups = sysconf(_SC_NGROUPS_MAX);
-				if (ngroups > NGROUPS) {
+				if (ngroups > NGROUPS_MAX) {
 					gidsetp = malloc(ngroups * sizeof(gid_t));
 					if (!gidsetp) {
 						gid2group(id, name);
Signature · 1 line
2.5.0
#4 lore raw

PATCH 4/5 Provide fallback definitions for MNTTYPE_NFS and MNTTYPE_NOAUTO

In reply to Theodore Ts'o

Not all C library's /usr/include/mntent.h are guaranteed to define MNTTYPE_NFS and MNTTYPE_AUTO. Since we already are defining a large number of MNTTYPE_* macros for our own use in mntopt.h, add fallback definitions for MNTTYPE_NFS and MNTTYPE_NOAUTO there.

---
 mntopt.h | 8 ++++++++
 1 file changed, 8 insertions(+)
mntopt.h +8 -0
index a70b4a4..3b33879 100644
@@ -21,6 +21,10 @@
 #define MNTTYPE_OCFS2		"ocfs2"	/* Oracle Cluster filesystem */
 #define MNTTYPE_GFS2		"gfs2"	/* Red Hat Global filesystem 2 */
 
+#ifndef MNTTYPE_NFS
+#define MNTTYPE_NFS	"nfs"		/* Network file system.  */
+#endif
+
 /* mount options */
 #define MNTOPT_NOQUOTA		"noquota"	/* don't enforce quota */
 #define MNTOPT_QUOTA		"quota"	/* enforce user quota */
@@ -34,4 +38,8 @@
 #define MNTOPT_LOOP		"loop"		/* loopback mount */
 #define MNTOPT_JQFMT		"jqfmt"		/* journaled quota format */
 
+#ifndef MNTOPT_NOAUTO
+#define MNTOPT_NOAUTO	"noauto"	/* Do not auto mount.  */
+#endif
+
 #endif
Signature · 1 line
2.5.0
#5 lore raw

PATCH 5/5 Support systems which do not have nl_langinfo()

In reply to Theodore Ts'o

Add a configure check and skip use of nl_langinfo if it is not present.

---
 configure.ac | 1 +
 warnquota.c  | 4 ++++
 2 files changed, 5 insertions(+)
configure.ac +1 -0
index d17b18c..0d0ba57 100644
@@ -32,6 +32,7 @@ PKG_PROG_PKG_CONFIG([0.20])
 
 AC_C_CONST
 AC_C_INLINE
+AC_CHECK_FUNC(nl_langinfo)
 
 # ===============
 # Gettext support
warnquota.c +4 -0
index e9868c1..0d911e4 100644
@@ -30,7 +30,9 @@
 #include <time.h>
 #include <getopt.h>
 #include <locale.h>
+#ifdef HAVE_NL_LANGINFO
 #include <langinfo.h>
+#endif
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/utsname.h>
@@ -723,10 +725,12 @@ static int readconfigfile(const char *filename, struct configparams *config)
 	(config->charset)[0] = '\0';
 	setlocale(LC_ALL, NULL);
 	locale = setlocale(LC_MESSAGES, NULL);
+#ifdef HAVE_NL_LANGINFO
 	if (locale && strcasecmp(locale, "posix") && strcasecmp(locale, "c")) {
 		locale = nl_langinfo(CODESET);
 		sstrncpy(config->charset, locale, CNF_BUFFER);
 	}
+#endif
 	maildev[0] = 0;
 	config->user_signature = config->user_message = config->group_signature = config->group_message = NULL;
 	config->cc_before = -1;
Signature · 1 line
2.5.0
reviewer
#6 lore raw
In reply to Theodore Ts'o

Hi Ted,

Quoted 10 lines · Ted Tso

Here are some patches that provide some additional compatibility for quota-tools package.

No, this isn't quite enough to allow quota-tools to build for Android/Bionic. These changes are sufficient to allow things to build, but there are still a few missing functions, most notably a syscall wrapper for quotactl(2), that are missing and which I'll add to a compatibility library in xfstests-bld, and/or get upstream into the Bionic libc at some point, if I can.

Quoted 4 lines

I think these changes are generally useful, though. For example, with glibc on x86, if you try to do a build after configuring with --enable-rpc=no, the result is a huge number of build failures. This patch series will fix things so we can compile without rpc support.

Thanks for the fixes! I have merged them all. I had to slightly fix nl_langinfo() checking so that HAVE_NL_LANGINFO is really defined in case we have nl_langinfo() but it was easy enough.

I have also added explicit includes of stdlib.h into some files as otherwise compilation without RPC emitted some warnings.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR