[master] 8aa1d8b Eliminate nested <*.h> includes from include/*

Poul-Henning Kamp phk at varnish-cache.org
Mon Oct 10 11:54:44 CEST 2011


commit 8aa1d8b8b87e009ae06f3cfed452bf8c6594b931
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Oct 10 09:53:50 2011 +0000

    Eliminate nested <*.h> includes from include/*
    
    Sort #includes according to rules which are for me to know and you
    to guess.

diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c
index b857f8a..e519b01 100644
--- a/bin/varnishadm/varnishadm.c
+++ b/bin/varnishadm/varnishadm.c
@@ -29,23 +29,25 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
+#include <sys/socket.h>
+
+#ifdef HAVE_LIBEDIT
+#include <editline/readline.h>
+#endif
 
+#include <errno.h>
 #include <fcntl.h>
 #include <poll.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
-#include <sys/socket.h>
-
-#ifdef HAVE_LIBEDIT
-#include <editline/readline.h>
-#endif
+#include <unistd.h>
 
 #include "vcli.h"
 #include "cli_common.h"
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vss.h"
 
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index c5bc614..41efdad 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -34,6 +34,8 @@
  */
 #define VARNISH_CACHE_CHILD	1
 
+#include "common.h"
+
 #include "vapi/vsc_int.h"
 #include "vapi/vsl_int.h"
 
@@ -53,7 +55,6 @@
 #include <sys/epoll.h>
 #endif
 
-#include "common.h"
 
 #include "heritage.h"
 
diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 4feefb6..80d7b81 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -32,10 +32,10 @@
 
 #include "cache.h"
 
+#include "cli_priv.h"
 #include "vcli.h"
 #include "vtcp.h"
 #include "vtim.h"
-#include "cli_priv.h"
 
 static pthread_t	VCA_thread;
 static struct timeval	tv_sndtimeo;
diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c
index 3ed7fcd..0026259 100644
--- a/bin/varnishd/cache_backend.c
+++ b/bin/varnishd/cache_backend.c
@@ -32,8 +32,8 @@
 
 #include "config.h"
 
-#include <stdlib.h>
 #include <poll.h>
+#include <stdlib.h>
 
 #include "cache.h"
 
diff --git a/bin/varnishd/cache_backend_cfg.c b/bin/varnishd/cache_backend_cfg.c
index e08e09e..2e6d83c 100644
--- a/bin/varnishd/cache_backend_cfg.c
+++ b/bin/varnishd/cache_backend_cfg.c
@@ -36,9 +36,10 @@
 #include <stdlib.h>
 
 #include "cache.h"
-#include "vrt.h"
+
 #include "cache_backend.h"
 #include "cli_priv.h"
+#include "vrt.h"
 
 struct lock VBE_mtx;
 
diff --git a/bin/varnishd/cache_backend_poll.c b/bin/varnishd/cache_backend_poll.c
index c9497bb..a0ad62b 100644
--- a/bin/varnishd/cache_backend_poll.c
+++ b/bin/varnishd/cache_backend_poll.c
@@ -37,17 +37,18 @@
 
 #include "config.h"
 
-#include <stdio.h>
 #include <math.h>
-#include <stdlib.h>
 #include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
 
-#include "cli_priv.h"
 #include "cache.h"
+
+#include "cache_backend.h"
+#include "cli_priv.h"
 #include "vrt.h"
 #include "vtcp.h"
 #include "vtim.h"
-#include "cache_backend.h"
 
 /* Default averaging rate, we want something pretty responsive */
 #define AVG_RATE			4
diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c
index 8396c7f..bec8d85 100644
--- a/bin/varnishd/cache_ban.c
+++ b/bin/varnishd/cache_ban.c
@@ -62,17 +62,16 @@
 
 #include "config.h"
 
-#include <stdio.h>
-
 #include <pcre.h>
+#include <stdio.h>
 
 #include "cache.h"
 
+#include "cli_priv.h"
+#include "hash_slinger.h"
 #include "vcli.h"
 #include "vend.h"
 #include "vtim.h"
