laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/42205?usp=email )
Change subject: core: fix config.h ......................................................................
core: fix config.h
While exploring why logging is disabled but still shows up in the binaries I kind of wondered how all the config.h HAVE_XX checks we have everwhere work. Apparently they do not work at all, due to missing or misplaced include of config.h.
This affects tons of other checks as well.
The jenkins hook ensures the include order is checked to ensure config.h does not get misplaced or lost in the future.
Change-Id: Ic2cf52a3b60f43a2f5d3fe01c41a41f6fd9a8000 --- M contrib/jenkins_common.sh M src/core/application.c M src/core/backtrace.c M src/core/base64.c M src/core/bitcomp.c M src/core/bits.c M src/core/bitvec.c M src/core/context.c M src/core/conv_acc_generic.c M src/core/counter.c M src/core/crc16.c M src/core/crcXXgen.c.tpl M src/core/fsm.c M src/core/isdnhdlc.c M src/core/logging_emscripten.c M src/core/logging_systemd.c M src/core/loggingrb.c M src/core/mnl.c M src/core/msgb.c M src/core/msgfile.c M src/core/panic.c M src/core/prbs.c M src/core/prim.c M src/core/rate_ctr.c M src/core/rbtree.c M src/core/select.c M src/core/serial.c M src/core/signal.c M src/core/soft_uart.c M src/core/stat_item.c M src/core/strrb.c M src/core/tdef.c M src/core/timer.c M src/core/timer_gettimeofday.c M src/core/use_count.c M src/core/utils.c M src/core/write_queue.c 37 files changed, 66 insertions(+), 6 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved Jenkins Builder: Verified
diff --git a/contrib/jenkins_common.sh b/contrib/jenkins_common.sh index 82dd471..5c4239c 100644 --- a/contrib/jenkins_common.sh +++ b/contrib/jenkins_common.sh @@ -43,6 +43,35 @@ } verify_gsm_08_05_tlv_definition
+# Verify config.h is included before any osmocom header or HAVE_*/LIBOSMOCORE_* +# guard in src/core/*.c (required for LIBOSMOCORE_NO_LOGGING and feature guards). +verify_config_h_order() { + set +x; + rc=0 + for f in src/core/*.c; do + case "$(basename "$f")" in + crc*gen.c) continue ;; # generated files + esac + config_line=$(grep -n '#include "config.h"|#include "../config.h"' "$f" | head -1 | cut -d: -f1) + dep_line=$(grep -n -E \ + '^#[[:space:]]*(ifdef|ifndef)[[:space:]]+(HAVE_|LIBOSMOCORE_)|^#[[:space:]]*if[[:space:]].*(HAVE_|LIBOSMOCORE_)|^#include[[:space:]]+<osmocom/' \ + "$f" | head -1 | cut -d: -f1) + if [ -z "$config_line" ] && [ -n "$dep_line" ]; then + echo "$f: missing config.h (needed before line $dep_line)" + rc=1 + elif [ -n "$config_line" ] && [ -n "$dep_line" ] && [ "$config_line" -gt "$dep_line" ]; then + echo "$f:$config_line: config.h too late (needed before line $dep_line)" + rc=1 + fi + done + if [ "$rc" -ne 0 ]; then + echo "config.h must be included before osmocom headers and HAVE_* guards!" + exit 1 + fi + set -x; +} +verify_config_h_order + prep_build() { _src_dir="$1" _build_dir="$2" diff --git a/src/core/application.c b/src/core/application.c index f7e5816..bb89adb 100644 --- a/src/core/application.c +++ b/src/core/application.c @@ -68,6 +68,7 @@ * http://sysmocom.de/ */
+#include "config.h" #include <osmocom/core/application.h> #include <osmocom/core/logging.h>
diff --git a/src/core/backtrace.c b/src/core/backtrace.c index 60bd238..5930cb7 100644 --- a/src/core/backtrace.c +++ b/src/core/backtrace.c @@ -22,9 +22,9 @@
#include <stdio.h> #include <stdlib.h> +#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/logging.h> -#include "config.h"
#ifdef HAVE_EXECINFO_H #include <execinfo.h> diff --git a/src/core/base64.c b/src/core/base64.c index 0c161ce..0be4e8c 100644 --- a/src/core/base64.c +++ b/src/core/base64.c @@ -16,6 +16,7 @@ * GNU General Public License for more details. */
+#include "config.h" #include <osmocom/core/base64.h>
#include <stdint.h> diff --git a/src/core/bitcomp.c b/src/core/bitcomp.c index 5fb2cba..193c149 100644 --- a/src/core/bitcomp.c +++ b/src/core/bitcomp.c @@ -29,6 +29,7 @@ #include <errno.h> #include <string.h>
+#include "config.h" #include <osmocom/core/bitvec.h> #include <osmocom/core/bitcomp.h>
diff --git a/src/core/bits.c b/src/core/bits.c index 3da7d9b..8616d32 100644 --- a/src/core/bits.c +++ b/src/core/bits.c @@ -20,6 +20,7 @@
#include <stdint.h>
+#include "config.h" #include <osmocom/core/bits.h>
/*! \addtogroup bits diff --git a/src/core/bitvec.c b/src/core/bitvec.c index ac702b9..5e1d2c8 100644 --- a/src/core/bitvec.c +++ b/src/core/bitvec.c @@ -38,6 +38,7 @@ #include <stdio.h> #include <stdbool.h>
+#include "config.h" #include <osmocom/core/bits.h> #include <osmocom/core/bitvec.h> #include <osmocom/core/panic.h> diff --git a/src/core/context.c b/src/core/context.c index a0b3a55..b194b9e 100644 --- a/src/core/context.c +++ b/src/core/context.c @@ -18,6 +18,7 @@ */ #include <string.h> #include <errno.h> +#include "config.h" #include <osmocom/core/talloc.h> #include <osmocom/core/utils.h>
diff --git a/src/core/conv_acc_generic.c b/src/core/conv_acc_generic.c index 2257e6a..8589e2f 100644 --- a/src/core/conv_acc_generic.c +++ b/src/core/conv_acc_generic.c @@ -22,6 +22,7 @@ #include <stdlib.h> #include <stdint.h> #include <string.h> +#include "config.h"
/* Add-Compare-Select (ACS-Butterfly) * Compute 4 accumulated path metrics and 4 path selections. Note that path diff --git a/src/core/counter.c b/src/core/counter.c index dace15f..62b7d70 100644 --- a/src/core/counter.c +++ b/src/core/counter.c @@ -21,6 +21,7 @@
#include <string.h>
+#include "config.h" #include <osmocom/core/linuxlist.h> #include <osmocom/core/talloc.h> #include <osmocom/core/counter.h> diff --git a/src/core/crc16.c b/src/core/crc16.c index 29dace2..bbded42 100644 --- a/src/core/crc16.c +++ b/src/core/crc16.c @@ -12,6 +12,7 @@ * SPDX-License-Identifier: GPL-2.0 */
+#include "config.h" #include <osmocom/core/crc16.h>
/*! CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ diff --git a/src/core/crcXXgen.c.tpl b/src/core/crcXXgen.c.tpl index 154291c..75de2ad 100644 --- a/src/core/crcXXgen.c.tpl +++ b/src/core/crcXXgen.c.tpl @@ -25,7 +25,7 @@ * \file crcXXgen.c.tpl */
#include <stdint.h> - +#include "config.h" #include <osmocom/core/bits.h> #include <osmocom/core/crcXXgen.h>
diff --git a/src/core/fsm.c b/src/core/fsm.c index a4f1bcb..54cea99 100644 --- a/src/core/fsm.c +++ b/src/core/fsm.c @@ -21,6 +21,7 @@ #include <string.h> #include <inttypes.h>
+#include "config.h" #include <osmocom/core/fsm.h> #include <osmocom/core/talloc.h> #include <osmocom/core/logging.h> diff --git a/src/core/isdnhdlc.c b/src/core/isdnhdlc.c index 4ced5af..af9c941 100644 --- a/src/core/isdnhdlc.c +++ b/src/core/isdnhdlc.c @@ -22,6 +22,7 @@
#include <string.h>
+#include "config.h" #include <osmocom/core/crc16.h> #include <osmocom/core/bits.h> #include <osmocom/core/isdnhdlc.h> diff --git a/src/core/logging_emscripten.c b/src/core/logging_emscripten.c index a186fd2..76af90c 100644 --- a/src/core/logging_emscripten.c +++ b/src/core/logging_emscripten.c @@ -27,6 +27,7 @@
#include <stdarg.h> #include <stdio.h> +#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/logging.h> #include <osmocom/core/logging_internal.h> diff --git a/src/core/logging_systemd.c b/src/core/logging_systemd.c index 2e86feb..7ce8aa5 100644 --- a/src/core/logging_systemd.c +++ b/src/core/logging_systemd.c @@ -28,6 +28,7 @@
#include <systemd/sd-journal.h>
+#include "config.h" #include <osmocom/core/talloc.h> #include <osmocom/core/utils.h> #include <osmocom/core/logging.h> diff --git a/src/core/loggingrb.c b/src/core/loggingrb.c index 2bf7b66..1cb2cde 100644 --- a/src/core/loggingrb.c +++ b/src/core/loggingrb.c @@ -29,6 +29,7 @@ * * \file loggingrb.c */
+#include "config.h" #include <osmocom/core/strrb.h> #include <osmocom/core/logging.h> #include <osmocom/core/loggingrb.h> diff --git a/src/core/mnl.c b/src/core/mnl.c index d148e1b..d789015 100644 --- a/src/core/mnl.c +++ b/src/core/mnl.c @@ -23,6 +23,7 @@ * GNU General Public License for more details. */
+#include "config.h" #include <osmocom/core/select.h> #include <osmocom/core/talloc.h> #include <osmocom/core/logging.h> diff --git a/src/core/msgb.c b/src/core/msgb.c index 6f081bb..52cfc66 100644 --- a/src/core/msgb.c +++ b/src/core/msgb.c @@ -56,6 +56,7 @@ #include <stdarg.h> #include <errno.h>
+#include "config.h" #include <osmocom/core/msgb.h> #include <osmocom/core/talloc.h> #include <osmocom/core/logging.h> @@ -202,7 +203,7 @@ bool _msgb_eq(const char *file, size_t line, const char *func, uint8_t level, const struct msgb *msg, const uint8_t *data, size_t len, bool print) { - const char *m_dump; + const char *m_dump __attribute__((unused)); unsigned int m_len, i; uint8_t *m_data;
diff --git a/src/core/msgfile.c b/src/core/msgfile.c index abb4e7c..4a9592b 100644 --- a/src/core/msgfile.c +++ b/src/core/msgfile.c @@ -21,6 +21,7 @@
#define _WITH_GETLINE
+#include "config.h" #include <osmocom/core/msgfile.h> #include <osmocom/core/talloc.h>
diff --git a/src/core/panic.c b/src/core/panic.c index bbf6d08..b22af59 100644 --- a/src/core/panic.c +++ b/src/core/panic.c @@ -24,10 +24,10 @@ * \file panic.c */
#include <unistd.h> +#include "config.h" #include <osmocom/core/panic.h> #include <osmocom/core/backtrace.h>
-#include "config.h"
static osmo_panic_handler_t osmo_panic_handler = (void*)0; diff --git a/src/core/prbs.c b/src/core/prbs.c index 8fa04bb..31797ab 100644 --- a/src/core/prbs.c +++ b/src/core/prbs.c @@ -7,6 +7,7 @@
#include <stdint.h> #include <string.h> +#include "config.h" #include <osmocom/core/bits.h> #include <osmocom/core/prbs.h>
diff --git a/src/core/prim.c b/src/core/prim.c index 3c8a7f1..2cd00e6 100644 --- a/src/core/prim.c +++ b/src/core/prim.c @@ -8,6 +8,7 @@ * @{ * \file prim.c */
+#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/prim.h>
diff --git a/src/core/rate_ctr.c b/src/core/rate_ctr.c index 44e2658..a90ad88 100644 --- a/src/core/rate_ctr.c +++ b/src/core/rate_ctr.c @@ -60,6 +60,7 @@ #include <unistd.h> #include <inttypes.h>
+#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/linuxlist.h> #include <osmocom/core/talloc.h> diff --git a/src/core/rbtree.c b/src/core/rbtree.c index f4dc219..d651210 100644 --- a/src/core/rbtree.c +++ b/src/core/rbtree.c @@ -18,6 +18,7 @@ linux/lib/rbtree.c */
+#include "config.h" #include <osmocom/core/linuxrbtree.h>
static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) diff --git a/src/core/select.c b/src/core/select.c index a577c5b..726eb5b 100644 --- a/src/core/select.c +++ b/src/core/select.c @@ -27,6 +27,7 @@ #include <stdbool.h> #include <errno.h>
+#include "config.h" #include <osmocom/core/select.h> #include <osmocom/core/linuxlist.h> #include <osmocom/core/timer.h> @@ -36,7 +37,6 @@ #include <osmocom/core/stat_item.h> #include <osmocom/core/stats_tcp.h>
-#include "config.h"
#if defined(HAVE_SYS_SELECT_H) && defined(HAVE_POLL_H) #include <sys/select.h> diff --git a/src/core/serial.c b/src/core/serial.c index 117c049..91ee0e0 100644 --- a/src/core/serial.c +++ b/src/core/serial.c @@ -36,6 +36,7 @@ #include <linux/serial.h> #endif
+#include "config.h" #include <osmocom/core/serial.h>
diff --git a/src/core/signal.c b/src/core/signal.c index ba1555a..111513a 100644 --- a/src/core/signal.c +++ b/src/core/signal.c @@ -18,6 +18,7 @@ * */
+#include "config.h" #include <osmocom/core/signal.h> #include <osmocom/core/talloc.h> #include <osmocom/core/linuxlist.h> diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c index f969ab7..259099e 100644 --- a/src/core/soft_uart.c +++ b/src/core/soft_uart.c @@ -24,6 +24,7 @@ #include <stdint.h> #include <errno.h>
+#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/timer.h> #include <osmocom/core/soft_uart.h> diff --git a/src/core/stat_item.c b/src/core/stat_item.c index 804972b..3b2d1bf 100644 --- a/src/core/stat_item.c +++ b/src/core/stat_item.c @@ -154,6 +154,7 @@ #include <stdint.h> #include <string.h>
+#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/linuxlist.h> #include <osmocom/core/logging.h> diff --git a/src/core/strrb.c b/src/core/strrb.c index c5a5ed6..d162d3a 100644 --- a/src/core/strrb.c +++ b/src/core/strrb.c @@ -41,6 +41,7 @@ #include <string.h> #include <string.h>
+#include "config.h" #include <osmocom/core/strrb.h> #include <osmocom/core/talloc.h>
diff --git a/src/core/tdef.c b/src/core/tdef.c index f0c0f2e..c565639 100644 --- a/src/core/tdef.c +++ b/src/core/tdef.c @@ -27,6 +27,7 @@ #include <limits.h> #include <errno.h>
+#include "config.h" #include <osmocom/core/fsm.h> #include <osmocom/core/tdef.h>
diff --git a/src/core/timer.c b/src/core/timer.c index 067bd87..c9cd841 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -31,6 +31,7 @@ #include <assert.h> #include <string.h> #include <limits.h> +#include "config.h" #include <osmocom/core/timer.h> #include <osmocom/core/timer_compat.h> #include <osmocom/core/linuxlist.h> diff --git a/src/core/timer_gettimeofday.c b/src/core/timer_gettimeofday.c index e0212b5..bad7053 100644 --- a/src/core/timer_gettimeofday.c +++ b/src/core/timer_gettimeofday.c @@ -39,6 +39,7 @@
#include <stdbool.h> #include <sys/time.h> +#include "config.h" #include <osmocom/core/timer_compat.h>
bool osmo_gettimeofday_override = false; diff --git a/src/core/use_count.c b/src/core/use_count.c index 9714403..e99f5e3 100644 --- a/src/core/use_count.c +++ b/src/core/use_count.c @@ -25,6 +25,7 @@ #include <inttypes.h> #include <string.h>
+#include "config.h" #include <osmocom/core/linuxlist.h> #include <osmocom/core/utils.h> #include <osmocom/core/use_count.h> diff --git a/src/core/utils.c b/src/core/utils.c index 5757b52..2ae68f1 100644 --- a/src/core/utils.c +++ b/src/core/utils.c @@ -36,6 +36,7 @@ #include <inttypes.h> #include <limits.h>
+#include "config.h" #include <osmocom/core/utils.h> #include <osmocom/core/bit64gen.h>
@@ -469,7 +470,6 @@ __attribute__((weak, alias("osmo_hexdump_nospc"))); #endif
-#include "config.h" #ifdef HAVE_CTYPE_H #include <ctype.h> /*! Convert an entire string to lower case diff --git a/src/core/write_queue.c b/src/core/write_queue.c index 8fb73a6..cea875f 100644 --- a/src/core/write_queue.c +++ b/src/core/write_queue.c @@ -19,6 +19,7 @@ */
#include <errno.h> +#include "config.h" #include <osmocom/core/write_queue.h> #include <osmocom/core/logging.h>