*: make sure `config.h` or `zebra.h` is first

`config.h` has all the defines from autoconf, which may include things
that switch behavior of other included headers (e.g. _GNU_SOURCE
enabling prototypes for additional functions.)

So, the first include in any `.c` file must be either `config.h` (with
the appropriate guard) or `zebra.h` (which includes `config.h` first
thing.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2021-04-23 12:04:58 +02:00
parent b38f1fd03d
commit 1f8031f79a
68 changed files with 296 additions and 16 deletions

View File

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "bgpd/bgp_conditional_adv.h"
#include "bgpd/bgp_vty.h"

View File

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "bgpd/bgp_nb.h"

View File

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "log.h"

View File

@ -18,6 +18,8 @@
*/
#include <zebra.h>
#include "lib/command.h"
#include "lib/log.h"
#include "lib/northbound.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/command.h"
#include "lib/log.h"
#include "lib/northbound.h"

View File

@ -1,4 +1,6 @@
#define TRACEPOINT_CREATE_PROBES
#define TRACEPOINT_DEFINE
#include <zebra.h>
#include "bgp_trace.h"

View File

@ -21,6 +21,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrpd.h"
#include "eigrpd/eigrp_types.h"

View File

@ -1,4 +1,6 @@
#define TRACEPOINT_CREATE_PROBES
#define TRACEPOINT_DEFINE
#include <zebra.h>
#include "libfrr_trace.h"

View File

@ -22,6 +22,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "if.h"
#include "linklist.h"
#include "log.h"

View File

@ -16,6 +16,8 @@
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "routing_nb.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "vrf.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/northbound.h"
#include "lib/routemap.h"
#include "ospf6_routemap_nb.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/command.h"
#include "lib/log.h"
#include "lib/northbound.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/northbound.h"
#include "lib/routemap.h"
#include "ospf_routemap_nb.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/command.h"
#include "lib/log.h"
#include "lib/northbound.h"

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include <float.h>
#include <math.h>
#include <zebra.h>

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include <northbound.h>
#include <yang.h>
#include <printfrr.h>

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "thread.h"
#include "log.h"
#include "lib_errors.h"

View File

@ -25,6 +25,10 @@
* This is the implementation of a High Level PCEP message API.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <arpa/inet.h>
#include <stdarg.h>

View File

@ -25,6 +25,10 @@
* Encoding and decoding for PCEP messages.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

View File

@ -19,6 +19,10 @@
* Author : Brady Johnson <brady@voltanet.io>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include "pcep_msg_object_error_types.h"

View File

@ -25,6 +25,10 @@
* This is the implementation of a High Level PCEP message object API.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <arpa/inet.h>
#include <stdarg.h>

View File

@ -25,6 +25,10 @@
* Encoding and decoding for PCEP Objects.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>

View File

@ -25,6 +25,10 @@
* This is the implementation of a High Level PCEP message object TLV API.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdbool.h>
#include <stdint.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stdio.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <limits.h>
#include <pthread.h>

View File

@ -25,6 +25,10 @@
* PCEP session logic counters configuration.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <time.h>

View File

@ -20,6 +20,10 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>

View File

@ -20,6 +20,10 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>

View File

@ -27,6 +27,10 @@
* created.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netinet/in.h>
#include <stdbool.h>
#include <stdlib.h>

View File

@ -25,6 +25,10 @@
* Implementation of public API timer functions.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <limits.h>
#include <pthread.h>
#include <stddef.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stddef.h>
#include <stdbool.h>

View File

@ -20,6 +20,10 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stddef.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdarg.h>
#include <stdio.h>
#include "pcep_utils_logging.h"

View File

@ -20,6 +20,10 @@
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdb.h> // gethostbyname
#include <pthread.h>
#include <stdlib.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <pthread.h>
#include <stdlib.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <time.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <pthread.h>
#include <stdlib.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netinet/in.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdbool.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <CUnit/CUnit.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/CUnit.h>
#include "pcep_utils_double_linked_list.h"

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdint.h>

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/CUnit.h>
#include "pcep_utils_ordered_list.h"

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/CUnit.h>
#include "pcep_utils_queue.h"

View File

@ -21,6 +21,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "pimd.h"
#include "pim_nb.h"
#include "lib/northbound_cli.h"

View File

@ -1,30 +1,90 @@
#
# check that the first header included in C files is either
# zebra.h or config.h
#
# Copyright (C) 2020 David Lamparter for NetDEF, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; see the file COPYING; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import sys, os, re, subprocess
import sys
import os
import re
import subprocess
import argparse
argp = argparse.ArgumentParser(description="include fixer")
argp.add_argument("--autofix", action="store_const", const=True)
argp.add_argument("--warn-empty", action="store_const", const=True)
argp.add_argument("--pipe", action="store_const", const=True)
include_re = re.compile('^#\s*include\s+["<]([^ ">]+)[">]', re.M)
errors = 0
ignore = [
lambda fn: fn.startswith("tools/"),
lambda fn: fn
in [
"lib/elf_py.c",
],
]
def run(args):
out = []
files = subprocess.check_output(["git", "ls-files"]).decode("ASCII")
for fn in files.splitlines():
if not fn.endswith(".c"):
continue
if max([i(fn) for i in ignore]):
continue
with open(fn, "r") as fd:
data = fd.read()
files = subprocess.check_output(["git", "ls-files"]).decode("ASCII")
for fn in files.splitlines():
if not fn.endswith(".c"):
continue
if fn.startswith("tools/"):
continue
with open(fn, "r") as fd:
data = fd.read()
m = include_re.search(data)
if m is None:
# sys.stderr.write('no #include in %s?\n' % (fn))
if args.warn_empty:
sys.stderr.write("no #include in %s?\n" % (fn))
continue
if m.group(1) in ["config.h", "zebra.h", "lib/zebra.h"]:
continue
sys.stderr.write("%s: %s\n" % (fn, m.group(0)))
errors += 1
if errors:
sys.exit(1)
if args.autofix:
sys.stderr.write("%s: %s - fixing\n" % (fn, m.group(0)))
if fn.startswith("pceplib/"):
insert = '#ifdef HAVE_CONFIG_H\n#include "config.h"\n#endif\n\n'
else:
insert = "#include <zebra.h>\n\n"
pos = m.span()[0]
data = data[:pos] + insert + data[pos:]
with open(fn + ".new", "w") as fd:
fd.write(data)
os.rename(fn + ".new", fn)
else:
sys.stderr.write("%s: %s\n" % (fn, m.group(0)))
out.append(fn)
if len(out):
if args.pipe:
# for "vim `firstheader.py`"
print("\n".join(out))
return 1
return 0
if __name__ == "__main__":
args = argp.parse_args()
sys.exit(run(args))

View File

@ -16,6 +16,8 @@
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "static_nb.h"

View File

@ -16,6 +16,8 @@
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "log.h"

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "northbound.h"
#include "libfrr.h"
#include "zebra_routemap_nb.h"