From 3df5c1f25c70d6ddca3e357ff8eb197c39ec4951 Mon Sep 17 00:00:00 2001 From: hpa Date: Mon, 12 Nov 2001 06:46:56 +0000 Subject: [PATCH] Even more portability work... --- aclocal.m4 | 18 +++++++++++++ config.h.in | 26 ++++++++++++++++++ configure.in | 7 ++++- tftp/Makefile | 1 + tftp/main.c | 1 - tftpd/Makefile | 1 + tftpd/recvfrom.c | 7 ++--- tftpd/remap.c | 2 +- tftpd/tftpd.c | 69 ++++++++++++++++++++++++++++++------------------ 9 files changed, 100 insertions(+), 32 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index 6824e99..62a339e 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -31,6 +31,24 @@ 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 diff --git a/config.h.in b/config.h.in index 6a07b14..398923e 100644 --- a/config.h.in +++ b/config.h.in @@ -28,4 +28,30 @@ #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 301c1d6..e0abe0a 100644 --- a/configure.in +++ b/configure.in @@ -11,8 +11,8 @@ AC_PROG_CC AC_C_CONST AC_C_INLINE -PA_ADD_CFLAGS(-Wall) PA_ADD_CFLAGS(-W) +PA_ADD_CFLAGS(-Wall) PA_ADD_CFLAGS(-Wpointer-arith) PA_ADD_CFLAGS(-Wbad-function-cast) PA_ADD_CFLAGS(-Wcast-equal) @@ -22,11 +22,15 @@ PA_ADD_CFLAGS(-Wmissing-declarations) PA_ADD_CFLAGS(-Wnested-externs) PA_ADD_CFLAGS(-Winline) PA_ADD_CFLAGS(-Wwrite-strings) +PA_ADD_CFLAGS(-Wundef) +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_CHECK_HEADERS(inttypes.h) AC_CHECK_HEADERS(sys/filio.h) AC_SEARCH_LIBS(socket, socket, , [AC_MSG_ERROR(socket library not found)]) @@ -64,6 +68,7 @@ PA_WITH_BOOL(remap, 1, ],:) 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") diff --git a/tftp/Makefile b/tftp/Makefile index 71a6614..ddf744f 100644 --- a/tftp/Makefile +++ b/tftp/Makefile @@ -11,6 +11,7 @@ tftp: $(OBJS) $(OBJS): tftpsubs.h install: tftp + mkdir -p $(INSTALLROOT)$(BINDIR) $(INSTALLROOT)$(MANDIR)/man1 $(INSTALL_PROGRAM) -s tftp $(INSTALLROOT)$(BINDIR) $(INSTALL_DATA) tftp.1 $(INSTALLROOT)$(MANDIR)/man1 diff --git a/tftp/main.c b/tftp/main.c index de11120..69fdae6 100644 --- a/tftp/main.c +++ b/tftp/main.c @@ -349,7 +349,6 @@ put(int argc, char *argv[]) } targ = argv[argc - 1]; if (strchr(argv[argc - 1], ':')) { - char *cp; struct hostent *hp; for (n = 1; n < argc - 1; n++) diff --git a/tftpd/Makefile b/tftpd/Makefile index defaf8d..dc192ce 100644 --- a/tftpd/Makefile +++ b/tftpd/Makefile @@ -16,6 +16,7 @@ tftpsubs.h: $(OBJS): tftpsubs.h install: tftpd + mkdir -p $(INSTALLROOT)$(SBINDIR) $(INSTALLROOT)$(MANDIR)/man8 $(INSTALL_PROGRAM) tftpd $(INSTALLROOT)$(SBINDIR)/in.tftpd $(INSTALL_DATA) tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/in.tftpd.8 ln -sf in.tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/tftpd.8 diff --git a/tftpd/recvfrom.c b/tftpd/recvfrom.c index fbe902b..b33dd23 100644 --- a/tftpd/recvfrom.c +++ b/tftpd/recvfrom.c @@ -26,13 +26,14 @@ #include #include #include - -#include "../config.h" -#include "recvfrom.h" #ifdef HAVE_STRINGS_H #include #endif +#include "../config.h" +#include "recvfrom.h" +#include "tftpsubs.h" + #if defined(HAVE_RECVMSG) && defined(HAVE_MSGHDR_MSG_CONTROL) #include diff --git a/tftpd/remap.c b/tftpd/remap.c index e2425c1..9613b76 100644 --- a/tftpd/remap.c +++ b/tftpd/remap.c @@ -295,7 +295,7 @@ char *rewrite_string(const char *input, const struct rule *rules, int is_put) if ( ruleptr->rule_flags & RULE_ABORT ) { if ( verbosity >= 3 ) { - syslog(LOG_INFO, "remap: rule %d: abort", + syslog(LOG_INFO, "remap: rule %d: abort: %s", ruleptr->nrule, current); } free(current); diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index 220b2b8..8868928 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -149,7 +149,7 @@ struct options { { "blksize", set_blksize }, { "blksize2", set_blksize2 }, { "tsize", set_tsize }, - { "timeout", set_timeout }, + { "timeout", set_timeout }, { NULL, NULL } }; @@ -201,12 +201,12 @@ main(int argc, char **argv) int n; int on = 1; int fd = 0; - int listen = 0; /* Standalone (listen) mode */ + int standalone = 0; /* Standalone (listen) mode */ char *address = NULL; /* Address to listen to */ int pid; int c; int setrv; - int timeout = 900; /* Default timeout */ + int waittime = 900; /* Default time to wait for a connect*/ const char *user = "nobody"; /* Default user */ char *p; #ifdef WITH_REGEX @@ -229,13 +229,13 @@ main(int argc, char **argv) secure = 1; break; case 'l': - listen = 1; + standalone = 1; break; case 'a': address = optarg; break; case 't': - timeout = atoi(optarg); + waittime = atoi(optarg); break; case 'u': user = optarg; @@ -307,7 +307,7 @@ main(int argc, char **argv) #endif /* If we're running standalone, set up the input port */ - if ( listen ) { + if ( standalone ) { fd = socket(PF_INET, SOCK_DGRAM, 0); memset(&bindaddr, 0, sizeof bindaddr); @@ -376,8 +376,12 @@ main(int argc, char **argv) } /* This means we don't want to wait() for children */ +#ifdef SA_NOCLDWAIT + set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP|SA_NOCLDWAIT); +#else set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP); - +#endif + /* Take SIGHUP and use it to set a variable. This is polled synchronously to make sure we don't lose packets as a result. */ @@ -385,12 +389,12 @@ main(int argc, char **argv) while ( 1 ) { fd_set readset; - struct timeval tv_timeout; + struct timeval tv_waittime; int rv; if ( caught_sighup ) { caught_sighup = 0; - if ( listen ) { + if ( standalone ) { #ifdef HAVE_REGEX if ( rewrite_file ) { freerules(rewrite_rules); @@ -405,11 +409,11 @@ main(int argc, char **argv) FD_ZERO(&readset); FD_SET(fd, &readset); - tv_timeout.tv_sec = timeout; - tv_timeout.tv_usec = 0; + tv_waittime.tv_sec = waittime; + tv_waittime.tv_usec = 0; - /* Never time out if we're in listen mode */ - rv = select(fd+1, &readset, NULL, NULL, listen ? NULL : &tv_timeout); + /* Never time out if we're in standalone mode */ + rv = select(fd+1, &readset, NULL, NULL, standalone ? NULL : &tv_waittime); if ( rv == -1 && errno == EINTR ) continue; /* Signal caught, reloop */ if ( rv == -1 ) { @@ -424,7 +428,7 @@ main(int argc, char **argv) (struct sockaddr *)&from, &fromlen, &myaddr); - if ( listen && myaddr.sin_addr.s_addr == INADDR_ANY ) { + if ( standalone && myaddr.sin_addr.s_addr == INADDR_ANY ) { /* myrecvfrom() didn't capture the source address; but we might have bound to a specific address, if so we should use it */ memcpy(&myaddr.sin_addr, &bindaddr.sin_addr, sizeof bindaddr.sin_addr); @@ -651,9 +655,12 @@ int set_blksize(char *val, char **ret) { static char b_ret[6]; - unsigned int sz = atoi(val); + unsigned int sz; + char *vend; - if ( blksize_set ) + sz = (unsigned int)strtoul(val, &vend, 10); + + if ( blksize_set || *vend ) return 0; if (sz < 8) @@ -676,9 +683,12 @@ int set_blksize2(char *val, char **ret) { static char b_ret[6]; - unsigned int sz = atoi(val); + unsigned int sz; + char *vend; - if ( blksize_set ) + sz = (unsigned int)strtoul(val, &vend, 10); + + if ( blksize_set || *vend ) return 0; if (sz < 8) @@ -711,15 +721,19 @@ set_blksize2(char *val, char **ret) int set_tsize(char *val, char **ret) { - static char b_ret[sizeof(off_t)*CHAR_BIT/3+2]; - off_t sz = atol(val); + static char b_ret[sizeof(uintmax_t)*CHAR_BIT/3+2]; + uintmax_t sz; + char *vend; + + sz = strtoumax(val, &vend, 10); - if ( !tsize_ok ) + if ( !tsize_ok || *vend ) return 0; if (sz == 0) - sz = tsize; - sprintf(*ret = b_ret, "%lu", sz); + sz = (uintmax_t)tsize; + + sprintf(*ret = b_ret, "%"PRIuMAX, sz); return(1); } @@ -730,9 +744,12 @@ int set_timeout(char *val, char **ret) { static char b_ret[4]; - unsigned long to = atol(val); - - if ( to < 1 || to > 255 ) + unsigned long to; + char *vend; + + to = strtoul(val, &vend, 10); + + if ( to < 1 || to > 255 || *vend ) return 0; timeout = to;