-#include "cli_priv.h"
-#include "hash_slinger.h"
 
 struct ban {
 	unsigned		magic;
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 6ab8a11..ba61e9c 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -57,25 +57,25 @@ DOT acceptor -> start [style=bold,color=green]
 
 #include "config.h"
 
-#include <stdio.h>
 #include <errno.h>
 #include <math.h>
 #include <poll.h>
+#include <stdio.h>
 #include <stdlib.h>
 
-#ifndef HAVE_SRANDOMDEV
-#include "compat/srandomdev.h"
-#endif
-
 #include "cache.h"
 
-#include "vcl.h"
-#include "vtcp.h"
-#include "vtim.h"
 #include "cli_priv.h"
 #include "hash_slinger.h"
 #include "stevedore.h"
+#include "vcl.h"
 #include "vsha256.h"
+#include "vtcp.h"
+#include "vtim.h"
+
+#ifndef HAVE_SRANDOMDEV
+#include "compat/srandomdev.h"
+#endif
 
 static unsigned xids;
 
diff --git a/bin/varnishd/cache_cli.c b/bin/varnishd/cache_cli.c
index 3635aec..f66075e 100644
--- a/bin/varnishd/cache_cli.c
+++ b/bin/varnishd/cache_cli.c
@@ -41,8 +41,8 @@
 #include "cache.h"
 
 #include "vcli.h"
-#include "cli_priv.h"
 #include "cli_common.h"
+#include "cli_priv.h"
 #include "cli_serve.h"
 #include "hash_slinger.h"		// objhead
 
diff --git a/bin/varnishd/cache_dir.c b/bin/varnishd/cache_dir.c
index ef882bf..3fd0475 100644
--- a/bin/varnishd/cache_dir.c
+++ b/bin/varnishd/cache_dir.c
@@ -33,6 +33,7 @@
 #include "config.h"
 
 #include "cache.h"
+
 #include "cache_backend.h"
 #include "vtcp.h"
 
diff --git a/bin/varnishd/cache_dir_dns.c b/bin/varnishd/cache_dir_dns.c
index 3fd2aa1..acb3689 100644
--- a/bin/varnishd/cache_dir_dns.c
+++ b/bin/varnishd/cache_dir_dns.c
@@ -29,14 +29,15 @@
 
 #include "config.h"
 
+#include <netinet/in.h>
+
 #include <errno.h>
-#include <stdlib.h>
 #include <netdb.h>
-
 #include <stdio.h>
-#include <netinet/in.h>
+#include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_backend.h"
 #include "vrt.h"
 
diff --git a/bin/varnishd/cache_dir_random.c b/bin/varnishd/cache_dir_random.c
index f05d8f4..f18c7d7 100644
--- a/bin/varnishd/cache_dir_random.c
+++ b/bin/varnishd/cache_dir_random.c
@@ -50,10 +50,11 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_backend.h"
+#include "vend.h"
 #include "vrt.h"
 #include "vsha256.h"
-#include "vend.h"
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/cache_dir_round_robin.c b/bin/varnishd/cache_dir_round_robin.c
index 9d0a257..7d75473 100644
--- a/bin/varnishd/cache_dir_round_robin.c
+++ b/bin/varnishd/cache_dir_round_robin.c
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_backend.h"
 #include "vrt.h"
 
diff --git a/bin/varnishd/cache_esi_deliver.c b/bin/varnishd/cache_esi_deliver.c
index 063464a..f7daeeb 100644
--- a/bin/varnishd/cache_esi_deliver.c
+++ b/bin/varnishd/cache_esi_deliver.c
@@ -30,10 +30,11 @@
 
 #include "config.h"
 
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_esi.h"
 #include "vend.h"
 #include "vgz.h"
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index cac2eb6..b6ef527 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -33,9 +33,10 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_esi.h"
-#include "vct.h"
 #include "stevedore.h"
+#include "vct.h"
 
 /*---------------------------------------------------------------------
  * Read some bytes.
diff --git a/bin/varnishd/cache_esi_parse.c b/bin/varnishd/cache_esi_parse.c
index c659dd5..37c20e7 100644
--- a/bin/varnishd/cache_esi_parse.c
+++ b/bin/varnishd/cache_esi_parse.c
@@ -34,9 +34,10 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_esi.h"
-#include "vend.h"
 #include "vct.h"
+#include "vend.h"
 #include "vgz.h"
 
 //#define Debug(fmt, ...) printf(fmt, __VA_ARGS__)
diff --git a/bin/varnishd/cache_expire.c b/bin/varnishd/cache_expire.c
index aed6807..8e18cb5 100644
--- a/bin/varnishd/cache_expire.c
+++ b/bin/varnishd/cache_expire.c
@@ -53,8 +53,9 @@
 
 #include <math.h>
 
-#include "binary_heap.h"
 #include "cache.h"
+
+#include "binary_heap.h"
 #include "hash_slinger.h"
 #include "stevedore.h"
 #include "vtim.h"
diff --git a/bin/varnishd/cache_fetch.c b/bin/varnishd/cache_fetch.c
index d18e726..4bbc272 100644
--- a/bin/varnishd/cache_fetch.c
+++ b/bin/varnishd/cache_fetch.c
@@ -29,14 +29,15 @@
 
 #include "config.h"
 
-#include <stdio.h>
+#include <fcntl.h>
 #include <inttypes.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <fcntl.h>
 
 #include "cache.h"
-#include "stevedore.h"
+
 #include "cli_priv.h"
+#include "stevedore.h"
 #include "vct.h"
 #include "vtcp.h"
 
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 28d61d9..156ac52 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -65,6 +65,7 @@
  */
 
 #include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c
index 4001c7c..67aa3af 100644
--- a/bin/varnishd/cache_hash.c
+++ b/bin/varnishd/cache_hash.c
@@ -52,17 +52,18 @@
 
 #include "config.h"
 
+#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <math.h>
 #include <string.h>
 
 #include "cache.h"
-#include "stevedore.h"
+
+#include "cache_backend.h"
 #include "hash_slinger.h"
-#include "vsha256.h"
+#include "stevedore.h"
 #include "vav.h"
-#include "cache_backend.h"
+#include "vsha256.h"
 
 static const struct hash_slinger *hash;
 
diff --git a/bin/varnishd/cache_main.c b/bin/varnishd/cache_main.c
index b4ee185..54d71f8 100644
--- a/bin/varnishd/cache_main.c
+++ b/bin/varnishd/cache_main.c
@@ -34,9 +34,9 @@
 
 #include "cache.h"
 
-#include "stevedore.h"
-#include "hash_slinger.h"
 #include "cache_waiter.h"
+#include "hash_slinger.h"
+#include "stevedore.h"
 
 /*--------------------------------------------------------------------
  * Per thread storage for the session currently being processed by
diff --git a/bin/varnishd/cache_panic.c b/bin/varnishd/cache_panic.c
index 63ab6a3..482708d 100644
--- a/bin/varnishd/cache_panic.c
+++ b/bin/varnishd/cache_panic.c
@@ -29,23 +29,23 @@
 
 #include "config.h"
 
-#include "vapi/vsm_int.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
 #ifndef HAVE_EXECINFO_H
 #include "compat/execinfo.h"
 #else
 #include <execinfo.h>
 #endif
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #include "cache.h"
 
+#include "vapi/vsm_int.h"
+
 #include "cache_backend.h"
 #include "cache_waiter.h"
-#include "vcl.h"
 #include "libvcl.h"
+#include "vcl.h"
 
 /*
  * The panic string is constructed in memory, then copied to the
diff --git a/bin/varnishd/cache_pipe.c b/bin/varnishd/cache_pipe.c
index 418ded1..c9bc0ac 100644
--- a/bin/varnishd/cache_pipe.c
+++ b/bin/varnishd/cache_pipe.c
@@ -31,10 +31,11 @@
 
 #include "config.h"
 
-#include <stdio.h>
 #include <poll.h>
+#include <stdio.h>
 
 #include "cache.h"
+
 #include "vtcp.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index b4459da..bacf906 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
 #include "stevedore.h"
 #include "vct.h"
 #include "vtim.h"
diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c
index bb96780..d55bae0 100644
--- a/bin/varnishd/cache_session.c
+++ b/bin/varnishd/cache_session.c
@@ -35,10 +35,11 @@
 
 #include "config.h"
 
-#include <stdlib.h>
 #include <math.h>
+#include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_waiter.h"
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache_shmlog.c b/bin/varnishd/cache_shmlog.c
index d16a744..da39e2d 100644
--- a/bin/varnishd/cache_shmlog.c
+++ b/bin/varnishd/cache_shmlog.c
@@ -29,7 +29,6 @@
 
 #include "config.h"
 
-
 #include <stdio.h>
 
 #include "cache.h"
diff --git a/bin/varnishd/cache_vary.c b/bin/varnishd/cache_vary.c
index 4440d55..c528fb8 100644
--- a/bin/varnishd/cache_vary.c
+++ b/bin/varnishd/cache_vary.c
@@ -56,8 +56,8 @@
 
 #include "cache.h"
 
-#include "vend.h"
 #include "vct.h"
+#include "vend.h"
 
 struct vsb *
 VRY_Create(const struct sess *sp, const struct http *hp)
diff --git a/bin/varnishd/cache_vcl.c b/bin/varnishd/cache_vcl.c
index 99364b5..48568ff 100644
--- a/bin/varnishd/cache_vcl.c
+++ b/bin/varnishd/cache_vcl.c
@@ -33,15 +33,16 @@
 
 #include "config.h"
 
+#include <dlfcn.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <dlfcn.h>
 
 #include "cache.h"
-#include "vcli.h"
+
 #include "cli_priv.h"
-#include "vcl.h"
 #include "libvcl.h"
+#include "vcl.h"
+#include "vcli.h"
 
 struct vcls {
 	unsigned		magic;
diff --git a/bin/varnishd/cache_vrt.c b/bin/varnishd/cache_vrt.c
index 5c633e2..2302b86 100644
--- a/bin/varnishd/cache_vrt.c
+++ b/bin/varnishd/cache_vrt.c
@@ -39,13 +39,13 @@
 
 #include "cache.h"
 
-#include "vrt.h"
-#include "vrt_obj.h"
+#include "cache_backend.h"
+#include "hash_slinger.h"
 #include "vav.h"
 #include "vcl.h"
+#include "vrt.h"
+#include "vrt_obj.h"
 #include "vtim.h"
-#include "hash_slinger.h"
-#include "cache_backend.h"
 
 const void * const vrt_magic_string_end = &vrt_magic_string_end;
 
diff --git a/bin/varnishd/cache_vrt_re.c b/bin/varnishd/cache_vrt_re.c
index d28510f..d9a7090 100644
--- a/bin/varnishd/cache_vrt_re.c
+++ b/bin/varnishd/cache_vrt_re.c
@@ -36,8 +36,8 @@
 
 #include "cache.h"
 
-#include "vrt.h"
 #include "vre.h"
+#include "vrt.h"
 
 void
 VRT_re_init(void **rep, const char *re)
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index ff523df..a00b1b7 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -35,12 +35,12 @@
 
 #include "cache.h"
 
+#include "cache_backend.h"
+#include "hash_slinger.h"
 #include "vrt.h"
+#include "vrt_obj.h"
 #include "vtcp.h"
 #include "vtim.h"
-#include "vrt_obj.h"
-#include "cache_backend.h"
-#include "hash_slinger.h"
 
 static char vrt_hostname[255] = "";
 
diff --git a/bin/varnishd/cache_vrt_vmod.c b/bin/varnishd/cache_vrt_vmod.c
index 4eb3e84..bb4eeb8 100644
--- a/bin/varnishd/cache_vrt_vmod.c
+++ b/bin/varnishd/cache_vrt_vmod.c
@@ -31,8 +31,8 @@
 
 #include "config.h"
 
-#include <stdlib.h>
 #include <dlfcn.h>
+#include <stdlib.h>
 
 #include "cache.h"
 
diff --git a/bin/varnishd/cache_waiter.c b/bin/varnishd/cache_waiter.c
index cd3e007..08c5809 100644
--- a/bin/varnishd/cache_waiter.c
+++ b/bin/varnishd/cache_waiter.c
@@ -30,10 +30,11 @@
 
 #include "config.h"
 
-#include "vcli.h"
-#include "cli_priv.h"
 #include "cache.h"
+
 #include "cache_waiter.h"
+#include "cli_priv.h"
+#include "vcli.h"
 
 static const struct waiter * const vca_waiters[] = {
     #if defined(HAVE_KQUEUE)
diff --git a/bin/varnishd/cache_waiter_epoll.c b/bin/varnishd/cache_waiter_epoll.c
index c66d15a..3eaa627 100644
--- a/bin/varnishd/cache_waiter_epoll.c
+++ b/bin/varnishd/cache_waiter_epoll.c
@@ -35,12 +35,14 @@
 
 #if defined(HAVE_EPOLL_CTL)
 
+#include <sys/epoll.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sys/epoll.h>
 
 #include "cache.h"
+
 #include "cache_waiter.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/cache_waiter_kqueue.c b/bin/varnishd/cache_waiter_kqueue.c
index e7cb299..a81f4c2 100644
--- a/bin/varnishd/cache_waiter_kqueue.c
+++ b/bin/varnishd/cache_waiter_kqueue.c
@@ -35,13 +35,16 @@
 
 #if defined(HAVE_KQUEUE)
 
+#include <sys/types.h>
+#include <sys/event.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/event.h>
 
 #include "cache.h"
+
 #include "cache_waiter.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/cache_waiter_poll.c b/bin/varnishd/cache_waiter_poll.c
index f3f3289..eb48870 100644
--- a/bin/varnishd/cache_waiter_poll.c
+++ b/bin/varnishd/cache_waiter_poll.c
@@ -30,8 +30,8 @@
 
 #include "config.h"
 
-#include <stdlib.h>
 #include <poll.h>
+#include <stdlib.h>
 
 #include "cache.h"
 
diff --git a/bin/varnishd/cache_waiter_ports.c b/bin/varnishd/cache_waiter_ports.c
index ca7e229..2e02406 100644
--- a/bin/varnishd/cache_waiter_ports.c
+++ b/bin/varnishd/cache_waiter_ports.c
@@ -33,15 +33,16 @@
 
 #if defined(HAVE_PORT_CREATE)
 
-#include <stdio.h>
+#include <sys/time.h>
+
 #include <errno.h>
-#include <stdlib.h>
 #include <math.h>
-
 #include <port.h>
-#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #include "cache.h"
+
 #include "cache_waiter.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/cache_wrk.c b/bin/varnishd/cache_wrk.c
index 7e80f04..1032691 100644
--- a/bin/varnishd/cache_wrk.c
+++ b/bin/varnishd/cache_wrk.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
 #include "hash_slinger.h"
 #include "vsha256.h"
 
diff --git a/bin/varnishd/cache_wrw.c b/bin/varnishd/cache_wrw.c
index 5f9c29b..4fef1aa 100644
--- a/bin/varnishd/cache_wrw.c
+++ b/bin/varnishd/cache_wrw.c
@@ -34,21 +34,21 @@
 
 #include "config.h"
 
-#include <stdio.h>
 #include <sys/types.h>
-#include <sys/uio.h>
-
 #ifdef SENDFILE_WORKS
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-   // We're fine
-#elif defined(__linux__)
-#  include <sys/sendfile.h>
-#elif defined(__sun)
-#  include <sys/sendfile.h>
-#else
-#  error Unknown sendfile() implementation
-#endif
+#  if defined(__FreeBSD__) || defined(__DragonFly__)
+#    include <sys/socket.h>
+#  elif defined(__linux__)
+#    include <sys/sendfile.h>
+#  elif defined(__sun)
+#    include <sys/sendfile.h>
+#  else
+#     error Unknown sendfile() implementation
+#  endif
 #endif /* SENDFILE_WORKS */
+#include <sys/uio.h>
+
+#include <stdio.h>
 
 #include "cache.h"
 
diff --git a/bin/varnishd/common.h b/bin/varnishd/common.h
index 7fd15b7..13249eb 100644
--- a/bin/varnishd/common.h
+++ b/bin/varnishd/common.h
@@ -28,6 +28,11 @@
  *
  */
 
+#include <errno.h>
+#include <stdint.h>
+
+#include <sys/types.h>
+
 #include "miniobj.h"
 #include "vas.h"
 #include "vcs.h"
@@ -73,8 +78,8 @@ const void *pick(const struct choice *cp, const char *which, const char *kind);
 #define NEEDLESS_RETURN(foo)	return (foo)
 
 /* vsm.c */
-extern struct VSM_head		*VSM_head;
-extern const struct VSM_chunk	*vsm_end;
+// extern struct VSM_head		*VSM_head;
+// extern const struct VSM_chunk	*vsm_end;
 
 /*
  * These three should not be called directly, but only through
diff --git a/bin/varnishd/hash_classic.c b/bin/varnishd/hash_classic.c
index 9b8c7d8..1428864 100644
--- a/bin/varnishd/hash_classic.c
+++ b/bin/varnishd/hash_classic.c
@@ -31,12 +31,14 @@
 
 #include "config.h"
 
+#include <sys/types.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include "cache.h"
+
 #include "hash_slinger.h"
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/hash_critbit.c b/bin/varnishd/hash_critbit.c
index e5b0746..add2397 100644
--- a/bin/varnishd/hash_critbit.c
+++ b/bin/varnishd/hash_critbit.c
@@ -28,15 +28,16 @@
  * A Crit Bit tree based hash
  */
 
-#undef PHK
+// #define PHK
 
 #include "config.h"
 
 #include <stdlib.h>
 
 #include "cache.h"
-#include "hash_slinger.h"
+
 #include "cli_priv.h"
+#include "hash_slinger.h"
 #include "vmb.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/hash_simple_list.c b/bin/varnishd/hash_simple_list.c
index 13cf0ee..c1c17da 100644
--- a/bin/varnishd/hash_simple_list.c
+++ b/bin/varnishd/hash_simple_list.c
@@ -32,6 +32,7 @@
 #include "config.h"
 
 #include "cache.h"
+
 #include "hash_slinger.h"
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt_child.c b/bin/varnishd/mgt_child.c
index ac76594..7338e6c 100644
--- a/bin/varnishd/mgt_child.c
+++ b/bin/varnishd/mgt_child.c
@@ -31,27 +31,30 @@
 
 #include "config.h"
 
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <errno.h>
 #include <fcntl.h>
-#include <stdlib.h>
+#include <poll.h>
 #include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <syslog.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
+#include <unistd.h>
 
 #include "mgt.h"
-#include "vapi/vsm_int.h"
-#include "heritage.h"
-#include "vcli.h"
+
 #include "cli_priv.h"
+#include "heritage.h"
 #include "mgt_cli.h"
+#include "vapi/vsm_int.h"
+#include "vbm.h"
+#include "vcli.h"
 #include "vev.h"
 #include "vlu.h"
 #include "vss.h"
-#include "vbm.h"
 #include "vtcp.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/mgt_cli.c b/bin/varnishd/mgt_cli.c
index 4488d51..4a7925a 100644
--- a/bin/varnishd/mgt_cli.c
+++ b/bin/varnishd/mgt_cli.c
@@ -31,32 +31,33 @@
 
 #include "config.h"
 
+#include <sys/socket.h>
+
+#include <fcntl.h>
+#include <poll.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <fcntl.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include <string.h>
+#include <syslog.h>
 #include <unistd.h>
-#include <sys/socket.h>
 
-#ifndef HAVE_SRANDOMDEV
-#include "compat/srandomdev.h"
-#endif
+#include "mgt.h"
 
-#include "cli_priv.h"
 #include "vcli.h"
 #include "cli_common.h"
+#include "cli_priv.h"
 #include "cli_serve.h"
+#include "heritage.h"
+#include "mgt_cli.h"
 #include "vev.h"
 #include "vlu.h"
 #include "vss.h"
 #include "vtcp.h"
 
-
-#include "mgt.h"
-#include "heritage.h"
-#include "mgt_cli.h"
+#ifndef HAVE_SRANDOMDEV
+#include "compat/srandomdev.h"
+#endif
 
 static int		cli_i = -1, cli_o = -1;
 static struct VCLS	*cls;
diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c
index f849fbb..4bb1adf 100644
--- a/bin/varnishd/mgt_param.c
+++ b/bin/varnishd/mgt_param.c
@@ -37,17 +37,16 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "vcli.h"
-#include "cli_priv.h"
-#include "cli_common.h"
 #include "mgt.h"
-#include "mgt_cli.h"
 
-#include "heritage.h"
-#include "vparam.h"
+#include "vcli.h"
 #include "cache_waiter.h"
-
+#include "cli_common.h"
+#include "cli_priv.h"
+#include "heritage.h"
+#include "mgt_cli.h"
 #include "vav.h"
+#include "vparam.h"
 #include "vss.h"
 
 #define MAGIC_INIT_STRING	"\001"
diff --git a/bin/varnishd/mgt_pool.c b/bin/varnishd/mgt_pool.c
index 4b3fe92..489fab8 100644
--- a/bin/varnishd/mgt_pool.c
+++ b/bin/varnishd/mgt_pool.c
@@ -42,15 +42,15 @@
 
 #include "config.h"
 
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
-#include <limits.h>
 #include <unistd.h>
 
 #include "mgt.h"
 
-#include "vparam.h"
 #include "heritage.h"
+#include "vparam.h"
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/mgt_sandbox.c b/bin/varnishd/mgt_sandbox.c
index 94f9f4d..3aba7cc 100644
--- a/bin/varnishd/mgt_sandbox.c
+++ b/bin/varnishd/mgt_sandbox.c
@@ -44,15 +44,16 @@
 
 #include "config.h"
 
-#include <stdio.h>
-#include <syslog.h>
-#include <unistd.h>
-
 #ifdef __linux__
 #include <sys/prctl.h>
 #endif
 
+#include <stdio.h>
+#include <syslog.h>
+#include <unistd.h>
+
 #include "mgt.h"
+
 #include "heritage.h"
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt_sandbox_solaris.c b/bin/varnishd/mgt_sandbox_solaris.c
index a90d8b2..5c50c83 100644
--- a/bin/varnishd/mgt_sandbox_solaris.c
+++ b/bin/varnishd/mgt_sandbox_solaris.c
@@ -34,15 +34,15 @@
 
 #ifdef HAVE_SETPPRIV
 
-#include <stdio.h>
-#include <syslog.h>
-#include <string.h>
-
 #ifdef HAVE_PRIV_H
 #include <priv.h>
 #endif
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
 
 #include "mgt.h"
+
 #include "heritage.h"
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/mgt_shmem.c b/bin/varnishd/mgt_shmem.c
index 8fa5cd9..ae0a50d 100644
--- a/bin/varnishd/mgt_shmem.c
+++ b/bin/varnishd/mgt_shmem.c
@@ -86,25 +86,27 @@
 
 #include "config.h"
 
-#include "vapi/vsl_int.h"
-#include "vapi/vsc_int.h"
+#include <sys/mman.h>
+#include <sys/stat.h>
 
+#include <fcntl.h>
 #include <signal.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
+#include <unistd.h>
 
 #include "mgt.h"
+
+#include "flopen.h"
 #include "heritage.h"
-#include "vmb.h"
+#include "vapi/vsc_int.h"
+#include "vapi/vsl_int.h"
 #include "vapi/vsm_int.h"
 #include "vav.h"
+#include "vmb.h"
 #include "vnum.h"
-#include "flopen.h"
 
 #ifndef MAP_HASSEMAPHORE
 #define MAP_HASSEMAPHORE 0 /* XXX Linux */
diff --git a/bin/varnishd/mgt_vcc.c b/bin/varnishd/mgt_vcc.c
index df46c41..78a29dd 100644
--- a/bin/varnishd/mgt_vcc.c
+++ b/bin/varnishd/mgt_vcc.c
@@ -40,13 +40,13 @@
 
 #include "mgt.h"
 
+#include "cli_priv.h"
 #include "libvcl.h"
-#include "vcli.h"
-#include "vsub.h"
+#include "mgt_cli.h"
 #include "vcl.h"
+#include "vcli.h"
 #include "vfil.h"
-#include "cli_priv.h"
-#include "mgt_cli.h"
+#include "vsub.h"
 
 struct vclprog {
 	VTAILQ_ENTRY(vclprog)	list;
diff --git a/bin/varnishd/rfc2616.c b/bin/varnishd/rfc2616.c
index 6de52e2..d4d5a05 100644
--- a/bin/varnishd/rfc2616.c
+++ b/bin/varnishd/rfc2616.c
@@ -29,10 +29,11 @@
 
 #include "config.h"
 
-#include <stdlib.h>
 #include <math.h>
+#include <stdlib.h>
 
 #include "cache.h"
+
 #include "vtim.h"
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/stevedore.c b/bin/varnishd/stevedore.c
index 6d71635..538ae27 100644
--- a/bin/varnishd/stevedore.c
+++ b/bin/varnishd/stevedore.c
@@ -37,9 +37,11 @@
 #include <stdlib.h>
 
 #include "cache.h"
+
+#include "cli_priv.h"
 #include "stevedore.h"
 #include "vav.h"
-#include "cli_priv.h"
+#include "vrt.h"
 #include "vrt_obj.h"
 
 static VTAILQ_HEAD(, stevedore)	stevedores =
@@ -560,8 +562,6 @@ struct cli_proto cli_stv[] = {
  * VRT functions for stevedores
  */
 
-#include "vrt.h"
-
 static const struct stevedore *
 stv_find(const char *nm)
 {
diff --git a/bin/varnishd/stevedore_utils.c b/bin/varnishd/stevedore_utils.c
index 725a086..42c2b47 100644
--- a/bin/varnishd/stevedore_utils.c
+++ b/bin/varnishd/stevedore_utils.c
@@ -31,27 +31,26 @@
 
 #include "config.h"
 
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-
 #ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
+#  include <sys/mount.h>
 #endif
-
 #ifdef HAVE_SYS_STATVFS_H
-#include <sys/statvfs.h>
+#  include <sys/statvfs.h>
 #endif
-
 #ifdef HAVE_SYS_VFS_H
-#include <sys/vfs.h>
+#  include <sys/vfs.h>
 #endif
 
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "mgt.h"
+
 #include "stevedore.h"
 #include "vnum.h"
 
diff --git a/bin/varnishd/storage_file.c b/bin/varnishd/storage_file.c
index 25c9947..171d9d0 100644
--- a/bin/varnishd/storage_file.c
+++ b/bin/varnishd/storage_file.c
@@ -32,6 +32,7 @@
 #include "config.h"
 
 #include <sys/mman.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/bin/varnishd/storage_persistent.c b/bin/varnishd/storage_persistent.c
index 3ba7061..18b96c3 100644
--- a/bin/varnishd/storage_persistent.c
+++ b/bin/varnishd/storage_persistent.c
@@ -35,22 +35,24 @@
 
 #include "config.h"
 
-#include <stdio.h>
+#include <sys/param.h>
+#include <sys/mman.h>
+
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/param.h>
-#include <sys/mman.h>
 
 #include "cache.h"
-#include "stevedore.h"
+
+#include "cli_priv.h"
 #include "hash_slinger.h"
-#include "vsha256.h"
+#include "persistent.h"
+#include "stevedore.h"
 #include "vcli.h"
-#include "cli_priv.h"
 #include "vend.h"
+#include "vsha256.h"
 
-#include "persistent.h"
 #include "storage_persistent.h"
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/storage_persistent_mgt.c b/bin/varnishd/storage_persistent_mgt.c
index c91fb43..7ec9089 100644
--- a/bin/varnishd/storage_persistent_mgt.c
+++ b/bin/varnishd/storage_persistent_mgt.c
@@ -35,12 +35,14 @@
 
 #include "config.h"
 
+#include <sys/mman.h>
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/mman.h>
 
 #include "cache.h"
+
 #include "stevedore.h"
 #include "vsha256.h"
 
diff --git a/bin/varnishd/storage_persistent_silo.c b/bin/varnishd/storage_persistent_silo.c
index 2defc0d..be2e2bf 100644
--- a/bin/varnishd/storage_persistent_silo.c
+++ b/bin/varnishd/storage_persistent_silo.c
@@ -38,8 +38,9 @@
 #include <stdlib.h>
 
 #include "cache.h"
-#include "stevedore.h"
+
 #include "hash_slinger.h"
+#include "stevedore.h"
 #include "vsha256.h"
 #include "vtim.h"
 
diff --git a/bin/varnishd/storage_persistent_subr.c b/bin/varnishd/storage_persistent_subr.c
index 6fad388..e3df368 100644
--- a/bin/varnishd/storage_persistent_subr.c
+++ b/bin/varnishd/storage_persistent_subr.c
@@ -35,12 +35,14 @@
 
 #include "config.h"
 
+#include <sys/mman.h>
+
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stddef.h>
-#include <sys/mman.h>
 
 #include "cache.h"
+
 #include "vsha256.h"
 
 #include "persistent.h"
diff --git a/bin/varnishd/storage_umem.c b/bin/varnishd/storage_umem.c
index 197d0ac..4459a47 100644
--- a/bin/varnishd/storage_umem.c
+++ b/bin/varnishd/storage_umem.c
@@ -37,11 +37,10 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-
 #include <umem.h>
 
-#include "config.h"
 #include "cache.h"
+
 #include "stevedore.h"
 
 static size_t			smu_max = SIZE_MAX;
diff --git a/bin/varnishd/varnishd.c b/bin/varnishd/varnishd.c
index 9ba9570..7cecfe4 100644
--- a/bin/varnishd/varnishd.c
+++ b/bin/varnishd/varnishd.c
@@ -32,6 +32,7 @@
 #include "config.h"
 
 #include <sys/stat.h>
+#include <sys/utsname.h>
 
 #include <ctype.h>
 #include <errno.h>
@@ -43,25 +44,22 @@
 #include <time.h>
 #include <unistd.h>
 
-#include <sys/utsname.h>
-
-#include "compat/daemon.h"
-
-#include "vev.h"
-#include "vpf.h"
-#include "vsha256.h"
+#include "mgt.h"
 
 #include "vcli.h"
 #include "cli_common.h"
-
+#include "hash_slinger.h"
+#include "heritage.h"
+#include "stevedore.h"
 #include "vav.h"
-#include "vin.h"
+#include "vev.h"
 #include "vfil.h"
+#include "vin.h"
+#include "vpf.h"
+#include "vsha256.h"
 #include "vtim.h"
-#include "heritage.h"
-#include "mgt.h"
-#include "hash_slinger.h"
-#include "stevedore.h"
+
+#include "compat/daemon.h"
 
 #ifndef HAVE_SRANDOMDEV
 #include "compat/srandomdev.h"
diff --git a/bin/varnishd/vsm.c b/bin/varnishd/vsm.c
index bc44c21..5298381 100644
--- a/bin/varnishd/vsm.c
+++ b/bin/varnishd/vsm.c
@@ -54,8 +54,8 @@
 
 #include "common.h"
 
-#include "vmb.h"
 #include "vapi/vsm_int.h"
+#include "vmb.h"
 #include "vtim.h"
 
 /* These two come from beyond (mgt_shmem.c actually) */
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index e2fc652..6d68a5d 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -32,10 +32,8 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <sys/types.h>
+
 #include <curses.h>
 #include <errno.h>
 #include <limits.h>
@@ -48,6 +46,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vcs.h"
 
diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index 86c8504..e6c4bf8 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -31,9 +31,6 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -42,13 +39,15 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "compat/daemon.h"
-
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vcs.h"
 #include "vpf.h"
 #include "vsb.h"
 
+#include "compat/daemon.h"
+
 static int	b_flag, c_flag;
 
 /* Ordering-----------------------------------------------------------*/
diff --git a/bin/varnishncsa/base64.c b/bin/varnishncsa/base64.c
index 3758604..ee1a87b 100644
--- a/bin/varnishncsa/base64.c
+++ b/bin/varnishncsa/base64.c
@@ -6,11 +6,13 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <sys/types.h>
+
+#include <stdio.h>		// for test-prog
+
 #include "base64.h"
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 
 static const char b64[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -62,7 +64,6 @@ VB64_decode(char *d, unsigned dlen, const char *s)
 }
 
 #ifdef TEST_DRIVER
-#include <stdio.h>
 
 const char *test1 =
 "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 05b8dfe..97a3642 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -59,20 +59,19 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <ctype.h>
+#include <errno.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
-#include <unistd.h>
 #include <time.h>
+#include <unistd.h>
 
-#include "compat/daemon.h"
-
+#include "base64.h"
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vcs.h"
 #include "vpf.h"
@@ -80,7 +79,7 @@
 #include "vre.h"
 #include "vsb.h"
 
-#include "base64.h"
+#include "compat/daemon.h"
 
 static volatile sig_atomic_t reopen;
 
diff --git a/bin/varnishreplay/varnishreplay.c b/bin/varnishreplay/varnishreplay.c
index ffc403f..77758eb 100644
--- a/bin/varnishreplay/varnishreplay.c
+++ b/bin/varnishreplay/varnishreplay.c
@@ -28,9 +28,6 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <sys/types.h>
 #include <sys/signal.h>
 #include <sys/uio.h>
@@ -39,13 +36,15 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <pthread.h>
-#include <stdarg.h>
 #include <signal.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vcs.h"
 #include "vqueue.h"
diff --git a/bin/varnishsizes/varnishsizes.c b/bin/varnishsizes/varnishsizes.c
index d3e3218..a78be9b 100644
--- a/bin/varnishsizes/varnishsizes.c
+++ b/bin/varnishsizes/varnishsizes.c
@@ -32,10 +32,8 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <sys/types.h>
+
 #include <curses.h>
 #include <errno.h>
 #include <limits.h>
@@ -48,6 +46,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vcs.h"
 
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index b160a26..3c6c4b5 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -32,9 +32,6 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsc.h"
-
 #include <sys/time.h>
 
 #include <errno.h>
@@ -46,6 +43,7 @@
 
 #include "varnishstat.h"
 
+
 /*--------------------------------------------------------------------*/
 
 static int
diff --git a/bin/varnishstat/varnishstat.h b/bin/varnishstat/varnishstat.h
index 314c7c5..0a5d80f 100644
--- a/bin/varnishstat/varnishstat.h
+++ b/bin/varnishstat/varnishstat.h
@@ -27,7 +27,13 @@
  *
  */
 
+#include <stdint.h>
+
+#include "vapi/vsm.h"
+#include "vapi/vsc.h"
+
 #include "vas.h"
 #include "vcs.h"
 
+
 void do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main, int delay);
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 1e93155..9fa6b82 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -32,15 +32,16 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsc.h"
-
 #include <sys/time.h>
 
 #ifdef HAVE_NCURSES_CURSES_H
-#include <ncurses/curses.h>
-#elif HAVE_CURSES_H
-#include <curses.h>
+#  include <ncurses/curses.h>
+#endif
+
+#ifndef HAVE_NCURSES_CURSES_H
+#  ifdef HAVE_CURSES_H
+#    include <curses.h>
+#  endif
 #endif
 #include <errno.h>
 #include <signal.h>
@@ -50,9 +51,12 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "vqueue.h"
 #include "varnishstat.h"
 
+#include "vapi/vsc.h"
+#include "vapi/vsm.h"
+#include "vqueue.h"
+
 #if 0
 #define AC(x) assert((x) != ERR)
 #else
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 5c6bbfd..b496f9e 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -28,14 +28,15 @@
 
 #include "config.h"
 
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <unistd.h>
 
 #include "vtc.h"
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 1340314..6093656 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -27,6 +27,7 @@
  *
  */
 
+#include <errno.h>
 #include <limits.h>
 #include <signal.h>
 #include <pthread.h>
diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c
index 2547d80..7eb430f 100644
--- a/bin/varnishtest/vtc_client.c
+++ b/bin/varnishtest/vtc_client.c
@@ -28,13 +28,13 @@
 
 #include "config.h"
 
+#include <sys/types.h>
+#include <sys/socket.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
-
 #include "vtc.h"
 
 #include "vss.h"
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 889891b..698ffb0 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -28,17 +28,18 @@
 
 #include "config.h"
 
-#include <string.h>
-#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
 #include <poll.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
+#include "vtc.h"
 
 #include "vct.h"
 #include "vgz.h"
-#include "vtc.h"
 #include "vtcp.h"
 
 #define MAX_HDR		50
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 753de58..d6d15c1 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -28,12 +28,13 @@
 
 #include "config.h"
 
+#include <stdarg.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
+#include <string.h>
 
 #include "vtc.h"
+
 #include "vtim.h"
 
 static pthread_mutex_t	vtclog_mtx;
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index 3b9d81b..fb1c42e 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -28,18 +28,22 @@
 
 #include "config.h"
 
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#include "vev.h"
+#include <fcntl.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "vtc.h"
+
+#include "vev.h"
+#include "vqueue.h"
 #include "vtim.h"
 
 #ifndef HAVE_SRANDOMDEV
diff --git a/bin/varnishtest/vtc_sema.c b/bin/varnishtest/vtc_sema.c
index c363b4a..48d4c68 100644
--- a/bin/varnishtest/vtc_sema.c
+++ b/bin/varnishtest/vtc_sema.c
@@ -30,8 +30,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "vtc.h"
 
diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c
index 5a768a1..75c4f30 100644
--- a/bin/varnishtest/vtc_server.c
+++ b/bin/varnishtest/vtc_server.c
@@ -28,16 +28,17 @@
 
 #include "config.h"
 
-#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
+#include "vtc.h"
 
 #include "vss.h"
-#include "vtc.h"
 #include "vtcp.h"
 
 struct server {
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index ba19464..87b9423 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -28,26 +28,25 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsc.h"
-#include "vapi/vsl.h"
-
-#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
 
 #include <fcntl.h>
+#include <inttypes.h>
+#include <poll.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
-#include <poll.h>
-#include <inttypes.h>
+#include <unistd.h>
 
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
+#include "vtc.h"
 
+#include "vapi/vsc.h"
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vcli.h"
 #include "vss.h"
-#include "vtc.h"
 #include "vtcp.h"
 
 struct varnish {
diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c
index 34278ea..07070c8 100644
--- a/bin/varnishtop/varnishtop.c
+++ b/bin/varnishtop/varnishtop.c
@@ -32,20 +32,19 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <ctype.h>
 #include <curses.h>
 #include <errno.h>
+#include <limits.h>
 #include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <limits.h>
 
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
 #include "vas.h"
 #include "vcs.h"
 #include "vqueue.h"
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index 1101e53..bc52d65 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -33,6 +33,8 @@
 
 #include "vapi/vsc_int.h"
 
+struct VSM_data;
+
 /*---------------------------------------------------------------------
  * VSC level access functions
  */
diff --git a/include/vapi/vsc_int.h b/include/vapi/vsc_int.h
index 0a9cbf9..6ceb723 100644
--- a/include/vapi/vsc_int.h
+++ b/include/vapi/vsc_int.h
@@ -28,8 +28,6 @@
  *
  */
 
-#include <stdint.h>
-
 #define VSC_CLASS          "Stat"
 
 #define VSC_TYPE_MAIN		""
diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h
index 5068f1c..9c9a4c9 100644
--- a/include/vapi/vsl.h
+++ b/include/vapi/vsl.h
@@ -31,10 +31,10 @@
 #ifndef VAPI_VSL_H_INCLUDED
 #define VAPI_VSL_H_INCLUDED
 
-#include <stdint.h>
-
 #include "vapi/vsl_int.h"
 
+struct VSM_data;
+
 /*---------------------------------------------------------------------
  * VSL level access functions
  */
diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h
index 0b7cdd8..fd7fbee 100644
--- a/include/vapi/vsm.h
+++ b/include/vapi/vsm.h
@@ -31,6 +31,9 @@
 #ifndef VAPI_VSM_H_INCLUDED
 #define VAPI_VSM_H_INCLUDED
 
+struct VSM_head;
+struct VSM_data;
+
 /*---------------------------------------------------------------------
  * VSM level access functions
  */
diff --git a/include/vapi/vsm_int.h b/include/vapi/vsm_int.h
index 0055b73..3554982 100644
--- a/include/vapi/vsm_int.h
+++ b/include/vapi/vsm_int.h
@@ -36,8 +36,6 @@
 
 #define VSM_FILENAME		"_.vsm"
 
-#include <stdint.h>
-
 /*
  * This structure describes each allocation from the shmlog
  */
@@ -81,6 +79,9 @@ struct VSM_head {
  */
 #ifdef CHECK_OBJ_NOTNULL
 
+extern struct VSM_head *VSM_head;
+extern const struct VSM_chunk *vsm_end;
+
 static inline struct VSM_chunk *
 vsm_iter_0(void)
 {
diff --git a/include/vas.h b/include/vas.h
index a4c9c6f..ff20036 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -38,8 +38,6 @@
 #ifndef VAS_H_INCLUDED
 #define VAS_H_INCLUDED
 
-#include <errno.h>
-
 typedef void vas_f(const char *, const char *, int, const char *, int, int);
 
 extern vas_f *VAS_Fail;
diff --git a/include/vct.h b/include/vct.h
index fb4c2af..52530a6 100644
--- a/include/vct.h
+++ b/include/vct.h
@@ -28,8 +28,6 @@
  *
  */
 
-#include <stdint.h>
-
 /* from libvarnish/vct.c */
 
 #define VCT_SP			(1<<0)
diff --git a/include/vev.h b/include/vev.h
index 60737bf..37db60f 100644
--- a/include/vev.h
+++ b/include/vev.h
@@ -28,10 +28,6 @@
  *
  */
 
-#include <poll.h>
-
-#include "vqueue.h"
-
 struct vev;
 struct vev_base;
 
diff --git a/include/vnum.h b/include/vnum.h
index a821355..cf55c9a 100644
--- a/include/vnum.h
+++ b/include/vnum.h
@@ -28,7 +28,5 @@
  *
  */
 
-#include <stdint.h>
-
 /* from libvarnish/vnum.c */
 const char *VNUM_2bytes(const char *p, uintmax_t *r, uintmax_t rel);
diff --git a/include/vsb.h b/include/vsb.h
index 5bfbce7..0a8e2bf 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -31,8 +31,6 @@
 #ifndef VSB_H_INCLUDED
 #define VSB_H_INCLUDED
 
-#include <sys/types.h>
-
 /*
  * Structure definition
  */
diff --git a/include/vsha256.h b/include/vsha256.h
index 66811d3..bf42c11 100644
--- a/include/vsha256.h
+++ b/include/vsha256.h
@@ -29,8 +29,6 @@
 #ifndef _SHA256_H_
 #define _SHA256_H_
 
-#include <stdint.h>
-
 #define SHA256_LEN		32
 
 typedef struct SHA256Context {
diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/binary_heap.c
index 4b0edc3..ed99f13 100644
--- a/lib/libvarnish/binary_heap.c
+++ b/lib/libvarnish/binary_heap.c
@@ -35,12 +35,15 @@
 
 #include "config.h"
 
+#include <errno.h>
 #include <limits.h>
 #include <stdint.h>
+#include <stdio.h>		// for testcase
 #include <stdlib.h>
 #include <unistd.h>
 
 #include "binary_heap.h"
+#include "miniobj.h"		// for testcase
 #include "vas.h"
 
 /* Parameters --------------------------------------------------------*/
@@ -455,8 +458,6 @@ binheap_reorder(const struct binheap *bh, unsigned idx)
 
 #ifdef TEST_DRIVER
 /* Test driver -------------------------------------------------------*/
-#include <stdio.h>
-#include "miniobj.h"
 
 static void
 vasfail(const char *func, const char *file, int line,
diff --git a/lib/libvarnish/cli_auth.c b/lib/libvarnish/cli_auth.c
index da0a241..396a127 100644
--- a/lib/libvarnish/cli_auth.c
+++ b/lib/libvarnish/cli_auth.c
@@ -29,6 +29,8 @@
 #include "config.h"
 
 #include <sys/types.h>
+
+#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 
diff --git a/lib/libvarnish/cli_common.c b/lib/libvarnish/cli_common.c
index e423da4..cb4e8af 100644
--- a/lib/libvarnish/cli_common.c
+++ b/lib/libvarnish/cli_common.c
@@ -43,13 +43,11 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "vsb.h"
-
-#include "vas.h"
-
 #include "vcli.h"
-#include "cli_priv.h"
 #include "cli_common.h"
+#include "cli_priv.h"
+#include "vas.h"
+#include "vsb.h"
 
 /*lint -e{818} cli could be const */
 void
diff --git a/lib/libvarnish/cli_serve.c b/lib/libvarnish/cli_serve.c
index 13b9663..2c3a09c 100644
--- a/lib/libvarnish/cli_serve.c
+++ b/lib/libvarnish/cli_serve.c
@@ -32,23 +32,25 @@
 #include "config.h"
 
 #include <ctype.h>
+#include <errno.h>
 #include <poll.h>
-#include <string.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <unistd.h>
 
+#include "miniobj.h"
 #include "vas.h"
-#include "vqueue.h"
-#include "vsb.h"
-#include "vav.h"
-#include "vlu.h"
+
 #include "vcli.h"
-#include "cli_priv.h"
 #include "cli_common.h"
+#include "cli_priv.h"
 #include "cli_serve.h"
-#include "miniobj.h"
+#include "vav.h"
+#include "vlu.h"
+#include "vqueue.h"
+#include "vsb.h"
 
 struct VCLS_func {
 	unsigned			magic;
diff --git a/lib/libvarnish/vav.c b/lib/libvarnish/vav.c
index a0c57bb..24b16b7 100644
--- a/lib/libvarnish/vav.c
+++ b/lib/libvarnish/vav.c
@@ -39,8 +39,9 @@
 #include "config.h"
 
 #include <ctype.h>
-#include <stdlib.h>
+#include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "vas.h"
diff --git a/lib/libvarnish/vct.c b/lib/libvarnish/vct.c
index 2740aa1..f0e1635 100644
--- a/lib/libvarnish/vct.c
+++ b/lib/libvarnish/vct.c
@@ -31,6 +31,7 @@
 #include "config.h"
 
 #include <stdint.h>
+
 #include "vct.h"
 
 /* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index 004ce08..87d1582 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -29,20 +29,22 @@
 
 #include "config.h"
 
-#include <stdio.h>
 #include <errno.h>
 #include <poll.h>
-#include <time.h>
+#include <pthread.h>
 #include <signal.h>
-#include <string.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <pthread.h>
+#include <string.h>
+#include <time.h>
 
-#include "vas.h"
-#include "vtim.h"
-#include "vev.h"
 #include "miniobj.h"
+#include "vas.h"
+
 #include "binary_heap.h"
+#include "vqueue.h"
+#include "vev.h"
+#include "vtim.h"
 
 #undef DEBUG_EVENTS
 
diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c
index a4bab9e..ca1d965 100644
--- a/lib/libvarnish/vfil.c
+++ b/lib/libvarnish/vfil.c
@@ -29,15 +29,15 @@
 
 #include "config.h"
 
+#include <sys/stat.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <time.h>
-
-#include <sys/stat.h>
+#include <unistd.h>
 
 #include "vas.h"
 #include "vdef.h"
diff --git a/lib/libvarnish/vin.c b/lib/libvarnish/vin.c
index cd3e7d0..4dba302 100644
--- a/lib/libvarnish/vin.c
+++ b/lib/libvarnish/vin.c
@@ -30,14 +30,14 @@
 
 #include "config.h"
 
-#include "vapi/vsm_int.h"
-
 #include <errno.h>
 #include <limits.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 
+#include "vapi/vsm_int.h"
 #include "vas.h"
 #include "vdef.h"
 #include "vin.h"
diff --git a/lib/libvarnish/vlu.c b/lib/libvarnish/vlu.c
index 1334a28..f149a57 100644
--- a/lib/libvarnish/vlu.c
+++ b/lib/libvarnish/vlu.c
@@ -29,13 +29,16 @@
 
 #include "config.h"
 
+#include <errno.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
+
+#include "miniobj.h"
 #include "vas.h"
+
 #include "vlu.h"
-#include "miniobj.h"
 
 struct vlu {
 	unsigned	magic;
diff --git a/lib/libvarnish/vmb.c b/lib/libvarnish/vmb.c
index e6b0f25..3f5c12d 100644
--- a/lib/libvarnish/vmb.c
+++ b/lib/libvarnish/vmb.c
@@ -26,8 +26,11 @@
  * SUCH DAMAGE.
  */
 
+#include "config.h"
+
 #include <pthread.h>
 #include <unistd.h>
+
 #include "vas.h"
 #include "vmb.h"
 
diff --git a/lib/libvarnish/vnum.c b/lib/libvarnish/vnum.c
index 7940e9b..d2f423b 100644
--- a/lib/libvarnish/vnum.c
+++ b/lib/libvarnish/vnum.c
@@ -31,10 +31,11 @@
 #include "config.h"
 
 #include <math.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
 
+#include "vas.h"
 #include "vnum.h"
 
 static const char err_miss_num[] = "Missing number";
@@ -112,10 +113,6 @@ VNUM_2bytes(const char *p, uintmax_t *r, uintmax_t rel)
 
 #ifdef NUM_C_TEST
 /* Compile with: "cc -o foo -DNUM_C_TEST -I../.. -I../../include num.c -lm" */
-#include "vas.h"
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
 
 struct test_case {
 	const char *str;
diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c
index 2810bc2..9b1d911 100644
--- a/lib/libvarnish/vre.c
+++ b/lib/libvarnish/vre.c
@@ -26,11 +26,15 @@
  * SUCH DAMAGE.
  */
 
+#include "config.h"
+
+#include <errno.h>
 #include <pcre.h>
 #include <string.h>
 
 #include "miniobj.h"
 #include "vas.h"
+
 #include "vre.h"
 
 struct vre {
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index 4930be2..16f6d4b 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD: head/sys/kern/subr_vsb.c 222004 2011-05-17 06:36:32Z phk $")
 #include "config.h"
 
 #include <ctype.h>
+#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/lib/libvarnish/vsha256.c b/lib/libvarnish/vsha256.c
index 942a186..10b7a6a 100644
--- a/lib/libvarnish/vsha256.c
+++ b/lib/libvarnish/vsha256.c
@@ -28,23 +28,24 @@
 
 #include "config.h"
 
-#include <stdint.h>
-#include <string.h>
+#ifdef HAVE_SYS_ENDIAN_H
+#include <sys/endian.h>
+#define VBYTE_ORDER	_BYTE_ORDER
+#define VBIG_ENDIAN	_BIG_ENDIAN
+#endif
 
 #ifdef HAVE_ENDIAN_H
 #include <endian.h>
 #define VBYTE_ORDER	__BYTE_ORDER
 #define VBIG_ENDIAN	__BIG_ENDIAN
 #endif
-#ifdef HAVE_SYS_ENDIAN_H
-#include <sys/endian.h>
-#define VBYTE_ORDER	_BYTE_ORDER
-#define VBIG_ENDIAN	_BIG_ENDIAN
-#endif
+#include <errno.h>
+#include <stdint.h>
+#include <string.h>
 
 #include "vas.h"
-#include "vsha256.h"
 #include "vend.h"
+#include "vsha256.h"
 
 #if defined(VBYTE_ORDER) && VBYTE_ORDER == VBIG_ENDIAN
 
diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c
index 297df11..77b8f38 100644
--- a/lib/libvarnish/vss.c
+++ b/lib/libvarnish/vss.c
@@ -44,8 +44,8 @@
 #include <unistd.h>
 
 #include "vas.h"
-#include "vtcp.h"
 #include "vss.h"
+#include "vtcp.h"
 
 /* lightweight addrinfo */
 struct vss_addr {
diff --git a/lib/libvarnish/vsub.c b/lib/libvarnish/vsub.c
index 90ceacb..497119c 100644
--- a/lib/libvarnish/vsub.c
+++ b/lib/libvarnish/vsub.c
@@ -31,12 +31,13 @@
 
 #include "config.h"
 
+#include <sys/wait.h>
+
+#include <errno.h>
 #include <fcntl.h>
+#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
-#include <stdio.h>
-
-#include <sys/wait.h>
 
 #include "vas.h"
 #include "vlu.h"
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index c955e65..10c3664 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -31,25 +31,24 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
+#ifdef HAVE_SYS_FILIO_H
+#  include <sys/filio.h>
+#endif
 
 #include <netinet/in.h>
-
 #ifdef __linux
-#include <netinet/tcp.h>
+#  include <netinet/tcp.h>
 #endif
 
 #include <errno.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_FILIO_H
-#include <sys/filio.h>
-#endif
+#include <math.h>
 #include <netdb.h>
 #include <poll.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <math.h>
 
 #include "vas.h"
 #include "vtcp.h"
diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c
index 772b559..42c1558 100644
--- a/lib/libvarnish/vtim.c
+++ b/lib/libvarnish/vtim.c
@@ -48,11 +48,13 @@
 
 #include <sys/time.h>
 
+#include <errno.h>
+#include <math.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <math.h>
 
 #include "vas.h"
 #include "vtim.h"
@@ -200,8 +202,6 @@ VTIM_timespec(double t)
 
 #ifdef TEST_DRIVER
 
-#include <stdlib.h>
-
 /*
  * Compile with:
  *  cc -o foo -DTEST_DRIVER -I../.. -I../../include time.c assert.c
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 211d284..eea7f5c 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -29,20 +29,22 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsm_int.h"
-#include "vapi/vsc.h"
-
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <string.h>
+
+#include <errno.h>
+#include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 
+#include "miniobj.h"
 #include "vas.h"
+
+#include "vapi/vsc.h"
+#include "vapi/vsm.h"
+#include "vapi/vsm_int.h"
 #include "vav.h"
 #include "vqueue.h"
-#include "miniobj.h"
-
 #include "vsm_api.h"
 
 struct vsc_sf {
diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c
index 9fa6a48..88bd9d6 100644
--- a/lib/libvarnishapi/vsl.c
+++ b/lib/libvarnishapi/vsl.c
@@ -29,26 +29,27 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsm_int.h"
-#include "vapi/vsl.h"
-
-#include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 
+#include <errno.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#include "vas.h"
-#include "vre.h"
-#include "vbm.h"
 #include "miniobj.h"
+#include "vas.h"
 
-#include "vsm_api.h"
-#include "vsl_api.h"
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
+#include "vapi/vsm_int.h"
+#include "vbm.h"
 #include "vmb.h"
+#include "vre.h"
+#include "vsl_api.h"
+#include "vsm_api.h"
 
 /*--------------------------------------------------------------------*/
 
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index f41129b..56f93e2 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -29,27 +29,27 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsl.h"
-
 #include <sys/types.h>
 #include <sys/stat.h>
 
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#include "vas.h"
-#include "vre.h"
-#include "vbm.h"
 #include "miniobj.h"
+#include "vas.h"
 
-#include "vsm_api.h"
+#include "vapi/vsl.h"
+#include "vapi/vsm.h"
+#include "vbm.h"
+#include "vre.h"
 #include "vsl_api.h"
+#include "vsm_api.h"
 
 /*--------------------------------------------------------------------
  * Look up a tag
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index eeb2b3c..8e8b27b 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -29,26 +29,25 @@
 
 #include "config.h"
 
-#include "vapi/vsm.h"
-#include "vapi/vsm_int.h"
-
-#include <stdint.h>
-#include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#include "vas.h"
-#include "vin.h"
-#include "vbm.h"
 #include "miniobj.h"
+#include "vas.h"
 
+#include "vapi/vsm.h"
+#include "vapi/vsm_int.h"
+#include "vbm.h"
+#include "vin.h"
 #include "vsm_api.h"
 
 #ifndef MAP_HASSEMAPHORE
diff --git a/lib/libvarnishcompat/daemon.c b/lib/libvarnishcompat/daemon.c
index ef14e23..6b3fbb1 100644
--- a/lib/libvarnishcompat/daemon.c
+++ b/lib/libvarnishcompat/daemon.c
@@ -35,8 +35,8 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <stdlib.h>
 #include <signal.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #include "compat/daemon.h"
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 9342aaf..dde0e89 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -805,7 +805,9 @@ file_header(fo)
 
 fo.write("""
 #include "config.h"
+
 #include <stdio.h>
+
 #include "vcc_compile.h"
 
 const struct var vcc_vars[] = {
@@ -863,9 +865,10 @@ file_header(fo)
 fo.write("""
 
 #include "config.h"
-#include <stdio.h>
+
 #include <ctype.h>
-#include "config.h"
+#include <stdio.h>
+
 #include "vcc_compile.h"
 """)
 
diff --git a/lib/libvcl/vcc_acl.c b/lib/libvcl/vcc_acl.c
index 985a18e..c962044 100644
--- a/lib/libvcl/vcc_acl.c
+++ b/lib/libvcl/vcc_acl.c
@@ -29,16 +29,18 @@
 
 #include "config.h"
 
-#include <stdio.h>
-#include <stddef.h>
-#include <string.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <netdb.h>
+
 #include <netinet/in.h>
 
+#include <netdb.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "vcc_compile.h"
+
 #include "vrt.h"
 
 struct acl_e {
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index 61bfb87..9d72b51 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -32,7 +32,6 @@
 
 #include "config.h"
 
-
 #include "vcc_compile.h"
 
 /*--------------------------------------------------------------------*/
diff --git a/lib/libvcl/vcc_backend.c b/lib/libvcl/vcc_backend.c
index 0c72c1c..03482c4 100644
--- a/lib/libvcl/vcc_backend.c
+++ b/lib/libvcl/vcc_backend.c
@@ -59,6 +59,7 @@
 #include <string.h>
 
 #include "vcc_compile.h"
+
 #include "vss.h"
 
 struct host {
@@ -99,8 +100,6 @@ emit_sockaddr(struct vcc *tl, void *sa, unsigned sal)
  * and put it in an official sockaddr when we load the VCL.
  */
 
-#include <stdio.h>
-
 void
 Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port)
 {
diff --git a/lib/libvcl/vcc_backend_util.c b/lib/libvcl/vcc_backend_util.c
index 28510f5..efba623 100644
--- a/lib/libvcl/vcc_backend_util.c
+++ b/lib/libvcl/vcc_backend_util.c
@@ -30,8 +30,8 @@
 
 #include "config.h"
 
-#include <stdio.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <string.h>
 
 #include "vcc_compile.h"
diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index dbae2ab..a0c6232 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -54,12 +54,13 @@
 
 #include <ctype.h>
 #include <errno.h>
-#include <stdio.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "vcc_compile.h"
+
 #include "libvcl.h"
 #include "vfil.h"
 
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index a245a36..c59c632 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -28,6 +28,10 @@
  *
  */
 
+#include <sys/types.h>
+
+#include <errno.h>
+#include <stdio.h>
 #include <stdint.h>
 
 #include "miniobj.h"
@@ -37,6 +41,7 @@
 #include "vqueue.h"
 #include "vsb.h"
 
+
 #include "vcc_token_defs.h"
 
 #ifndef NULL
diff --git a/lib/libvcl/vcc_dir_dns.c b/lib/libvcl/vcc_dir_dns.c
index 2e3951e..a91c021 100644
--- a/lib/libvcl/vcc_dir_dns.c
+++ b/lib/libvcl/vcc_dir_dns.c
@@ -28,9 +28,9 @@
 
 #include "config.h"
 
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
-#include <limits.h>
 
 #include "vcc_compile.h"
 
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index dc7d99d..3dfeeaa 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -31,11 +31,11 @@
 
 #include "config.h"
 
+#include <math.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <math.h>
 
 #include "vcc_compile.h"
 
diff --git a/lib/libvcl/vcc_string.c b/lib/libvcl/vcc_string.c
index dfc82cf..4e4762e 100644
--- a/lib/libvcl/vcc_string.c
+++ b/lib/libvcl/vcc_string.c
@@ -34,8 +34,8 @@
 
 #include "vcc_compile.h"
 
-#include "vrt.h"
 #include "vre.h"
+#include "vrt.h"
 
 /*--------------------------------------------------------------------*/
 
diff --git a/lib/libvcl/vcc_vmod.c b/lib/libvcl/vcc_vmod.c
index 40c9ed5..55b43d7 100644
--- a/lib/libvcl/vcc_vmod.c
+++ b/lib/libvcl/vcc_vmod.c
@@ -28,11 +28,12 @@
 
 #include "config.h"
 
-#include <stdio.h>
 #include <dlfcn.h>
+#include <stdio.h>
 #include <string.h>
 
 #include "vcc_compile.h"
+
 #include "vmod_abi.h"
 
 void
diff --git a/lib/libvmod_std/vmod.py b/lib/libvmod_std/vmod.py
index 1b0f1c0..6a9b4fc 100755
--- a/lib/libvmod_std/vmod.py
+++ b/lib/libvmod_std/vmod.py
@@ -278,6 +278,8 @@ fh.write("\n");
 fh.write(plist)
 
 
+fc.write('#include "config.h"\n')
+fc.write('\n')
 fc.write('#include "vrt.h"\n')
 fc.write('#include "vcc_if.h"\n')
 fc.write('#include "vmod_abi.h"\n')
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 847c705..79cbf02 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -26,13 +26,20 @@
  * SUCH DAMAGE.
  */
 
+#include "config.h"
+
+#include <netinet/in.h>
+
 #include <ctype.h>
+#include <errno.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <syslog.h>
-#include <netinet/in.h>
+
 #include "vrt.h"
 #include "vtcp.h"
+
 #include "../../bin/varnishd/cache.h"
 
 #include "vcc_if.h"
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index 6f06c2c..156cf13 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -27,8 +27,12 @@
  *
  */
 
+#include "config.h"
+
 #include <ctype.h>
+#include <errno.h>
 #include <math.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "../../bin/varnishd/cache.h"
diff --git a/lib/libvmod_std/vmod_std_fileread.c b/lib/libvmod_std/vmod_std_fileread.c
index cae57a2..8476bd6 100644
--- a/lib/libvmod_std/vmod_std_fileread.c
+++ b/lib/libvmod_std/vmod_std_fileread.c
@@ -37,13 +37,19 @@
  * XXX: underlying file has been updated.
  */
 
+#include "config.h"
+
+#include <errno.h>
+#include <stdint.h>
 #include <stdlib.h>
-#include "vrt.h"
+
 #include "../../bin/varnishd/cache.h"
 
-#include "vcc_if.h"
+#include "vrt.h"
 #include "vfil.h"
 
+#include "vcc_if.h"
+
 struct frfile {
 	unsigned			magic;
 #define CACHED_FILE_MAGIC 0xa8e9d87a
diff --git a/man/vsc2rst.c b/man/vsc2rst.c
index ad5dec6..bf4091f 100644
--- a/man/vsc2rst.c
+++ b/man/vsc2rst.c
@@ -1,3 +1,5 @@
+/* XXX: Copyright ?? */
+#include "config.h"
 
 #include <stdio.h>
 



More information about the varnish-commit mailing list