1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
From 7df350b6ac6c3b97172a5599f7423acd09ba0b41 Mon Sep 17 00:00:00 2001
From: Hal Murray <halmurray@sonic.net>
Date: Sat, 1 Feb 2025 07:56:41 -0800
Subject: [PATCH 3/4] Cleanup struct timex long long mess
There is a trap that should go off for the CI cross armhf case
---
ntpd/ntp_control.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -185,9 +185,7 @@
enum var_type_special {
vs_peer, vs_peeradr, vs_peermode,
vs_systime,
- vs_refid, vs_mruoldest, vs_varlist,
- /* for slots in struct timex -- see comment above */
- vs_tx_con, vs_tx_cal, vs_tx_err, vs_tx_jit, vs_tx_stb};
+ vs_refid, vs_mruoldest, vs_varlist};
struct var {
const char* name;
const int flags;
@@ -198,6 +196,7 @@
const double* dbl;
const unsigned long int* uli;
const long int* li;
+ const long long* ll;
const int64_t* timex_li;
const unsigned int* uinnt;
const int* innt;
@@ -281,12 +280,16 @@
#define Var_mrumem(xname, xflags, xlocation) { \
.name = xname, .flags = xflags, .type = v_mrumem, .p.u64 = &xlocation }
+#ifdef NTP_TIMEX_LONG_LONG
+ DING DING DING: We got here. Tell Hal
+#define Var_kli(xname, xflags, xlocation) { \
+ .name = xname, .flags = xflags, .type = v_kli, .p.ll = &xlocation }
+#else
#define Var_kli(xname, xflags, xlocation) { \
.name = xname, .flags = xflags, .type = v_kli, .p.li = &xlocation }
+#endif
#define Var_special(xname, xflags, xspecial) { \
.name = xname, .flags = xflags, .type = v_special, .p.special = xspecial }
-#define Var_timex(xname, xflags, xspecial) { \
- .name = xname, .flags = xflags, .type = v_special, .p.special = xspecial }
static const struct var sys_var[] = {
Var_u8("leap", RO|DEF, sys_vars.sys_leap), // Was RW
@@ -387,17 +390,17 @@
Var_kli("kmaxerr", RO|N_CLOCK|KUToMS, ntx.maxerror),
Var_kli("kesterr", RO|N_CLOCK|KUToMS, ntx.esterror),
Var_int("kstflags", RO|N_CLOCK, ntx.status), // turn to text
- Var_timex("ktimeconst", RO|N_CLOCK, vs_tx_con),
+ Var_kli("ktimeconst", RO|N_CLOCK, ntx.constant),
Var_kli("kprecis", RO|N_CLOCK|KUToMS, ntx.precision),
Var_kli("kfreqtol", RO|N_CLOCK|K_16, ntx.tolerance), // Not in man page
Var_kli("kppsfreq", RO|N_CLOCK|K_16, ntx.ppsfreq),
- Var_kli("kppsstab", RO|N_CLOCK|K_16, ntx.stabil),
Var_kli("kppsjitter", RO|N_CLOCK|KNUToMS, ntx.jitter),
Var_int("kppscalibdur", RO|N_CLOCK, ntx.shift), // 1<<shift
- Var_timex("kppscalibs", RO|N_CLOCK, vs_tx_cal),
- Var_timex("kppscaliberrs", RO|N_CLOCK, vs_tx_err),
- Var_timex("kppsjitexc", RO|N_CLOCK, vs_tx_jit),
- Var_timex("kppsstbexc", RO|N_CLOCK, vs_tx_stb),
+ Var_kli("kppsstab", RO|N_CLOCK|K_16, ntx.stabil),
+ Var_kli("kppsjitexc", RO|N_CLOCK, ntx.jitcnt),
+ Var_kli("kppscalibs", RO|N_CLOCK, ntx.calcnt),
+ Var_kli("kppscaliberrs", RO|N_CLOCK, ntx.errcnt),
+ Var_kli("kppsstbexc", RO|N_CLOCK, ntx.stbcnt),
/* refclock stuff in ntp_io */
@@ -1595,11 +1598,6 @@
ctl_putdata(cv->text, strlen(cv->text), false);
}
break;
- case vs_tx_con: ctl_putint(v->name, ntx.constant); break;
- case vs_tx_cal: ctl_putint(v->name, ntx.calcnt); break;
- case vs_tx_err: ctl_putint(v->name, ntx.errcnt); break;
- case vs_tx_jit: ctl_putint(v->name, ntx.jitcnt); break;
- case vs_tx_stb: ctl_putint(v->name, ntx.stbcnt); break;
default:
/* -Wswitch-enum will warn if this is possible */
if (log_limit++ > 10) return; /* Avoid log file clutter/DDoS */
diff --git a/wafhelpers/check_sizeof.py b/wafhelpers/check_sizeof.py
index 951035464..b732c30f4 100644
--- a/wafhelpers/check_sizeof.py
+++ b/wafhelpers/check_sizeof.py
@@ -87,3 +87,38 @@ def check_sizeof(*kwargs):
check_sizeof_cross(*kwargs)
else:
check_sizeof_host(*kwargs)
+
+
+# timex slots are documented as long
+# #if (__TIMESIZE == 64 && __WORDSIZE == 32)
+# they turn into long long
+# This fails to build in the normal case.
+# So we set NTP_TIMEX_LONG_LONG to 0
+SIZE_FRAG_TIMEX = """
+#include <sys/time.h> /* for NetBSD */
+#include <sys/timex.h>
+#include <stdio.h>
+int main(void) {
+ struct timex dummy;
+ long long *foo = &dummy.jitter;
+ *foo = 1; /* supress unused warning */
+ if (*foo) printf("1");
+ return 0;
+}
+"""
+
+def check_timex(ctx):
+ name = "NTP_TIMEX_LONG_LONG"
+ ctx.start_msg("Checking sizeof struct timex slot")
+ ctx.check_cc(
+ cflags="-Werror",
+ fragment=SIZE_FRAG_TIMEX,
+ define_name=name,
+ execute=not ctx.env.ENABLE_CROSS,
+ define_ret=True,
+ quote=False,
+ mandatory=False,
+ comment="Does struct timex use long long"
+ )
+ ctx.end_msg(ctx.get_define(name))
+
diff --git a/wscript b/wscript
index a65c6a1b2..62d58c48a 100644
--- a/wscript
+++ b/wscript
@@ -219,7 +219,7 @@ def configure(ctx):
msg("--- Configuring main ---")
ctx.setenv("main", ctx.env.derive())
- from wafhelpers.check_sizeof import check_sizeof
+ from wafhelpers.check_sizeof import check_sizeof, check_timex
for opt in opt_map:
ctx.env[opt] = opt_map[opt]
@@ -604,9 +604,10 @@ int main(int argc, char **argv) {
)
# mostly used by timespecops.h
- # Also handy for discovering what a system is doing
+ # Some are unused, but handy for discovering what a system is doing
sizeofs = [
("time.h", "struct timespec"),
+ ("sys/time.h", "struct timeval"),
("time.h", "time_t"),
(None, "long"),
]
@@ -614,6 +615,8 @@ int main(int argc, char **argv) {
for header, sizeof in sorted(sizeofs, key=lambda x: x[1:]):
check_sizeof(ctx, header, sizeof)
+ check_timex(ctx)
+
# Parts of attic need libssl
if not ctx.options.disable_nts or ctx.options.enable_attic:
# Check via pkg-config first, then fall back to a direct search
--
2.34.1
|