summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-28 18:41:20 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-28 18:41:20 -0600
commit0922e0b31b3a476c250d8677fb76fdf2d542723e (patch)
tree370be0681bb6460db49adcbfe3f73d9591267215
parenta7fba8259f2054812cea4cfc6ab4c14f27da26b0 (diff)
downloadwhoson-0922e0b31b3a476c250d8677fb76fdf2d542723e.tar.gz
Build as C23 and pin the control-block layout
The overlays become packed C23 structs, so the offsets are the sum of the field widths instead of hand-written padding, and every field the walk reads is pinned by static_assert. The CSCB and the ASSB are now validated by their eye-catchers (and CHASID for the CSCB) before they supply a userid, a logon procedure or CPU time. The CPU column prints a compact duration instead of hours:minutes:seconds, which read 1947:50:11 for a long session.
-rw-r--r--.clangd2
-rw-r--r--CHANGELOG.md11
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--Makefile2
-rw-r--r--README.md9
-rw-r--r--whoson.c124
6 files changed, 100 insertions, 50 deletions
diff --git a/.clangd b/.clangd
index fd1c86e..27f3e89 100644
--- a/.clangd
+++ b/.clangd
@@ -2,7 +2,7 @@
# compilation database, so the editor is told the same language level and
# macros here.
CompileFlags:
- Add: [-std=c17, -D_XOPEN_SOURCE=600, -D_POSIX_C_SOURCE=200809L,
+ Add: [-std=c23, -D_XOPEN_SOURCE=600, -D_POSIX_C_SOURCE=200809L,
-D_ALL_SOURCE, -D_EXT, -D_OPEN_SYS, -D_OPEN_SYS_FILE_EXT,
-Wall, -Wextra, -Wshadow, -Wconversion]
# IBM Open XL only: the editor is not that compiler.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef0b3df..dfd8ad7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog
+## Unreleased
+
+- The CPU column prints a compact duration (`2.34s`, `12m31s`, `1h02m`,
+ `3d04h`) instead of `hours:minutes:seconds`, so a long session no longer
+ reads `1947:50:11`.
+- The ASCB, CSCB and ASSB overlays are packed C23 structs with every offset
+ the walk reads pinned by `static_assert`; hand-written padding arrays are
+ gone.
+- The CSCB is validated by its eye-catcher and `CHASID`, and the ASSB by its
+ eye-catcher, before either supplies a userid, logon procedure or CPU time.
+
## 1.1.0
Rewritten to read the system directly, and packaged as a zopen port. This is
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 12b56ff..35934f8 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -4,7 +4,7 @@ Small tool, small rules.
## Building
-whoson is a single C17 file with no external library, so it builds on z/OS
+whoson is a single C23 file with no external library, so it builds on z/OS
and nowhere else:
```sh
diff --git a/Makefile b/Makefile
index e5caf8c..ffa5f04 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,7 @@ CC = $(CCDIR)/ibm-clang
CPPFLAGS = -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200809L -D_ALL_SOURCE \
-D_EXT -D_OPEN_SYS -D_OPEN_SYS_FILE_EXT \
-DWHOSON_VERSION=\"$(VERSION)\"
-CFLAGS = -std=c17 -O3 -m64 -mzos-target=zosv2r5 -fzos-le-char-mode=ascii \
+CFLAGS = -std=c23 -O3 -m64 -mzos-target=zosv2r5 -fzos-le-char-mode=ascii \
-Wall -Wextra -Wpedantic -Wshadow -Wconversion
CEEOPTS = HEAPCHK(ON,1,32),RPTSTG(ON),FILETAG(AUTOCVT,AUTOTAG),POSIX(ON)
diff --git a/README.md b/README.md
index f4bdad3..d08271d 100644
--- a/README.md
+++ b/README.md
@@ -10,9 +10,9 @@ with the address space, the job name, the logon procedure and its CPU time.
```text
$ whoson
USER TYPE ASID JOBNAME LOGONPROC PID CPU
-CBT002 TSO/E 0046 CBT002 CBT002 - 0:12:31
-SKURTZ z/OSMF 003D SKURTZ IZUFPROC - 0:03:41
-SKURTZ SSH 004C SKURTZ - 33555303 0:00:02
+CBT002 TSO/E 0046 CBT002 CBT002 - 12m31s
+SKURTZ z/OSMF 003D SKURTZ IZUFPROC - 3m41s
+SKURTZ SSH 004C SKURTZ - 33555303 2.00s
```
Three types of session are listed, and nothing else:
@@ -47,7 +47,8 @@ CSCB key (`CHKEY`), the userid for a TSO/E session, and the POSIX effective
uid for an SSH session. `ASID` is the address space id, `PID` the POSIX
process id where one exists (`-` for a session that has none), and `CPU` is
TCB time (`ASCBEJST`) plus SRB time (`ASCBSRBT`) plus additional preemptable
-SRB time (`ASSBASST`) as `hours:minutes:seconds`. All three are TOD-clock
+SRB time (`ASSBASST`) as a compact duration (`2.34s`, `12m31s`, `1h02m`,
+`3d04h`). All three are TOD-clock
accumulators, so the low 12 bits are the fraction, not 1024-microsecond
units.
diff --git a/whoson.c b/whoson.c
index 66896a7..62a213c 100644
--- a/whoson.c
+++ b/whoson.c
@@ -84,52 +84,71 @@
#define ASVT_ENTY_OFF 0x210u
#define ASVT_ACRONYM 0xC1E2E5E3u /* "ASVT" in EBCDIC */
#define ASCB_ACRONYM 0xC1E2C3C2u /* "ASCB" in EBCDIC */
+#define CSCB_ACRONYM 0xC3E2C3C2u /* "CSCB" in EBCDIC */
+#define ASSB_ACRONYM 0xC1E2E2C2u /* "ASSB" in EBCDIC */
-/* Field offsets are checked against these overlays (static_assert below).
+/* Packed so the compiler adds no padding of its own: every offset is the sum
+ * of the field widths, and the static asserts pin the fields the walk reads.
* The overlays describe layout only; every read goes through the accessors,
* so the compiler never assumes the block is stable. */
-typedef struct ascb {
- uint32_t ascbascb;
- unsigned char pad0[0x24 - 0x04];
- uint16_t ascbasid;
- unsigned char pad1[0x38 - 0x26];
- uint32_t ascbcscb;
- uint32_t ascbtsb;
- uint64_t ascbejst;
- unsigned char pad2[0xAC - 0x48];
- uint32_t ascbjbni;
- uint32_t ascbjbns;
- unsigned char pad3[0xC8 - 0xB4];
- uint64_t ascbsrbt;
- unsigned char pad4[0x150 - 0xD0];
- uint32_t ascbassb;
+typedef struct __attribute__((packed)) ascb {
+ uint32_t ascbascb; /* X'00' eye-catcher */
+ unsigned char ascbresv0[0x24 - 0x04];
+ uint16_t ascbasid; /* X'24' */
+ unsigned char ascbresv1[0x38 - 0x26];
+ uint32_t ascbcscb; /* X'38' */
+ uint32_t ascbtsb; /* X'3C' */
+ uint64_t ascbejst; /* X'40' TCB CPU in TOD units */
+ unsigned char ascbresv2[0xAC - 0x48];
+ uint32_t ascbjbni; /* X'AC' */
+ uint32_t ascbjbns; /* X'B0' */
+ unsigned char ascbresv3[0xC8 - 0xB4];
+ uint64_t ascbsrbt; /* X'C8' SRB CPU in TOD units */
+ unsigned char ascbresv4[0x150 - 0xD0];
+ uint32_t ascbassb; /* X'150' */
} ascb;
-typedef struct cscb {
- unsigned char pad0[0x08];
- char chkey[8];
- char chcls[8];
- unsigned char pad1[0x1C - 0x18];
- unsigned char chtrkid;
+typedef struct __attribute__((packed)) cscb {
+ uint32_t chptr; /* X'00' */
+ unsigned char chvcd; /* X'04' */
+ unsigned char chsze; /* X'05' */
+ unsigned char chresv0[0x08 - 0x06];
+ char chkey[8]; /* X'08' userid */
+ char chcls[8]; /* X'10' logon procedure */
+ uint32_t chunit; /* X'18' */
+ unsigned char chtrkid; /* X'1C' X'01' is a TSO/E session */
+ unsigned char chresv1; /* X'1D' */
+ uint16_t chasid; /* X'1E' address space id */
+ unsigned char chresv2[0xD8 - 0x20];
+ char chcscbid[4]; /* X'D8' eye-catcher */
} cscb;
-typedef struct assb {
- unsigned char pad[0x160];
- uint64_t assbasst;
+typedef struct __attribute__((packed)) assb {
+ char assbassb[4]; /* X'000' eye-catcher */
+ unsigned char assbresv[0x160 - 0x04];
+ uint64_t assbasst; /* X'160' preemptable SRB CPU in TOD units */
} assb;
-_Static_assert(offsetof(ascb, ascbasid) == 0x24, "ASCBASID");
-_Static_assert(offsetof(ascb, ascbcscb) == 0x38, "ASCBCSCB");
-_Static_assert(offsetof(ascb, ascbtsb) == 0x3C, "ASCBTSB");
-_Static_assert(offsetof(ascb, ascbejst) == 0x40, "ASCBEJST");
-_Static_assert(offsetof(ascb, ascbjbni) == 0xAC, "ASCBJBNI");
-_Static_assert(offsetof(ascb, ascbjbns) == 0xB0, "ASCBJBNS");
-_Static_assert(offsetof(ascb, ascbsrbt) == 0xC8, "ASCBSRBT");
-_Static_assert(offsetof(ascb, ascbassb) == 0x150, "ASCBASSB");
-_Static_assert(offsetof(cscb, chkey) == 0x08, "CHKEY");
-_Static_assert(offsetof(cscb, chcls) == 0x10, "CHCLS");
-_Static_assert(offsetof(cscb, chtrkid) == 0x1C, "CHTRKID");
-_Static_assert(offsetof(assb, assbasst) == 0x160, "ASSBASST");
+static_assert(alignof(ascb) == 1);
+static_assert(alignof(cscb) == 1);
+static_assert(alignof(assb) == 1);
+static_assert(sizeof(ascb) == 0x154);
+static_assert(sizeof(cscb) == 0xDC);
+static_assert(sizeof(assb) == 0x168);
+static_assert(offsetof(ascb, ascbasid) == 0x24, "ASCBASID");
+static_assert(offsetof(ascb, ascbcscb) == 0x38, "ASCBCSCB");
+static_assert(offsetof(ascb, ascbtsb) == 0x3C, "ASCBTSB");
+static_assert(offsetof(ascb, ascbejst) == 0x40, "ASCBEJST");
+static_assert(offsetof(ascb, ascbjbni) == 0xAC, "ASCBJBNI");
+static_assert(offsetof(ascb, ascbjbns) == 0xB0, "ASCBJBNS");
+static_assert(offsetof(ascb, ascbsrbt) == 0xC8, "ASCBSRBT");
+static_assert(offsetof(ascb, ascbassb) == 0x150, "ASCBASSB");
+static_assert(offsetof(cscb, chkey) == 0x08, "CHKEY");
+static_assert(offsetof(cscb, chcls) == 0x10, "CHCLS");
+static_assert(offsetof(cscb, chtrkid) == 0x1C, "CHTRKID");
+static_assert(offsetof(cscb, chasid) == 0x1E, "CHASID");
+static_assert(offsetof(cscb, chcscbid) == 0xD8, "CHCSCBID");
+static_assert(offsetof(assb, assbasst) == 0x160, "ASSBASST");
/* One address space, as read from its ASCB, indexed by ASID - 1. */
typedef struct space {
@@ -441,10 +460,16 @@ static int scan_one(unsigned idx, uint32_t entry, uint32_t entries,
uint32_t assb_addr =
read_u32(ascb_addr + (uint32_t)offsetof(ascb, ascbassb));
- if (assb_addr != 0)
+ if (assb_addr != 0 && read_u32(assb_addr) == ASSB_ACRONYM)
tod += read_u64(assb_addr + (uint32_t)offsetof(assb, assbasst));
}
- if (cscb_addr != 0) {
+ /* A CSCB that has already been released can still be reachable through a
+ * stale ASCB pointer; its eye-catcher and CHASID say whether the block
+ * still belongs to this address space. */
+ if (cscb_addr != 0 &&
+ read_u32(cscb_addr + (uint32_t)offsetof(cscb, chcscbid)) ==
+ CSCB_ACRONYM &&
+ read_u16(cscb_addr + (uint32_t)offsetof(cscb, chasid)) == asid) {
read_name(cscb_addr + (uint32_t)offsetof(cscb, chkey), key,
sizeof(key));
read_name(cscb_addr + (uint32_t)offsetof(cscb, chcls), cls,
@@ -917,12 +942,25 @@ static int cmp_rows(const void *a, const void *b) {
return 0;
}
-/* TOD units are 2^-12 microseconds; print the total as h:mm:ss. */
+/* TOD units are 2^-12 microseconds. Print a duration in the largest unit
+ * that keeps it short: hundredths of a second under a minute, then whole
+ * minutes, hours and days. A long session could otherwise read 1947:50:11. */
static void fmt_cpu(uint64_t us, char *out, size_t outlen) {
- uint64_t secs = (us + 500000u) / 1000000u;
+ uint64_t hundredths = (us + 5000u) / 10000u;
+ uint64_t secs = hundredths / 100u;
- snprintf(out, outlen, "%" PRIu64 ":%02" PRIu64 ":%02" PRIu64, secs / 3600u,
- secs % 3600u / 60u, secs % 60u);
+ if (secs < 60u)
+ snprintf(out, outlen, "%" PRIu64 ".%02" PRIu64 "s", secs,
+ hundredths % 100u);
+ else if (secs < 3600u)
+ snprintf(out, outlen, "%" PRIu64 "m%02" PRIu64 "s", secs / 60u,
+ secs % 60u);
+ else if (secs < 86400u)
+ snprintf(out, outlen, "%" PRIu64 "h%02" PRIu64 "m", secs / 3600u,
+ secs % 3600u / 60u);
+ else
+ snprintf(out, outlen, "%" PRIu64 "d%02" PRIu64 "h", secs / 86400u,
+ secs % 86400u / 3600u);
}
typedef struct outbuf {