[Git][NTPsec/ntpsec][master] 2 commits: Add struct timespec to sizeof list

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Sun Feb 2 01:01:13 UTC 2025



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
dc3f4254 by Hal Murray at 2025-02-01T07:58:55-08:00
Add struct timespec to sizeof list

Mostly for documentation

- - - - -
7df350b6 by Hal Murray at 2025-02-01T07:58:55-08:00
Cleanup struct timex long long mess

There is a trap that should go off for the CI cross armhf case

- - - - -


3 changed files:

- ntpd/ntp_control.c
- wafhelpers/check_sizeof.py
- wscript


Changes:

=====================================
ntpd/ntp_control.c
=====================================
@@ -185,9 +185,7 @@ enum var_type {v_time,
 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 @@ struct var {
     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 @@ struct var {
 
 #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 @@ static const struct var sys_var[] = {
   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 */
@@ -1582,11 +1585,6 @@ ctl_putspecial(const struct var * v) {
     case vs_varlist:
 	do_sys_var_list(v->name, sys_var);
         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 */


=====================================
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))
+


=====================================
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,7 +604,10 @@ int main(int argc, char **argv) {
         )
 
     # mostly used by timespecops.h
+    # 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"),
     ]
@@ -612,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



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/dc69f9e6c5a2583036b793bd93939f9cd3bdf665...7df350b6ac6c3b97172a5599f7423acd09ba0b41

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/dc69f9e6c5a2583036b793bd93939f9cd3bdf665...7df350b6ac6c3b97172a5599f7423acd09ba0b41
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20250202/503da472/attachment-0001.htm>


More information about the vc mailing list