Skip to content

Commit

Permalink
Check autoconf results before #including; clean up header inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
dleonard committed Sep 25, 2008
1 parent b04406e commit 60e4c08
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 28 deletions.
6 changes: 1 addition & 5 deletions conf-t.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@

/* Unit tests for conf */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "conf.h"

#define TESTFILEPATH "/tmp/_conf_test.txt"
Expand Down
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ AC_C_CONST
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS([netdb.h unistd.h sys/socket.h errno.h netinet/in.h fcntl.h])
AC_CHECK_HEADERS([signal.h syslog.h])
AC_CHECK_HEADERS([signal.h syslog.h sys/un.h sys/types.h sys/wait.h sys/poll.h])
AC_CHECK_HEADERS([netinet/in.h arpa/inet.h])

AC_PATH_PROG([VASCONFIG], [vas-config], [no], [/opt/quest/bin:$PATH])
if test x"$VASCONFIG" = x"no"; then
Expand All @@ -31,6 +32,7 @@ AC_CHECK_FUNC([getopt], [], [AC_LIBOBJ([getopt])])
dnl AC_CHECK_FUNCS([err errx warn warnx], [], [AC_LIBOBJ([err]) ; break])
AC_SEARCH_LIBS([socket], [socket])
AC_SEARCH_LIBS([gethostbyname], [nsl])
AC_CHECK_FUNC([socketpair])
AC_FUNC_FORK

AC_CHECK_TYPE([socklen_t],[AC_DEFINE([HAVE_SOCKLEN_T],[1],[socklen_t])],,[
Expand Down
14 changes: 13 additions & 1 deletion dnstcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "err.h"
#include "dns.h"
#include "dnstcp.h"
#include <sys/un.h>
#if HAVE_SYS_UN_H
# include <sys/un.h>
#endif

/*
* DNS over TCP
Expand Down Expand Up @@ -117,6 +119,7 @@ tcp_connect(const char *host, const char *service)
static int
unix_connect(const char *local)
{
#ifdef AF_UNIX
int s;
struct sockaddr_un unaddr;

Expand All @@ -136,6 +139,10 @@ unix_connect(const char *local)
return -1;
}
return s;
#else
warnx("AF_UNIX not implemented");
return -1;
#endif
}

/*
Expand Down Expand Up @@ -164,10 +171,15 @@ debug_connect_exec(const char *wrapper, const char *host)
{
int sp[2];

#if HAVE_SOCKETPAIR && defined(AF_UNIX)
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) < 0) {
warn("socketpair");
return -1;
}
#else
warnx("unable to create bidirectional IPC");
return -1;
#endif

if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
warn("signal SIGCHLD");
Expand Down
5 changes: 1 addition & 4 deletions list-t.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

/* Unit tests for lists */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "list.h"

#define streq(a,b) ((a)!=NULL && (b)!=NULL && strcmp(a,b)==0)
Expand Down
3 changes: 1 addition & 2 deletions list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/* Manage lists. A list is a null terminated array of string pointers.
* This code is meant to be convenient, not efficient. Won't scale */

#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "list.h"

/* Creates a list out of a whitespace separated string.
Expand Down
3 changes: 0 additions & 3 deletions resconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
* Records resolver configuration, as read from /etc/resolv.conf
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "resconf.h"
#include "stream.h"
Expand Down
35 changes: 26 additions & 9 deletions server-t.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,27 @@
#include "dnsdebug.h"
#include "err.h"

#include <signal.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/poll.h>
#if HAVE_SIGNAL_H
# include <signal.h>
#endif
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_SYS_UN_H
# include <sys/un.h>
#endif
#if HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#if HAVE_SYS_POLL_H
# include <sys/poll.h>
#endif
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#if HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif

#define TAG "server-t: "

Expand Down Expand Up @@ -749,10 +765,6 @@ match_query(struct dns_msg *qmsg, const char *pattern)
return 1;
}

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

/* Waits and accepts a single connection on the given port */
int
tcp_accept(int port)
Expand Down Expand Up @@ -1224,6 +1236,10 @@ delete_unix_listener()
static int
build_unix_listener()
{
#if !defined(AF_UNIX)
warnx("AF_UNIX not available on this system");
return -1;
#else
int s;
struct sockaddr_un unaddr;
char *path;
Expand Down Expand Up @@ -1252,6 +1268,7 @@ build_unix_listener()
err(1, "listen");
add_fd(s, unix_listener_ready, 0);
return s;
#endif
}

static RETSIGTYPE
Expand Down
4 changes: 1 addition & 3 deletions stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* a primitive lexical analyser.
*/

#include <stdio.h>
#include <stdlib.h>

#include "common.h"
#include "stream.h"

/* Prototypes */
Expand Down

0 comments on commit 60e4c08

Please sign in to comment.