From 2c31169f575d100056d3403abfaadf96d747d6c1 Mon Sep 17 00:00:00 2001 From: hpa Date: Mon, 12 Nov 2001 10:03:04 +0000 Subject: [PATCH] Major overhaul of the portability stuff; port to autoconf 2.52 --- MCONFIG.in | 21 ++++++- Makefile | 17 ++++-- README | 7 ++- aclocal.m4 | 27 +++------ config.h | 144 +++++++++++++++++++++++++++++++++++++++++++++++ config.h.in | 57 ------------------- configure.in | 36 ++++++++++-- lib/Makefile | 2 + tftp/Makefile | 2 + tftp/tftpsubs.h | 25 +------- tftpd/Makefile | 2 + tftpd/misc.c | 2 +- tftpd/recvfrom.c | 14 +---- tftpd/remap.c | 14 ++--- tftpd/tftpd.c | 7 ++- tftpd/tftpd.h | 35 ------------ 16 files changed, 236 insertions(+), 176 deletions(-) create mode 100644 config.h delete mode 100644 config.h.in diff --git a/MCONFIG.in b/MCONFIG.in index a3f205c..d9d5718 100644 --- a/MCONFIG.in +++ b/MCONFIG.in @@ -1,3 +1,20 @@ +## -*- makefile -*- ------------------------------------------------------ +## +## Copyright 2001 H. Peter Anvin - All Rights Reserved +## +## This program is free software available under the same license +## as the "OpenBSD" operating system, distributed at +## http://www.openbsd.org/. +## +## ----------------------------------------------------------------------- +## $Id$ + +## +## MCONFIG.in +## +## Basic Makefile definitions +## + # Prefixes prefix = @prefix@ exec_prefix = @exec_prefix@ @@ -11,7 +28,7 @@ MANDIR = @mandir@ # System binaries SBINDIR = @sbindir@ -# Install into chroot area +# Install into alternate root area, e.g. for package generation INSTALLROOT = # Install program @@ -21,7 +38,7 @@ INSTALL_DATA = @INSTALL_DATA@ # Compiler and compiler flags CC = @CC@ -CFLAGS = @CFLAGS@ +CFLAGS = @CFLAGS@ -I$(SRCROOT) # Link flags LDFLAGS = @LDFLAGS@ diff --git a/Makefile b/Makefile index 9980caa..3218aef 100644 --- a/Makefile +++ b/Makefile @@ -22,24 +22,29 @@ install: MCONFIG $(patsubst %, %.install, $(SUB)) clean: $(patsubst %, %.clean, $(SUB)) distclean: $(patsubst %, %.distclean, $(SUB)) - rm -f MCONFIG config.status config.cache config.log config.h *~ \#* + rm -f MCONFIG config.status config.log acconfig.h *~ \#* + rm -rf *.cache find . -type f \( -name \*.orig -o -name \*.rej \) | xargs -r rm -f spotless: distclean - rm -f configure + rm -f configure acconfig.h.in config: MCONFIG release: - $(MAKE) configure + $(MAKE) configure acconfig.h.in $(MAKE) distclean -MCONFIG: configure MCONFIG.in config.h.in +MCONFIG: configure MCONFIG.in acconfig.h.in ./configure -config.h: MCONFIG +acconfig.h: MCONFIG : Generated by side effect +acconfig.h.in: configure.in aclocal.m4 + autoheader + rm -f acconfig.h + configure: configure.in aclocal.m4 autoconf - rm -f MCONFIG config.cache config.log config.h + rm -f MCONFIG config.cache config.log acconfig.h diff --git a/README b/README index 6e63a90..d4c0daa 100644 --- a/README +++ b/README @@ -22,10 +22,13 @@ Changes in 0.22: Even more portability improvements: FreeBSD and Tru64/Digital Unix. - Some minor source cleanups. - Fix tsize option on systems on which off_t is "long long". + Support large files on systems which need _LARGE_FILE_BITS or + similar. + + Some source cleanups; change to autoconf 2.52. + Changes in 0.21: Support running in standalone mode, without inetd. diff --git a/aclocal.m4 b/aclocal.m4 index 62a339e..db5f3e2 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -31,29 +31,14 @@ AC_DEFUN(PA_SIGSETJMP, AC_MSG_RESULT([no]) $2)]) -dnl -------------------------------------------------------------------------- -dnl PA_HAVE_LONG_LONG -dnl -dnl Does the C compiler support long long? -dnl -------------------------------------------------------------------------- -AC_DEFUN(PA_HAVE_LONG_LONG, -[AC_MSG_CHECKING([if C compiler supports long long]) - AC_TRY_LINK( - [], - [long long foo = 1LL; - unsigned long long bar = 1ULL; - return (int)(foo-bar); - ], - AC_MSG_RESULT([yes]) - $1, - AC_MSG_RESULT([no]) - $2)]) - dnl -------------------------------------------------------------------------- dnl PA_MSGHDR_MSG_CONTROL dnl dnl Does struct msghdr have the msg_control field? dnl -------------------------------------------------------------------------- +AH_TEMPLATE([HAVE_MSGHDR_MSG_CONTROL], +[Define to 1 if struct msghdr has the msg_control field.]) + AC_DEFUN(PA_MSGHDR_MSG_CONTROL, [AC_MSG_CHECKING([for msg_control in struct msghdr]) AC_TRY_COMPILE( @@ -82,6 +67,9 @@ dnl Look for definition of struct in_pktinfo. Some versions of glibc dnl lack struct in_pktinfo; if so we need to include the definition dnl ourselves -- but we only want to do that if absolutely necessary! dnl ------------------------------------------------------------------------ +AH_TEMPLATE([HAVE_STRUCT_IN_PKTINFO], +[Define to 1 if struct in_pktinfo is defined.]) + AC_DEFUN(PA_STRUCT_IN_PKTINFO, [AC_MSG_CHECKING([for definition of struct in_pktinfo]) AC_TRY_COMPILE( @@ -112,6 +100,9 @@ dnl dnl Do we have the tcpwrappers -lwrap? This can't be done using AC_CHECK_LIBS dnl due to the need to provide "allow_severity" and "deny_severity" variables dnl -------------------------------------------------------------------------- +AH_TEMPLATE([HAVE_TCPWRAPPERS], +[Define to 1 if we have tcpwrappers (-lwrap) and .]) + AC_DEFUN(PA_HAVE_TCPWRAPPERS, [AC_CHECK_LIB([wrap], [main]) AC_MSG_CHECKING([for tcpwrappers]) diff --git a/config.h b/config.h new file mode 100644 index 0000000..b8744bc --- /dev/null +++ b/config.h @@ -0,0 +1,144 @@ +/* -*- c -*- ------------------------------------------------------------- * + * + * Copyright 2001 H. Peter Anvin - All Rights Reserved + * + * This program is free software available under the same license + * as the "OpenBSD" operating system, distributed at + * http://www.openbsd.org/. + * + * ----------------------------------------------------------------------- */ +/* $Id$ */ + +/* + * config.h + * + * Sets up a common baseline environment, based on "autoconf" findings... + */ + +#ifndef CONFIG_H +#define CONFIG_H 1 + +/* Must be included before we include any system headers! */ +#include "acconfig.h" + +/* Standard includes */ + +#include + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef STDC_HEADERS +#include +#include +#else +#ifdef HAVE_STDLIB_H +#include +#endif +#endif + +#ifdef HAVE_MEMORY_H +#ifndef STDC_HEADERS +#include +#endif +#endif + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef HAVE_STRINGS_H +#include +#endif + +#ifdef HAVE_INTTYPES_H +#include +#else +#ifdef HAVE_STDINT_H +#include +#endif +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#include +#include + +/* If we don't have intmax_t, try creating it */ + +#ifndef HAVE_INTMAX_T +#ifdef HAVE_LONG_LONG +typedef long long intmax_t; +typedef unsigned long long uintmax_t; +#define PRIdMAX "%Ld" +#define PRIuMAX "%Lu" +#define PRIxMAX "%Lx" +#define INTMAX_C(x) (x##LL) +#define UINTMAX_C(x) (x##ULL) +#define strtoumax(p,e,b) strtoull(p,e,b) +#else +typedef long intmax_t; +typedef unsigned long uintmax_t; +#define PRIdMAX "%ld" +#define PRIuMAX "%lu" +#define PRIxMAX "%lx" +#define INTMAX_C(x) (x##L) +#define UINTMAX_C(x) (x##UL) +#define strtoumax(p,e,b) strtoul(p,e,b) +#endif +#endif + +#ifdef HAVE_SYSEXITS_H +#include +#else +#define EX_USAGE 64 /* command line usage error */ +#define EX_DATAERR 65 /* data format error */ +#define EX_NOINPUT 66 /* cannot open input */ +#define EX_NOUSER 67 /* addressee unknown */ +#define EX_NOHOST 68 /* host name unknown */ +#define EX_UNAVAILABLE 69 /* service unavailable */ +#define EX_SOFTWARE 70 /* internal software error */ +#define EX_OSERR 71 /* system error (e.g., can't fork) */ +#define EX_OSFILE 72 /* critical OS file missing */ +#define EX_CANTCREAT 73 /* can't create (user) output file */ +#define EX_IOERR 74 /* input/output error */ +#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +#define EX_PROTOCOL 76 /* remote error in protocol */ +#define EX_NOPERM 77 /* permission denied */ +#define EX_CONFIG 78 /* configuration error */ +#endif + +/* If we don't have sigsetjmp() et all, setjmp() will have to do */ + +#ifndef HAVE_SIGSETJMP +#define sigsetjmp(x,y) setjmp(x) +#define siglongjmp(x,y) longjmp(x,y) +#define sigjmp_buf jmp_buf +#endif + +/* How do we annotate unused data items? */ + +#ifndef UNUSED +#ifdef __GNUC__ +#define UNUSED __attribute__((unused)) +#else +#define UNUSED +#endif +#endif + +/* Sometimes IPPORT_TFTP isn't defined */ +#ifndef HAVE_IPPORT_TFTP_DEFINITION +#ifndef IPPORT_TFTP +#define IPPORT_TFTP 69 +#endif +#endif + +#endif diff --git a/config.h.in b/config.h.in deleted file mode 100644 index 398923e..0000000 --- a/config.h.in +++ /dev/null @@ -1,57 +0,0 @@ -/* $Id$ */ -/* ----------------------------------------------------------------------- * - * - * Copyright 2001 H. Peter Anvin - All Rights Reserved - * - * This program is free software available under the same license - * as the "OpenBSD" operating system, distributed at - * http://www.openbsd.org/. - * - * ----------------------------------------------------------------------- */ - -/* - * config.h.in - * - * Pattern file for configurations - */ - -#undef HAVE_SIGSETJMP -#undef HAVE_MSGHDR_MSG_CONTROL -#undef HAVE_RECVMSG -#undef HAVE_TCPWRAPPERS -#undef HAVE_STRUCT_IN_PKTINFO -#undef HAVE_SETREUID -#undef HAVE_SETREGID -#undef HAVE_SETSID -#undef HAVE_IPPORT_TFTP_DEFINITION -#undef HAVE_SYSEXITS_H -#undef HAVE_STRINGS_H -#undef HAVE_LIBGEN_H -#undef HAVE_SYS_FILIO_H -#undef HAVE_INTTYPES_H -#undef HAVE_LONG_LONG -#undef WITH_REGEX - -#ifdef HAVE_INTTYPES_H -#include -#else -#ifdef HAVE_LONG_LONG -typedef long long intmax_t; -typedef unsigned long long uintmax_t; -#define PRIdMAX "%Ld" -#define PRIuMAX "%Lu" -#define PRIxMAX "%Lx" -#define INTMAX_C(x) (x##LL) -#define UINTMAX_C(x) (x##ULL) -#define strtoumax(p,e,b) strtoull(p,e,b) -#else -typedef long intmax_t; -typedef unsigned long uintmax_t; -#define PRIdMAX "%ld" -#define PRIuMAX "%lu" -#define PRIxMAX "%lx" -#define INTMAX_C(x) (x##L) -#define UINTMAX_C(x) (x##UL) -#define strtoumax(p,e,b) strtoul(p,e,b) -#endif -#endif diff --git a/configure.in b/configure.in index e0abe0a..4054740 100644 --- a/configure.in +++ b/configure.in @@ -2,15 +2,20 @@ dnl dnl autoconf input file to generate MCONFIG dnl -AC_PREREQ(2.13) +AC_PREREQ(2.52) AC_REVISION([$Id$]) AC_INIT(MCONFIG.in) AC_PREFIX_DEFAULT(/usr) +AC_ISC_POSIX +AC_AIX +AC_MINIX AC_PROG_CC AC_C_CONST AC_C_INLINE +AC_SYS_LARGEFILE + PA_ADD_CFLAGS(-W) PA_ADD_CFLAGS(-Wall) PA_ADD_CFLAGS(-Wpointer-arith) @@ -27,11 +32,24 @@ PA_ADD_CFLAGS(-Wshadow) PA_ADD_CFLAGS(-Wsign-compare) PA_ADD_CFLAGS(-pipe) -AC_CHECK_HEADERS(sysexits.h) -AC_CHECK_HEADERS(strings.h) -AC_CHECK_HEADERS(libgen.h) +AC_HEADER_STDC AC_CHECK_HEADERS(inttypes.h) +AC_CHECK_HEADERS(libgen.h) +AC_CHECK_HEADERS(memory.h) +AC_CHECK_HEADERS(stddef.h) +AC_CHECK_HEADERS(stdint.h) +AC_CHECK_HEADERS(stdlib.h) +AC_CHECK_HEADERS(string.h) +AC_CHECK_HEADERS(strings.h) +AC_CHECK_HEADERS(sysexits.h) +AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(sys/filio.h) +AC_CHECK_HEADERS(sys/stat.h) +AC_CHECK_HEADERS(sys/types.h) + +AC_CHECK_TYPES(intmax_t) +AC_CHECK_TYPES(long long) +AC_TYPE_PID_T AC_SEARCH_LIBS(socket, socket, , [AC_MSG_ERROR(socket library not found)]) AC_SEARCH_LIBS(gethostbyname, [nsl resolv], , [AC_MSG_ERROR(gethostbyname not found)]) @@ -45,6 +63,8 @@ AC_CHECK_FUNCS(setregid) PA_MSGHDR_MSG_CONTROL PA_STRUCT_IN_PKTINFO +AH_TEMPLATE([HAVE_IPPORT_TFTP_DEFINITION], +[Define to 1 if netinet/in.h defines IPPORT_TFTP.]) PA_HEADER_DEFINES(netinet/in.h, int, IPPORT_TFTP) PA_WITH_BOOL(tcpwrappers, 1, @@ -54,6 +74,9 @@ PA_WITH_BOOL(tcpwrappers, 1, PA_HAVE_TCPWRAPPERS ],:) +AH_TEMPLATE([WITH_REGEX], +[Define to 1 if we are compiling with regex filename remapping.]) + PA_WITH_BOOL(remap, 1, [ --without-remap Disable regex-based filename remapping], [ @@ -67,8 +90,9 @@ PA_WITH_BOOL(remap, 1, ]) ],:) +AH_TEMPLATE([HAVE_SIGSETJMP], +[Define to 1 if we have sigsetjmp, siglongjmp and sigjmp_buf.]) PA_SIGSETJMP([AC_DEFINE(HAVE_SIGSETJMP)]) -PA_HAVE_LONG_LONG([AC_DEFINE(HAVE_LONG_LONG)]) LIBXTRA=false AC_SEARCH_LIBS(xmalloc, iberty, , LIBXTRA=true LIBOBJS="$LIBOBJS xmalloc.o") @@ -84,5 +108,5 @@ AC_SUBST(TFTPDOBJS) AC_PROG_RANLIB AC_PROG_INSTALL -AC_CONFIG_HEADER(config.h) +AC_CONFIG_HEADER(acconfig.h) AC_OUTPUT(MCONFIG) diff --git a/lib/Makefile b/lib/Makefile index 7c4ed06..4e20ad3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,6 +2,8 @@ # Extra functions which may not be available everywhere # +SRCROOT = .. + -include ../MCONFIG include ../MRULES diff --git a/tftp/Makefile b/tftp/Makefile index ddf744f..ca91196 100644 --- a/tftp/Makefile +++ b/tftp/Makefile @@ -1,5 +1,7 @@ all: tftp +SRCROOT = .. + -include ../MCONFIG include ../MRULES diff --git a/tftp/tftpsubs.h b/tftp/tftpsubs.h index 5976235..645c6b9 100644 --- a/tftp/tftpsubs.h +++ b/tftp/tftpsubs.h @@ -45,15 +45,7 @@ #ifndef TFTPSUBS_H #define TFTPSUBS_H -#include -#include -#include -#include -#include "../config.h" - -#ifndef HAVE_IPPORT_TFTP_DEFINITION -#define IPPORT_TFTP 69 -#endif +#include "config.h" struct tftphdr; @@ -81,19 +73,4 @@ extern char *xstrdup(const char *); */ void (*bsd_signal(int, void (*)(int)))(int); -#ifndef HAVE_SIGSETJMP -#define sigsetjmp(x,y) setjmp(x) -#define siglongjmp(x,y) longjmp(x,y) -#define sigjmp_buf jmp_buf -#endif - -/* - * How to annotate unused variables - */ -#ifdef __GNUC__ -#define UNUSED __attribute__((unused)) -#else -#define UNUSED -#endif - #endif diff --git a/tftpd/Makefile b/tftpd/Makefile index dc192ce..f538c97 100644 --- a/tftpd/Makefile +++ b/tftpd/Makefile @@ -1,5 +1,7 @@ all: tftpd +SRCROOT = .. + -include ../MCONFIG include ../MRULES diff --git a/tftpd/misc.c b/tftpd/misc.c index 3d1bee7..62f2c07 100644 --- a/tftpd/misc.c +++ b/tftpd/misc.c @@ -15,9 +15,9 @@ * Minor help routines. */ +#include "config.h" /* Must be included first! */ #include #include -#include #include "tftpd.h" /* diff --git a/tftpd/recvfrom.c b/tftpd/recvfrom.c index b33dd23..2d7452c 100644 --- a/tftpd/recvfrom.c +++ b/tftpd/recvfrom.c @@ -18,19 +18,7 @@ * */ -#define _XPG4_2 /* Needed on Solaris */ -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_STRINGS_H -#include -#endif - -#include "../config.h" +#include "config.h" /* Must be included first! */ #include "recvfrom.h" #include "tftpsubs.h" diff --git a/tftpd/remap.c b/tftpd/remap.c index 9613b76..ee93c98 100644 --- a/tftpd/remap.c +++ b/tftpd/remap.c @@ -15,20 +15,16 @@ * Perform regular-expression based filename remapping. */ -#include -#include -#include +#include "config.h" /* Must be included first! */ #include #include -#include /* FreeBSD 3.3 need this before regex.h */ #include -#include #include "tftpd.h" #include "remap.h" #define DEADMAN_MAX_STEPS 1024 /* Timeout after this many steps */ -#define LINE_MAX 16384 /* Truncate a line at this many bytes */ +#define MAXLINE 16384 /* Truncate a line at this many bytes */ #define RULE_REWRITE 0x01 /* This is a rewrite rule */ #define RULE_GLOBAL 0x02 /* Global rule (repeat until no match) */ @@ -134,7 +130,7 @@ static int readescstring(char *buf, char **str) /* Parse a line into a set of instructions */ static int parseline(char *line, struct rule *r, int lineno) { - char buffer[LINE_MAX]; + char buffer[MAXLINE]; char *p; int rv; int rxflags = REG_EXTENDED; @@ -211,7 +207,7 @@ static int parseline(char *line, struct rule *r, int lineno) /* Read a rule file */ struct rule *parserulefile(FILE *f) { - char line[LINE_MAX]; + char line[MAXLINE]; struct rule *first_rule = NULL; struct rule **last_rule = &first_rule; struct rule *this_rule = tfmalloc(sizeof(struct rule)); @@ -219,7 +215,7 @@ struct rule *parserulefile(FILE *f) int lineno = 0; int err = 0; - while ( lineno++, fgets(line, LINE_MAX, f) ) { + while ( lineno++, fgets(line, MAXLINE, f) ) { rv = parseline(line, this_rule, lineno); if ( rv < 0 ) err = 1; diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index 8868928..bdcd49d 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -35,6 +35,7 @@ * SUCH DAMAGE. */ +#include "config.h" /* Must be included first */ #include "tftpd.h" #ifndef lint @@ -203,7 +204,7 @@ main(int argc, char **argv) int fd = 0; int standalone = 0; /* Standalone (listen) mode */ char *address = NULL; /* Address to listen to */ - int pid; + pid_t pid; int c; int setrv; int waittime = 900; /* Default time to wait for a connect*/ @@ -218,7 +219,7 @@ main(int argc, char **argv) p = strrchr(argv[0], '/'); __progname = (p && p[1]) ? p+1 : argv[0]; - openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); + openlog(__progname, LOG_PID|LOG_NDELAY, LOG_DAEMON); while ((c = getopt(argc, argv, "csvla:u:r:t:m:")) != -1) switch (c) { @@ -358,7 +359,7 @@ main(int argc, char **argv) /* Daemonize this process */ { - int f = fork(); + pid_t f = fork(); if ( f > 0 ) exit(0); if ( f < 0 ) { diff --git a/tftpd/tftpd.h b/tftpd/tftpd.h index 22499c6..789ee94 100644 --- a/tftpd/tftpd.h +++ b/tftpd/tftpd.h @@ -18,45 +18,10 @@ #ifndef TFTPD_TFTPD_H #define TFTPD_TFTPD_H -#include -#include -#include "../config.h" -#ifdef HAVE_SYSEXITS_H -#include -#else -#define EX_USAGE 64 /* command line usage error */ -#define EX_DATAERR 65 /* data format error */ -#define EX_NOINPUT 66 /* cannot open input */ -#define EX_NOUSER 67 /* addressee unknown */ -#define EX_NOHOST 68 /* host name unknown */ -#define EX_UNAVAILABLE 69 /* service unavailable */ -#define EX_SOFTWARE 70 /* internal software error */ -#define EX_OSERR 71 /* system error (e.g., can't fork) */ -#define EX_OSFILE 72 /* critical OS file missing */ -#define EX_CANTCREAT 73 /* can't create (user) output file */ -#define EX_IOERR 74 /* input/output error */ -#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ -#define EX_PROTOCOL 76 /* remote error in protocol */ -#define EX_NOPERM 77 /* permission denied */ -#define EX_CONFIG 78 /* configuration error */ -#endif - -#ifndef HAVE_SIGSETJMP -#define sigsetjmp(x,y) setjmp(x) -#define siglongjmp(x,y) longjmp(x,y) -#define sigjmp_buf jmp_buf -#endif - void set_signal(int, void (*)(int), int); void *tfmalloc(size_t); char *tfstrdup(const char *); extern int verbosity; -#ifdef __GNUC__ -#define UNUSED __attribute__((unused)) -#else -#define UNUSED -#endif - #endif